Commit 95216790 authored by Julien Muchembled's avatar Julien Muchembled

neoctl: new 'print ids' command

parent b08a8600
...@@ -62,6 +62,8 @@ class AdminEventHandler(EventHandler): ...@@ -62,6 +62,8 @@ class AdminEventHandler(EventHandler):
master_node = self.app.master_node master_node = self.app.master_node
conn.answer(Packets.AnswerPrimary(master_node.getUUID())) conn.answer(Packets.AnswerPrimary(master_node.getUUID()))
askLastIDs = forward_ask(Packets.AskLastIDs)
askLastTransaction = forward_ask(Packets.AskLastTransaction)
addPendingNodes = forward_ask(Packets.AddPendingNodes) addPendingNodes = forward_ask(Packets.AddPendingNodes)
tweakPartitionTable = forward_ask(Packets.TweakPartitionTable) tweakPartitionTable = forward_ask(Packets.TweakPartitionTable)
setClusterState = forward_ask(Packets.SetClusterState) setClusterState = forward_ask(Packets.SetClusterState)
...@@ -90,7 +92,7 @@ class MasterEventHandler(EventHandler): ...@@ -90,7 +92,7 @@ class MasterEventHandler(EventHandler):
def dispatch(self, conn, packet, kw={}): def dispatch(self, conn, packet, kw={}):
if 'conn' in kw: if 'conn' in kw:
# expected answer # expected answer
if packet.isError(): if packet.isResponse():
packet.setId(kw['msg_id']) packet.setId(kw['msg_id'])
kw['conn'].answer(packet) kw['conn'].answer(packet)
else: else:
...@@ -126,3 +128,4 @@ class MasterEventHandler(EventHandler): ...@@ -126,3 +128,4 @@ class MasterEventHandler(EventHandler):
class MasterRequestEventHandler(EventHandler): class MasterRequestEventHandler(EventHandler):
""" This class handle all answer from primary master node""" """ This class handle all answer from primary master node"""
# XXX: to be deleted ?
...@@ -62,6 +62,18 @@ class MasterHandler(EventHandler): ...@@ -62,6 +62,18 @@ class MasterHandler(EventHandler):
state = self.app.getClusterState() state = self.app.getClusterState()
conn.answer(Packets.AnswerClusterState(state)) conn.answer(Packets.AnswerClusterState(state))
def askLastIDs(self, conn):
app = self.app
conn.answer(Packets.AnswerLastIDs(
app.tm.getLastOID(),
app.tm.getLastTID(),
app.pt.getID(),
app.backup_tid))
def askLastTransaction(self, conn):
conn.answer(Packets.AnswerLastTransaction(
self.app.getLastTransaction()))
def askNodeInformation(self, conn): def askNodeInformation(self, conn):
nm = self.app.nm nm = self.app.nm
node_list = [] node_list = []
......
...@@ -104,10 +104,6 @@ class ClientServiceHandler(MasterHandler): ...@@ -104,10 +104,6 @@ class ClientServiceHandler(MasterHandler):
else: else:
conn.answer(Packets.AnswerPack(False)) conn.answer(Packets.AnswerPack(False))
def askLastTransaction(self, conn):
conn.answer(Packets.AnswerLastTransaction(
self.app.getLastTransaction()))
def abortTransaction(self, conn, tid): def abortTransaction(self, conn, tid):
self.app.tm.remove(conn.getUUID(), tid) self.app.tm.remove(conn.getUUID(), tid)
...@@ -49,14 +49,6 @@ class StorageServiceHandler(BaseServiceHandler): ...@@ -49,14 +49,6 @@ class StorageServiceHandler(BaseServiceHandler):
if app.packing is not None: if app.packing is not None:
self.answerPack(conn, False) self.answerPack(conn, False)
def askLastIDs(self, conn):
app = self.app
conn.answer(Packets.AnswerLastIDs(
app.tm.getLastOID(),
app.tm.getLastTID(),
app.pt.getID(),
app.backup_tid))
def askUnfinishedTransactions(self, conn): def askUnfinishedTransactions(self, conn):
app = self.app app = self.app
if app.backup_tid: if app.backup_tid:
......
...@@ -16,12 +16,13 @@ ...@@ -16,12 +16,13 @@
from operator import itemgetter from operator import itemgetter
from .neoctl import NeoCTL, NotReadyException from .neoctl import NeoCTL, NotReadyException
from neo.lib.util import bin, p64 from neo.lib.util import bin, p64, u64
from neo.lib.protocol import uuid_str, ClusterStates, NodeTypes, \ from neo.lib.protocol import uuid_str, ClusterStates, NodeTypes, \
UUID_NAMESPACES, ZERO_TID UUID_NAMESPACES, ZERO_TID
action_dict = { action_dict = {
'print': { 'print': {
'ids': 'getLastIds',
'pt': 'getPartitionRowList', 'pt': 'getPartitionRowList',
'node': 'getNodeList', 'node': 'getNodeList',
'cluster': 'getClusterState', 'cluster': 'getClusterState',
...@@ -77,6 +78,17 @@ class TerminalNeoCTL(object): ...@@ -77,6 +78,17 @@ class TerminalNeoCTL(object):
for node_type, address, uuid, state in node_list) for node_type, address, uuid, state in node_list)
# Actual actions # Actual actions
def getLastIds(self, params):
"""
Get last ids.
"""
assert not params
r = self.neoctl.getLastIds()
if r[3]:
return "last_tid = 0x%x" % u64(self.neoctl.getLastTransaction())
return "last_oid = 0x%x\nlast_tid = 0x%x\nlast_ptid = %u" % (
u64(r[0]), u64(r[1]), r[2])
def getPartitionRowList(self, params): def getPartitionRowList(self, params):
""" """
Get a list of partition rows, bounded by min & max and involving Get a list of partition rows, bounded by min & max and involving
......
...@@ -59,3 +59,5 @@ class CommandEventHandler(EventHandler): ...@@ -59,3 +59,5 @@ class CommandEventHandler(EventHandler):
answerNodeList = __answer(Packets.AnswerNodeList) answerNodeList = __answer(Packets.AnswerNodeList)
answerClusterState = __answer(Packets.AnswerClusterState) answerClusterState = __answer(Packets.AnswerClusterState)
answerPrimary = __answer(Packets.AnswerPrimary) answerPrimary = __answer(Packets.AnswerPrimary)
answerLastIDs = __answer(Packets.AnswerLastIDs)
answerLastTransaction = __answer(Packets.AnswerLastTransaction)
...@@ -119,6 +119,18 @@ class NeoCTL(object): ...@@ -119,6 +119,18 @@ class NeoCTL(object):
raise RuntimeError(response) raise RuntimeError(response)
return response[1] return response[1]
def getLastIds(self):
response = self.__ask(Packets.AskLastIDs())
if response[0] != Packets.AnswerLastIDs:
raise RuntimeError(response)
return response[1:]
def getLastTransaction(self):
response = self.__ask(Packets.AskLastTransaction())
if response[0] != Packets.AnswerLastTransaction:
raise RuntimeError(response)
return response[1]
def getNodeList(self, node_type=None): def getNodeList(self, node_type=None):
""" """
Get a list of nodes, filtering with given type. Get a list of nodes, filtering with given type.
......
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