[Zodb-checkins] CVS: Packages/ZEO - ClientStorage.py:1.26.4.5

jeremy@digicool.com jeremy@digicool.com
Fri, 30 Mar 2001 16:16:04 -0500 (EST)


Update of /cvs-repository/Packages/ZEO
In directory korak:/tmp/cvs-serv14082

Modified Files:
      Tag: ZEO-ZRPC-Dev
	ClientStorage.py 
Log Message:
XXX Update ClientStorage to work with Zope.  

It still doesn't work correctly, but is getting closer to full
functionality.

Remove _connected attr from ClientStorage.
Use __super_init to get at BaseStore.__init__ rather than using
    "inheritedAttribute".
Initialize _db.
"Fix" getName().  It's doesn't fail, but it doesn't say if the client
    is connected either.
Defer DisconnectedError to zrpc2, rather than raising in tpc_begin().
Reformat and rename invalidator code -- and import cPickle so that it
    works.



--- Updated File ClientStorage.py in package Packages/ZEO --
--- ClientStorage.py	2001/03/30 04:46:59	1.26.4.4
+++ ClientStorage.py	2001/03/30 21:16:02	1.26.4.5
@@ -91,6 +91,8 @@
 import zrpc2
 import ServerStub
 
+import cPickle
+
 from struct import pack, unpack
 from ZODB import POSException, BaseStorage
 from ZODB.TimeStamp import TimeStamp
@@ -109,8 +111,8 @@
     """The database storage is disconnected from the storage."""
 
 class ClientStorage(ExtensionClass.Base, BaseStorage.BaseStorage):
+    __super_init = BaseStorage.BaseStorage.__init__
 
-    _connected = 0 # XXX is this needed? can probably use self._server
     _server = None
 
     def __init__(self, addr, storage='1', cache_size=20000000,
@@ -136,11 +138,10 @@
         # XXX It's confusing to have _serial, _serials, and _seriald. 
         self._serials = []
         self._seriald = {}
-
-        ClientStorage.inheritedAttribute('__init__')(self, name)
 
-        self.__lock_acquire = self._lock_acquire # XXX
+        self.__super_init(name)
 
+        self._db = None
         self._cache = ClientCache.ClientCache(storage, cache_size,
                                               client=client, var=var) 
         self._cache.open() # XXX
@@ -149,13 +150,13 @@
                                                 #debug=debug,
                                                 tmin=min_disconnect_poll,
                                                 tmax=max_disconnect_poll)
-        # XXX make this method call the default CnMgr behavior
-        if not self._rpc_mgr.attempt_connect(callback=self.notifyConnected):
-            self._rpc_mgr.connect(callback=self.notifyConnected)
+        self._server = None
+        # XXX make this method call the default CnMgr behavior?
+        if not self._rpc_mgr.attempt_connect():
+            self._rpc_mgr.connect()
 
     def registerDB(self, db, limit):
-        """Register that the storage is controlled by the given DB.
-        """
+        """Register that the storage is controlled by the given DB."""
         self._db = db
 
     def notifyConnected(self, c):
@@ -164,7 +165,6 @@
         try:
             self._server = ServerStub.StorageServer(c)
 
-            self._connected = 1
             self._oids = []
 
             self._server.register(str(self._storage))
@@ -196,9 +196,6 @@
 
     def notifyDisconnected(self, ignored):
         LOG("ClientStorage", PROBLEM, "Disconnected from storage")
-        # XXX does this need to be called by ConnectionManager?
-        # oh yes!  need to release the lock
-        self._connected = 0
         self._transaction = None
         try:
             self._commit_lock_release()
@@ -249,8 +246,9 @@
             self._lock_release()
 
     def getName(self):
-        return "%s (%s)" % (self.__name__,
-                            self._connected and 'connected' or 'disconnected')
+        return "%s (%s)" % (self.__name__, "XXX")
+##                            # XXX self._connected is gone
+##                            self._connected and 'connected' or 'disconnected')
 
     def getSize(self):
         return self._info['size']
@@ -380,6 +378,8 @@
             self._lock_release()
 
     def tpc_begin(self, transaction):
+        # XXX plan is to have begin be a local operation until the
+        # vote stage.  
         self._lock_acquire()
         try:
             if self._transaction is transaction: return
@@ -401,26 +401,25 @@
                 id=`t`
                 
                 try:
-                    if not self._connected:
-                        raise ClientDisconnected("This action is temporarily "
-                                                 "unavailable.")
                     r = self._server.tpc_begin(id, user, desc, ext)
                 except:
                     self._commit_lock_release()
                     raise
                 
-                if r is None: break
+                if r is None:
+                    break
 
             # We have *BOTH* the local and distributed commit
             # lock, now we can actually get ready to get started.
-            self._serial=id
+            self._serial = id
             self._tfile.seek(0)
             self._seriald.clear()
             del self._serials[:]
 
-            self._transaction=transaction
+            self._transaction = transaction
             
-        finally: self._lock_release()
+        finally:
+            self._lock_release()
 
     def tpc_finish(self, transaction, f=None):
         self._lock_acquire()
@@ -540,23 +539,19 @@
         if self._pickler is None:
             return
         self._pickler.dump((0,0))
-        self._pickler.dump=None
+        self._pickler.dump = None
         self._tfile.seek(0)
-        load=cPickle.Unpickler(self._tfile).load
-        self._tfile=None
-
-        cinvalidate=self._cache.invalidate
-        dinvalidate=self._pickler.dumpb.invalidate
+        load = cPickle.Unpickler(self._tfile).load
+        self._tfile = None
 
         while 1:
             oid, version = load()
-            if not oid: break
-            cinvalidate(oid, version=version)
-            dinvalidate(oid, version=version)
+            if not oid:
+                break
+            self._cache.invalidate(oid, version=version)
+            self._db.invalidate(oid, version=version)
 
     def Invalidate(self, args):
-        cinvalidate=self._cache.invalidate
-        dinvalidate=self._pickler.dumpb.invalidate
         for oid, version in args:
-            cinvalidate(oid, version=version)
-            dinvalidate(oid, version=version)
+            self._cache.invalidate(oid, version=version)
+            self._db.invalidate(oid, version=version)