From 7aee1e34baeafcc12d44c304bac7fb6fcf3be562 Mon Sep 17 00:00:00 2001 From: drebs Date: Thu, 27 Dec 2012 11:09:39 -0200 Subject: Fix imports and namespaces --- src/leap/soledad/backends/objectstore.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/leap/soledad/backends/objectstore.py') diff --git a/src/leap/soledad/backends/objectstore.py b/src/leap/soledad/backends/objectstore.py index 61445a1f..9fce88f6 100644 --- a/src/leap/soledad/backends/objectstore.py +++ b/src/leap/soledad/backends/objectstore.py @@ -1,7 +1,7 @@ import uuid from u1db.backends import CommonBackend from u1db import errors, Document -from soledad.util import SyncLog, TransactionLog +from leap.soledad import util as soledadutil class ObjectStore(CommonBackend): @@ -14,8 +14,8 @@ class ObjectStore(CommonBackend): # with the database is established, so it can ensure that u1db data is # configured and up-to-date. self.set_document_factory(Document) - self._sync_log = SyncLog() - self._transaction_log = TransactionLog() + self._sync_log = soledadutil.SyncLog() + self._transaction_log = soledadutil.TransactionLog() self._ensure_u1db_data() #------------------------------------------------------------------------- -- cgit v1.2.3 From 9175349330a205f2c799a02722469cc86efd33db Mon Sep 17 00:00:00 2001 From: drebs Date: Tue, 8 Jan 2013 16:12:41 -0200 Subject: Refactor and details of ObjectStore and CouchDatabase --- src/leap/soledad/backends/objectstore.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/leap/soledad/backends/objectstore.py') diff --git a/src/leap/soledad/backends/objectstore.py b/src/leap/soledad/backends/objectstore.py index 9fce88f6..54ffa9dd 100644 --- a/src/leap/soledad/backends/objectstore.py +++ b/src/leap/soledad/backends/objectstore.py @@ -9,13 +9,14 @@ class ObjectStore(CommonBackend): A backend for storing u1db data in an object store. """ - def __init__(self): + def __init__(self, replica_uid=None): # This initialization method should be called after the connection # with the database is established, so it can ensure that u1db data is # configured and up-to-date. self.set_document_factory(Document) self._sync_log = soledadutil.SyncLog() self._transaction_log = soledadutil.TransactionLog() + self._replica_uid = replica_uid self._ensure_u1db_data() #------------------------------------------------------------------------- @@ -183,7 +184,8 @@ class ObjectStore(CommonBackend): """ Create u1db data object in store. """ - self._replica_uid = uuid.uuid4().hex + if self._replica_uid is None: + self._replica_uid = uuid.uuid4().hex doc = self._factory(doc_id=self.U1DB_DATA_DOC_ID) doc.content = { 'transaction_log' : [], 'sync_log' : [], @@ -200,11 +202,14 @@ class ObjectStore(CommonBackend): """ Save u1db configuration data on backend storage. """ - doc = self._factory(doc_id=self.U1DB_DATA_DOC_ID) - doc.content = { 'transaction_log' : self._transaction_log.log, - 'sync_log' : self._sync_log.log, - 'replica_uid' : self._replica_uid, - '_rev' : self._couch_rev} - self._put_doc(doc) + NotImplementedError(self._set_u1db_data) + + def _set_replica_uid(self, replica_uid): + self._replica_uid = replica_uid + self._set_u1db_data() + def _get_replica_uid(self): + return self._replica_uid + replica_uid = property( + _get_replica_uid, _set_replica_uid, doc="Replica UID of the database") -- cgit v1.2.3 From 9b7728b80027f35c013a449b884235cf8eac503c Mon Sep 17 00:00:00 2001 From: drebs Date: Wed, 9 Jan 2013 11:46:58 -0200 Subject: CouchDatabase passes u1db LocalDatabaseTests. --- src/leap/soledad/backends/objectstore.py | 69 +++++++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 10 deletions(-) (limited to 'src/leap/soledad/backends/objectstore.py') diff --git a/src/leap/soledad/backends/objectstore.py b/src/leap/soledad/backends/objectstore.py index 54ffa9dd..cd051588 100644 --- a/src/leap/soledad/backends/objectstore.py +++ b/src/leap/soledad/backends/objectstore.py @@ -16,6 +16,7 @@ class ObjectStore(CommonBackend): self.set_document_factory(Document) self._sync_log = soledadutil.SyncLog() self._transaction_log = soledadutil.TransactionLog() + self._conflict_log = soledadutil.ConflictLog() self._replica_uid = replica_uid self._ensure_u1db_data() @@ -44,6 +45,12 @@ class ObjectStore(CommonBackend): def _put_doc(self, doc): raise NotImplementedError(self._put_doc) + def _update_gen_and_transaction_log(self, doc_id): + new_gen = self._get_generation() + 1 + trans_id = self._allocate_transaction_id() + self._transaction_log.append((new_gen, doc_id, trans_id)) + self._set_u1db_data() + def put_doc(self, doc): # consistency check if doc.doc_id is None: @@ -66,11 +73,7 @@ class ObjectStore(CommonBackend): new_rev = self._allocate_doc_rev(doc.rev) doc.rev = new_rev self._put_doc(doc) - # update u1db generation and logs - new_gen = self._get_generation() + 1 - trans_id = self._allocate_transaction_id() - self._transaction_log.append((new_gen, doc.doc_id, trans_id)) - self._set_u1db_data() + self._update_gen_and_transaction_log(doc.doc_id) return doc.rev def delete_doc(self, doc): @@ -87,6 +90,7 @@ class ObjectStore(CommonBackend): doc.rev = new_rev doc.make_tombstone() self._put_doc(doc) + self._update_gen_and_transaction_log(doc.doc_id) return new_rev # start of index-related methods: these are not supported by this backend. @@ -130,6 +134,16 @@ class ObjectStore(CommonBackend): other_transaction_id) self._set_u1db_data() + def _do_set_replica_gen_and_trans_id(self, other_replica_uid, + other_generation, other_transaction_id): + return self._set_replica_gen_and_trans_id( + other_replica_uid, + other_generation, + other_transaction_id) + + def _get_transaction_log(self): + return self._transaction_log.get_transaction_log() + #------------------------------------------------------------------------- # implemented methods from CommonBackend #------------------------------------------------------------------------- @@ -146,9 +160,10 @@ class ObjectStore(CommonBackend): # Documents never have conflicts on server. return False - def _put_and_update_indexes(self, doc_id, old_doc, new_rev, content): - raise NotImplementedError(self._put_and_update_indexes) - + def _put_and_update_indexes(self, old_doc, doc): + # TODO: implement index update + self._put_doc(doc) + self._update_gen_and_transaction_log(doc.doc_id) def _get_trans_id_for_gen(self, generation): self._get_u1db_data() @@ -187,8 +202,9 @@ class ObjectStore(CommonBackend): if self._replica_uid is None: self._replica_uid = uuid.uuid4().hex doc = self._factory(doc_id=self.U1DB_DATA_DOC_ID) - doc.content = { 'transaction_log' : [], - 'sync_log' : [], + doc.content = { 'sync_log' : [], + 'transaction_log' : [], + 'conflict_log' : [], 'replica_uid' : self._replica_uid } self._put_doc(doc) @@ -213,3 +229,36 @@ class ObjectStore(CommonBackend): replica_uid = property( _get_replica_uid, _set_replica_uid, doc="Replica UID of the database") + + + #------------------------------------------------------------------------- + # The methods below were cloned from u1db sqlite backend. They should at + # least exist and raise a NotImplementedError exception in CommonBackend + # (should we maybe fill a bug in u1db bts?). + #------------------------------------------------------------------------- + + def _add_conflict(self, doc_id, my_doc_rev, my_content): + self._conflict_log.append((doc_id, my_doc_rev, my_content)) + + def _delete_conflicts(self, doc, conflict_revs): + deleting = [(doc.doc_id, c_rev) for c_rev in conflict_revs] + self._conflict_log.delete_conflicts(deleting) + doc.has_conflicts = self._has_conflicts(doc.doc_id) + + def _prune_conflicts(self, doc, doc_vcr): + if self._has_conflicts(doc.doc_id): + autoresolved = False + c_revs_to_prune = [] + for c_doc in self._get_conflicts(doc.doc_id): + c_vcr = vectorclock.VectorClockRev(c_doc.rev) + if doc_vcr.is_newer(c_vcr): + c_revs_to_prune.append(c_doc.rev) + elif doc.same_content_as(c_doc): + c_revs_to_prune.append(c_doc.rev) + doc_vcr.maximize(c_vcr) + autoresolved = True + if autoresolved: + doc_vcr.increment(self._replica_uid) + doc.rev = doc_vcr.as_str() + c = self._db_handle.cursor() + self._delete_conflicts(c, doc, c_revs_to_prune) -- cgit v1.2.3 From 8909a16a12c17098ae8d5ecd31af6765b543622c Mon Sep 17 00:00:00 2001 From: drebs Date: Thu, 10 Jan 2013 13:18:48 -0200 Subject: CouchDatabase passes all relevant u1db tests. --- src/leap/soledad/backends/objectstore.py | 66 +++++++++++++++++++------------- 1 file changed, 40 insertions(+), 26 deletions(-) (limited to 'src/leap/soledad/backends/objectstore.py') diff --git a/src/leap/soledad/backends/objectstore.py b/src/leap/soledad/backends/objectstore.py index cd051588..2ab07675 100644 --- a/src/leap/soledad/backends/objectstore.py +++ b/src/leap/soledad/backends/objectstore.py @@ -1,9 +1,7 @@ -import uuid from u1db.backends import CommonBackend -from u1db import errors, Document +from u1db import errors, Document, vectorclock from leap.soledad import util as soledadutil - class ObjectStore(CommonBackend): """ A backend for storing u1db data in an object store. @@ -11,12 +9,12 @@ class ObjectStore(CommonBackend): def __init__(self, replica_uid=None): # This initialization method should be called after the connection - # with the database is established, so it can ensure that u1db data is - # configured and up-to-date. + # with the database is established in each implementation, so it can + # ensure that u1db data is configured and up-to-date. self.set_document_factory(Document) self._sync_log = soledadutil.SyncLog() self._transaction_log = soledadutil.TransactionLog() - self._conflict_log = soledadutil.ConflictLog() + self._conflict_log = soledadutil.ConflictLog(self._factory) self._replica_uid = replica_uid self._ensure_u1db_data() @@ -72,8 +70,7 @@ class ObjectStore(CommonBackend): raise errors.RevisionConflict() new_rev = self._allocate_doc_rev(doc.rev) doc.rev = new_rev - self._put_doc(doc) - self._update_gen_and_transaction_log(doc.doc_id) + self._put_and_update_indexes(old_doc, doc) return doc.rev def delete_doc(self, doc): @@ -89,8 +86,7 @@ class ObjectStore(CommonBackend): new_rev = self._allocate_doc_rev(doc.rev) doc.rev = new_rev doc.make_tombstone() - self._put_doc(doc) - self._update_gen_and_transaction_log(doc.doc_id) + self._put_and_update_indexes(old_doc, doc) return new_rev # start of index-related methods: these are not supported by this backend. @@ -117,10 +113,25 @@ class ObjectStore(CommonBackend): # end of index-related methods: these are not supported by this backend. def get_doc_conflicts(self, doc_id): - return [] + self._get_u1db_data() + conflict_docs = self._conflict_log.get_conflicts(doc_id) + if not conflict_docs: + return [] + this_doc = self._get_doc(doc_id) + this_doc.has_conflicts = True + return [this_doc] + list(conflict_docs) def resolve_doc(self, doc, conflicted_doc_revs): - raise NotImplementedError(self.resolve_doc) + cur_doc = self._get_doc(doc.doc_id) + new_rev = self._ensure_maximal_rev(cur_doc.rev, + conflicted_doc_revs) + superseded_revs = set(conflicted_doc_revs) + doc.rev = new_rev + if cur_doc.rev in superseded_revs: + self._put_and_update_indexes(cur_doc, doc) + else: + self._add_conflict(doc.doc_id, new_rev, doc.get_json()) + self._delete_conflicts(doc, superseded_revs) def _get_replica_gen_and_trans_id(self, other_replica_uid): self._get_u1db_data() @@ -142,6 +153,7 @@ class ObjectStore(CommonBackend): other_transaction_id) def _get_transaction_log(self): + self._get_u1db_data() return self._transaction_log.get_transaction_log() #------------------------------------------------------------------------- @@ -157,11 +169,12 @@ class ObjectStore(CommonBackend): return self._transaction_log.get_generation_info() def _has_conflicts(self, doc_id): - # Documents never have conflicts on server. - return False + self._get_u1db_data() + return self._conflict_log.has_conflicts(doc_id) def _put_and_update_indexes(self, old_doc, doc): - # TODO: implement index update + # for now we ignore indexes as this backend is used to store encrypted + # blobs of data in the server. self._put_doc(doc) self._update_gen_and_transaction_log(doc.doc_id) @@ -199,14 +212,7 @@ class ObjectStore(CommonBackend): """ Create u1db data object in store. """ - if self._replica_uid is None: - self._replica_uid = uuid.uuid4().hex - doc = self._factory(doc_id=self.U1DB_DATA_DOC_ID) - doc.content = { 'sync_log' : [], - 'transaction_log' : [], - 'conflict_log' : [], - 'replica_uid' : self._replica_uid } - self._put_doc(doc) + NotImplementedError(self._initialize) def _get_u1db_data(self, u1db_data_doc_id): """ @@ -239,17 +245,19 @@ class ObjectStore(CommonBackend): def _add_conflict(self, doc_id, my_doc_rev, my_content): self._conflict_log.append((doc_id, my_doc_rev, my_content)) + self._set_u1db_data() def _delete_conflicts(self, doc, conflict_revs): deleting = [(doc.doc_id, c_rev) for c_rev in conflict_revs] self._conflict_log.delete_conflicts(deleting) + self._set_u1db_data() doc.has_conflicts = self._has_conflicts(doc.doc_id) def _prune_conflicts(self, doc, doc_vcr): if self._has_conflicts(doc.doc_id): autoresolved = False c_revs_to_prune = [] - for c_doc in self._get_conflicts(doc.doc_id): + for c_doc in self._conflict_log.get_conflicts(doc.doc_id): c_vcr = vectorclock.VectorClockRev(c_doc.rev) if doc_vcr.is_newer(c_vcr): c_revs_to_prune.append(c_doc.rev) @@ -260,5 +268,11 @@ class ObjectStore(CommonBackend): if autoresolved: doc_vcr.increment(self._replica_uid) doc.rev = doc_vcr.as_str() - c = self._db_handle.cursor() - self._delete_conflicts(c, doc, c_revs_to_prune) + self._delete_conflicts(doc, c_revs_to_prune) + + def _force_doc_sync_conflict(self, doc): + my_doc = self._get_doc(doc.doc_id) + self._prune_conflicts(doc, vectorclock.VectorClockRev(doc.rev)) + self._add_conflict(doc.doc_id, my_doc.rev, my_doc.get_json()) + doc.has_conflicts = True + self._put_and_update_indexes(my_doc, doc) -- cgit v1.2.3 From 7759f6c6b862e792adb4a005d9ec27e313fb6e06 Mon Sep 17 00:00:00 2001 From: drebs Date: Tue, 15 Jan 2013 18:52:56 -0200 Subject: Refactor and fix ObjectStore. --- src/leap/soledad/backends/objectstore.py | 183 +++++++++++++++++++++++++++++-- 1 file changed, 171 insertions(+), 12 deletions(-) (limited to 'src/leap/soledad/backends/objectstore.py') diff --git a/src/leap/soledad/backends/objectstore.py b/src/leap/soledad/backends/objectstore.py index 2ab07675..03694532 100644 --- a/src/leap/soledad/backends/objectstore.py +++ b/src/leap/soledad/backends/objectstore.py @@ -1,6 +1,5 @@ from u1db.backends import CommonBackend from u1db import errors, Document, vectorclock -from leap.soledad import util as soledadutil class ObjectStore(CommonBackend): """ @@ -12,9 +11,9 @@ class ObjectStore(CommonBackend): # with the database is established in each implementation, so it can # ensure that u1db data is configured and up-to-date. self.set_document_factory(Document) - self._sync_log = soledadutil.SyncLog() - self._transaction_log = soledadutil.TransactionLog() - self._conflict_log = soledadutil.ConflictLog(self._factory) + self._sync_log = SyncLog() + self._transaction_log = TransactionLog() + self._conflict_log = ConflictLog(self._factory) self._replica_uid = replica_uid self._ensure_u1db_data() @@ -139,19 +138,18 @@ class ObjectStore(CommonBackend): def _set_replica_gen_and_trans_id(self, other_replica_uid, other_generation, other_transaction_id): - self._get_u1db_data() + return self._do_set_replica_gen_and_trans_id( + other_replica_uid, + other_generation, + other_transaction_id) + + def _do_set_replica_gen_and_trans_id(self, other_replica_uid, + other_generation, other_transaction_id): self._sync_log.set_replica_gen_and_trans_id(other_replica_uid, other_generation, other_transaction_id) self._set_u1db_data() - def _do_set_replica_gen_and_trans_id(self, other_replica_uid, - other_generation, other_transaction_id): - return self._set_replica_gen_and_trans_id( - other_replica_uid, - other_generation, - other_transaction_id) - def _get_transaction_log(self): self._get_u1db_data() return self._transaction_log.get_transaction_log() @@ -276,3 +274,164 @@ class ObjectStore(CommonBackend): self._add_conflict(doc.doc_id, my_doc.rev, my_doc.get_json()) doc.has_conflicts = True self._put_and_update_indexes(my_doc, doc) + + +#---------------------------------------------------------------------------- +# U1DB's Transaction, Sync, and conflict Logs +#---------------------------------------------------------------------------- + +class SimpleList(object): + def __init__(self): + self._log = [] + + def _set_log(self, log): + self._log = log + + def _get_log(self): + return self._log + + log = property( + _get_log, _set_log, doc="Log contents.") + + def append(self, msg): + self._log.append(msg) + + def reduce(self, func, initializer=None): + return reduce(func, self._log, initializer) + + def map(self, func): + return map(func, self._get_log()) + + def filter(self, func): + return filter(func, self._get_log()) + + +class TransactionLog(SimpleList): + """ + An ordered list of (generation, doc_id, transaction_id) tuples. + """ + + def _set_log(self, log): + self._log = log + + def _get_log(self): + return sorted(self._log, reverse=True) + + log = property( + _get_log, _set_log, doc="Log contents.") + + def get_generation(self): + """ + Return the current generation. + """ + gens = self.map(lambda x: x[0]) + if not gens: + return 0 + return max(gens) + + def get_generation_info(self): + """ + Return the current generation and transaction id. + """ + if not self._log: + return(0, '') + info = self.map(lambda x: (x[0], x[2])) + return reduce(lambda x, y: x if (x[0] > y[0]) else y, info) + + def get_trans_id_for_gen(self, gen): + """ + Get the transaction id corresponding to a particular generation. + """ + log = self.reduce(lambda x, y: y if y[0] == gen else x) + if log is None: + return None + return log[2] + + def whats_changed(self, old_generation): + """ + Return a list of documents that have changed since old_generation. + """ + results = self.filter(lambda x: x[0] > old_generation) + seen = set() + changes = [] + newest_trans_id = '' + for generation, doc_id, trans_id in results: + if doc_id not in seen: + changes.append((doc_id, generation, trans_id)) + seen.add(doc_id) + if changes: + cur_gen = changes[0][1] # max generation + newest_trans_id = changes[0][2] + changes.reverse() + else: + results = self._get_log() + if not results: + cur_gen = 0 + newest_trans_id = '' + else: + cur_gen, _, newest_trans_id = results[0] + + return cur_gen, newest_trans_id, changes + + + def get_transaction_log(self): + """ + Return only a list of (doc_id, transaction_id) + """ + return map(lambda x: (x[1], x[2]), sorted(self._log)) + + +class SyncLog(SimpleList): + """ + A list of (replica_id, generation, transaction_id) tuples. + """ + + def find_by_replica_uid(self, replica_uid): + if not self._get_log(): + return () + return self.reduce(lambda x, y: y if y[0] == replica_uid else x) + + def get_replica_gen_and_trans_id(self, other_replica_uid): + """ + Return the last known generation and transaction id for the other db + replica. + """ + info = self.find_by_replica_uid(other_replica_uid) + if not info: + return (0, '') + return (info[1], info[2]) + + def set_replica_gen_and_trans_id(self, other_replica_uid, + other_generation, other_transaction_id): + """ + Set the last-known generation and transaction id for the other + database replica. + """ + self._log = self.filter(lambda x: x[0] != other_replica_uid) + self.append((other_replica_uid, other_generation, + other_transaction_id)) + +class ConflictLog(SimpleList): + """ + A list of (doc_id, my_doc_rev, my_content) tuples. + """ + + def __init__(self, factory): + super(ConflictLog, self).__init__() + self._factory = factory + + def delete_conflicts(self, conflicts): + for conflict in conflicts: + self._log = self.filter(lambda x: + x[0] != conflict[0] or x[1] != conflict[1]) + + def get_conflicts(self, doc_id): + conflicts = self.filter(lambda x: x[0] == doc_id) + if not conflicts: + return [] + return reversed(map(lambda x: self._factory(doc_id, x[1], x[2]), + conflicts)) + + def has_conflicts(self, doc_id): + return bool(self.filter(lambda x: x[0] == doc_id)) + -- cgit v1.2.3 From e83572610574e8d3d96c0117fdb45764ffbeb538 Mon Sep 17 00:00:00 2001 From: drebs Date: Wed, 16 Jan 2013 09:55:27 -0200 Subject: Fix copy_database for couch tests. --- src/leap/soledad/backends/objectstore.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/leap/soledad/backends/objectstore.py') diff --git a/src/leap/soledad/backends/objectstore.py b/src/leap/soledad/backends/objectstore.py index 03694532..2ddd4c79 100644 --- a/src/leap/soledad/backends/objectstore.py +++ b/src/leap/soledad/backends/objectstore.py @@ -212,7 +212,7 @@ class ObjectStore(CommonBackend): """ NotImplementedError(self._initialize) - def _get_u1db_data(self, u1db_data_doc_id): + def _get_u1db_data(self): """ Fetch u1db configuration data from backend storage. """ -- cgit v1.2.3 From 8ee7ba49fd3ae902fd0a9d8a3a80b7b6a9ab999b Mon Sep 17 00:00:00 2001 From: drebs Date: Wed, 16 Jan 2013 11:04:42 -0200 Subject: Couch backend passes test_sync without indexes. --- src/leap/soledad/backends/objectstore.py | 60 ++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 23 deletions(-) (limited to 'src/leap/soledad/backends/objectstore.py') diff --git a/src/leap/soledad/backends/objectstore.py b/src/leap/soledad/backends/objectstore.py index 2ddd4c79..b6523336 100644 --- a/src/leap/soledad/backends/objectstore.py +++ b/src/leap/soledad/backends/objectstore.py @@ -277,45 +277,59 @@ class ObjectStore(CommonBackend): #---------------------------------------------------------------------------- -# U1DB's Transaction, Sync, and conflict Logs +# U1DB's TransactionLog, SyncLog, ConflictLog, and Index #---------------------------------------------------------------------------- class SimpleList(object): def __init__(self): - self._log = [] + self._data = [] - def _set_log(self, log): - self._log = log + def _set_data(self, data): + self._data = data - def _get_log(self): - return self._log + def _get_data(self): + return self._data - log = property( - _get_log, _set_log, doc="Log contents.") + data = property( + _get_data, _set_data, doc="List contents.") def append(self, msg): - self._log.append(msg) + self._data.append(msg) def reduce(self, func, initializer=None): - return reduce(func, self._log, initializer) + return reduce(func, self._data, initializer) def map(self, func): - return map(func, self._get_log()) + return map(func, self._get_data()) def filter(self, func): - return filter(func, self._get_log()) + return filter(func, self._get_data()) + + +class SimpleLog(SimpleList): + + def _set_log(self, log): + self._data = log + def _get_log(self): + return self._data + + log = property( + _get_log, _set_log, doc="Log contents.") -class TransactionLog(SimpleList): + +class TransactionLog(SimpleLog): """ An ordered list of (generation, doc_id, transaction_id) tuples. """ def _set_log(self, log): - self._log = log + self._data = log - def _get_log(self): - return sorted(self._log, reverse=True) + def _get_data(self, reverse=True): + return sorted(self._data, reverse=reverse) + + _get_log = _get_data log = property( _get_log, _set_log, doc="Log contents.") @@ -333,7 +347,7 @@ class TransactionLog(SimpleList): """ Return the current generation and transaction id. """ - if not self._log: + if not self._get_log(): return(0, '') info = self.map(lambda x: (x[0], x[2])) return reduce(lambda x, y: x if (x[0] > y[0]) else y, info) @@ -378,10 +392,10 @@ class TransactionLog(SimpleList): """ Return only a list of (doc_id, transaction_id) """ - return map(lambda x: (x[1], x[2]), sorted(self._log)) + return map(lambda x: (x[1], x[2]), sorted(self._get_log(reverse=False))) -class SyncLog(SimpleList): +class SyncLog(SimpleLog): """ A list of (replica_id, generation, transaction_id) tuples. """ @@ -407,11 +421,11 @@ class SyncLog(SimpleList): Set the last-known generation and transaction id for the other database replica. """ - self._log = self.filter(lambda x: x[0] != other_replica_uid) + self._set_log(self.filter(lambda x: x[0] != other_replica_uid)) self.append((other_replica_uid, other_generation, other_transaction_id)) -class ConflictLog(SimpleList): +class ConflictLog(SimpleLog): """ A list of (doc_id, my_doc_rev, my_content) tuples. """ @@ -422,8 +436,8 @@ class ConflictLog(SimpleList): def delete_conflicts(self, conflicts): for conflict in conflicts: - self._log = self.filter(lambda x: - x[0] != conflict[0] or x[1] != conflict[1]) + self._set_log(self.filter(lambda x: + x[0] != conflict[0] or x[1] != conflict[1])) def get_conflicts(self, doc_id): conflicts = self.filter(lambda x: x[0] == doc_id) -- cgit v1.2.3