[Zodb-checkins] SVN: ZODB/branches/3.8/src/ZEO/ClientStorage.py In
ClientStorage, There was a flag to record whether a connection is
Jim Fulton
jim at zope.com
Tue Jul 8 17:17:59 EDT 2008
Log message for revision 88123:
In ClientStorage, There was a flag to record whether a connection is
read_only. It was set when a connection was tested, before the
connection was attached t the storage. This made me wonder if the
flag and connection could get out of sync. Because of details of the
complex connection dance, it appears that the flag will have a usable
value, almost by accident. Ironically, if the storage was opened
read-only, this flag was set to true. This all seemed very fragile,
and probably a bug magnet. I refactored this so the flag is on the
connection, rather than the storage. I also arranged that if the
storage is opened read-only, the flag is True.
Changed:
U ZODB/branches/3.8/src/ZEO/ClientStorage.py
-=-
Modified: ZODB/branches/3.8/src/ZEO/ClientStorage.py
===================================================================
--- ZODB/branches/3.8/src/ZEO/ClientStorage.py 2008-07-08 18:51:04 UTC (rev 88122)
+++ ZODB/branches/3.8/src/ZEO/ClientStorage.py 2008-07-08 21:17:57 UTC (rev 88123)
@@ -251,8 +251,6 @@
# _is_read_only stores the constructor argument
self._is_read_only = read_only
- # _conn_is_read_only stores the status of the current connection
- self._conn_is_read_only = 0
self._storage = storage
self._read_only_fallback = read_only_fallback
self._username = username
@@ -454,7 +452,7 @@
"""
log2("Testing connection %r" % conn)
# TODO: Should we check the protocol version here?
- self._conn_is_read_only = 0
+ conn._is_read_only = self._is_read_only
stub = self.StorageServerStubClass(conn)
auth = stub.getAuthProtocol()
@@ -476,7 +474,7 @@
raise
log2("Got ReadOnlyError; trying again with read_only=1")
stub.register(str(self._storage), read_only=1)
- self._conn_is_read_only = 1
+ conn._is_read_only = True
return 0
def notifyConnected(self, conn):
@@ -674,12 +672,16 @@
def isReadOnly(self):
"""Storage API: return whether we are in read-only mode."""
if self._is_read_only:
- return 1
+ return True
else:
# If the client is configured for a read-write connection
- # but has a read-only fallback connection, _conn_is_read_only
- # will be True.
- return self._conn_is_read_only
+ # but has a read-only fallback connection, conn._is_read_only
+ # will be True. If self._connection is None, we'll behave as
+ # read_only
+ try:
+ return self._connection._is_read_only
+ except AttributeError:
+ return True
def _check_trans(self, trans):
"""Internal helper to check a transaction argument for sanity."""
More information about the Zodb-checkins
mailing list