[Zodb-checkins] CVS: ZODB3/ZEO/tests - ConnectionTests.py:1.15

Jeremy Hylton jeremy@zope.com
Tue, 14 Jan 2003 14:08:37 -0500


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

Modified Files:
	ConnectionTests.py 
Log Message:
Prevent client from using stale cache data while connecting.

XXX Maybe there should be an option to allow this.

A ZEO client can run in disconnected mode, using data from
its cache, or in connected mode.  Several instance variables
are related to whether the client is connected.

_server: All method calls are invoked through the server
   stub.  When not connect, set to disconnected_stub an
   object that raises ClientDisconnected errors.

_ready: A threading Event that is set only if _server
   is set to a real stub.

_connection: The current zrpc connection or None.

_connection is set as soon as a connection is established,
but _server is set only after cache verification has finished
and clients can safely use the server.  _pending_server holds
a server stub while it is being verified.

Before this change, a client could start using a connection before
verification finished.  If verification took a long time, it could
even commit a new transaction using a mixing of old and new data.


=== ZODB3/ZEO/tests/ConnectionTests.py 1.14 => 1.15 ===
--- ZODB3/ZEO/tests/ConnectionTests.py:1.14	Thu Jan  9 18:57:21 2003
+++ ZODB3/ZEO/tests/ConnectionTests.py	Tue Jan 14 14:08:34 2003
@@ -202,6 +202,7 @@
                 self._dostore()
                 break
             except Disconnected:
+                self._storage.sync()
                 time.sleep(0.5)
 
     def checkReadOnlyClient(self):
@@ -345,13 +346,15 @@
             try:
                 self._dostore(oid, data=obj)
                 break
-            except (Disconnected, select.error,
-                    threading.ThreadError, socket.error):
+            except Disconnected:
+                # Maybe the exception mess is better now
+##            except (Disconnected, select.error,
+##                    threading.ThreadError, socket.error):
                 zLOG.LOG("checkReconnection", zLOG.INFO,
                          "Error after server restart; retrying.",
                          error=sys.exc_info())
                 get_transaction().abort()
-                time.sleep(0.1) # XXX how long to sleep
+                self._storage.sync()
             # XXX This is a bloody pain.  We're placing a heavy burden
             # on users to catch a plethora of exceptions in order to
             # write robust code.  Need to think about implementing
@@ -564,9 +567,8 @@
             try:
                 self._dostore()
                 break
-            except (Disconnected, ReadOnlyError,
-                    select.error, threading.ThreadError, socket.error):
-                time.sleep(0.1)
+            except (Disconnected, ReadOnlyError):
+                self._storage.sync()
         else:
             self.fail("Couldn't store after starting a read-write server")