From 479d6050f3f07e12488e6bb9a40b0aec3452a19c Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Mon, 28 Jul 2014 10:39:29 -0700 Subject: [PATCH] Further cleanup of reservations index It was discovered that the duplicate index checking does not work on db2, so this fixes it. Change-Id: I1a80b9c1fb6cfe916a2110de3151a09fa3618e75 Partial-bug: 1348720 --- .../023_add_expire_reservations_index.py | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/cinder/db/sqlalchemy/migrate_repo/versions/023_add_expire_reservations_index.py b/cinder/db/sqlalchemy/migrate_repo/versions/023_add_expire_reservations_index.py index eb9edabcd..996ebbdfc 100644 --- a/cinder/db/sqlalchemy/migrate_repo/versions/023_add_expire_reservations_index.py +++ b/cinder/db/sqlalchemy/migrate_repo/versions/023_add_expire_reservations_index.py @@ -13,7 +13,6 @@ # under the License. from sqlalchemy import Index, MetaData, Table -from sqlalchemy.exc import OperationalError from cinder.openstack.common.gettextutils import _ from cinder.openstack.common import log as logging @@ -21,21 +20,29 @@ from cinder.openstack.common import log as logging LOG = logging.getLogger(__name__) +def _get_deleted_expire_index(table): + members = sorted(['deleted', 'expire']) + for idx in table.indexes: + if sorted(idx.columns.keys()) == members: + return idx + + def upgrade(migrate_engine): meta = MetaData() meta.bind = migrate_engine reservations = Table('reservations', meta, autoload=True) + if _get_deleted_expire_index(reservations): + LOG.info(_('Skipped adding reservations_deleted_expire_idx ' + 'because an equivalent index already exists.')) + return # Based on expire_reservations query # from: cinder/db/sqlalchemy/api.py index = Index('reservations_deleted_expire_idx', reservations.c.deleted, reservations.c.expire) - try: - index.create(migrate_engine) - except OperationalError: - LOG.info(_('Skipped adding reservations_deleted_expire_idx ' - 'because an equivalent index already exists.')) + + index.create(migrate_engine) def downgrade(migrate_engine): @@ -44,10 +51,9 @@ def downgrade(migrate_engine): reservations = Table('reservations', meta, autoload=True) - index = Index('reservations_deleted_expire_idx', - reservations.c.deleted, reservations.c.expire) - try: + index = _get_deleted_expire_index(reservations) + if index: index.drop(migrate_engine) - except OperationalError: + else: LOG.info(_('Skipped removing reservations_deleted_expire_idx ' 'because index does not exist.')) -- 2.45.2