Triggers shouldn't be execute in offline migration

Recently this change [1] in glance-manage db_sync is internally
using Expand, Migrate and Contract. EMC is explicitly used for
online migration for which glance uses triggers to sync data
between old columns and new columns. DB Sync is used for
offline migartion for which adding triggers is not required.

Made provision to execute triggers explicitly in case of
online migration (EMC pattern) and skip the same in
case of offline migration (db sync).

[1] https://review.openstack.org/#/c/433934/

Closes-Bug: #1749640
Change-Id: I816c73405dd61d933182ad5efc24445a0add4eea
This commit is contained in:
Abhishek Kekane 2018-02-20 15:32:00 +00:00
parent 28fb47092f
commit 14e8a7b53b
3 changed files with 14 additions and 2 deletions

View File

@ -59,6 +59,7 @@ from glance.i18n import _
CONF = cfg.CONF
USE_TRIGGERS = True
# Decorators for actions
@ -142,6 +143,13 @@ class DbCommands(object):
@args('--version', metavar='<version>', help='Database version')
def sync(self, version=None):
"""Perform a complete (offline) database migration"""
global USE_TRIGGERS
# This flags let's us bypass trigger setup & teardown for non-rolling
# upgrades. We set this as a global variable immediately before handing
# off to sqlalchemy-migrate, because we can't pass arguments directly
# to migrations that depend on it.
USE_TRIGGERS = False
curr_heads = alembic_migrations.get_current_alembic_heads()
contract = alembic_migrations.get_alembic_branch_head(

View File

@ -21,6 +21,7 @@ Create Date: 2017-01-27 12:58:16.647499
from alembic import op
from sqlalchemy import MetaData, Enum
from glance.cmd import manage
from glance.db import migration
# revision identifiers, used by Alembic.
@ -70,5 +71,6 @@ def upgrade():
meta = MetaData(bind=migrate_engine)
_drop_column()
_drop_triggers(migrate_engine)
if manage.USE_TRIGGERS:
_drop_triggers(migrate_engine)
_set_nullability_and_default_on_visibility(meta)

View File

@ -21,6 +21,7 @@ Create Date: 2017-01-27 12:58:16.647499
from alembic import op
from sqlalchemy import Column, Enum, MetaData, Table
from glance.cmd import manage
from glance.db import migration
# revision identifiers, used by Alembic.
@ -148,4 +149,5 @@ def upgrade():
_add_visibility_column(meta)
_change_nullability_and_default_on_is_public(meta)
_add_triggers(migrate_engine)
if manage.USE_TRIGGERS:
_add_triggers(migrate_engine)