[Zodb-checkins] SVN: ZODB/branches/3.9/src/ Applied the patch (slightly modified) from

Jim Fulton jim at zope.com
Sun Mar 7 14:54:59 EST 2010


Log message for revision 109789:
  Applied the patch (slightly modified) from
  
  https://bugs.launchpad.net/zodb/+bug/533015
  
  Much thanks to Hanno Schlichting and Nikolay Kim for coming up with
  the patch.
  

Changed:
  U   ZODB/branches/3.9/src/ZODB/tests/testConnection.py
  U   ZODB/branches/3.9/src/persistent/cPickleCache.c

-=-
Modified: ZODB/branches/3.9/src/ZODB/tests/testConnection.py
===================================================================
--- ZODB/branches/3.9/src/ZODB/tests/testConnection.py	2010-03-07 16:58:43 UTC (rev 109788)
+++ ZODB/branches/3.9/src/ZODB/tests/testConnection.py	2010-03-07 19:54:59 UTC (rev 109789)
@@ -662,11 +662,25 @@
         # 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, conn, cache = self.obj, self.conn, 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 != 0)
 
-
-
-
-
 # ---- stubs
 
 class StubObject(Persistent):

Modified: ZODB/branches/3.9/src/persistent/cPickleCache.c
===================================================================
--- ZODB/branches/3.9/src/persistent/cPickleCache.c	2010-03-07 16:58:43 UTC (rev 109788)
+++ ZODB/branches/3.9/src/persistent/cPickleCache.c	2010-03-07 19:54:59 UTC (rev 109789)
@@ -668,7 +668,8 @@
   PyObject *oid;
   cPersistentObject *v;
   unsigned int new_size;
-  if (!PyArg_ParseTuple(args, "OI:updateObjectSizeEstimation", &oid, &new_size))
+  if (!PyArg_ParseTuple(args, "OI:updateObjectSizeEstimation",
+                        &oid, &new_size))
     return NULL;
   /* Note: reference borrowed */
   v = (cPersistentObject *)PyDict_GetItem(self->data, oid);
@@ -680,8 +681,9 @@
       if (v->ring.r_next)
         {
           self->total_estimated_size += _estimated_size_in_bytes(
-               _estimated_size_in_24_bits(new_size) - v->estimated_size
-                                                                 );
+               (int)(_estimated_size_in_24_bits(new_size))
+                - (int)(v->estimated_size)
+               );
           /* we do this in "Connection" as we need it even when the
              object is not in the cache (or not the ring)
           */



More information about the Zodb-checkins mailing list