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

Jeremy Hylton jeremy@zope.com
Tue, 12 Nov 2002 14:49:50 -0500


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

Modified Files:
      Tag: ZODB3-deadlock-debug-branch
	StorageServer.py 
Log Message:
Remove TimeoutThread in anticipation of merge with release branches.


=== ZODB3/ZEO/StorageServer.py 1.74.2.3.2.3 => 1.74.2.3.2.4 ===
--- ZODB3/ZEO/StorageServer.py:1.74.2.3.2.3	Tue Nov 12 12:55:16 2002
+++ ZODB3/ZEO/StorageServer.py	Tue Nov 12 14:49:49 2002
@@ -25,7 +25,6 @@
 import os
 import sys
 import threading
-import time
 
 from ZEO import ClientStub
 from ZEO.CommitLog import CommitLog
@@ -212,13 +211,10 @@
         self.storage_id = "uninitialized"
         self.transaction = None
         self.read_only = read_only
-        self.timeout = TimeoutThread()
-        self.timeout.start()
 
     def notifyConnected(self, conn):
         self.connection = conn # For restart_other() below
         self.client = self.ClientStorageStubClass(conn)
-        self.timeout.notifyConnected(conn)
 
     def notifyDisconnected(self):
         # When this storage closes, we must ensure that it aborts
@@ -228,7 +224,6 @@
             self.abort()
         else:
             self.log("disconnected")
-        self.timeout.notifyDisconnected()
 
     def __repr__(self):
         tid = self.transaction and repr(self.transaction.id)
@@ -412,7 +407,6 @@
     def tpc_finish(self, id):
         if not self.check_tid(id):
             return
-        self.timeout.end()
         invalidated = self.strategy.tpc_finish()
         if invalidated:
             self.server.invalidate(self, self.storage_id,
@@ -424,7 +418,6 @@
     def tpc_abort(self, id):
         if not self.check_tid(id):
             return
-        self.timeout.end()
         strategy = self.strategy
         strategy.tpc_abort()
         self.transaction = None
@@ -477,7 +470,6 @@
                      "Clients waiting: %d." % len(self.storage._waiting))
             return d
         else:
-            self.timeout.begin()
             return self.restart()
 
     def dontwait(self):
@@ -513,7 +505,6 @@
         assert isinstance(old_strategy, DelayedCommitStrategy)
         self.strategy = ImmediateCommitStrategy(self.storage,
                                                 self.client)
-        self.timeout.begin()
         resp = old_strategy.restart(self.strategy)
         if delay is not None:
             delay.reply(resp)
@@ -747,80 +738,6 @@
             self.delay.error(sys.exc_info())
         else:
             self.delay.reply(result)
-
-class TimeoutThread(threading.Thread):
-    # A TimeoutThread is associated with a ZEOStorage.  It trackes
-    # how long transactions take to commit.  If a transaction takes
-    # too long, it will close the connection.
-
-    TIMEOUT = 30
-
-    def __init__(self):
-        threading.Thread.__init__(self)
-        self._lock = threading.Lock()
-        self._timestamp = None
-        self._conn = None
-
-    def begin(self):
-        self._lock.acquire()
-        try:
-            self._timestamp = time.time()
-        finally:
-            self._lock.release()
-
-    def end(self):
-        self._lock.acquire()
-        try:
-            self._timestamp = None
-        finally:
-            self._lock.release()
-
-    # There's a race here, but I hope it is harmless.
-
-    def notifyConnected(self, conn):
-        self._conn = conn
-
-    def notifyDisconnected(self):
-        self._conn = None
-
-    def run(self):
-        log("TimeoutThread created", zLOG.BLATHER)
-        timeout = self.TIMEOUT
-        while self._conn is not None:
-            time.sleep(timeout)
-            
-            self._lock.acquire()
-            try:
-                if self._timestamp is not None:
-                    deadline = self._timestamp + self.TIMEOUT
-                else:
-                    log("TimeoutThread no current transaction",
-                        zLOG.BLATHER)
-                    timeout = self.TIMEOUT
-                    continue
-            finally:
-                self._lock.release()
-                
-            timeout = deadline - time.time()
-            if deadline < time.time():
-                self._abort()
-                break
-            else:
-                elapsed = self.TIMEOUT - timeout
-                log("TimeoutThread transaction has %0.2f sec to complete"
-                    " (%.2f elapsed)" % (timeout, elapsed), zLOG.BLATHER)
-        log("TimeoutThread exiting.  Connection closed.", zLOG.BLATHER)
-
-    def _abort(self):
-        # It's possible for notifyDisconnected to remove the connection
-        # just before we use it.  I think that's harmless, since it means
-        # the connection was closed.
-        log("TimeoutThread aborting transaction", zLOG.WARNING)
-        try:
-            self._conn.close()
-        except AttributeError, msg:
-            log(msg)
-
 
 # Patch up class references
 StorageServer.ZEOStorageClass = ZEOStorage