Merge lp:~julian-edwards/maas/race-for-staticip-bug-1387262 into lp:~maas-committers/maas/trunk
Status: | Merged |
---|---|
Approved by: | Julian Edwards |
Approved revision: | no longer in the source branch. |
Merged at revision: | 3337 |
Proposed branch: | lp:~julian-edwards/maas/race-for-staticip-bug-1387262 |
Merge into: | lp:~maas-committers/maas/trunk |
Diff against target: |
128 lines (+50/-11) 3 files modified
src/maasserver/locks.py (+3/-0) src/maasserver/models/staticipaddress.py (+22/-11) src/maasserver/models/tests/test_staticipaddress.py (+25/-0) |
To merge this branch: | bzr merge lp:~julian-edwards/maas/race-for-staticip-bug-1387262 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Graham Binns (community) | Approve | ||
Newell Jensen (community) | Approve | ||
Review via email: mp+240669@code.launchpad.net |
Commit message
Use a lock in the critical section of the code that finds and records a new static IP address in the database. Some users have reported errors in the PG log file complaining about inserting duplicates, so there must be a race.
Description of the change
With reference to the attached bug, it looks like we need a lock around the section of code that acquires static IP addresses. At least, I can't see any other reason for errors like this in the PG log:
2014-10-28 15:40:35 UTC ERROR: duplicate key value violates unique constraint "maasserver_
2014-10-28 15:40:35 UTC DETAIL: Key (ip)=(10.245.0.201) already exists.
2014-10-28 15:40:35 UTC STATEMENT: INSERT INTO "maasserver_
However the error that bubbles up to the appserver is a little odd (see the bug), you'd think it would be an IntegrityError. Maybe it's a consequence of the atomic context manager used in Node.claim_
Approve. One question inline.