Commit 7246ece8 authored by Dmitry Vasiliev's avatar Dmitry Vasiliev

Merge rev 28208 from ZODB 3.3 branch.

Code cleanups.
parent ca9cfcf9
......@@ -22,15 +22,17 @@ The Mapping storage uses a single data structure to map object ids to data.
"""
from ZODB.utils import u64, z64
from ZODB import BaseStorage
from ZODB.BaseStorage import BaseStorage
from ZODB import POSException
from persistent.TimeStamp import TimeStamp
class MappingStorage(BaseStorage.BaseStorage):
class MappingStorage(BaseStorage):
def __init__(self, name='Mapping Storage'):
BaseStorage.BaseStorage.__init__(self, name)
BaseStorage.__init__(self, name)
self._index = {}
# FIXME: Why we don't use dict for _tindex?
self._tindex = []
self._ltid = None
# Note: If you subclass this and use a persistent mapping facility
......@@ -41,12 +43,15 @@ class MappingStorage(BaseStorage.BaseStorage):
return len(self._index)
def getSize(self):
# These constants are for Python object memory overheads
s = 32
for oid in self._index.keys():
p = self._index[oid]
s += 56 + len(p)
return s
self._lock_acquire()
try:
# These constants are for Python object memory overheads
s = 32
for p in self._index.itervalues():
s += 56 + len(p)
return s
finally:
self._lock_release()
def load(self, oid, version):
self._lock_acquire()
......@@ -70,8 +75,7 @@ class MappingStorage(BaseStorage.BaseStorage):
self._lock_acquire()
try:
# The tid is the first 8 bytes of the buffer.
s = self._index[oid]
return s[:8]
return self._index[oid][:8]
finally:
self._lock_release()
......@@ -81,13 +85,12 @@ class MappingStorage(BaseStorage.BaseStorage):
raise POSException.StorageTransactionError(self, transaction)
if version:
raise POSException.Unsupported, "Versions aren't supported"
raise POSException.Unsupported("Versions aren't supported")
self._lock_acquire()
try:
if self._index.has_key(oid):
old = self._index[oid]
oserial = old[:8]
if oid in self._index:
oserial = self._index[oid][:8]
if serial != oserial:
raise POSException.ConflictError(oid=oid,
serials=(oserial, serial),
......@@ -102,8 +105,7 @@ class MappingStorage(BaseStorage.BaseStorage):
self._tindex = []
def _finish(self, tid, user, desc, ext):
for oid, p in self._tindex:
self._index[oid] = p
self._index.update(dict(self._tindex))
self._ltid = self._tid
def lastTransaction(self):
......@@ -119,17 +121,16 @@ class MappingStorage(BaseStorage.BaseStorage):
pindex = {}
while rootl:
oid = rootl.pop()
if pindex.has_key(oid):
if oid in pindex:
continue
# Scan non-version pickle for references
r = self._index[oid]
pindex[oid] = r
p = r[8:]
referencesf(p, rootl)
referencesf(r[8:], rootl)
# Now delete any unreferenced entries:
for oid in self._index.keys():
if not pindex.has_key(oid):
if oid not in pindex:
del self._index[oid]
finally:
......@@ -137,13 +138,12 @@ class MappingStorage(BaseStorage.BaseStorage):
def _splat(self):
"""Spit out a string showing state."""
o = []
o.append('Index:')
o = ['Index:']
keys = self._index.keys()
keys.sort()
for oid in keys:
r = self._index[oid]
o.append(' %s: %s, %s' %
(u64(oid),TimeStamp(r[:8]),`r[8:]`))
(u64(oid), TimeStamp(r[:8]), repr(r[8:])))
return '\n'.join(o)
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