Commit d9dd39f0 authored by Iliya Manolov's avatar Iliya Manolov Committed by Julien Muchembled

neoctl: make 'print ids' command display time of TIDs

Currently, the command "neoctl [arguments] print ids" has the following output:

    last_oid = 0x...
    last_tid = 0x...
    last_ptid = ...

or

    backup_tid = 0x...
    last_tid = 0x...
    last_ptid = ...

depending on whether the cluster is in normal or backup mode.

This is extremely unreadable since the admin is often interested in the time that corresponds to each tid. Now the output is:

    last_oid = 0x...
    last_tid = 0x... (yyyy-mm-dd hh:mm:ss.ssssss)
    last_ptid = ...

or

    backup_tid = 0x... (yyyy-mm-dd hh:mm:ss.ssssss)
    last_tid = 0x... (yyyy-mm-dd hh:mm:ss.ssssss)
    last_ptid = ...

/reviewed-on nexedi/neoppod!2
parent eaa00a88
Pipeline #3104 skipped
......@@ -81,6 +81,16 @@ def unpackTID(ptid):
higher.reverse()
return (tuple(higher), lower)
def timeStringFromTID(ptid):
"""
Return a string in the format "yyyy-mm-dd hh:mm:ss.ssssss" from a TID
"""
higher, lower = unpackTID(ptid)
seconds = lower * SECOND_PER_TID_LOW
return '%04d-%02d-%02d %02d:%02d:%09.6f' % (higher[0], higher[1], higher[2],
higher[3], higher[4], seconds)
  • @Thetechguy, @jm I was going through persistent sources and there is already function for converting tid <-> time <-> string there:

    In [1]: from persistent.TimeStamp import TimeStamp
    
    In [8]: tid = '0285cbac258bf266'.decode('hex')
    
    In [9]: tid
    Out[9]: '\x02\x85\xcb\xac%\x8b\xf2f'
    
    In [10]: ts = TimeStamp(tid)
    
    In [11]: ts
    Out[11]: '\x02\x85\xcb\xac%\x8b\xf2f'
    
    In [12]: str(ts)
    Out[12]: '1979-01-03 21:00:08.800000'
    
    In [14]: ts.month()
    Out[14]: 1
    
    In [15]: ts.year()
    Out[15]: 1979
    
    In [16]: ts.timeTime()
    Out[16]: 284245208.8000002
    
    ...

    so when you have tid to print it what is only needed is "%s ..." % TimeStamp(tid)

    similarly for unpackTid / packTid maybe the out-of-the-box TimeStamp could be also reused.

    https://github.com/zopefoundation/persistent/blob/master/persistent/timestamp.py
    https://github.com/zopefoundation/persistent/blob/master/persistent/_timestamp.c

    Just FYI.

    /cc @vpelletier

  • True but this would add a dependency on persistent. Currently, only the client (and tests) depends on ZODB/persistent.

    That's the initial reason, before I came into the project.

Please register or sign in to reply
def addTID(ptid, offset):
"""
Offset given packed TID.
......
......@@ -16,7 +16,7 @@
from operator import itemgetter
from .neoctl import NeoCTL, NotReadyException
from neo.lib.util import p64, u64, tidFromTime
from neo.lib.util import p64, u64, tidFromTime, timeStringFromTID
from neo.lib.protocol import uuid_str, ClusterStates, NodeTypes, \
UUID_NAMESPACES, ZERO_TID
......@@ -89,11 +89,13 @@ class TerminalNeoCTL(object):
ptid, backup_tid, truncate_tid = self.neoctl.getRecovery()
if backup_tid:
ltid = self.neoctl.getLastTransaction()
r = "backup_tid = 0x%x" % u64(backup_tid)
r = "backup_tid = 0x%x (%s)" % (u64(backup_tid),
timeStringFromTID(backup_tid))
else:
loid, ltid = self.neoctl.getLastIds()
r = "last_oid = 0x%x" % u64(loid)
return r + "\nlast_tid = 0x%x\nlast_ptid = %u" % (u64(ltid), ptid)
r = "last_oid = 0x%x" % (u64(loid))
return r + "\nlast_tid = 0x%x (%s)\nlast_ptid = %u" % \
(u64(ltid), timeStringFromTID(ltid), ptid)
def getPartitionRowList(self, params):
"""
......@@ -311,4 +313,3 @@ class Application(object):
" e.g. '257684787499560686', '0x3937af2eeeeeeee' or '1325421296.'"
" for 2012-01-01 12:34:56 UTC")
return '\n'.join(output_list)
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