diff options
author | drebs <drebs@leap.se> | 2015-08-18 12:16:47 -0300 |
---|---|---|
committer | drebs <drebs@leap.se> | 2015-08-19 15:41:25 -0300 |
commit | 3180d0544afc8000c06065c223d5cf104e806275 (patch) | |
tree | a8dbe5e6689c3b9b59cb831784100425d3432d48 /client/src/leap/soledad | |
parent | a8b9f9a659abd4b1eb7d4a7e7c48e8e1216ddcca (diff) |
[bug] hold sync lock while running post-sync hooks
Previous to this modification, the post-sync hooks were run after the sync
lock was released. In that scenario, the next sync process could start before
the previous sync's post-sync hooks were run. In general, we want the hooks to
run while the current sync lock is still locked, even though for some plugins
this might not make a difference.
Diffstat (limited to 'client/src/leap/soledad')
-rw-r--r-- | client/src/leap/soledad/client/api.py | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/client/src/leap/soledad/client/api.py b/client/src/leap/soledad/client/api.py index 6fcc8d79..b91e497f 100644 --- a/client/src/leap/soledad/client/api.py +++ b/client/src/leap/soledad/client/api.py @@ -656,31 +656,39 @@ class Soledad(object): """ Synchronize documents with the server replica. + This method uses a lock to prevent multiple concurrent sync processes + over the same local db file. + :param defer_decryption: Whether to defer decryption of documents, or do it inline while syncing. :type defer_decryption: bool - :return: A deferred whose callback will be invoked with the local - generation before the synchronization was performed. + :return: A deferred lock that will run the actual sync process when + the lock is acquired, and which will fire with with the local + generation before the synchronization was performed. :rtype: twisted.internet.defer.Deferred """ + d = self.sync_lock.run( + self._sync, + defer_decryption) + return d - # ----------------------------------------------------------------- - # TODO this needs work. - # Should review/write tests to check that this: - - # (1) Defer to the syncer pool -- DONE (on dbsyncer) - # (2) Return the deferred - # (3) Add the callback for signaling the event (executed on reactor - # thread) - # (4) Check that the deferred is called with the local gen. + def _sync(self, defer_decryption): + """ + Synchronize documents with the server replica. - # ----------------------------------------------------------------- + :param defer_decryption: + Whether to defer decryption of documents, or do it inline while + syncing. + :type defer_decryption: bool + :return: A deferred whose callback will be invoked with the local + generation before the synchronization was performed. + :rtype: twisted.internet.defer.Deferred + """ sync_url = urlparse.urljoin(self._server_url, 'user-%s' % self.uuid) - d = self.sync_lock.run( - self._dbsyncer.sync, + d = self._dbsyncer.sync( sync_url, creds=self._creds, defer_decryption=defer_decryption) |