[Zodb-checkins] CVS: ZODB3/ZEO1 - ClientCache.py:1.2
Guido van Rossum
guido@python.org
Wed, 28 Aug 2002 18:10:48 -0400
Update of /cvs-repository/ZODB3/ZEO1
In directory cvs.zope.org:/tmp/cvs-serv9856
Modified Files:
ClientCache.py
Log Message:
Fix the most egregious bugs (mirroring the fixes to ZEO2):
- Module docstring: document the persistent filenames correctly,
mention magic.
- __init__(): correct seek to read the first record's serial.
- invalidate(): correct seek reversing from reading to writing.
- checkSize(): when flipping the cache, delete the index entries that
are invalidated by this action.
- Normalize whitespace.
=== ZODB3/ZEO1/ClientCache.py 1.1.1.1 => 1.2 ===
--- ZODB3/ZEO1/ClientCache.py:1.1.1.1 Mon Aug 12 16:39:51 2002
+++ ZODB3/ZEO1/ClientCache.py Wed Aug 28 18:10:48 2002
@@ -2,20 +2,21 @@
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
-#
+#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
-#
+#
##############################################################################
"""Implement a client cache
-
-The cache is managed as two files, var/c0.zec and var/c1.zec.
-Each cache file is a sequence of records of the form:
+The cache is managed as two files, var/c<storage>-<client>-{0,1}.zec
+
+Each cache file has a 4-byte magic number followed by a sequence of
+records of the form:
oid -- 8-byte object id
@@ -117,12 +118,12 @@
if fi.read(4)==magic: # Minimal sanity
fi.seek(0,2)
if fi.tell() > 30:
- fi.seek(22)
+ fi.seek(23)
s[i]=fi.read(8)
# If we found a non-zero serial, then use the file
if s[i] != '\0\0\0\0\0\0\0\0': f[i]=fi
fi=None
-
+
# Whoever has the larger serial is the current
if s[1] > s[0]: current=1
elif s[0] > s[1]: current=0
@@ -174,7 +175,7 @@
f.seek(ap)
h=f.read(8)
if h != oid: return
- f.seek(8,1) # Dang, we shouldn't have to do this. Bad Solaris & NT
+ f.seek(p+8) # Switch from reading to writing
if version:
f.write('n')
else:
@@ -200,11 +201,11 @@
del self._index[oid]
return None
- if h[8]=='n':
+ if h[8]=='n':
if version: return None
if not dlen:
del self._index[oid]
- return None
+ return None
if not vlen or not version:
if dlen: return read(dlen), h[19:]
@@ -248,7 +249,7 @@
if dlen:
p=read(dlen)
s=h[19:]
- else:
+ else:
return self._store(oid, '', '', version, data, serial)
self._store(oid, p, s, version, data, serial)
@@ -290,6 +291,11 @@
if self._pos+size > self._limit:
current=not self._current
self._current=current
+ # Delete the half of the index that's no longer valid
+ index = self._index
+ for oid in index.keys():
+ if (index[oid] < 0) == current:
+ del index[oid]
if self._p[current] is not None:
# Persistent cache file:
# Note that due to permission madness, waaa,
@@ -308,7 +314,7 @@
self._f[current].write(magic)
self._pos=pos=4
finally: self._release()
-
+
def store(self, oid, p, s, version, pv, sv):
self._acquire()
@@ -386,14 +392,14 @@
# We have a record for this oid, but it was invalidated!
del serial[oid]
del index[oid]
-
-
+
+
pos=pos+tlen
f.seek(pos)
try: f.truncate()
except: pass
-
+
return pos
def main(files):