Commit 695f2ef4 authored by Guido van Rossum's avatar Guido van Rossum

Another bunch of small cleanups and fixes.

Open the cache later to avoid scanning it twice if a connection is
made right away.

ClientStorage.close() is now idempotent.

ClientStorage stores its addr argument as self._addr so the test suite
doesn't have to dig it out of the rpc manager to reopen the storage as
readonly.

Renamed some of the callbacks into the client for clarity:
begin -> beginVerify
end -> endVerify
invalidate -> invalidateVerify
Invalidate -> invalidateTrans
parent 365c17b6
This diff is collapsed.
...@@ -18,19 +18,16 @@ class ClientStorage: ...@@ -18,19 +18,16 @@ class ClientStorage:
self.rpc = rpc self.rpc = rpc
def beginVerify(self): def beginVerify(self):
self.rpc.callAsync('begin') self.rpc.callAsync('beginVerify')
# XXX must rename the two invalidate messages. I can never def invalidateVerify(self, args):
# remember which is which self.rpc.callAsync('invalidateVerify', args)
def invalidate(self, args):
self.rpc.callAsync('invalidate', args)
def Invalidate(self, args):
self.rpc.callAsync('Invalidate', args)
def endVerify(self): def endVerify(self):
self.rpc.callAsync('end') self.rpc.callAsync('endVerify')
def invalidateTrans(self, args):
self.rpc.callAsync('invalidateTrans', args)
def serialnos(self, arg): def serialnos(self, arg):
self.rpc.callAsync('serialnos', arg) self.rpc.callAsync('serialnos', arg)
......
...@@ -86,11 +86,11 @@ class StorageServer: ...@@ -86,11 +86,11 @@ class StorageServer:
l = self.connections[storage_id] = [] l = self.connections[storage_id] = []
l.append(proxy) l.append(proxy)
def invalidate(self, conn, storage_id, invalidated=(), info=0): def invalidate(self, conn, storage_id, invalidated=(), info=None):
for p in self.connections.get(storage_id, ()): for p in self.connections.get(storage_id, ()):
if invalidated and p is not conn: if invalidated and p is not conn:
p.client.Invalidate(invalidated) p.client.invalidateTrans(invalidated)
else: elif info is not None:
p.client.info(info) p.client.info(info)
def close_server(self): def close_server(self):
...@@ -108,11 +108,9 @@ class StorageServer: ...@@ -108,11 +108,9 @@ class StorageServer:
pass pass
def close(self, conn): def close(self, conn):
removed = 0
for sid, cl in self.connections.items(): for sid, cl in self.connections.items():
if conn.obj in cl: if conn.obj in cl:
cl.remove(conn.obj) cl.remove(conn.obj)
removed = 1
class ZEOStorage: class ZEOStorage:
"""Proxy to underlying storage for a single remote client.""" """Proxy to underlying storage for a single remote client."""
...@@ -130,7 +128,7 @@ class ZEOStorage: ...@@ -130,7 +128,7 @@ class ZEOStorage:
# any pending transaction. Not sure if this is the clearest way. # any pending transaction. Not sure if this is the clearest way.
if self._transaction is not None: if self._transaction is not None:
self.__storage.tpc_abort(self._transaction) self.__storage.tpc_abort(self._transaction)
self._transaction is None self._transaction = None
self._conn.close() self._conn.close()
def notifyConnected(self, conn): def notifyConnected(self, conn):
...@@ -240,9 +238,9 @@ class ZEOStorage: ...@@ -240,9 +238,9 @@ class ZEOStorage:
except: # except what? except: # except what?
return None return None
if os != s: if os != s:
self.client.invalidate((oid, '')) self.client.invalidateVerify((oid, ''))
elif osv != sv: elif osv != sv:
self.client.invalidate((oid, v)) self.client.invalidateVerify((oid, v))
def endZeoVerify(self): def endZeoVerify(self):
self.client.endVerify() self.client.endVerify()
...@@ -257,6 +255,8 @@ class ZEOStorage: ...@@ -257,6 +255,8 @@ class ZEOStorage:
t.start() t.start()
if wait is not None: if wait is not None:
return wait return wait
else:
return None
def _pack(self, t, delay): def _pack(self, t, delay):
try: try:
...@@ -277,7 +277,8 @@ class ZEOStorage: ...@@ -277,7 +277,8 @@ class ZEOStorage:
def new_oids(self, n=100): def new_oids(self, n=100):
"""Return a sequence of n new oids, where n defaults to 100""" """Return a sequence of n new oids, where n defaults to 100"""
if n < 0: if n <= 0:
# Always return at least one
n = 1 n = 1
return [self.__storage.new_oid() for i in range(n)] return [self.__storage.new_oid() for i in range(n)]
...@@ -374,6 +375,7 @@ class ZEOStorage: ...@@ -374,6 +375,7 @@ class ZEOStorage:
return d return d
else: else:
self.restart() self.restart()
return None
def _handle_waiting(self): def _handle_waiting(self):
while self.__storage._waiting: while self.__storage._waiting:
...@@ -495,7 +497,7 @@ class ImmediateCommitStrategy: ...@@ -495,7 +497,7 @@ class ImmediateCommitStrategy:
self.invalidated.append((oid, version)) self.invalidated.append((oid, version))
try: try:
nil = dump(newserial, 1) dump(newserial, 1)
except: except:
msg = "Couldn't pickle storage exception: %s" % repr(newserial) msg = "Couldn't pickle storage exception: %s" % repr(newserial)
slog(self.storage, msg, zLOG.ERROR) slog(self.storage, msg, zLOG.ERROR)
......
...@@ -119,10 +119,10 @@ class GenericTests(StorageTestBase.StorageTestBase, ...@@ -119,10 +119,10 @@ class GenericTests(StorageTestBase.StorageTestBase,
# XXX Needed to support ReadOnlyStorage tests. Ought to be a # XXX Needed to support ReadOnlyStorage tests. Ought to be a
# cleaner way. # cleaner way.
# Is this the only way to get the address? addr = self._storage._addr
addr = self._storage._rpc_mgr.addr[0][1]
self._storage.close() self._storage.close()
self._storage = ZEO.ClientStorage.ClientStorage(addr, read_only=1, self._storage = ZEO.ClientStorage.ClientStorage(addr,
read_only=read_only,
wait=1) wait=1)
def checkLargeUpdate(self): def checkLargeUpdate(self):
...@@ -130,7 +130,7 @@ class GenericTests(StorageTestBase.StorageTestBase, ...@@ -130,7 +130,7 @@ class GenericTests(StorageTestBase.StorageTestBase,
self._dostore(data=obj) self._dostore(data=obj)
def checkZEOInvalidation(self): def checkZEOInvalidation(self):
addr = self._storage._rpc_mgr.addr[0][1] addr = self._storage._addr
storage2 = ZEO.ClientStorage.ClientStorage(addr, wait=1, storage2 = ZEO.ClientStorage.ClientStorage(addr, wait=1,
min_disconnect_poll=0.1) min_disconnect_poll=0.1)
try: try:
......
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