Commit 2e618202 authored by Jim Fulton's avatar Jim Fulton

Added undo support

parent 0b549c3f
...@@ -32,27 +32,31 @@ class CommitLog: ...@@ -32,27 +32,31 @@ class CommitLog:
self.pickler = cPickle.Pickler(self.file, 1) self.pickler = cPickle.Pickler(self.file, 1)
self.pickler.fast = 1 self.pickler.fast = 1
self.stores = 0 self.stores = 0
self.read = 0
def size(self): def size(self):
return self.file.tell() return self.file.tell()
def delete(self, oid, serial): def delete(self, oid, serial):
self.pickler.dump(('d', oid, serial)) self.pickler.dump(('_delete', (oid, serial)))
self.stores += 1 self.stores += 1
def store(self, oid, serial, data): def store(self, oid, serial, data):
self.pickler.dump(('s', oid, serial, data)) self.pickler.dump(('_store', (oid, serial, data)))
self.stores += 1 self.stores += 1
def restore(self, oid, serial, data, prev_txn): def restore(self, oid, serial, data, prev_txn):
self.pickler.dump(('r', oid, serial, data, prev_txn)) self.pickler.dump(('_restore', (oid, serial, data, prev_txn)))
self.stores += 1 self.stores += 1
def get_loader(self): def undo(self, transaction_id):
self.read = 1 self.pickler.dump(('_undo', (transaction_id, )))
self.stores += 1
def __iter__(self):
self.file.seek(0) self.file.seek(0)
return self.stores, cPickle.Unpickler(self.file) unpickler = cPickle.Unpickler(self.file)
for i in range(self.stores):
yield unpickler.load()
def close(self): def close(self):
if self.file: if self.file:
......
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