Commit 29cb71f0 authored by Christian Theune's avatar Christian Theune

fix for #184057: make zeo filecache not fail for small sizes

parent 3bfaa547
...@@ -37,6 +37,9 @@ New Features ...@@ -37,6 +37,9 @@ New Features
Bugs Fixed Bugs Fixed
---------- ----------
- Fix for bug #184057: Make initialisation of small ZEO client file cache
sizes not fail.
- Fix for bug #184054: MappingStorage used to raise a KeyError during `load` - Fix for bug #184054: MappingStorage used to raise a KeyError during `load`
instead of a POSKeyError. instead of a POSKeyError.
......
...@@ -684,11 +684,11 @@ class FileCache(object): ...@@ -684,11 +684,11 @@ class FileCache(object):
# (and it sets self.f). # (and it sets self.f).
self.fpath = fpath self.fpath = fpath
self.f = None
if fpath and os.path.exists(fpath): if fpath and os.path.exists(fpath):
# Reuse an existing file. scan() will open & read it. # Reuse an existing file. scan() will open & read it.
self.f = None
logger.info("reusing persistent cache file %r", fpath) logger.info("reusing persistent cache file %r", fpath)
else: elif self.maxsize >= 12:
if fpath: if fpath:
self.f = open(fpath, 'wb+') self.f = open(fpath, 'wb+')
logger.info("created persistent cache file %r", fpath) logger.info("created persistent cache file %r", fpath)
......
...@@ -326,6 +326,107 @@ We can reset the stats by calling the `clearStats` method: ...@@ -326,6 +326,107 @@ We can reset the stats by calling the `clearStats` method:
>>> fc.getStats() >>> fc.getStats()
(0, 0, 0, 0, 0) (0, 0, 0, 0, 0)
Small file cache sizes
======================
The file cache requires a few bytes at the beginning of the file for itself.
Therefore cache sizes smaller than this threshold do not create a file and
will cause the cache to be disabled.
>>> obj_small = Object(key=(oid(1), tid(1)), data='#',
... start_tid=tid(1), end_tid=None)
>>> sizes = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 53, 54]
>>> for i in sizes: # doctest: +ELLIPSIS
... print "*" * 20
... print "Cache file size", i
... try:
... fc = FileCache(maxsize=i, fpath=None, parent=cache_dummy)
... except Exception, v:
... print i, v
... continue
... print "Added", fc.add(obj_small)
... print "Length", len(fc)
... print "Content", list(fc)
... print "Statistics", fc.getStats()
********************
Cache file size 0
Added False
Length 0
Content []
Statistics (0, 0, 0, 0, 0)
********************
Cache file size 1
Added False
Length 0
Content []
Statistics (0, 0, 0, 0, 0)
********************
Cache file size 2
Added False
Length 0
Content []
Statistics (0, 0, 0, 0, 0)
********************
Cache file size 3
Added False
Length 0
Content []
Statistics (0, 0, 0, 0, 0)
********************
Cache file size 4
Added False
Length 0
Content []
Statistics (0, 0, 0, 0, 0)
********************
Cache file size 5
Added False
Length 0
Content []
Statistics (0, 0, 0, 0, 0)
********************
Cache file size 6
Added False
Length 0
Content []
Statistics (0, 0, 0, 0, 0)
********************
Cache file size 7
Added False
Length 0
Content []
Statistics (0, 0, 0, 0, 0)
********************
Cache file size 8
Added False
Length 0
Content []
Statistics (0, 0, 0, 0, 0)
********************
Cache file size 9
Added False
Length 0
Content []
Statistics (0, 0, 0, 0, 0)
********************
Cache file size 10
Added False
Length 0
Content []
Statistics (0, 0, 0, 0, 0)
********************
Cache file size 53
Added False
Length 0
Content []
Statistics (0, 0, 0, 0, 0)
********************
Cache file size 54
Added True
Length 1
Content [<ZEO.cache.Entry object at 0x...>]
Statistics (1, 42, 0, 0, 0)
Cleanup Cleanup
======= =======
......
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