Commit 3a14526f authored by Vincent Pelletier's avatar Vincent Pelletier

SQUASH Use MAX_TID as stand-in for "no known First TID"

This simplifies the code a lot.
parent 08ce5273
......@@ -239,8 +239,7 @@ class AdministrationHandler(MasterHandler):
app = self.app
if app.getLastTransaction() <= tid:
raise AnswerDenied("Truncating after last transaction does nothing")
first_tid = app.tm.getFirstTID()
if first_tid is None or first_tid > tid:
if app.tm.getFirstTID() > tid:
raise AnswerDenied("Truncating before first transaction is "
"probably not what you intended to do")
if app.pm.getApprovedRejected(add64(tid, 1))[0]:
......
......@@ -20,7 +20,7 @@ from struct import pack, unpack
from neo.lib import logging
from neo.lib.exception import ProtocolError
from neo.lib.handler import DelayEvent, EventQueue
from neo.lib.protocol import uuid_str, ZERO_OID, ZERO_TID
from neo.lib.protocol import uuid_str, ZERO_OID, ZERO_TID, MAX_TID
from neo.lib.util import dump, u64, addTID, tidFromTime
class Transaction(object):
......@@ -179,7 +179,7 @@ class TransactionManager(EventQueue):
self._ttid_dict = {}
self._last_oid = ZERO_OID
self._last_tid = ZERO_TID
self._first_tid = None
self._first_tid = MAX_TID
self._unlockPending = self._firstUnlockPending
# queue filled with ttids pointing to transactions with increasing tids
self._queue = deque()
......@@ -215,8 +215,7 @@ class TransactionManager(EventQueue):
return oid_list
def setFirstTID(self, tid):
first_tid = self._first_tid
if tid is not None and (first_tid is None or first_tid > tid):
if self._first_tid > tid:
self._first_tid = tid
def getFirstTID(self):
......
......@@ -770,14 +770,8 @@ class DatabaseManager(object):
"""
x = self._readable_set
if x:
getFirstTID = self._getFirstTID
min_tid = None
for partition in x:
tid = getFirstTID(partition)
if tid is not None and (min_tid is None or tid < min_tid):
min_tid = tid
if min_tid is not None:
return util.p64(min_tid)
return util.p64(min(map(self._getFirstTID, x)))
return MAX_TID
def _getLastTID(self, partition, max_tid=None):
"""Return tid of last transaction <= 'max_tid' in given 'partition'
......
......@@ -53,7 +53,7 @@ from .manager import MVCCDatabaseManager, splitOIDField
from neo.lib import logging, util
from neo.lib.exception import NonReadableCell, UndoPackError
from neo.lib.interfaces import implements
from neo.lib.protocol import CellStates, ZERO_OID, ZERO_TID, ZERO_HASH
from neo.lib.protocol import CellStates, ZERO_OID, ZERO_TID, ZERO_HASH, MAX_TID
class MysqlError(DatabaseFailure):
......@@ -464,6 +464,7 @@ class MySQLDatabaseManager(MVCCDatabaseManager):
if tid_list:
(tid, ), = tid_list
return tid
return util.u64(MAX_TID)
def _getLastTID(self, partition, max_tid=None):
x = "WHERE `partition`=%s" % partition
......
......@@ -28,7 +28,7 @@ from .manager import DatabaseManager, splitOIDField
from neo.lib import logging, util
from neo.lib.exception import NonReadableCell, UndoPackError
from neo.lib.interfaces import implements
from neo.lib.protocol import CellStates, ZERO_OID, ZERO_TID, ZERO_HASH
from neo.lib.protocol import CellStates, ZERO_OID, ZERO_TID, ZERO_HASH, MAX_TID
def unique_constraint_message(table, *columns):
c = sqlite3.connect(":memory:")
......@@ -344,11 +344,11 @@ class SQLiteDatabaseManager(DatabaseManager):
return self.query("SELECT * FROM pt")
def _getFirstTID(self, partition):
try:
return self.query("SELECT MIN(tid) FROM trans WHERE partition=?",
(partition,)).fetchone()[0]
except TypeError:
pass
tid = self.query("SELECT MIN(tid) FROM trans WHERE partition=?",
(partition,)).fetchone()[0]
if tid is None:
return util.u64(MAX_TID)
return tid
def _getLastTID(self, partition, max_tid=None):
x = self.query
......
......@@ -13,7 +13,7 @@ AnswerFetchObjects(?p64,?p64,{:})
AnswerFetchTransactions(?p64,[],?p64)
AnswerFinalTID(p64)
AnswerInformationLocked(p64)
AnswerLastIDs(?p64,?p64,?p64)
AnswerLastIDs(?p64,?p64,p64)
AnswerLastTransaction(p64)
AnswerLockedTransactions({p64:?p64})
AnswerMonitorInformation([?bin],[?bin],bin)
......
......@@ -183,7 +183,7 @@ class StorageDBTests(NeoUnitTestBase):
txn1, objs1 = self.getTransaction([oid1])
txn2, objs2 = self.getTransaction([oid2])
# nothing in database
self.assertEqual(self.db.getFirstTID(), None)
self.assertEqual(self.db.getFirstTID(), MAX_TID)
self.assertEqual(self.db.getLastIDs(), (None, None))
self.assertEqual(self.db.getUnfinishedTIDDict(), {})
self.assertEqual(self.db.getObject(oid1), None)
......
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