Commit 12cd6915 authored by Jim Fulton's avatar Jim Fulton

Clarified the return Value for lastTransaction in the case when

there aren't any transactions.  Now a string of 8 nulls (aka "z64")
is specified.
parent c1b08456
......@@ -21,6 +21,10 @@ Bugs fixed
- Objects added in transactions that were later aborted could have
_p_changed still set (https://bugs.launchpad.net/zodb/+bug/615758).
- Clarified the return Value for lastTransaction in the case when
there aren't any transactions. Now a string of 8 nulls (aka "z64")
is specified.
3.10.0b6 (2010-09-08)
=====================
......
......@@ -1343,7 +1343,7 @@ class ClientStorage(object):
if not self._cache:
logger.info("%s No verification necessary -- empty cache",
self.__name__)
if ltid and ltid != utils.z64:
if ltid != utils.z64:
self._cache.setLastTid(ltid)
self.finish_verification()
return "empty cache"
......@@ -1375,14 +1375,14 @@ class ClientStorage(object):
self.__name__, len(pair[1]))
self.finish_verification(pair)
return "quick verification"
elif ltid and ltid != utils.z64:
elif ltid != utils.z64:
# XXX Hm, to have gotten here, the cache is non-empty, but
# Hm, to have gotten here, the cache is non-empty, but
# it has no last tid. This doesn't seem like good situation.
# We shouldn't treat it so lightly.
# We'll have to verify the cache, if we're willing.
self._cache.setLastTid(ltid)
zope.event.notify(ZEO.interfaces.StaleCache(self))
# From this point on, we do not have complete information about
......
......@@ -15,6 +15,7 @@
import os
import time
from ZODB.utils import z64
##
# ZEO storage server.
......@@ -86,7 +87,7 @@ class StorageServer:
def lastTransaction(self):
# Not in protocol version 2.0.0; see __init__()
return self.rpc.call('lastTransaction')
return self.rpc.call('lastTransaction') or z64
##
# Return invalidations for all transactions after tid.
......
......@@ -926,11 +926,9 @@ class StorageServer:
# be good. :) Doing this allows clients that were up to
# date when a server was restarted to pick up transactions
# it subsequently missed.
self.invq[name] = [(storage.lastTransaction(), None)]
self.invq[name] = [(storage.lastTransaction() or z64, None)]
else:
self.invq[name] = list(
lastInvalidations(self.invq_bound)
)
self.invq[name] = list(lastInvalidations(self.invq_bound))
self.invq[name].reverse()
......
......@@ -473,13 +473,9 @@ class ClientCache(object):
##
# Return the last transaction seen by the cache.
# @return a transaction id
# @defreturn string, or None if no transaction is yet known
# @defreturn string, or 8 nulls if no transaction is yet known
def getLastTid(self):
tid = self.tid
if tid == z64:
return None
else:
return tid
return self.tid
##
# Return the current data record for oid.
......
......@@ -128,7 +128,7 @@ class MiscZEOTests:
addr = self._storage._addr
storage2 = ClientStorage(addr)
self.assert_(storage2.is_connected())
self.assertEquals(None, storage2.lastTransaction())
self.assertEquals(ZODB.utils.z64, storage2.lastTransaction())
storage2.close()
self._dostore()
......
......@@ -27,7 +27,7 @@ import ZODB.tests.util
import zope.testing.setupstack
import ZEO.cache
from ZODB.utils import p64, u64
from ZODB.utils import p64, u64, z64
n1 = p64(1)
n2 = p64(2)
......@@ -79,7 +79,7 @@ class CacheTests(ZODB.tests.util.TestCase):
ZODB.tests.util.TestCase.tearDown(self)
def testLastTid(self):
self.assertEqual(self.cache.getLastTid(), None)
self.assertEqual(self.cache.getLastTid(), z64)
self.cache.setLastTid(n2)
self.assertEqual(self.cache.getLastTid(), n2)
self.assertEqual(self.cache.getLastTid(), n2)
......
......@@ -39,7 +39,7 @@ class MappingStorage(object):
self.__name__ = name
self._data = {} # {oid->{tid->pickle}}
self._transactions = BTrees.OOBTree.OOBTree() # {tid->TransactionRecord}
self._ltid = None
self._ltid = ZODB.utils.z64
self._last_pack = None
_lock = threading.RLock()
self._lock_acquire = _lock.acquire
......@@ -129,8 +129,7 @@ class MappingStorage(object):
# ZODB.interfaces.IStorage
@ZODB.utils.locked(opened)
def lastTransaction(self):
if self._ltid is not None:
return self._ltid
return self._ltid
# ZODB.interfaces.IStorage
@ZODB.utils.locked(opened)
......
......@@ -532,7 +532,10 @@ class IStorage(Interface):
# transiently. It would be better to just have read-only errors.
def lastTransaction():
"""Return the id of the last committed transaction
"""Return the id of the last committed transaction.
If no transactions have been committed, return a string of 8
null (0) characters.
"""
def __len__():
......
......@@ -34,6 +34,8 @@ ZERO = '\0'*8
class BasicStorage:
def checkBasics(self):
self.assertEqual(self._storage.lastTransaction(), '\0'*8)
t = transaction.Transaction()
self._storage.tpc_begin(t)
self.assertRaises(POSException.StorageTransactionError,
......
......@@ -60,6 +60,8 @@ class MinimalMemoryStorage(BaseStorage, object):
# _cur maps oid to current tid
self._cur = {}
self._ltid = z64
def isCurrent(self, oid, serial):
return serial == self._cur[oid]
......
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