Merge lp:~markmc/nova/sqlalchemy-0.7-migration-fixes into lp:~hudson-openstack/nova/trunk

Proposed by Mark McLoughlin
Status: Merged
Approved by: Joshua McKenty
Approved revision: 1486
Merged at revision: 1499
Proposed branch: lp:~markmc/nova/sqlalchemy-0.7-migration-fixes
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 92 lines (+25/-10)
3 files modified
Authors (+1/-0)
nova/db/sqlalchemy/migrate_repo/versions/016_make_quotas_key_and_value.py (+14/-4)
nova/db/sqlalchemy/migrate_repo/versions/036_change_flavor_id_in_migrations.py (+10/-6)
To merge this branch: bzr merge lp:~markmc/nova/sqlalchemy-0.7-migration-fixes
Reviewer Review Type Date Requested Status
Joshua McKenty (community) Approve
Brian Lamar (community) Approve
Review via email: mp+72800@code.launchpad.net

Description of the change

Just a couple of small changes I needed to get the migrations working with SQLAlchemy 0.7.x on Fedora 16

To post a comment you must log in.
Revision history for this message
Brian Lamar (blamar) wrote :

Thanks for this, been wanting to use latest SQLAlchemy for a bit now. One question, what is the reason/logic for the changes in 036_change_flavor_id_in_migrations.py? At a glance it looks like the logic/queries aren't changing but I most certainly could be missing something.

review: Needs Information
Revision history for this message
Mark McLoughlin (markmc) wrote :

Hi Brian,

I guess it's a bit hard to see in the diff, but the new code looks like:

   ...
   itypes = {}
   for instance_type in migrate_engine.execute(instance_types.select()):
       itypes[instance_type.id] = instance_type.flavorid

   for instance_type_id in itypes.keys():
       migrate_engine.execute(migrations.update()\
   ...

i.e. we run the query to get the instance types, collect the results and
drop the lock before doing the updates

The issue with the current code is that the lock appears to be held as
we try to do the updates

Cheers,
Mark.

Revision history for this message
Brian Lamar (blamar) wrote :

Understood now. I guess I'm not used to any database locking on selects, but it seems that SQLlite does and SQLALchemy 0.7 somehow exposed that? Anyway, the logic is sound so thanks for the updates to fix this.

review: Approve
Revision history for this message
Joshua McKenty (joshua-mckenty) wrote :

lgtm - I see meta.clear() in SQLAlchemy at least back to 0.68

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Authors'
--- Authors 2011-08-23 18:16:04 +0000
+++ Authors 2011-08-24 21:44:18 +0000
@@ -69,6 +69,7 @@
69Lorin Hochstein <lorin@isi.edu>69Lorin Hochstein <lorin@isi.edu>
70Lvov Maxim <usrleon@gmail.com>70Lvov Maxim <usrleon@gmail.com>
71Mandell Degerness <mdegerne@gmail.com>71Mandell Degerness <mdegerne@gmail.com>
72Mark McLoughlin <markmc@redhat.com>
72Mark Washenberger <mark.washenberger@rackspace.com>73Mark Washenberger <mark.washenberger@rackspace.com>
73Masanori Itoh <itoumsn@nttdata.co.jp>74Masanori Itoh <itoumsn@nttdata.co.jp>
74Matt Dietz <matt.dietz@rackspace.com>75Matt Dietz <matt.dietz@rackspace.com>
7576
=== modified file 'nova/db/sqlalchemy/migrate_repo/versions/016_make_quotas_key_and_value.py'
--- nova/db/sqlalchemy/migrate_repo/versions/016_make_quotas_key_and_value.py 2011-06-16 19:00:14 +0000
+++ nova/db/sqlalchemy/migrate_repo/versions/016_make_quotas_key_and_value.py 2011-08-24 21:44:18 +0000
@@ -75,8 +75,8 @@
75 )75 )
7676
7777
78def existing_quotas_table(migrate_engine):78def quotas_table(migrate_engine, name='quotas'):
79 return Table('quotas', meta, autoload=True, autoload_with=migrate_engine)79 return Table(name, meta, autoload=True, autoload_with=migrate_engine)
8080
8181
82def _assert_no_duplicate_project_ids(quotas):82def _assert_no_duplicate_project_ids(quotas):
@@ -179,13 +179,18 @@
179 # bind migrate_engine to your metadata179 # bind migrate_engine to your metadata
180 meta.bind = migrate_engine180 meta.bind = migrate_engine
181181
182 old_quotas = existing_quotas_table(migrate_engine)182 old_quotas = quotas_table(migrate_engine)
183 assert_old_quotas_have_no_active_duplicates(migrate_engine, old_quotas)183 assert_old_quotas_have_no_active_duplicates(migrate_engine, old_quotas)
184184
185 new_quotas = new_style_quotas_table('quotas_new')185 new_quotas = new_style_quotas_table('quotas_new')
186 new_quotas.create()186 new_quotas.create()
187 convert_forward(migrate_engine, old_quotas, new_quotas)187 convert_forward(migrate_engine, old_quotas, new_quotas)
188 old_quotas.drop()188 old_quotas.drop()
189
190 # clear metadata to work around this:
191 # http://code.google.com/p/sqlalchemy-migrate/issues/detail?id=128
192 meta.clear()
193 new_quotas = quotas_table(migrate_engine, 'quotas_new')
189 new_quotas.rename('quotas')194 new_quotas.rename('quotas')
190195
191196
@@ -193,11 +198,16 @@
193 # Operations to reverse the above upgrade go here.198 # Operations to reverse the above upgrade go here.
194 meta.bind = migrate_engine199 meta.bind = migrate_engine
195200
196 new_quotas = existing_quotas_table(migrate_engine)201 new_quotas = quotas_table(migrate_engine)
197 assert_new_quotas_have_no_active_duplicates(migrate_engine, new_quotas)202 assert_new_quotas_have_no_active_duplicates(migrate_engine, new_quotas)
198203
199 old_quotas = old_style_quotas_table('quotas_old')204 old_quotas = old_style_quotas_table('quotas_old')
200 old_quotas.create()205 old_quotas.create()
201 convert_backward(migrate_engine, old_quotas, new_quotas)206 convert_backward(migrate_engine, old_quotas, new_quotas)
202 new_quotas.drop()207 new_quotas.drop()
208
209 # clear metadata to work around this:
210 # http://code.google.com/p/sqlalchemy-migrate/issues/detail?id=128
211 meta.clear()
212 old_quotas = quotas_table(migrate_engine, 'quotas_old')
203 old_quotas.rename('quotas')213 old_quotas.rename('quotas')
204214
=== modified file 'nova/db/sqlalchemy/migrate_repo/versions/036_change_flavor_id_in_migrations.py'
--- nova/db/sqlalchemy/migrate_repo/versions/036_change_flavor_id_in_migrations.py 2011-08-03 21:44:03 +0000
+++ nova/db/sqlalchemy/migrate_repo/versions/036_change_flavor_id_in_migrations.py 2011-08-24 21:44:18 +0000
@@ -40,13 +40,17 @@
40 migrations.create_column(new_instance_type_id)40 migrations.create_column(new_instance_type_id)
4141
42 # Convert flavor_id to instance_type_id42 # Convert flavor_id to instance_type_id
43 itypes = {}
43 for instance_type in migrate_engine.execute(instance_types.select()):44 for instance_type in migrate_engine.execute(instance_types.select()):
44 migrate_engine.execute(migrations.update()\45 itypes[instance_type.id] = instance_type.flavorid
45 .where(migrations.c.old_flavor_id == instance_type.flavorid)\46
46 .values(old_instance_type_id=instance_type.id))47 for instance_type_id in itypes.keys():
47 migrate_engine.execute(migrations.update()\48 migrate_engine.execute(migrations.update()\
48 .where(migrations.c.new_flavor_id == instance_type.flavorid)\49 .where(migrations.c.old_flavor_id == itypes[instance_type_id])\
49 .values(new_instance_type_id=instance_type.id))50 .values(old_instance_type_id=instance_type_id))
51 migrate_engine.execute(migrations.update()\
52 .where(migrations.c.new_flavor_id == itypes[instance_type_id])\
53 .values(new_instance_type_id=instance_type_id))
5054
51 migrations.c.old_flavor_id.drop()55 migrations.c.old_flavor_id.drop()
52 migrations.c.new_flavor_id.drop()56 migrations.c.new_flavor_id.drop()