Commit d016205a authored by Tim Peters's avatar Tim Peters

Merge rev 31016 from 3.4 branch.

Simplify.

Primarily, _tindex should have been a dict all along, pack()
worked too hard at the end, and loadEx() is a minor variant
of load().
parent 31b7c342
...@@ -31,9 +31,11 @@ class MappingStorage(BaseStorage): ...@@ -31,9 +31,11 @@ class MappingStorage(BaseStorage):
def __init__(self, name='Mapping Storage'): def __init__(self, name='Mapping Storage'):
BaseStorage.__init__(self, name) BaseStorage.__init__(self, name)
# ._index maps an oid to a string s. s[:8] is the tid of the
# transaction that created oid's current state, and s[8:] is oid's
# current state.
self._index = {} self._index = {}
# FIXME: Why we don't use dict for _tindex? self._clear_temp()
self._tindex = []
self._ltid = None self._ltid = None
# Note: If you subclass this and use a persistent mapping facility # Note: If you subclass this and use a persistent mapping facility
# (e.g. a dbm file), you will need to get the maximum key and save it # (e.g. a dbm file), you will need to get the maximum key and save it
...@@ -45,7 +47,7 @@ class MappingStorage(BaseStorage): ...@@ -45,7 +47,7 @@ class MappingStorage(BaseStorage):
def getSize(self): def getSize(self):
self._lock_acquire() self._lock_acquire()
try: try:
# These constants are for Python object memory overheads # These constants are for Python object memory overheads. Heh.
s = 32 s = 32
for p in self._index.itervalues(): for p in self._index.itervalues():
s += 56 + len(p) s += 56 + len(p)
...@@ -62,14 +64,9 @@ class MappingStorage(BaseStorage): ...@@ -62,14 +64,9 @@ class MappingStorage(BaseStorage):
self._lock_release() self._lock_release()
def loadEx(self, oid, version): def loadEx(self, oid, version):
self._lock_acquire() # Since we don't support versions, just tack the empty version
try: # string onto load's result.
# Since this storage doesn't support versions, tid and return self.load(oid, version) + ("",)
# serial will always be the same.
p = self._index[oid]
return p[8:], p[:8], "" # pickle, tid, version
finally:
self._lock_release()
def getTid(self, oid): def getTid(self, oid):
self._lock_acquire() self._lock_acquire()
...@@ -79,7 +76,6 @@ class MappingStorage(BaseStorage): ...@@ -79,7 +76,6 @@ class MappingStorage(BaseStorage):
finally: finally:
self._lock_release() self._lock_release()
def store(self, oid, serial, data, version, transaction): def store(self, oid, serial, data, version, transaction):
if transaction is not self._transaction: if transaction is not self._transaction:
raise POSException.StorageTransactionError(self, transaction) raise POSException.StorageTransactionError(self, transaction)
...@@ -95,17 +91,18 @@ class MappingStorage(BaseStorage): ...@@ -95,17 +91,18 @@ class MappingStorage(BaseStorage):
raise POSException.ConflictError(oid=oid, raise POSException.ConflictError(oid=oid,
serials=(oserial, serial), serials=(oserial, serial),
data=data) data=data)
self._tindex[oid] = self._tid + data
self._tindex.append((oid, self._tid + data))
finally: finally:
self._lock_release() self._lock_release()
return self._tid return self._tid
def _clear_temp(self): def _clear_temp(self):
self._tindex = [] # store() saves data in _tindex; if the transaction completes
# successfully, _finish() merges _tindex into _index.
self._tindex = {}
def _finish(self, tid, user, desc, ext): def _finish(self, tid, user, desc, ext):
self._index.update(dict(self._tindex)) self._index.update(self._tindex)
self._ltid = self._tid self._ltid = self._tid
def lastTransaction(self): def lastTransaction(self):
...@@ -121,17 +118,12 @@ class MappingStorage(BaseStorage): ...@@ -121,17 +118,12 @@ class MappingStorage(BaseStorage):
pindex = {} pindex = {}
while rootl: while rootl:
oid = rootl.pop() oid = rootl.pop()
if oid in pindex: if oid not in pindex:
continue # Scan non-version pickle for references.
# Scan non-version pickle for references
r = self._index[oid] r = self._index[oid]
pindex[oid] = r pindex[oid] = r
referencesf(r[8:], rootl) referencesf(r[8:], rootl)
self._index = pindex
# Now delete any unreferenced entries:
for oid in self._index.keys():
if oid not in pindex:
del self._index[oid]
finally: finally:
self._lock_release() self._lock_release()
......
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