[Zope3-checkins] CVS: ZODB4/src/zodb/storage - mapping.py:1.3.4.2
Barry Warsaw
barry@wooz.org
Wed, 12 Feb 2003 16:05:42 -0500
Update of /cvs-repository/ZODB4/src/zodb/storage
In directory cvs.zope.org:/tmp/cvs-serv26814
Modified Files:
Tag: opaque-pickles-branch
mapping.py
Log Message:
store(): Don't concatenate the serial string with the pickle string
just to split it up in load().
Eliminate use of findrefs() since we're passing this in as part of the
data arg tuple for store(). Use the stored refs in the pack() method.
General code cleanup.
=== ZODB4/src/zodb/storage/mapping.py 1.3.4.1 => 1.3.4.2 ===
--- ZODB4/src/zodb/storage/mapping.py:1.3.4.1 Mon Feb 10 18:14:37 2003
+++ ZODB4/src/zodb/storage/mapping.py Wed Feb 12 16:05:42 2003
@@ -94,15 +94,14 @@
from zodb.interfaces import ZERO
from zodb.storage import base
from zodb.storage.interfaces import *
-from zodb.serialize import findrefs
from zodb.timestamp import TimeStamp
-def DB(name="Mapping Storage",
- pool_size=7, cache_size=400):
+def DB(name="Mapping Storage", pool_size=7, cache_size=400):
ms = MappingStorage(name)
db = zodb.db.DB(ms, pool_size, cache_size)
return db
+
class MappingStorage(base.BaseStorage):
__implements__ = IStorage
@@ -122,9 +121,10 @@
def load(self, oid, version):
self._lock_acquire()
try:
- p=self._index[oid]
- return p[8:], p[:8] # pickle, serial
- finally: self._lock_release()
+ serial, data, refs = self._index[oid]
+ return data, serial
+ finally:
+ self._lock_release()
def store(self, oid, serial, data, version, transaction):
if transaction is not self._transaction:
@@ -133,66 +133,56 @@
if version:
raise NotImplementedError
- # XXX Store the refs natively
- data, refs = data
+ pckdata, refs = data
self._lock_acquire()
try:
if self._index.has_key(oid):
- old=self._index[oid]
- oserial=old[:8]
+ oserial, odata, orefs = self._index[oid]
if serial != oserial:
raise interfaces.ConflictError(serials=(oserial, serial))
-
- serial=self._serial
- self._tindex.append((oid,serial+data))
- finally: self._lock_release()
-
+ serial = self._serial
+ self._tindex.append((oid, serial, pckdata, refs))
+ finally:
+ self._lock_release()
return serial
def _clear_temp(self):
- self._tindex=[]
+ self._tindex = []
def _finish(self, tid, user, desc, ext):
-
- index=self._index
- for oid, p in self._tindex: index[oid]=p
+ for oid, serial, data, refs in self._tindex:
+ self._index[oid] = serial, data, refs
def pack(self, t):
self._lock_acquire()
try:
- # Build an index of *only* those objects reachable
- # from the root.
- index=self._index
+ # Build an index of those objects reachable from the root.
rootl = [ZERO]
- pop=rootl.pop
- pindex={}
- referenced=pindex.has_key
+ packmark = {}
while rootl:
- oid=pop()
- if referenced(oid): continue
-
- # Scan non-version pickle for references
- r=index[oid]
- pindex[oid]=r
- p=r[8:]
- rootl.extend(findrefs(p))
-
+ oid = rootl.pop()
+ if packmark.has_key(oid):
+ continue
+ # Register this oid and append the objects referenced by this
+ # object to the root search list.
+ rec = self._index[oid]
+ packmark[oid] = rec
+ rootl.extend(rec[3])
# Now delete any unreferenced entries:
for oid in index.keys():
- if not referenced(oid): del index[oid]
-
- finally: self._lock_release()
+ if not packmark.has_key(oid):
+ del index[oid]
+ finally:
+ self._lock_release()
def _splat(self):
"""Spit out a string showing state."""
- o=[]
+ o = []
o.append('Index:')
- index=self._index
- keys=index.keys()
+ keys = self._index.keys()
keys.sort()
for oid in keys:
- r=index[oid]
+ r = self._index[oid]
o.append(' %s: %s, %s' %
(utils.u64(oid),TimeStamp(r[:8]),`r[8:]`))
-
return "\n".join(o)