~rvb/maas/1.5-bug-1298790

« back to all changes in this revision

Viewing changes to src/maasserver/rpc/regionservice.py

  • Committer: MaaS Lander
  • Author(s): Gavin Panella
  • Date: 2014-04-01 17:33:24 UTC
  • mfrom: (2208.4.5 rpc-create-table-race)
  • Revision ID: maas_lander-20140401173324-6fx49valy79nggvd
[r=jtv][bug=1300363][author=allenap] Take an advisory lock to prevent concurrent creation of the eventloops table.

Creating tables in PostgreSQL is a transactional operation like any
other. If the isolation level is not sufficient - the default in Django
- it is susceptible to races. Using a higher isolation level may lead to
serialisation failures, for example. Advisory locking side-steps this.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
    connection,
31
31
    transaction,
32
32
    )
33
 
from maasserver import eventloop
 
33
from maasserver import (
 
34
    eventloop,
 
35
    locks,
 
36
    )
34
37
from maasserver.utils import synchronised
35
38
from provisioningserver.rpc import (
36
39
    cluster,
322
325
 
323
326
    @synchronous
324
327
    @synchronised(lock)
 
328
    @synchronised(locks.eventloop)
325
329
    @transactional
326
330
    def prepare(self):
327
331
        """Ensure that the ``eventloops`` table exists.