Commit e11618bf authored by Grégory Wisniewski's avatar Grégory Wisniewski

Rewrite computation of upper part of a new TID.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2235 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 2bdc8f14
...@@ -181,10 +181,13 @@ class TransactionManager(object): ...@@ -181,10 +181,13 @@ class TransactionManager(object):
def _nextTID(self): def _nextTID(self):
""" Compute the next TID based on the current time and check collisions """ """ Compute the next TID based on the current time and check collisions """
def make_upper(year, month, day, hour, minute):
return ((((year - 1900) * 12 + month - 1) * 31 \
+ day - 1) * 24 + hour) * 60 + minute
tm = time() tm = time()
gmt = gmtime(tm) gmt = gmtime(tm)
upper = ((((gmt.tm_year - 1900) * 12 + gmt.tm_mon - 1) * 31 \ upper = make_upper(gmt.tm_year, gmt.tm_mon, gmt.tm_mday, gmt.tm_hour,
+ gmt.tm_mday - 1) * 24 + gmt.tm_hour) * 60 + gmt.tm_min gmt.tm_min)
lower = int((gmt.tm_sec % 60 + (tm - int(tm))) / (60.0 / 65536.0 / 65536.0)) lower = int((gmt.tm_sec % 60 + (tm - int(tm))) / (60.0 / 65536.0 / 65536.0))
tid = pack('!LL', upper, lower) tid = pack('!LL', upper, lower)
if self._last_tid is not None and tid <= self._last_tid: if self._last_tid is not None and tid <= self._last_tid:
...@@ -193,9 +196,7 @@ class TransactionManager(object): ...@@ -193,9 +196,7 @@ class TransactionManager(object):
# This should not happen usually. # This should not happen usually.
d = datetime(gmt.tm_year, gmt.tm_mon, gmt.tm_mday, d = datetime(gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
gmt.tm_hour, gmt.tm_min) + timedelta(0, 60) gmt.tm_hour, gmt.tm_min) + timedelta(0, 60)
gmt.tm_hour, gmt.tm_min) \ upper = make_upper(d.year, d.month, d.day, d.hour, d.minute)
upper = ((((d.year - 1900) * 12 + d.month - 1) * 31 \
+ d.day - 1) * 24 + d.hour) * 60 + d.minute
lower = 0 lower = 0
else: else:
lower += 1 lower += 1
......
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