Commit e5b6e242 authored by Jim Fulton's avatar Jim Fulton

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.
parent 15d72c07
...@@ -251,8 +251,6 @@ class ClientStorage(object): ...@@ -251,8 +251,6 @@ class ClientStorage(object):
# _is_read_only stores the constructor argument # _is_read_only stores the constructor argument
self._is_read_only = read_only 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._storage = storage
self._read_only_fallback = read_only_fallback self._read_only_fallback = read_only_fallback
self._username = username self._username = username
...@@ -454,7 +452,7 @@ class ClientStorage(object): ...@@ -454,7 +452,7 @@ class ClientStorage(object):
""" """
log2("Testing connection %r" % conn) log2("Testing connection %r" % conn)
# TODO: Should we check the protocol version here? # 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) stub = self.StorageServerStubClass(conn)
auth = stub.getAuthProtocol() auth = stub.getAuthProtocol()
...@@ -476,7 +474,7 @@ class ClientStorage(object): ...@@ -476,7 +474,7 @@ class ClientStorage(object):
raise raise
log2("Got ReadOnlyError; trying again with read_only=1") log2("Got ReadOnlyError; trying again with read_only=1")
stub.register(str(self._storage), read_only=1) stub.register(str(self._storage), read_only=1)
self._conn_is_read_only = 1 conn._is_read_only = True
return 0 return 0
def notifyConnected(self, conn): def notifyConnected(self, conn):
...@@ -674,12 +672,16 @@ class ClientStorage(object): ...@@ -674,12 +672,16 @@ class ClientStorage(object):
def isReadOnly(self): def isReadOnly(self):
"""Storage API: return whether we are in read-only mode.""" """Storage API: return whether we are in read-only mode."""
if self._is_read_only: if self._is_read_only:
return 1 return True
else: else:
# If the client is configured for a read-write connection # If the client is configured for a read-write connection
# but has a read-only fallback connection, _conn_is_read_only # but has a read-only fallback connection, conn._is_read_only
# will be True. # will be True. If self._connection is None, we'll behave as
return self._conn_is_read_only # read_only
try:
return self._connection._is_read_only
except AttributeError:
return True
def _check_trans(self, trans): def _check_trans(self, trans):
"""Internal helper to check a transaction argument for sanity.""" """Internal helper to check a transaction argument for sanity."""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment