summaryrefslogtreecommitdiff
path: root/common/src/leap
diff options
context:
space:
mode:
authorTomás Touceda <chiiph@leap.se>2014-04-02 15:57:18 -0300
committerTomás Touceda <chiiph@leap.se>2014-04-02 15:57:18 -0300
commit7bc94242398ad220908a214d0f457db017396f81 (patch)
tree3af7fdc5ec5c9cba010fbc13fc62982ae6d7f886 /common/src/leap
parentd13c6b2567803d73c8c2fd33495c081ce736eb96 (diff)
parente2a3431c13773af43b50797566feedc15fdf94ce (diff)
Merge remote-tracking branch 'refs/remotes/drebs/feature/5388_avoid-concurrent-syncs-update-handler-conflict' into develop
Diffstat (limited to 'common/src/leap')
-rw-r--r--common/src/leap/soledad/common/couch.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/common/src/leap/soledad/common/couch.py b/common/src/leap/soledad/common/couch.py
index c0ebc425..ebe8477f 100644
--- a/common/src/leap/soledad/common/couch.py
+++ b/common/src/leap/soledad/common/couch.py
@@ -30,6 +30,7 @@ import threading
from StringIO import StringIO
+from collections import defaultdict
from couchdb.client import Server
@@ -338,6 +339,8 @@ class CouchDatabase(CommonBackend):
# We spawn threads to parallelize the CouchDatabase.get_docs() method
MAX_GET_DOCS_THREADS = 20
+ update_handler_lock = defaultdict(threading.Lock)
+
class _GetDocThread(threading.Thread):
"""
A thread that gets a document from a database.
@@ -1133,13 +1136,14 @@ class CouchDatabase(CommonBackend):
ddoc_path = ['_design', 'syncs', '_update', 'put', 'u1db_sync_log']
res = self._database.resource(*ddoc_path)
try:
- res.put_json(
- body={
- 'other_replica_uid': other_replica_uid,
- 'other_generation': other_generation,
- 'other_transaction_id': other_transaction_id,
- },
- headers={'content-type': 'application/json'})
+ with CouchDatabase.update_handler_lock[self._get_replica_uid()]:
+ res.put_json(
+ body={
+ 'other_replica_uid': other_replica_uid,
+ 'other_generation': other_generation,
+ 'other_transaction_id': other_transaction_id,
+ },
+ headers={'content-type': 'application/json'})
except ResourceNotFound as e:
raise_missing_design_doc_error(e, ddoc_path)
@@ -1367,7 +1371,7 @@ class CouchDatabase(CommonBackend):
if save_conflict:
self._force_doc_sync_conflict(doc)
if replica_uid is not None and replica_gen is not None:
- self._do_set_replica_gen_and_trans_id(
+ self._set_replica_gen_and_trans_id(
replica_uid, replica_gen, replica_trans_id)
# update info
old_doc.rev = doc.rev