Commit fdc141aa authored by Grégory Wisniewski's avatar Grégory Wisniewski

Implement our own copyTransactionFrom().

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1908 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent b2ec24e7
...@@ -136,6 +136,9 @@ class Storage(BaseStorage.BaseStorage, ...@@ -136,6 +136,9 @@ class Storage(BaseStorage.BaseStorage,
def sync(self): def sync(self):
self.app.sync() self.app.sync()
def copyTransactionsFrom(self, source, verbose=False):
return self.app.copyTransactionsFrom(source, self.tryToResolveConflict)
# def restore(self, oid, serial, data, version, prev_txn, transaction): # def restore(self, oid, serial, data, version, prev_txn, transaction):
# raise NotImplementedError # raise NotImplementedError
......
...@@ -981,6 +981,30 @@ class Application(object): ...@@ -981,6 +981,30 @@ class Application(object):
return history_list return history_list
def copyTransactionsFrom(self, source, tryToResolveConflict):
serials = {}
def updateLastSerial(oid, result):
if result:
if isinstance(result, str):
assert oid is not None
serials[oid] = result
else:
for oid, serial in result:
assert isinstance(serial, str), serial
serials[oid] = serial
transaction_iter = source.iterator()
for transaction in transaction_iter:
self.tpc_begin(transaction, transaction.tid, transaction.status)
for r in transaction:
pre = serials.get(r.oid, None)
# TODO: bypass conflict resolution, locks...
result = self.store(r.oid, pre, r.data, r.version, transaction)
updateLastSerial(r.oid, result)
updateLastSerial(None, self.tpc_vote(transaction,
tryToResolveConflict))
self.tpc_finish(transaction)
transaction_iter.close()
def iterator(self, start=None, stop=None): def iterator(self, start=None, stop=None):
return Iterator(self, start, stop) return Iterator(self, start, stop)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment