[Zodb-checkins] CVS: ZODB3/ZEO - ClientCache.py:1.30.2.4
Guido van Rossum
guido@python.org
Thu, 29 Aug 2002 11:42:35 -0400
Update of /cvs-repository/ZODB3/ZEO
In directory cvs.zope.org:/tmp/cvs-serv31136
Modified Files:
Tag: zeo_trace_branch
ClientCache.py
Log Message:
Move the trace support to the end of the class and rename it to have a
leading underscore (indicating that it is not a public API of the
class).
=== ZODB3/ZEO/ClientCache.py 1.30.2.3 => 1.30.2.4 ===
--- ZODB3/ZEO/ClientCache.py:1.30.2.3 Wed Aug 28 17:36:37 2002
+++ ZODB3/ZEO/ClientCache.py Thu Aug 29 11:42:34 2002
@@ -186,7 +186,7 @@
self._limit = size / 2
self._current = current
- self.setup_trace()
+ self._setup_trace()
def open(self):
# Two tasks:
@@ -219,37 +219,6 @@
except OSError:
pass
- def setup_trace(self):
- # See if cache tracing is requested through $ZEO_CACHE_TRACE.
- # If not, or if we can't write to the trace file,
- # disable tracing by setting self.trace to a dummy function.
- self._tracefile = None
- tfn = os.environ.get("ZEO_CACHE_TRACE")
- if tfn:
- try:
- self._tracefile = open(tfn, "a")
- self._tracefile.write("\n") # Force start of new line
- self.trace("Tracefile %s" % time.ctime(time.time()))
- except IOError:
- self._tracefile = None
- if self._tracefile is None:
- def notrace(msg, oid=None, version=None, serial=None, data=None):
- pass
- self.trace = notrace
-
- def trace(self, msg, oid=None, version=None, serial=None, data=None):
- # When tracing is disabled, this method is hidden by a dummy.
- parts = ["%14.3f" % time.time(), "%d" % self._current, msg]
- if oid is not None:
- parts.append("%016x" % U64(oid))
- if version is not None:
- parts.append("v=%r" % version)
- if serial is not None:
- parts.append("s=%016x" % U64(serial))
- if data is not None:
- parts.append("n=%d" % len(data))
- self._tracefile.write(" ".join(parts) + "\n")
-
def verify(self, verifyFunc):
"""Call the verifyFunc on every object in the cache.
@@ -263,7 +232,7 @@
try:
p = self._get(oid, None)
if p is None:
- self.trace("inva miss", oid, version)
+ self._trace("inva miss", oid, version)
return None
f = self._f[p < 0]
ap = abs(p)
@@ -283,11 +252,11 @@
return None
f.seek(p+8) # Switch from reading to writing
if version and h[15:19] != '\0\0\0\0':
- self.trace("inva upda", oid, version)
+ self._trace("inva upda", oid, version)
# There's still relevant non-version data in the cache record
f.write('n')
else:
- self.trace("inva dele", oid, version)
+ self._trace("inva dele", oid, version)
del self._index[oid]
f.write('i')
finally:
@@ -298,7 +267,7 @@
try:
p = self._get(oid, None)
if p is None:
- self.trace("load miss", oid, version)
+ self._trace("load miss", oid, version)
return None
f = self._f[p < 0]
ap = abs(p)
@@ -319,21 +288,21 @@
if h[8]=='n':
if version:
- self.trace("load inva", oid, version)
+ self._trace("load inva", oid, version)
return None
if not dlen:
# XXX This shouldn't actually happen
- self.trace("load dele", oid, version)
+ self._trace("load dele", oid, version)
del self._index[oid]
return None
if not vlen or not version:
if dlen:
data = read(dlen)
- self.trace("load hit ", oid, version, h[19:], data)
+ self._trace("load hit ", oid, version, h[19:], data)
return data, h[19:]
else:
- self.trace("load nove", oid, version)
+ self._trace("load nove", oid, version)
return None
if dlen:
@@ -344,16 +313,16 @@
if dlen:
seek(p+27)
data = read(dlen)
- self.trace("load nvhi", oid, version, h[19:], data)
+ self._trace("load nvhi", oid, version, h[19:], data)
return data, h[19:]
else:
- self.trace("load vmis", oid, version)
+ self._trace("load vmis", oid, version)
return None
vdlen = unpack(">i", vheader[-4:])[0]
vdata = read(vdlen)
vserial = read(8)
- self.trace("load vhit", oid, version, vserial, vdata)
+ self._trace("load vhit", oid, version, vserial, vdata)
return vdata, vserial
finally:
self._release()
@@ -363,7 +332,7 @@
try:
if version:
# We need to find and include non-version data
- self.trace("upda vers", oid, version, serial, data)
+ self._trace("upda vers", oid, version, serial, data)
p = self._get(oid, None)
if p is None:
return self._store(oid, '', '', version, data, serial)
@@ -390,7 +359,7 @@
self._store(oid, nvdata, nvserial, version, data, serial)
else:
# Simple case, just store new data:
- self.trace("upda nove", oid, version, serial, data)
+ self._trace("upda nove", oid, version, serial, data)
self._store(oid, data, serial, '', None, None)
finally:
self._release()
@@ -404,7 +373,7 @@
try:
p = self._get(oid, None)
if p is None:
- self.trace("modV miss", oid)
+ self._trace("modV miss", oid)
return None
f = self._f[p < 0]
ap = abs(p)
@@ -424,15 +393,15 @@
return None
if h[8] == 'n':
- self.trace("modV unkn", oid)
+ self._trace("modV unkn", oid)
return None
if not vlen:
- self.trace("modV nove", oid, '')
+ self._trace("modV nove", oid, '')
return ''
seek(dlen, 1)
version = read(vlen)
- self.trace("modV vers", oid, version)
+ self._trace("modV vers", oid, version)
return version
finally:
self._release()
@@ -445,7 +414,7 @@
if self._pos + size > self._limit:
current = not self._current
self._current = current
- self.trace("Flip-file %s" % time.ctime(time.time()))
+ self._trace("Flip-file %s" % time.ctime(time.time()))
log("flipping cache files. new current = %d" % current)
# Delete the half of the index that's no longer valid
index = self._index
@@ -475,9 +444,9 @@
def store(self, oid, p, s, version, pv, sv):
self._acquire()
if s:
- self.trace("stor nove", oid, version, s, p)
+ self._trace("stor nove", oid, version, s, p)
else:
- self.trace("stor vers", oid, version, sv, pv)
+ self._trace("stor vers", oid, version, sv, pv)
try:
self._store(oid, p, s, version, pv, sv)
finally:
@@ -514,6 +483,37 @@
self._index[oid] = self._pos
self._pos += tlen
+
+ def _setup_trace(self):
+ # See if cache tracing is requested through $ZEO_CACHE_TRACE.
+ # If not, or if we can't write to the trace file,
+ # disable tracing by setting self._trace to a dummy function.
+ self._tracefile = None
+ tfn = os.environ.get("ZEO_CACHE_TRACE")
+ if tfn:
+ try:
+ self._tracefile = open(tfn, "a")
+ self._tracefile.write("\n") # Force start of new line
+ self._trace("Tracefile %s" % time.ctime(time.time()))
+ except IOError:
+ self._tracefile = None
+ if self._tracefile is None:
+ def notrace(*args):
+ pass
+ self._trace = notrace
+
+ def _trace(self, msg, oid=None, version=None, serial=None, data=None):
+ # When tracing is disabled, this method is hidden by a dummy.
+ parts = ["%14.3f" % time.time(), "%d" % self._current, msg]
+ if oid is not None:
+ parts.append("%016x" % U64(oid))
+ if version is not None:
+ parts.append("v=%r" % version)
+ if serial is not None:
+ parts.append("s=%016x" % U64(serial))
+ if data is not None:
+ parts.append("n=%d" % len(data))
+ self._tracefile.write(" ".join(parts) + "\n")
def read_index(index, serial, f, fileindex):
seek = f.seek