From: Ann Kamyshnikova Date: Thu, 24 Jul 2014 10:33:02 +0000 (+0400) Subject: Set InnoDB engine for all existing tables X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=808452913af090009ee1a32235bdd0b52b4e6e5c;p=openstack-build%2Fneutron-build.git Set InnoDB engine for all existing tables Added the method in heal script that checks if mysql_engine parameter is needed to be changed and if it is neseccary do this. Also this change adds migation that set 'mysql_engine' to InnoDB for all tables that were added into the database after healing. Closes-bug: #1346966 Change-Id: Ia4d9038b99b2559d37272a17f5819a9dedd53f72 --- diff --git a/neutron/db/migration/alembic_migrations/heal_script.py b/neutron/db/migration/alembic_migrations/heal_script.py index 276008171..dacb87474 100644 --- a/neutron/db/migration/alembic_migrations/heal_script.py +++ b/neutron/db/migration/alembic_migrations/heal_script.py @@ -69,7 +69,7 @@ def heal(): 'compare_server_default': _compare_server_default, } mc = alembic.migration.MigrationContext.configure(op.get_bind(), opts=opts) - + set_storage_engine(op.get_bind(), "InnoDB") diff1 = autogen.compare_metadata(mc, models_metadata) # Alembic does not contain checks for foreign keys. Because of that it # checks separately. @@ -320,3 +320,11 @@ def _compare_server_default(ctxt, ins_col, meta_col, insp_def, meta_def, ) return None # tells alembic to use the default comparison method + + +def set_storage_engine(bind, engine): + insp = sqlalchemy.engine.reflection.Inspector.from_engine(bind) + if bind.dialect.name == 'mysql': + for table in insp.get_table_names(): + if insp.get_table_options(table)['mysql_engine'] != engine: + op.execute("ALTER TABLE %s ENGINE=%s" % (table, engine)) diff --git a/neutron/db/migration/alembic_migrations/versions/327ee5fde2c7_set_innodb_engine.py b/neutron/db/migration/alembic_migrations/versions/327ee5fde2c7_set_innodb_engine.py new file mode 100644 index 000000000..8b34c514b --- /dev/null +++ b/neutron/db/migration/alembic_migrations/versions/327ee5fde2c7_set_innodb_engine.py @@ -0,0 +1,46 @@ +# Copyright 2014 OpenStack Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# + +"""set_innodb_engine + +Revision ID: 327ee5fde2c7 +Revises: 2026156eab2f +Create Date: 2014-07-24 12:00:38.791287 + +""" + +# revision identifiers, used by Alembic. +revision = '327ee5fde2c7' +down_revision = '4eba2f05c2f4' + + +from alembic import op + +# This list contain tables that could be deployed before change that converts +# all tables to InnoDB appeared +TABLES = ['router_extra_attributes', 'dvr_host_macs', 'ml2_dvr_port_bindings', + 'csnat_l3_agent_bindings'] + + +def upgrade(active_plugins=None, options=None): + + if op.get_bind().dialect.name == 'mysql': + for table in TABLES: + op.execute("ALTER TABLE %s ENGINE=InnoDB" % table) + + +def downgrade(active_plugins=None, options=None): + + pass diff --git a/neutron/db/migration/alembic_migrations/versions/HEAD b/neutron/db/migration/alembic_migrations/versions/HEAD index 6ea58e91e..86f1f1dcb 100644 --- a/neutron/db/migration/alembic_migrations/versions/HEAD +++ b/neutron/db/migration/alembic_migrations/versions/HEAD @@ -1 +1 @@ -4eba2f05c2f4 +327ee5fde2c7