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