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
1=== modified file 'Authors'
2--- Authors 2011-08-23 18:16:04 +0000
3+++ Authors 2011-08-24 21:44:18 +0000
4@@ -69,6 +69,7 @@
5 Lorin Hochstein <lorin@isi.edu>
6 Lvov Maxim <usrleon@gmail.com>
7 Mandell Degerness <mdegerne@gmail.com>
8+Mark McLoughlin <markmc@redhat.com>
9 Mark Washenberger <mark.washenberger@rackspace.com>
10 Masanori Itoh <itoumsn@nttdata.co.jp>
11 Matt Dietz <matt.dietz@rackspace.com>
12
13=== modified file 'nova/db/sqlalchemy/migrate_repo/versions/016_make_quotas_key_and_value.py'
14--- nova/db/sqlalchemy/migrate_repo/versions/016_make_quotas_key_and_value.py 2011-06-16 19:00:14 +0000
15+++ nova/db/sqlalchemy/migrate_repo/versions/016_make_quotas_key_and_value.py 2011-08-24 21:44:18 +0000
16@@ -75,8 +75,8 @@
17 )
18
19
20-def existing_quotas_table(migrate_engine):
21- return Table('quotas', meta, autoload=True, autoload_with=migrate_engine)
22+def quotas_table(migrate_engine, name='quotas'):
23+ return Table(name, meta, autoload=True, autoload_with=migrate_engine)
24
25
26 def _assert_no_duplicate_project_ids(quotas):
27@@ -179,13 +179,18 @@
28 # bind migrate_engine to your metadata
29 meta.bind = migrate_engine
30
31- old_quotas = existing_quotas_table(migrate_engine)
32+ old_quotas = quotas_table(migrate_engine)
33 assert_old_quotas_have_no_active_duplicates(migrate_engine, old_quotas)
34
35 new_quotas = new_style_quotas_table('quotas_new')
36 new_quotas.create()
37 convert_forward(migrate_engine, old_quotas, new_quotas)
38 old_quotas.drop()
39+
40+ # clear metadata to work around this:
41+ # http://code.google.com/p/sqlalchemy-migrate/issues/detail?id=128
42+ meta.clear()
43+ new_quotas = quotas_table(migrate_engine, 'quotas_new')
44 new_quotas.rename('quotas')
45
46
47@@ -193,11 +198,16 @@
48 # Operations to reverse the above upgrade go here.
49 meta.bind = migrate_engine
50
51- new_quotas = existing_quotas_table(migrate_engine)
52+ new_quotas = quotas_table(migrate_engine)
53 assert_new_quotas_have_no_active_duplicates(migrate_engine, new_quotas)
54
55 old_quotas = old_style_quotas_table('quotas_old')
56 old_quotas.create()
57 convert_backward(migrate_engine, old_quotas, new_quotas)
58 new_quotas.drop()
59+
60+ # clear metadata to work around this:
61+ # http://code.google.com/p/sqlalchemy-migrate/issues/detail?id=128
62+ meta.clear()
63+ old_quotas = quotas_table(migrate_engine, 'quotas_old')
64 old_quotas.rename('quotas')
65
66=== modified file 'nova/db/sqlalchemy/migrate_repo/versions/036_change_flavor_id_in_migrations.py'
67--- nova/db/sqlalchemy/migrate_repo/versions/036_change_flavor_id_in_migrations.py 2011-08-03 21:44:03 +0000
68+++ nova/db/sqlalchemy/migrate_repo/versions/036_change_flavor_id_in_migrations.py 2011-08-24 21:44:18 +0000
69@@ -40,13 +40,17 @@
70 migrations.create_column(new_instance_type_id)
71
72 # Convert flavor_id to instance_type_id
73+ itypes = {}
74 for instance_type in migrate_engine.execute(instance_types.select()):
75- migrate_engine.execute(migrations.update()\
76- .where(migrations.c.old_flavor_id == instance_type.flavorid)\
77- .values(old_instance_type_id=instance_type.id))
78- migrate_engine.execute(migrations.update()\
79- .where(migrations.c.new_flavor_id == instance_type.flavorid)\
80- .values(new_instance_type_id=instance_type.id))
81+ itypes[instance_type.id] = instance_type.flavorid
82+
83+ for instance_type_id in itypes.keys():
84+ migrate_engine.execute(migrations.update()\
85+ .where(migrations.c.old_flavor_id == itypes[instance_type_id])\
86+ .values(old_instance_type_id=instance_type_id))
87+ migrate_engine.execute(migrations.update()\
88+ .where(migrations.c.new_flavor_id == itypes[instance_type_id])\
89+ .values(new_instance_type_id=instance_type_id))
90
91 migrations.c.old_flavor_id.drop()
92 migrations.c.new_flavor_id.drop()