[Zodb-checkins] CVS: ZODB3/ZEO - StorageServer.py:1.83

Jeremy Hylton jeremy@zope.com
Mon, 6 Jan 2003 19:51:18 -0500


Update of /cvs-repository/ZODB3/ZEO
In directory cvs.zope.org:/tmp/cvs-serv20415

Modified Files:
	StorageServer.py 
Log Message:
Refactor ZEOStorage to remove the strategy classes.

The strategy classes stopped being useful, because the code had been
modified to always use one of the strategies.  The classes were left
behind because editing the code to use a single class was too much
work at the time.

Move all the logic back into ZEOStorage.  Rename non-public methods on
the class to start with _.  Use lambda: rather than getattr()() to
invoke the method that gets delayed waiting for the storage lock.


=== ZODB3/ZEO/StorageServer.py 1.82 => 1.83 === (401/501 lines abridged)
--- ZODB3/ZEO/StorageServer.py:1.82	Fri Jan  3 17:07:38 2003
+++ ZODB3/ZEO/StorageServer.py	Mon Jan  6 19:51:13 2003
@@ -97,6 +97,11 @@
             allowed, even if the storages are writable.  Note that
             pack() is considered a read-only operation.
 
+        invalidation_queue_size -- The storage server keeps a queue
+            of the objects modified by the last N transactions, where
+            N == invalidation_queue_size.  This queue is used to
+            speed client cache verification when a client disconnects
+            for a short period of time.
         """
 
         self.addr = addr
@@ -236,8 +241,6 @@
     # Classes we instantiate.  A subclass might override.
 
     ClientStorageStubClass = ClientStub.ClientStorage
-    DelayedCommitStrategyClass = None # patched up later
-    ImmediateCommitStrategyClass = None # patched up later
 
     def __init__(self, server, read_only=0):
         self.server = server
@@ -247,6 +250,7 @@
         self.storage_id = "uninitialized"
         self.transaction = None
         self.read_only = read_only
+        self.locked = 0
         self.log_label = _label
 
     def notifyConnected(self, conn):
@@ -265,7 +269,7 @@
         # any pending transaction.
         if self.transaction is not None:
             self.log("disconnected during transaction %s" % self.transaction)
-            self.abort()
+            self._abort()
         else:
             self.log("disconnected")
 
@@ -430,15 +434,15 @@
     def pack(self, time, wait=1):
         # Yes, you can pack a read-only server or storage!
         if wait:
-            return run_in_thread(self.pack_impl, time)
+            return run_in_thread(self._pack_impl, time)
         else:
             # If the client isn't waiting for a reply, start a thread
             # and forget about it.
-            t = threading.Thread(target=self.pack_impl, args=(time,))

[-=- -=- -=- 401 lines omitted -=- -=- -=-]

-    def abortVersion(self, src):
-        self.name = "abortVersion"
-        self.args = src,
-        return self.block()
-
-    def transactionalUndo(self, trans_id):
-        self.name = "transactionalUndo"
-        self.args = trans_id,
-        return self.block()
-
-    def restart(self, new_strategy):
-        # called by the storage when the storage is available
-        assert isinstance(new_strategy, ImmediateCommitStrategy)
-        new_strategy.tpc_begin(self.txn, self.tid, self.status)
-        loads, loader = self.log.get_loader()
-        for i in range(loads):
-            oid, serial, data, version = loader.load()
-            new_strategy.store(oid, serial, data, version)
-        meth = getattr(new_strategy, self.name)
-        return meth(*self.args)
-
-    def abort(self, zeo_storage):
-        # Delete (d, zeo_storage) from the _waiting list, if found.
-        waiting = self.storage._waiting
-        for i in range(len(waiting)):
-            d, z = waiting[i]
-            if z is zeo_storage:
-                del waiting[i]
-                break
+    def _restart_other(self, zeo_storage, delay):
+        # Return True if the server restarted.
+        # call the restart() method on the appropriate server.
+        try:
+            zeo_storage._restart(delay)
+        except:
+            self.log("Unexpected error handling waiting transaction",
+                     level=zLOG.WARNING, error=sys.exc_info())
+            zeo_storage.connection.close()
+            return 0
+        else:
+            return 1
 
 def run_in_thread(method, *args):
     t = SlowMethodThread(method, args)
@@ -842,5 +733,3 @@
 
 # Patch up class references
 StorageServer.ZEOStorageClass = ZEOStorage
-ZEOStorage.DelayedCommitStrategyClass = DelayedCommitStrategy
-ZEOStorage.ImmediateCommitStrategyClass = ImmediateCommitStrategy