[Zope3-checkins] CVS: Zope3/lib/python/ZODB - utils.py:1.17 TmpStore.py:1.12 MappingStorage.py:1.13 IConnection.py:1.4 FileStorage.py:1.107 DB.py:1.56 Connection.py:1.89

Jeremy Hylton jeremy@zope.com
Tue, 3 Dec 2002 12:24:12 -0500


Update of /cvs-repository/Zope3/lib/python/ZODB
In directory cvs.zope.org:/tmp/cvs-serv2708/ZODB

Modified Files:
	utils.py TmpStore.py MappingStorage.py IConnection.py 
	FileStorage.py DB.py Connection.py 
Log Message:
Several small changes:

We now expect the Interface package to be present.
Define z64 in ZODB.utils and use it everywhere in place of having all
sorts of local definitions of "\0\0\0\0\0\0\0\0".
Remove __len__() and getSize() from MappingStorage.









=== Zope3/lib/python/ZODB/utils.py 1.16 => 1.17 ===
--- Zope3/lib/python/ZODB/utils.py:1.16	Mon Dec  2 16:15:10 2002
+++ Zope3/lib/python/ZODB/utils.py	Tue Dec  3 12:24:12 2002
@@ -15,6 +15,8 @@
 import struct
 import time
 
+z64 = "\0" * 8
+
 def p64(v):
     """Pack an integer or long into a 8-byte string"""
     return struct.pack(">Q", v)


=== Zope3/lib/python/ZODB/TmpStore.py 1.11 => 1.12 ===
--- Zope3/lib/python/ZODB/TmpStore.py:1.11	Mon Dec  2 15:22:38 2002
+++ Zope3/lib/python/ZODB/TmpStore.py	Tue Dec  3 12:24:12 2002
@@ -12,7 +12,7 @@
 # 
 ##############################################################################
 from ZODB import POSException
-from ZODB.utils import p64, u64, Set
+from ZODB.utils import p64, u64, Set, z64
 
 import tempfile
 
@@ -77,7 +77,7 @@
         self._file.seek(self._pos)
         l = len(data)
         if serial is None:
-            serial = '\0\0\0\0\0\0\0\0'
+            serial = z64
         self._file.write(oid + serial + p64(l))
         self._file.write(data)
         self._tindex[oid] = self._pos


=== Zope3/lib/python/ZODB/MappingStorage.py 1.12 => 1.13 ===
--- Zope3/lib/python/ZODB/MappingStorage.py:1.12	Tue Nov 26 12:41:21 2002
+++ Zope3/lib/python/ZODB/MappingStorage.py	Tue Dec  3 12:24:12 2002
@@ -93,6 +93,7 @@
 from ZODB import BaseStorage, POSException, utils
 from ZODB.Serialize import findrefs
 from ZODB.TimeStamp import TimeStamp
+from ZODB.utils import z64
 
 def DB(name="Mapping Storage",
        pool_size=7, cache_size=400, 
@@ -115,18 +116,6 @@
         # (e.g. a dbm file), you will need to get the maximum key and
         # save it as self._oid.  See dbmStorage.
 
-    def __len__(self):
-        return len(self._index)
-        
-    def getSize(self):
-        s=32
-        index=self._index
-        for oid in index.keys():
-            p=index[oid]
-            s=s+56+len(p)
-            
-        return s
-
     def load(self, oid, version):
         self._lock_acquire()
         try:
@@ -164,13 +153,12 @@
         for oid, p in self._tindex: index[oid]=p
 
     def pack(self, t):
-        
         self._lock_acquire()
         try:    
             # Build an index of *only* those objects reachable
             # from the root.
             index=self._index
-            rootl=['\0\0\0\0\0\0\0\0']
+            rootl = [z64]
             pop=rootl.pop
             pindex={}
             referenced=pindex.has_key
@@ -191,8 +179,7 @@
         finally: self._lock_release()
 
     def _splat(self):
-        """Spit out a string showing state.
-        """
+        """Spit out a string showing state."""
         o=[]
         o.append('Index:')
         index=self._index


=== Zope3/lib/python/ZODB/IConnection.py 1.3 => 1.4 ===
--- Zope3/lib/python/ZODB/IConnection.py:1.3	Tue Jul 16 18:32:43 2002
+++ Zope3/lib/python/ZODB/IConnection.py	Tue Dec  3 12:24:12 2002
@@ -11,11 +11,7 @@
 # FOR A PARTICULAR PURPOSE.
 # 
 ##############################################################################
-try:
-    from Interface import Interface
-except ImportError:
-    class Interface:
-        pass
+from Interface import Interface
 
 class IConnection(Interface):
     """Interface required of Connection by ZODB DB.
@@ -23,8 +19,8 @@
     The Connection also implements IPersistentDataManager.
     """
 
-    def reset():
-        """Reset the Connection."""
+    def reset(version):
+        """Reset connection to use specified version."""
 
     def getVersion():
         """Return the version that connection is using."""
@@ -44,3 +40,5 @@
     def close():
         pass
 
+    def cacheGC():
+        pass


=== Zope3/lib/python/ZODB/FileStorage.py 1.106 => 1.107 ===
--- Zope3/lib/python/ZODB/FileStorage.py:1.106	Mon Dec  2 17:46:37 2002
+++ Zope3/lib/python/ZODB/FileStorage.py	Tue Dec  3 12:24:12 2002
@@ -138,7 +138,7 @@
 from ZODB.Serialize import findrefs
 from ZODB.TimeStamp import TimeStamp, newTimeStamp
 from ZODB.lock_file import lock_file
-from ZODB.utils import p64, u64, cp
+from ZODB.utils import p64, u64, cp, z64
 
 try:
     from ZODB.fsIndex import fsIndex
@@ -148,7 +148,6 @@
 
 from zLOG import LOG, BLATHER, WARNING, ERROR, PANIC
 
-z64 = '\0'*8
 t32 = 1L << 32
 # the struct formats for the headers
 TRANS_HDR = ">8s8scHHH"


=== Zope3/lib/python/ZODB/DB.py 1.55 => 1.56 ===
--- Zope3/lib/python/ZODB/DB.py:1.55	Tue Nov 26 12:41:21 2002
+++ Zope3/lib/python/ZODB/DB.py	Tue Dec  3 12:24:12 2002
@@ -24,14 +24,13 @@
 from zLOG import LOG, ERROR
 from ZODB.Serialize import getDBRoot
 from ZODB.ZTransaction import Transaction
+from ZODB.utils import z64
 from Transaction import get_transaction
 
 from Transaction.IDataManager import IDataManager
 
 from types import StringType
 
-ROOT_KEY = "\0\0\0\0\0\0\0\0"
-
 class DB:
     """The Object Database
 
@@ -70,12 +69,12 @@
         self._storage = storage
         storage.registerDB(self)
         try:
-            storage.load(ROOT_KEY, "")
+            storage.load(z64, "")
         except KeyError:
             # Create the database's root in the storage if it doesn't exist
             t = Transaction(description="initial database creation")
             storage.tpc_begin(t)
-            storage.store(ROOT_KEY, None, getDBRoot(), '', t)
+            storage.store(z64, None, getDBRoot(), '', t)
             storage.tpc_vote(t)
             storage.tpc_finish(t)
 
@@ -111,6 +110,9 @@
 
     def abortVersion(self, version):
         AbortVersion(self, version)
+
+    # XXX I don't think the cache should be used via _cache.
+    # Not sure that both full sweep and minimize need to stay.
 
     def cacheFullSweep(self, value):
         self._connectionMap(lambda c: c._cache.full_sweep())


=== Zope3/lib/python/ZODB/Connection.py 1.88 => 1.89 ===
--- Zope3/lib/python/ZODB/Connection.py:1.88	Mon Dec  2 16:15:10 2002
+++ Zope3/lib/python/ZODB/Connection.py	Tue Dec  3 12:24:12 2002
@@ -50,10 +50,11 @@
 from ZODB.POSException import ConflictError, RollbackError
 from ZODB.Serialize import ConnectionObjectReader, \
      getClassMetadata, ObjectWriter
-from ZODB.utils import u64, Set
+from ZODB.utils import u64, Set, z64
 
 from Transaction import get_transaction
 from Persistence.Cache import Cache
+from Persistence.IPersistentDataManager import IPersistentDataManager
 from zLOG import LOG, ERROR, BLATHER, INFO, DEBUG
 
 import cPickle
@@ -82,7 +83,8 @@
     # Experimental. Other connections can register to be closed
     # when we close by putting something here.
 
-    __implements__ = IConnection
+    __implements__ = (IConnection,
+                      IPersistentDataManager)
 
     def __init__(self, db, version='', cache_size=400):
         self._db = db
@@ -112,7 +114,7 @@
             return self._version
 
     def root(self):
-        return self.__getitem__('\0\0\0\0\0\0\0\0')
+        return self.__getitem__(z64)
 
     def __getitem__(self, oid):
         # assume that a cache cannot store None as a valid object
@@ -129,7 +131,7 @@
         object._p_serial = serial
 
         self._cache[oid] = object
-        if oid == '\0\0\0\0\0\0\0\0':
+        if oid == z64:
             # Keep a reference to the root so that the pickle cache
             # won't evict it.  XXX Not sure if this is necessary.  If
             # the cache is LRU, it should know best if the root is needed.