ibmdb / python-ibmdbalembic

Automatically exported from code.google.com/p/ibm-db.ibm-db-alembic
2 stars 7 forks source link

db action will stuck when calling alter_column of /usr/lib/python2.7/site-packages/ibm_db_alembic/ibm_db.py #1

Closed sbookworm closed 3 years ago

sbookworm commented 9 years ago

When doing neutron_lbaas db migration, we faced a stuck problem, and after investigating, we found the call stack is below:

a, /usr/lib/python2.7/site-packages/neutron_lbaas/db/migration/alembic_migrations/versions/lbaasv2_tls.py migration.alter_enum('lbaas_listeners', 'protocol', new_listener_protocols, nullable=False)

b, /usr/lib/python2.7/site-packages/neutron/db/migration/init.py def alter_enum(table, column, enum_type, nullable): bind = op.get_bind() engine = bind.engine if engine.name == 'postgresql': values = {'table': table, 'column': column, 'name': enumtype.name} op.execute("ALTER TYPE %(name)s RENAME TO old%(name)s" % values) enumtype.create(bind, checkfirst=False) op.execute("ALTER TABLE %(table)s RENAME COLUMN %(column)s TO " "old%(column)s" % values) op.add_column(table, sa.Column(column, enumtype, nullable=nullable)) op.execute("UPDATE %(table)s SET %(column)s = " "old%(column)s::text::%(name)s" % values) op.execute("ALTER TABLE %(table)s DROP COLUMN old%(column)s" % values) op.execute("DROP TYPE old%(name)s" % values) else: op.altercolumn(table, column, type=enum_type, existing_nullable=nullable)

c. /usr/lib/python2.7/site-packages/ibm_db_alembic/ibm_db.py def alter_column(self, table_name, column_name, nullable=None, serverdefault=False, name=None, type=None, schema=None, autoincrement=None, existing_type=None, existing_server_default=None, existing_nullable=None, existing_autoincrement=None ):

After I print some stamp for the code in alter_column, I found that the line hang the progress primary_key_columns = insp.get_pk_constraint(table_name, schema).get('constrained_columns')

rpriyadh commented 9 years ago

Thanks for reporting this issue, This is happening since with another connection for checking metadata leads a deadlock. I have committed the changes with change-set https://github.com/ibmdb/python-ibmdbalembic/commit/63436045e79bf9affb05e47f7cd15b843d959914