[Zodb-checkins] SVN: ZODB/branches/tseaver-python_picklecache-2/src/persistent/ Add a previously-ghosted object to the ring during mru().

Tres Seaver tseaver at palladion.com
Wed Feb 16 00:04:30 EST 2011


Log message for revision 120363:
  Add a previously-ghosted object to the ring during mru().

Changed:
  U   ZODB/branches/tseaver-python_picklecache-2/src/persistent/picklecache.py
  U   ZODB/branches/tseaver-python_picklecache-2/src/persistent/tests/test_picklecache.py

-=-
Modified: ZODB/branches/tseaver-python_picklecache-2/src/persistent/picklecache.py
===================================================================
--- ZODB/branches/tseaver-python_picklecache-2/src/persistent/picklecache.py	2011-02-16 05:04:26 UTC (rev 120362)
+++ ZODB/branches/tseaver-python_picklecache-2/src/persistent/picklecache.py	2011-02-16 05:04:29 UTC (rev 120363)
@@ -109,12 +109,18 @@
         while node is not self.ring and node.object._p_oid != oid:
             node = node.next
         if node is self.ring:
-            raise KeyError('Unknown OID: %s' % oid)
-        # remove from old location
-        node.prev.next, node.next.prev = node.next, node.prev
-        # splice into new
-        self.ring.prev.next, node.prev = node, self.ring.prev
-        self.ring.prev, node.next = node, self.ring
+            value = self.data[oid]
+            if value._p_state != GHOST:
+                self.non_ghost_count += 1
+                mru = self.ring.prev
+                self.ring.prev = node = RingNode(value, self.ring, mru)
+                mru.next = node
+        else:
+            # remove from old location
+            node.prev.next, node.next.prev = node.next, node.prev
+            # splice into new
+            self.ring.prev.next, node.prev = node, self.ring.prev
+            self.ring.prev, node.next = node, self.ring
         
     def ringlen(self):
         """ See IPickleCache.

Modified: ZODB/branches/tseaver-python_picklecache-2/src/persistent/tests/test_picklecache.py
===================================================================
--- ZODB/branches/tseaver-python_picklecache-2/src/persistent/tests/test_picklecache.py	2011-02-16 05:04:26 UTC (rev 120362)
+++ ZODB/branches/tseaver-python_picklecache-2/src/persistent/tests/test_picklecache.py	2011-02-16 05:04:29 UTC (rev 120363)
@@ -205,6 +205,40 @@
         self.assertEqual(items[1][0], 'three')
         self.assertEqual(items[2][0], 'two')
 
+    def test_mru_ghost(self):
+        from persistent.interfaces import UPTODATE
+        from persistent.interfaces import GHOST
+        cache = self._makeOne()
+        cache['one'] = self._makePersist(oid='one', state=UPTODATE)
+        two = cache['two'] = self._makePersist(oid='two', state=GHOST)
+        cache['three'] = self._makePersist(oid='three', state=UPTODATE)
+
+        cache.mru('two')
+
+        self.assertEqual(cache.ringlen(), 2)
+        items = cache.lru_items()
+        self.assertEqual(len(items), 2)
+        self.assertEqual(items[0][0], 'one')
+        self.assertEqual(items[1][0], 'three')
+
+    def test_mru_was_ghost_now_active(self):
+        from persistent.interfaces import UPTODATE
+        from persistent.interfaces import GHOST
+        cache = self._makeOne()
+        cache['one'] = self._makePersist(oid='one', state=UPTODATE)
+        two = cache['two'] = self._makePersist(oid='two', state=GHOST)
+        cache['three'] = self._makePersist(oid='three', state=UPTODATE)
+
+        two._p_state = UPTODATE
+        cache.mru('two')
+
+        self.assertEqual(cache.ringlen(), 3)
+        items = cache.lru_items()
+        self.assertEqual(len(items), 3)
+        self.assertEqual(items[0][0], 'one')
+        self.assertEqual(items[1][0], 'three')
+        self.assertEqual(items[2][0], 'two')
+
     def test_mru_first(self):
         from persistent.interfaces import UPTODATE
         cache = self._makeOne()



More information about the Zodb-checkins mailing list