Commit 47f8e09b 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 597a68d9
...@@ -254,8 +254,6 @@ class ClientStorage(object): ...@@ -254,8 +254,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
...@@ -457,7 +455,7 @@ class ClientStorage(object): ...@@ -457,7 +455,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()
...@@ -479,7 +477,7 @@ class ClientStorage(object): ...@@ -479,7 +477,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):
...@@ -680,12 +678,16 @@ class ClientStorage(object): ...@@ -680,12 +678,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