[Zodb-checkins] SVN: ZODB/trunk/src/ fix for #184057: make zeo filecache not fail for small sizes

Christian Theune ct at gocept.com
Sat May 3 06:14:33 EDT 2008


Log message for revision 86166:
  fix for #184057: make zeo filecache not fail for small sizes
  

Changed:
  U   ZODB/trunk/src/CHANGES.txt
  U   ZODB/trunk/src/ZEO/cache.py
  U   ZODB/trunk/src/ZEO/tests/filecache.txt

-=-
Modified: ZODB/trunk/src/CHANGES.txt
===================================================================
--- ZODB/trunk/src/CHANGES.txt	2008-05-03 10:09:38 UTC (rev 86165)
+++ ZODB/trunk/src/CHANGES.txt	2008-05-03 10:14:32 UTC (rev 86166)
@@ -37,6 +37,9 @@
 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`
   instead of a POSKeyError.
 

Modified: ZODB/trunk/src/ZEO/cache.py
===================================================================
--- ZODB/trunk/src/ZEO/cache.py	2008-05-03 10:09:38 UTC (rev 86165)
+++ ZODB/trunk/src/ZEO/cache.py	2008-05-03 10:14:32 UTC (rev 86166)
@@ -684,11 +684,11 @@
         # (and it sets self.f).
 
         self.fpath = fpath
+        self.f = None
         if fpath and os.path.exists(fpath):
             # Reuse an existing file.  scan() will open & read it.
-            self.f = None
             logger.info("reusing persistent cache file %r", fpath)
-        else:
+        elif self.maxsize >= 12:
             if fpath:
                 self.f = open(fpath, 'wb+')
                 logger.info("created persistent cache file %r", fpath)

Modified: ZODB/trunk/src/ZEO/tests/filecache.txt
===================================================================
--- ZODB/trunk/src/ZEO/tests/filecache.txt	2008-05-03 10:09:38 UTC (rev 86165)
+++ ZODB/trunk/src/ZEO/tests/filecache.txt	2008-05-03 10:14:32 UTC (rev 86166)
@@ -326,7 +326,108 @@
   >>> fc.getStats()
   (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
 =======
 



More information about the Zodb-checkins mailing list