Commit 7f44cab0 authored by Jeremy Hylton's avatar Jeremy Hylton

Fix isReadOnly() to return True for a read-only fallback connection.

parent 914d5f53
...@@ -211,7 +211,10 @@ class ClientStorage: ...@@ -211,7 +211,10 @@ class ClientStorage:
self._pending_server = None self._pending_server = None
self._ready = threading.Event() self._ready = threading.Event()
# _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 = False
self._storage = storage self._storage = storage
self._read_only_fallback = read_only_fallback self._read_only_fallback = read_only_fallback
# _server_addr is used by sortKey() # _server_addr is used by sortKey()
...@@ -365,6 +368,7 @@ class ClientStorage: ...@@ -365,6 +368,7 @@ class ClientStorage:
""" """
log2(INFO, "Testing connection %r" % conn) log2(INFO, "Testing connection %r" % conn)
# XXX Check the protocol version here? # XXX Check the protocol version here?
self._conn_is_read_only = False
stub = self.StorageServerStubClass(conn) stub = self.StorageServerStubClass(conn)
try: try:
stub.register(str(self._storage), self._is_read_only) stub.register(str(self._storage), self._is_read_only)
...@@ -374,6 +378,7 @@ class ClientStorage: ...@@ -374,6 +378,7 @@ class ClientStorage:
raise raise
log2(INFO, "Got ReadOnlyError; trying again with read_only=1") log2(INFO, "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 = True
return 0 return 0
def notifyConnected(self, conn): def notifyConnected(self, conn):
...@@ -548,12 +553,14 @@ class ClientStorage: ...@@ -548,12 +553,14 @@ class ClientStorage:
return self._info['supportsTransactionalUndo'] return self._info['supportsTransactionalUndo']
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:
XXX In read-only fallback mode, this returns false, even if we return True
are currently connected to a read-only server. else:
""" # If the client is configured for a read-write connection
return self._is_read_only # but has a read-only fallback connection, _conn_is_read_only
# will be True.
return self._conn_is_read_only
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."""
......
...@@ -245,6 +245,7 @@ class ConnectionTests(CommonSetupTearDown): ...@@ -245,6 +245,7 @@ class ConnectionTests(CommonSetupTearDown):
self.startServer(create=0, index=0, ro_svr=1) self.startServer(create=0, index=0, ro_svr=1)
# Start a read-only-fallback client # Start a read-only-fallback client
self._storage = self.openClientStorage(read_only_fallback=1) self._storage = self.openClientStorage(read_only_fallback=1)
self.assert_(self._storage.isReadOnly())
# Stores should fail here # Stores should fail here
self.assertRaises(ReadOnlyError, self._dostore) self.assertRaises(ReadOnlyError, self._dostore)
......
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