SVN: ZODB/branches/hannosch-lp533015-bytesizecache/src/ Apply the patch

Hanno Schlichting <[email protected]>
Newsgroups gmane.comp.python.zope.zodb.cvs
Message-ID <20100305233647.CD252941DB__34926.4367403977$1267832218$gmane$org@cvs.zope.org>
Log message for revision 109691:
  Apply the patch
  

Changed:
  U   ZODB/branches/hannosch-lp533015-bytesizecache/src/CHANGES.txt
  U   ZODB/branches/hannosch-lp533015-bytesizecache/src/ZODB/tests/testConnection.py
  U   ZODB/branches/hannosch-lp533015-bytesizecache/src/persistent/cPickleCache.c

-=-
Modified: ZODB/branches/hannosch-lp533015-bytesizecache/src/CHANGES.txt
===================================================================
--- ZODB/branches/hannosch-lp533015-bytesizecache/src/CHANGES.txt	2010-03-05 23:23:37 UTC (rev 109690)
+++ ZODB/branches/hannosch-lp533015-bytesizecache/src/CHANGES.txt	2010-03-05 23:36:47 UTC (rev 109691)
@@ -13,6 +13,13 @@
   help in situations where object ids are used as BTree keys and the
   sequential allocation of object ids leads to conflict errors.
 
+Bugs Fixed
+----------
+
+- The byte size limited pickle cache could overflow and effectively disable
+  the cache. (https://bugs.launchpad.net/zodb/+bug/533015)
+
+
 3.10.0a1 (2010-02-08)
 =====================
 

Modified: ZODB/branches/hannosch-lp533015-bytesizecache/src/ZODB/tests/testConnection.py
===================================================================
--- ZODB/branches/hannosch-lp533015-bytesizecache/src/ZODB/tests/testConnection.py	2010-03-05 23:23:37 UTC (rev 109690)
+++ ZODB/branches/hannosch-lp533015-bytesizecache/src/ZODB/tests/testConnection.py	2010-03-05 23:36:47 UTC (rev 109691)
@@ -685,11 +685,26 @@
         # sanity check
         self.assert_(cache.total_estimated_size >= 0)
 
+    def test_cache_garbage_collection_shrinking_object(self):
+        db = self.db
+        # activate size based cache garbage collection
+        db.setCacheSizeBytes(1000)
+        obj, cache = self.obj, self.conn._cache
+        # verify the change worked as expected
+        self.assertEqual(cache.cache_size_bytes, 1000)
+        # verify our entrance assumption is fullfilled
+        self.assert_(cache.total_estimated_size > 1)
+        # give the objects some size
+        obj.setValueWithSize(500)
+        transaction.savepoint()
+        self.assert_(cache.total_estimated_size > 500)
+        # make the object smaller
+        obj.setValueWithSize(100)
+        transaction.savepoint()
+        # make sure there was no overflow
+        self.assert_(cache.total_estimated_size <= 1000)
 
 
-
-
-
 # ---- stubs
 
 class StubObject(Persistent):

Modified: ZODB/branches/hannosch-lp533015-bytesizecache/src/persistent/cPickleCache.c
===================================================================
--- ZODB/branches/hannosch-lp533015-bytesizecache/src/persistent/cPickleCache.c	2010-03-05 23:23:37 UTC (rev 109690)
+++ ZODB/branches/hannosch-lp533015-bytesizecache/src/persistent/cPickleCache.c	2010-03-05 23:36:47 UTC (rev 109691)
@@ -667,7 +667,7 @@
 {
   PyObject *oid;
   cPersistentObject *v;
-  unsigned int new_size;
+  int new_size;
   if (!PyArg_ParseTuple(args, "OI:updateObjectSizeEstimation", &oid, &new_size))
     return NULL;
   /* Note: reference borrowed */
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.