Merge lp:~adeuring/charmworld/queue-review-mutex into lp:~juju-jitsu/charmworld/trunk
Status: | Merged |
---|---|
Approved by: | Abel Deuring |
Approved revision: | 159 |
Merged at revision: | 161 |
Proposed branch: | lp:~adeuring/charmworld/queue-review-mutex |
Merge into: | lp:~juju-jitsu/charmworld/trunk |
Diff against target: |
398 lines (+271/-16) 7 files modified
charmworld/jobs/core_review.py (+11/-2) charmworld/jobs/lp.py (+16/-2) charmworld/jobs/review.py (+11/-2) charmworld/jobs/tests/test_utils.py (+152/-0) charmworld/jobs/utils.py (+66/-0) charmworld/testing/__init__.py (+10/-10) default.ini (+5/-0) |
To merge this branch: | bzr merge lp:~adeuring/charmworld/queue-review-mutex |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Abel Deuring (community) | Approve | ||
Review via email: mp+150853@code.launchpad.net |
Commit message
Use locks to prevent the jobs lp, core_review and review from running concurrently.
Description of the change
Locking for jobs
Charmworld runs a few cron jobs to keep the list of avaliable charms
up to date. If charmworld is installed on more than one machines, running
these jobs on all machines would cause unnecessary duplicate work,
like queueing the charms for further processing.
This branch adds a simple locking mechansim for these jobs. The core idea:
A lock is a record in the collection "locks" of the MongoDB with a given
ID. MongoDB can raise a DuplicateKey exception when a record with the ID
'some_name' already exists during a call of
collection.
("can" means: When I first attempted to use the lock for the jobs review and
core_review, locking simply did not work, while it worked fine in tests and
for the queueing job. It turned out that the parameter "fsync" msut be
specified when pymongo.Connection is instantiated. As the test
test_bad_
not important -- but it must be present...)
Hence lock() ensures that fsync was specified for the given DB connection.
Locks have a lease time; if the lease expires, a now stale lock is deleted
when another process wants to acquire the lock. The related call of
locks.remove(
might try concurrently to remove the stale lock. A simple tests shows that
duplicate remove(
just does nothing.
Reviewers: mp+150853_ code.launchpad. net,
Message:
Please take a look.
Description:
Locking for jobs
Charmworld runs a few cron jobs to keep the list of avaliable charms
up to date. If charmworld is installed on more than one machines,
running
these jobs on all machines would cause unnecessary duplicate work,
like queueing the charms for further processing.
This branch adds a simple locking mechansim for these jobs. The core insert( {'_id': 'some_name', ...})
idea:
A lock is a record in the collection "locks" of the MongoDB with a given
ID. MongoDB can raise a DuplicateKey exception when a record with the ID
'some_name' already exists during a call of
collection.
("can" means: When I first attempted to use the lock for the jobs review connection_ setup shows, the actual value of this parameter is
and
core_review, locking simply did not work, while it worked fine in tests
and
for the queueing job. It turned out that the parameter "fsync" msut be
specified when pymongo.Connection is instantiated. As the test
test_bad_
not important -- but it must be present...)
Hence lock() ensures that fsync was specified for the given DB
connection.
Locks have a lease time; if the lease expires, a now stale lock is existing_ lock) is a possible race condition: Two processes existing_ lock) calls succeed, even if the second call
deleted
when another process wants to acquire the lock. The related call of
locks.remove(
might try concurrently to remove the stale lock. A simple tests shows
that
duplicate remove(
just does nothing.
https:/ /code.launchpad .net/~adeuring/ charmworld/ queue-review- mutex/+ merge/150853
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/7379053/
Affected files: jobs/core_ review. py jobs/lp. py jobs/review. py jobs/tests/ test_utils. py jobs/utils. py testing/ __init_ _.py
A [revision details]
M charmworld/
M charmworld/
M charmworld/
A charmworld/
M charmworld/
M charmworld/
M default.ini