Commit a245abee authored by Jim Fulton's avatar Jim Fulton

Cleaned up whitespace and try to avoid a close race.

parent f65ea6d8
...@@ -39,19 +39,19 @@ from ZODB.utils import p64, u64, z64 ...@@ -39,19 +39,19 @@ from ZODB.utils import p64, u64, z64
logger = logging.getLogger("ZEO.cache") logger = logging.getLogger("ZEO.cache")
# A disk-based cache for ZEO clients. # A disk-based cache for ZEO clients.
# #
# This class provides an interface to a persistent, disk-based cache # This class provides an interface to a persistent, disk-based cache
# used by ZEO clients to store copies of database records from the # used by ZEO clients to store copies of database records from the
# server. # server.
# #
# The details of the constructor as unspecified at this point. # The details of the constructor as unspecified at this point.
# #
# Each entry in the cache is valid for a particular range of transaction # Each entry in the cache is valid for a particular range of transaction
# ids. The lower bound is the transaction that wrote the data. The # ids. The lower bound is the transaction that wrote the data. The
# upper bound is the next transaction that wrote a revision of the # upper bound is the next transaction that wrote a revision of the
# object. If the data is current, the upper bound is stored as None; # object. If the data is current, the upper bound is stored as None;
# the data is considered current until an invalidate() call is made. # the data is considered current until an invalidate() call is made.
# #
# It is an error to call store() twice with the same object without an # It is an error to call store() twice with the same object without an
# intervening invalidate() to set the upper bound on the first cache # intervening invalidate() to set the upper bound on the first cache
# entry. Perhaps it will be necessary to have a call the removes # entry. Perhaps it will be necessary to have a call the removes
...@@ -59,12 +59,12 @@ logger = logging.getLogger("ZEO.cache") ...@@ -59,12 +59,12 @@ logger = logging.getLogger("ZEO.cache")
# entry. # entry.
# Cache verification # Cache verification
# #
# When the client is connected to the server, it receives # When the client is connected to the server, it receives
# invalidations every time an object is modified. When the client is # invalidations every time an object is modified. When the client is
# disconnected then reconnects, it must perform cache verification to make # disconnected then reconnects, it must perform cache verification to make
# sure its cached data is synchronized with the storage's current state. # sure its cached data is synchronized with the storage's current state.
# #
# quick verification # quick verification
# full verification # full verification
# #
...@@ -206,7 +206,7 @@ class ClientCache(object): ...@@ -206,7 +206,7 @@ class ClientCache(object):
self.f = tempfile.TemporaryFile() self.f = tempfile.TemporaryFile()
self.f.write(magic+z64) self.f.write(magic+z64)
logger.info("created temporary cache file %r", self.f.name) logger.info("created temporary cache file %r", self.f.name)
self._initfile(fsize) self._initfile(fsize)
# Statistics: _n_adds, _n_added_bytes, # Statistics: _n_adds, _n_added_bytes,
...@@ -328,7 +328,7 @@ class ClientCache(object): ...@@ -328,7 +328,7 @@ class ClientCache(object):
seek(block_size-5, 1) seek(block_size-5, 1)
sync(self.f) sync(self.f)
# There is always data to read and # There is always data to read and
assert last and status in ' f1234' assert last and status in ' f1234'
first_free_offset = last first_free_offset = last
else: else:
...@@ -358,7 +358,7 @@ class ClientCache(object): ...@@ -358,7 +358,7 @@ class ClientCache(object):
except KeyError: except KeyError:
logger.error("Couldn't find non-current %r", (oid, tid)) logger.error("Couldn't find non-current %r", (oid, tid))
def clearStats(self): def clearStats(self):
self._n_adds = self._n_added_bytes = 0 self._n_adds = self._n_added_bytes = 0
self._n_evicts = self._n_evicted_bytes = 0 self._n_evicts = self._n_evicted_bytes = 0
...@@ -379,10 +379,12 @@ class ClientCache(object): ...@@ -379,10 +379,12 @@ class ClientCache(object):
# Close the underlying file. No methods accessing the cache should be # Close the underlying file. No methods accessing the cache should be
# used after this. # used after this.
def close(self): def close(self):
if self.f: f = self.f
sync(self.f) self.f = None
self.f.close() if f is not None:
self.f = None sync(f)
f.close()
if hasattr(self,'_lock_file'): if hasattr(self,'_lock_file'):
self._lock_file.close() self._lock_file.close()
...@@ -479,7 +481,7 @@ class ClientCache(object): ...@@ -479,7 +481,7 @@ class ClientCache(object):
data = read(ldata) data = read(ldata)
assert len(data) == ldata, (ofs, self.f.tell(), oid, len(data), ldata) assert len(data) == ldata, (ofs, self.f.tell(), oid, len(data), ldata)
assert read(8) == oid, (ofs, self.f.tell(), oid) assert read(8) == oid, (ofs, self.f.tell(), oid)
self._n_accesses += 1 self._n_accesses += 1
self._trace(0x22, oid, tid, end_tid, ldata) self._trace(0x22, oid, tid, end_tid, ldata)
...@@ -517,11 +519,11 @@ class ClientCache(object): ...@@ -517,11 +519,11 @@ class ClientCache(object):
data = read(ldata) data = read(ldata)
assert len(data) == ldata, (ofs, self.f.tell()) assert len(data) == ldata, (ofs, self.f.tell())
assert read(8) == oid, (ofs, self.f.tell(), oid) assert read(8) == oid, (ofs, self.f.tell(), oid)
if end_tid < before_tid: if end_tid < before_tid:
self._trace(0x24, oid, "", before_tid) self._trace(0x24, oid, "", before_tid)
return None return None
self._n_accesses += 1 self._n_accesses += 1
self._trace(0x26, oid, "", saved_tid) self._trace(0x26, oid, "", saved_tid)
return data, saved_tid, end_tid return data, saved_tid, end_tid
...@@ -613,7 +615,7 @@ class ClientCache(object): ...@@ -613,7 +615,7 @@ class ClientCache(object):
else: else:
self.current[oid] = ofs self.current[oid] = ofs
self._trace(0x52, oid, start_tid, dlen=len(data)) self._trace(0x52, oid, start_tid, dlen=len(data))
self.currentofs += size self.currentofs += size
## ##
...@@ -635,7 +637,7 @@ class ClientCache(object): ...@@ -635,7 +637,7 @@ class ClientCache(object):
# to threading issues, that when applying a local # to threading issues, that when applying a local
# invalidation after a store, that later invalidations from # invalidation after a store, that later invalidations from
# the server may already have arrived. # the server may already have arrived.
@locked @locked
def invalidate(self, oid, tid, server_invalidation=True): def invalidate(self, oid, tid, server_invalidation=True):
if tid is not None: if tid is not None:
...@@ -750,7 +752,7 @@ class ClientCache(object): ...@@ -750,7 +752,7 @@ class ClientCache(object):
except: except:
print `tid`, `end_tid` print `tid`, `end_tid`
raise raise
self._trace = _trace self._trace = _trace
_trace(0x00) _trace(0x00)
......
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