Merge lp:~rlucio/nova/lp677475 into lp:~hudson-openstack/nova/trunk

Proposed by Ryan Lucio
Status: Merged
Approved by: Eric Day
Approved revision: 440
Merged at revision: 441
Proposed branch: lp:~rlucio/nova/lp677475
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 25 lines (+2/-2)
2 files modified
nova/db/sqlalchemy/api.py (+1/-1)
nova/image/local.py (+1/-1)
To merge this branch: bzr merge lp:~rlucio/nova/lp677475
Reviewer Review Type Date Requested Status
David Pravec (community) Approve
Eric Day (community) Approve
Michael Gundlach (community) Approve
Review via email: mp+42584@code.launchpad.net

Description of the change

Addresses bug 677475 by changing the DB column for internal_id in the instances table to be unsigned.

To post a comment you must log in.
Revision history for this message
Jesse Andrews (anotherjesse) wrote :

How does this affect postgresql and sqlite users?

Revision history for this message
Soren Hansen (soren) wrote :

Perhaps we'd be better off with a smaller key space? I.e. change
nova.db.api instance_create to choose a random id that will fit in an
int32.

--
Soren Hansen
Ubuntu Developer    http://www.ubuntu.com/
OpenStack Developer http://www.openstack.org/

Revision history for this message
Ryan Lucio (rlucio) wrote :

- From my brief experience with the sqlalchemy libraries, it appears that all the mysql specific calls do is support its 'enhanced' column types/options. So if the db is not mysql the mysql.MSInteger call will simply ignore the mysql options as if you had called the base class sqlalchemy.types.Integer. I can do some testing for sqllite to see.

- Yes the easy alternative is simply to change the calculations to range from 0 to (2^31 - 1). The reason I didn't go that route is that it isn't documented why the 0 to (2^32 - 1) range was chosen in the first place, and I wasn't sure if it was arbitrary or chosen for a specific reason.

lp:~rlucio/nova/lp677475 updated
440. By Ryan Lucio

Decreased the maximum value for instance-id generation from uint32 to int32 to avoid truncation when being entered into the instance table. Reverted fix to make internal_id column a uint

Revision history for this message
Ryan Lucio (rlucio) wrote :

This fix was tested/verified on a multi-box deployment configured to use a mysql db.

Revision history for this message
Michael Gundlach (gundlach) wrote :

2^31 should work. This was my code (and my bug -- thanks for addressing it.) 2^32 isn't special -- we just wanted a large enough space so that we wouldn't run out of instance IDs. 2^31 should be fine.

When we split into one sqlite DB per compute worker instead of a centralized DB, we'll need to revisit this anyway, since creating a new instance currently relies on manually checking the DB for uniqueness.

Revision history for this message
Michael Gundlach (gundlach) wrote :

lgtm.

review: Approve
Revision history for this message
Eric Day (eday) wrote :

This needs to be refactored soon. The key space is too small and this is a very inefficient way to generate unique IDs (especially once the data can be distributed). Approving for now since it fixes the issue at hand.

review: Approve
Revision history for this message
David Pravec (alekibango) wrote :

lgtm for now. but i would also say refactor later...

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/db/sqlalchemy/api.py'
2--- nova/db/sqlalchemy/api.py 2010-12-01 21:53:27 +0000
3+++ nova/db/sqlalchemy/api.py 2010-12-03 21:58:09 +0000
4@@ -543,7 +543,7 @@
5 with session.begin():
6 while instance_ref.internal_id == None:
7 # Instances have integer internal ids.
8- internal_id = random.randint(0, 2 ** 32 - 1)
9+ internal_id = random.randint(0, 2 ** 31 - 1)
10 if not instance_internal_id_exists(context, internal_id,
11 session=session):
12 instance_ref.internal_id = internal_id
13
14=== modified file 'nova/image/local.py'
15--- nova/image/local.py 2010-11-18 21:27:52 +0000
16+++ nova/image/local.py 2010-12-03 21:58:09 +0000
17@@ -59,7 +59,7 @@
18 """
19 Store the image data and return the new image id.
20 """
21- id = random.randint(0, 2 ** 32 - 1)
22+ id = random.randint(0, 2 ** 31 - 1)
23 data['id'] = id
24 self.update(context, id, data)
25 return id