Commit 0d82139d authored by Grégory Wisniewski's avatar Grégory Wisniewski

When building a protocol packet, the ID is now added by the connection

through notify(), ask() and answer() methods instead of addPacket directly.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@483 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 7544eb06
......@@ -57,10 +57,9 @@ class MonitoringEventHandler(BaseEventHandler):
# Should not happen.
raise RuntimeError('connection completed while not trying to connect')
p = protocol.requestNodeIdentification(conn.getNextId(), ADMIN_NODE_TYPE,
p = protocol.requestNodeIdentification(ADMIN_NODE_TYPE,
app.uuid, app.server[0], app.server[1], app.name)
conn.addPacket(p)
conn.expectMessage(msg_id)
conn.ask(p)
EventHandler.connectionCompleted(self, conn)
def connectionFailed(self, conn):
......@@ -172,9 +171,7 @@ class MonitoringEventHandler(BaseEventHandler):
app.uuid = your_uuid
# Ask a primary master.
p = protocol.askPrimaryMaster(conn.getNextId())
conn.addPacket(p)
conn.expectMessage(msg_id)
conn.ask(protocol.askPrimaryMaster())
def handleAnswerPrimaryMaster(self, conn, packet, primary_uuid,
known_master_list):
......
......@@ -85,11 +85,9 @@ class ConnectionPool(object):
logging.error('Connection to storage node %s failed', node)
return None
msg_id = conn.getNextId()
p = protocol.requestNodeIdentification(msg_id, CLIENT_NODE_TYPE,
app.uuid, addr[0], addr[1], app.name)
conn.addPacket(p)
conn.expectMessage(msg_id)
p = protocol.requestNodeIdentification(CLIENT_NODE_TYPE,
app.uuid, addr[0], addr[1], app.name)
msg_id = conn.ask(p)
app.dispatcher.register(conn, msg_id, app.getQueue())
finally:
conn.unlock()
......@@ -303,10 +301,7 @@ class Application(object):
conn = self.master_conn
conn.lock()
try:
msg_id = conn.getNextId()
p = protocol.askNewOIDs(msg_id, 25)
conn.addPacket(p)
conn.expectMessage(msg_id)
msg_id = conn.ask(protocol.askNewOIDs(25))
self.dispatcher.register(conn, msg_id, self.getQueue())
finally:
conn.unlock()
......@@ -362,10 +357,7 @@ class Application(object):
continue
try:
msg_id = conn.getNextId()
p = protocol.askObject(msg_id, oid, serial, tid)
conn.addPacket(p)
conn.expectMessage(msg_id)
msg_id = conn.ask(protocol.askObject(oid, serial, tid))
self.dispatcher.register(conn, msg_id, self.getQueue())
self.local_var.asked_object = 0
finally:
......@@ -467,10 +459,7 @@ class Application(object):
raise NEOStorageError("Connection to master node failed")
conn.lock()
try:
msg_id = conn.getNextId()
p = protocol.askNewTID(msg_id)
conn.addPacket(p)
conn.expectMessage(msg_id)
msg_id = conn.ask(protocol.askNewTID())
self.dispatcher.register(conn, msg_id, self.getQueue())
finally:
conn.unlock()
......@@ -511,11 +500,9 @@ class Application(object):
continue
try:
msg_id = conn.getNextId()
p = protocol.askStoreObject(msg_id, oid, serial, 1,
p = protocol.askStoreObject(oid, serial, 1,
checksum, compressed_data, self.local_var.tid)
conn.addPacket(p)
conn.expectMessage(msg_id)
msg_id = conn.ask(p)
self.dispatcher.register(conn, msg_id, self.getQueue())
self.local_var.object_stored = 0
finally:
......@@ -562,11 +549,9 @@ class Application(object):
continue
try:
msg_id = conn.getNextId()
p = protocol.askStoreTransaction(msg_id, self.local_var.tid,
p = protocol.askStoreTransaction(self.local_var.tid,
user, desc, ext, oid_list)
conn.addPacket(p)
conn.expectMessage(msg_id)
msg_id = msg = conn.ask(p)
self.dispatcher.register(conn, msg_id, self.getQueue())
self.local_var.txn_voted = False
finally:
......@@ -610,7 +595,7 @@ class Application(object):
if conn is None:
continue
try:
conn.addPacket(protocol.abortTransaction(conn.getNextId(), self.local_var.tid))
conn.notify(protocol.abortTransaction(self.local_var.tid))
finally:
conn.unlock()
......@@ -618,7 +603,7 @@ class Application(object):
conn = self.master_conn
conn.lock()
try:
conn.addPacket(protocol.abortTransaction(conn.getNextId(), self.local_var.tid))
conn.notify(protocol.abortTransaction(self.local_var.tid))
finally:
conn.unlock()
......@@ -639,10 +624,8 @@ class Application(object):
conn = self.master_conn
conn.lock()
try:
msg_id = conn.getNextId()
p = protocol.finishTransaction(msg_id, oid_list, self.local_var.tid)
conn.addPacket(p)
conn.expectMessage(msg_id, additional_timeout = 300)
p = protocol.finishTransaction(oid_list, self.local_var.tid)
msg_id = conn.ask(p)
self.dispatcher.register(conn, msg_id, self.getQueue())
finally:
conn.unlock()
......@@ -685,10 +668,8 @@ class Application(object):
continue
try:
msg_id = conn.getNextId()
p = protocol.askTransactionInformation(msg_id, transaction_id)
conn.addPacket(p)
conn.expectMessage(msg_id)
p = protocol.askTransactionInformation(transaction_id)
msg_id = conn.ask(p)
self.dispatcher.register(conn, msg_id, self.getQueue())
self.local_var.txn_info = 0
finally:
......@@ -761,10 +742,8 @@ class Application(object):
continue
try:
msg_id = conn.getNextId()
p = protocol.askTIDs(msg_id, first, last, INVALID_PARTITION)
conn.addPacket(p)
conn.expectMessage(msg_id)
p = protocol.askTIDs(first, last, INVALID_PARTITION)
msg_id = conn.ask(p)
self.dispatcher.register(conn, msg_id, self.getQueue())
finally:
conn.unlock()
......@@ -799,10 +778,8 @@ class Application(object):
continue
try:
msg_id = conn.getNextId()
p = protocol.askTransactionInformation(msg_id, tid)
conn.addPacket(p)
conn.expectMessage(msg_id)
p = protocol.askTransactionInformation(tid)
msg_id = conn.ask(p)
self.dispatcher.register(conn, msg_id, self.getQueue())
self.local_var.txn_info = 0
finally:
......@@ -854,10 +831,8 @@ class Application(object):
continue
try:
msg_id = conn.getNextId()
p = protocol.askObjectHistory(msg_id, oid, 0, length)
conn.addPacket(p)
conn.expectMessage(msg_id)
p = protocol.askObjectHistory(oid, 0, length)
msg_id = conn.ask(p)
self.dispatcher.register(conn, msg_id, self.getQueue())
self.local_var.history = None
finally:
......@@ -894,10 +869,8 @@ class Application(object):
continue
try:
msg_id = conn.getNextId()
p = protocol.askTransactionInformation(msg_id, serial)
conn.addPacket(p)
conn.expectMessage(msg_id)
p = protocol.askTransactionInformation(serial)
msg_id = conn.ask(p)
self.dispatcher.register(conn, msg_id, self.getQueue())
self.local_var.txn_info = None
finally:
......@@ -976,11 +949,9 @@ class Application(object):
conn.lock()
try:
msg_id = conn.getNextId()
p = protocol.requestNodeIdentification(msg_id, CLIENT_NODE_TYPE,
p = protocol.requestNodeIdentification(CLIENT_NODE_TYPE,
self.uuid, '0.0.0.0', 0, self.name)
conn.addPacket(p)
conn.expectMessage(msg_id)
msg_id = conn.ask(p)
self.dispatcher.register(conn, msg_id, self.getQueue())
finally:
conn.unlock()
......
......@@ -82,8 +82,7 @@ class BaseClientEventHandler(EventHandler):
ip_address, port = node.getServer()
node_list = [(STORAGE_NODE_TYPE, ip_address, port,
node.getUUID(), state)]
p = protocol.notifyNodeInformation(conn.getNextId(), node_list)
conn.addPacket(p)
conn.notify(protocol.notifyNodeInformation(node_list))
finally:
conn.unlock()
......@@ -149,10 +148,7 @@ class PrimaryBoostrapEventHandler(BaseClientEventHandler):
# Ask a primary master.
conn.lock()
try:
msg_id = conn.getNextId()
p = protocol.askPrimaryMaster(msg_id)
conn.addPacket(p)
conn.expectMessage(msg_id)
msg_id = conn.ask(protocol.askPrimaryMaster())
self.dispatcher.register(conn, msg_id, app.getQueue())
finally:
conn.unlock()
......
......@@ -287,7 +287,7 @@ class Connection(BaseConnection):
self.write_buf += packet.encode()
except ProtocolError, m:
logging.critical('trying to send a too big message')
return self.addPacket(protocol.internalError(packet.getId(), m[0]))
return self.addPacket(protocol.internalError(m[0]))
# If this is the first time, enable polling for writing.
if self.write_buf:
......@@ -320,6 +320,24 @@ class Connection(BaseConnection):
self.event_dict[msg_id] = event
self.em.addIdleEvent(event)
def notify(self, packet):
msg_id = self.getNextId()
packet.setId(msg_id)
self.addPacket(packet)
return msg_id
def ask(self, packet, timeout=5, additional_timeout=30):
msg_id = self.getNextId()
packet.setId(msg_id)
self.expectMessage(msg_id)
self.addPacket(packet)
return msg_id
def answer(self, packet, answer_to):
msg_id = answer_to.getId()
packet.setId(msg_id)
self.addPacket(packet)
def isServerConnection(self):
raise NotImplementedError
......
......@@ -63,11 +63,8 @@ class IdleEvent(object):
self._additional_timeout -= 5
conn.expectMessage(self._id, 5, self._additional_timeout)
# Start a keep-alive packet.
logging.info('sending a ping to %s:%d',
*(conn.getAddress()))
msg_id = conn.getNextId()
conn.addPacket(protocol.ping(msg_id))
conn.expectMessage(msg_id, 5, 0)
logging.info('sending a ping to %s:%d', *(conn.getAddress()))
conn.ask(protocol.ping(), 5, 0)
else:
conn.expectMessage(self._id, self._additional_timeout, 0)
return True
......
......@@ -83,7 +83,7 @@ class EventHandler(object):
logging.info('malformed packet %x from %s:%d: %s',
packet.getType(), conn.getAddress()[0],
conn.getAddress()[1], error_message)
conn.addPacket(protocol.protocolError(packet.getId(), error_message))
conn.send(protocol.protocolError(error_message))
conn.abort()
self.peerBroken(conn)
......@@ -110,7 +110,7 @@ class EventHandler(object):
else:
message = 'unexpected packet: ' + message
logging.info('%s', message)
conn.addPacket(protocol.protocolError(packet.getId(), message))
conn.send(protocol.protocolError(message))
conn.abort()
self.peerBroken(conn)
......@@ -134,7 +134,7 @@ class EventHandler(object):
def handlePing(self, conn, packet):
logging.info('got a ping packet; am I overloaded?')
conn.addPacket(protocol.pong(packet.getId()))
conn.answer(protocol.pong(), packet)
def handlePong(self, conn, packet):
pass
......
......@@ -189,8 +189,7 @@ class Application(object):
logging.info('I am the primary, so sending an announcement')
for conn in em.getConnectionList():
if isinstance(conn, ClientConnection):
p = protocol.announcePrimaryMaster(conn.getNextId())
conn.addPacket(p)
conn.notify(protocol.announcePrimaryMaster())
conn.abort()
closed = False
t = time()
......@@ -239,7 +238,7 @@ class Application(object):
# Ask all connected nodes to reelect a single primary master.
for conn in em.getConnectionList():
if isinstance(conn, ClientConnection):
conn.addPacket(protocol.reelectPrimaryMaster(conn.getNextId()))
conn.notify(protocol.reelectPrimaryMaster())
conn.abort()
# Wait until the connections are closed.
......@@ -295,14 +294,12 @@ class Application(object):
n = self.nm.getNodeByUUID(c.getUUID())
if n.getNodeType() in (MASTER_NODE_TYPE, STORAGE_NODE_TYPE, ADMIN_NODE_TYPE):
node_list = [(node_type, ip_address, port, uuid, state)]
p = protocol.notifyNodeInformation(c.getNextId(), node_list)
c.addPacket(p)
c.notify(protocol.notifyNodeInformation(node_list))
elif node.getNodeType() in (MASTER_NODE_TYPE, STORAGE_NODE_TYPE):
for c in self.em.getConnectionList():
if c.getUUID() is not None:
node_list = [(node_type, ip_address, port, uuid, state)]
p = protocol.notifyNodeInformation(c.getNextId(), node_list)
c.addPacket(p)
c.notify(protocol.notifyNodeInformation(node_list))
elif node.getNodeType() != ADMIN_NODE_TYPE:
raise RuntimeError('unknown node type')
......@@ -318,9 +315,9 @@ class Application(object):
start = 0
while size:
amt = min(10000, size)
p = protocol.notifyPartitionChanges(c.getNextId(), ptid,
p = protocol.notifyPartitionChanges(ptid,
cell_list[start:start+amt])
c.addPacket(p)
c.notify(p)
size -= amt
start += amt
......@@ -354,10 +351,7 @@ class Application(object):
node = nm.getNodeByUUID(uuid)
if node.getNodeType() == STORAGE_NODE_TYPE \
and node.getState() == RUNNING_STATE:
msg_id = conn.getNextId()
p = protocol.askLastIDs(msg_id)
conn.addPacket(p)
conn.expectMessage(msg_id)
conn.ask(protocol.askLastIDs())
# Wait for at least one storage node to appear.
while self.target_uuid is None:
......@@ -397,10 +391,7 @@ class Application(object):
size = self.num_partitions
while size:
amt = min(1000, size)
msg_id = conn.getNextId()
p = protocol.askPartitionTable(msg_id, range(start, start + amt))
conn.addPacket(p)
conn.expectMessage(msg_id)
conn.ask(protocol.askPartitionTable(range(start, start + amt)))
size -= amt
start += amt
......@@ -455,10 +446,7 @@ class Application(object):
uuid = conn.getUUID()
if uuid in transaction_uuid_list:
self.asking_uuid_dict[uuid] = False
msg_id = conn.getNextId()
p = protocol.askTransactionInformation(msg_id, tid)
conn.addPacket(p)
conn.expectMessage(msg_id)
conn.ask(protocol.askTransactionInformation(tid))
if len(self.asking_uuid_dict) == 0:
raise VerificationFailure
......@@ -488,10 +476,7 @@ class Application(object):
uuid = conn.getUUID()
if uuid in object_uuid_list:
self.asking_uuid_dict[uuid] = False
msg_id = conn.getNextId()
p = protocol.askObjectPresent(msg_id, oid, tid)
conn.addPacket(p)
conn.expectMessage(msg_id)
conn.ask(protocol.askObjectPresent(oid, tid))
while 1:
em.poll(1)
......@@ -534,14 +519,12 @@ class Application(object):
for offset in xrange(self.num_partitions):
row_list.append((offset, self.pt.getRow(offset)))
if len(row_list) == 1000:
p = protocol.sendPartitionTable(conn.getNextId(),
self.lptid, row_list)
conn.addPacket(p)
p = protocol.sendPartitionTable( self.lptid, row_list)
conn.notify(p)
del row_list[:]
if len(row_list) != 0:
p = protocol.sendPartitionTable(conn.getNextId(),
self.lptid, row_list)
conn.addPacket(p)
p = protocol.sendPartitionTable(self.lptid, row_list)
conn.notify(p)
# Gather all unfinished transactions.
#
......@@ -567,10 +550,7 @@ class Application(object):
node = nm.getNodeByUUID(uuid)
if node.getNodeType() == STORAGE_NODE_TYPE:
self.asking_uuid_dict[uuid] = False
msg_id = conn.getNextId()
p = protocol.askUnfinishedTransactions(msg_id)
conn.addPacket(p)
conn.expectMessage(msg_id)
conn.ask(protocol.askUnfinishedTransactions())
while 1:
em.poll(1)
......@@ -591,14 +571,12 @@ class Application(object):
if uuid is not None:
node = nm.getNodeByUUID(uuid)
if node.getNodeType() == STORAGE_NODE_TYPE:
p = protocol.deleteTransaction(conn.getNextId(), tid)
conn.addPacket(p)
conn.notify(protocol.deleteTransaction(tid))
else:
for conn in em.getConnectionList():
uuid = conn.getUUID()
if uuid in uuid_set:
p = protocol.commitTransaction(conn.getNextId(), tid)
conn.addPacket(p)
conn.ask(protocol.commitTransaction(tid))
# If possible, send the packets now.
em.poll(0)
......@@ -644,7 +622,7 @@ class Application(object):
if uuid is not None:
node = nm.getNodeByUUID(uuid)
if node.getNodeType() == STORAGE_NODE_TYPE:
conn.addPacket(protocol.startOperation(conn.getNextId()))
conn.notify(protocol.startOperation())
# Now everything is passive.
expiration = 10
......@@ -682,7 +660,7 @@ class Application(object):
if uuid is not None:
node = nm.getNodeByUUID(uuid)
if node.getNodeType() in (STORAGE_NODE_TYPE, CLIENT_NODE_TYPE):
conn.addPacket(protocol.stopOperation(conn.getNextId()))
conn.notify(protocol.stopOperation())
if node.getNodeType() == CLIENT_NODE_TYPE:
conn.abort()
......
......@@ -40,11 +40,9 @@ class ElectionEventHandler(MasterEventHandler):
def connectionCompleted(self, conn):
app = self.app
# Request a node idenfitication.
msg_id = conn.getNextId()
p = protocol.requestNodeIdentification(msg_id, MASTER_NODE_TYPE, app.uuid,
p = protocol.requestNodeIdentification(MASTER_NODE_TYPE, app.uuid,
app.server[0], app.server[1], app.name)
conn.addPacket(p)
conn.expectMessage(msg_id)
conn.ask(p)
MasterEventHandler.connectionCompleted(self, conn)
def connectionFailed(self, conn):
......@@ -121,9 +119,7 @@ class ElectionEventHandler(MasterEventHandler):
node.setUUID(uuid)
# Ask a primary master.
msg_id = conn.getNextId()
conn.addPacket(protocol.askPrimaryMaster(msg_id))
conn.expectMessage(msg_id)
conn.ask(protocol.askPrimaryMaster())
else:
self.handleUnexpectedPacket(conn, packet)
......@@ -183,13 +179,12 @@ class ElectionEventHandler(MasterEventHandler):
app = self.app
if node_type != MASTER_NODE_TYPE:
logging.info('reject a connection from a non-master')
conn.addPacket(protocol.notReady(packet.getId(), 'retry later'))
conn.answer(protocol.notReady('retry later'), packet)
conn.abort()
return
if name != app.name:
logging.error('reject an alien cluster')
conn.addPacket(protocol.protocolError(packet.getId(),
'invalid cluster name'))
conn.answer(protocol.protocolError('invalid cluster name'), packet)
conn.abort()
return
......@@ -203,8 +198,8 @@ class ElectionEventHandler(MasterEventHandler):
# If this node is broken, reject it.
if node.getUUID() == uuid:
if node.getState() == BROKEN_STATE:
p = protocol.brokenNodeDisallowedError(packet.getId(), 'go away')
conn.addPacket(p)
conn.answer(protocol.brokenNodeDisallowedError(
'go away'), packet)
conn.abort()
return
......@@ -215,11 +210,11 @@ class ElectionEventHandler(MasterEventHandler):
node.setUUID(uuid)
conn.setUUID(uuid)
p = protocol.acceptNodeIdentification(packet.getId(), MASTER_NODE_TYPE,
p = protocol.acceptNodeIdentification(MASTER_NODE_TYPE,
app.uuid, app.server[0], app.server[1],
app.num_partitions, app.num_replicas,
uuid)
conn.addPacket(p)
conn.answer(p, packet)
# Next, the peer should ask a primary master node.
conn.expectMessage()
......@@ -246,8 +241,8 @@ class ElectionEventHandler(MasterEventHandler):
continue
info = n.getServer() + (n.getUUID() or INVALID_UUID,)
known_master_list.append(info)
p = protocol.answerPrimaryMaster(packet.getId(), primary_uuid, known_master_list)
conn.addPacket(p)
p = protocol.answerPrimaryMaster(primary_uuid, known_master_list)
conn.answer(p, packet)
def handleAnnouncePrimaryMaster(self, conn, packet):
if not conn.isServerConnection():
......
......@@ -68,13 +68,12 @@ class RecoveryEventHandler(MasterEventHandler):
app = self.app
if node_type not in (MASTER_NODE_TYPE, STORAGE_NODE_TYPE, ADMIN_NODE_TYPE):
logging.info('reject a connection from a client')
conn.addPacket(protocol.notReady(packet.getId(), 'retry later'))
conn.answer(protocol.notReady('retry later'), packet)
conn.abort()
return
if name != app.name:
logging.error('reject an alien cluster')
conn.addPacket(protocol.protocolError(packet.getId(),
'invalid cluster name'))
conn.answer(protocol.protocolError('invalid cluster name'), packet)
conn.abort()
return
......@@ -118,8 +117,8 @@ class RecoveryEventHandler(MasterEventHandler):
if node.getNodeType() != MASTER_NODE_TYPE or node_type != MASTER_NODE_TYPE:
# Error. This node uses the same server address as a master
# node.
conn.addPacket(protocol.protocolError(packet.getId(),
'invalid server address'))
p = protocol.protocolError('invalid server address')
conn.answer(p, packet)
conn.abort()
return
......@@ -131,8 +130,8 @@ class RecoveryEventHandler(MasterEventHandler):
# This node has a different UUID.
if node.getState() == RUNNING_STATE:
# If it is still running, reject this node.
conn.addPacket(protocol.protocolError(packet.getId(),
'invalid server address'))
p = protocol.protocolError('invalid server address')
conn.answer(p, packet)
conn.abort()
return
else:
......@@ -150,8 +149,8 @@ class RecoveryEventHandler(MasterEventHandler):
if node.getState() == RUNNING_STATE:
# If it is still running, reject this node.
conn.addPacket(protocol.protocolError(packet.getId(),
'invalid server address'))
p = protocol.protocolError('invalid server address')
conn.answer(p, packet)
conn.abort()
return
else:
......@@ -166,8 +165,8 @@ class RecoveryEventHandler(MasterEventHandler):
# If this node is broken, reject it. Otherwise, assume that it is
# working again.
if node.getState() == BROKEN_STATE:
p = protocol.brokenNodeDisallowedError(packet.getId(), 'go away')
conn.addPacket(p)
p = protocol.brokenNodeDisallowedError('go away')
conn.answer(p, packet)
conn.abort()
return
else:
......@@ -177,12 +176,11 @@ class RecoveryEventHandler(MasterEventHandler):
conn.setUUID(uuid)
p = protocol.acceptNodeIdentification(packet.getId(), MASTER_NODE_TYPE,
p = protocol.acceptNodeIdentification(MASTER_NODE_TYPE,
app.uuid, app.server[0], app.server[1],
app.num_partitions, app.num_replicas, uuid)
conn.addPacket(p)
# Next, the peer should ask a primary master node.
conn.expectMessage()
conn.answer(p, packet)
def handleAskPrimaryMaster(self, conn, packet):
uuid = conn.getUUID()
......@@ -195,8 +193,8 @@ class RecoveryEventHandler(MasterEventHandler):
# Merely tell the peer that I am the primary master node.
# It is not necessary to send known master nodes, because
# I must send all node information immediately.
p = protocol.answerPrimaryMaster(packet.getId(), app.uuid, [])
conn.addPacket(p)
p = protocol.answerPrimaryMaster(app.uuid, [])
conn.answer(p, packet)
# Send the information.
node_list = []
......@@ -209,19 +207,14 @@ class RecoveryEventHandler(MasterEventHandler):
n.getUUID() or INVALID_UUID, n.getState()))
if len(node_list) == 10000:
# Ugly, but it is necessary to split a packet, if it is too big.
p = protocol.notifyNodeInformation(conn.getNextId(), node_list)
conn.addPacket(p)
conn.notify(protocol.notifyNodeInformation(node_list))
del node_list[:]
p = protocol.notifyNodeInformation(conn.getNextId(), node_list)
conn.addPacket(p)
conn.notify(protocol.notifyNodeInformation(node_list))
# If this is a storage node, ask the last IDs.
node = app.nm.getNodeByUUID(uuid)
if node.getNodeType() == STORAGE_NODE_TYPE:
msg_id = conn.getNextId()
p = protocol.askLastIDs(msg_id)
conn.addPacket(p)
conn.expectMessage(msg_id)
conn.ask(protocol.askLastIDs())
elif node.getNodeType() == ADMIN_NODE_TYPE and app.lptid != INVALID_PTID:
# send partition table if exists
logging.info('sending partition table %s to %s' % (dump(app.lptid),
......@@ -231,12 +224,10 @@ class RecoveryEventHandler(MasterEventHandler):
for offset in xrange(app.num_partitions):
row_list.append((offset, app.pt.getRow(offset)))
if len(row_list) == 1000:
p = protocol.sendPartitionTable(conn.getNextId(), app.lptid, row_list)
conn.addPacket(p)
conn.notify(protocol.sendPartitionTable(app.lptid, row_list))
del row_list[:]
if len(row_list) != 0:
p = protocol.sendPartitionTable(conn.getNextId(), app.lptid, row_list)
conn.addPacket(p)
conn.notify(protocol.sendPartitionTable(app.lptid, row_list))
def handleAnnouncePrimaryMaster(self, conn, packet):
uuid = conn.getUUID()
......
......@@ -63,8 +63,7 @@ class SecondaryEventHandler(MasterEventHandler):
app = self.app
if name != app.name:
logging.error('reject an alien cluster')
conn.addPacket(protocol.protocolError(packet.getId(),
'invalid cluster name'))
conn.answer(protocol.protocolError('invalid cluster name'), packet)
conn.abort()
return
......@@ -81,11 +80,11 @@ class SecondaryEventHandler(MasterEventHandler):
conn.setUUID(uuid)
p = protocol.acceptNodeIdentification(packet.getId(), MASTER_NODE_TYPE,
p = protocol.acceptNodeIdentification(MASTER_NODE_TYPE,
app.uuid, app.server[0], app.server[1],
app.num_partitions, app.num_replicas,
uuid)
conn.addPacket(p)
conn.answer(p, packet)
# Next, the peer should ask a primary master node.
conn.expectMessage()
......@@ -108,8 +107,8 @@ class SecondaryEventHandler(MasterEventHandler):
info = n.getServer() + (n.getUUID() or INVALID_UUID,)
known_master_list.append(info)
p = protocol.answerPrimaryMaster(packet.getId(), primary_uuid, known_master_list)
conn.addPacket(p)
p = protocol.answerPrimaryMaster(primary_uuid, known_master_list)
conn.answer(p, packet)
def handleAnnouncePrimaryMaster(self, conn, packet):
self.handleUnexpectedPacket(conn, packet)
......
......@@ -153,8 +153,7 @@ class ServiceEventHandler(MasterEventHandler):
app = self.app
if name != app.name:
logging.error('reject an alien cluster')
conn.addPacket(protocol.protocolError(packet.getId(),
'invalid cluster name'))
conn.notify(protocol.protocolError('invalid cluster name'))
conn.abort()
return
......@@ -202,9 +201,7 @@ class ServiceEventHandler(MasterEventHandler):
or node_type != MASTER_NODE_TYPE:
# Error. This node uses the same server address as
# a master node.
p = protocol.protocolError(packet.getId(),
'invalid server address')
conn.addPacket(p)
conn.notify(protocol.protocolError( 'invalid server address'))
conn.abort()
return
......@@ -217,9 +214,7 @@ class ServiceEventHandler(MasterEventHandler):
# This node has a different UUID.
if node.getState() == RUNNING_STATE:
# If it is still running, reject this node.
p = protocol.protocolError(packet.getId(),
'invalid server address')
conn.addPacket(p)
conn.notify(protocol.protocolError('invalid server address'))
conn.abort()
return
else:
......@@ -246,9 +241,7 @@ class ServiceEventHandler(MasterEventHandler):
# This node has a different server address.
if node.getState() == RUNNING_STATE:
# If it is still running, reject this node.
p = protocol.protocolError(packet.getId(),
'invalid server address')
conn.addPacket(p)
conn.notify(protocol.protocolError('invalid server address'))
conn.abort()
return
else:
......@@ -269,8 +262,7 @@ class ServiceEventHandler(MasterEventHandler):
# If this node is broken, reject it. Otherwise, assume that
# it is working again.
if node.getState() == BROKEN_STATE:
p = protocol.brokenNodeDisallowedError(packet.getId(), 'go away')
conn.addPacket(p)
conn.notify(protocol.brokenNodeDisallowedError('go away'))
conn.abort()
return
else:
......@@ -297,12 +289,11 @@ class ServiceEventHandler(MasterEventHandler):
ptid = app.getNextPartitionTableID()
app.broadcastPartitionChanges(ptid, cell_list)
p = protocol.acceptNodeIdentification(packet.getId(), MASTER_NODE_TYPE,
p = protocol.acceptNodeIdentification(MASTER_NODE_TYPE,
app.uuid, app.server[0], app.server[1],
app.num_partitions, app.num_replicas, uuid)
conn.addPacket(p)
# Next, the peer should ask a primary master node.
conn.expectMessage()
conn.answer(p, packet)
def handleAskPrimaryMaster(self, conn, packet):
uuid = conn.getUUID()
......@@ -315,8 +306,7 @@ class ServiceEventHandler(MasterEventHandler):
# Merely tell the peer that I am the primary master node.
# It is not necessary to send known master nodes, because
# I must send all node information immediately.
p = protocol.answerPrimaryMaster(packet.getId(), app.uuid, [])
conn.addPacket(p)
conn.answer(protocol.answerPrimaryMaster(app.uuid, []), packet)
# Send the information.
logging.info('sending notify node information to %s:%d',
......@@ -331,11 +321,9 @@ class ServiceEventHandler(MasterEventHandler):
n.getUUID() or INVALID_UUID, n.getState()))
if len(node_list) == 10000:
# Ugly, but it is necessary to split a packet, if it is too big.
p = protocol.notifyNodeInformation(conn.getNextId(), node_list)
conn.addPacket(p)
conn.notify(protocol.notifyNodeInformation(node_list))
del node_list[:]
p = protocol.notifyNodeInformation(conn.getNextId(), node_list)
conn.addPacket(p)
conn.notify(protocol.notifyNodeInformation(node_list))
# If this is a storage node or a client node or an admin node, send the partition table.
node = app.nm.getNodeByUUID(uuid)
......@@ -347,16 +335,14 @@ class ServiceEventHandler(MasterEventHandler):
for offset in xrange(app.num_partitions):
row_list.append((offset, app.pt.getRow(offset)))
if len(row_list) == 1000:
p = protocol.sendPartitionTable(conn.getNextId(), app.lptid, row_list)
conn.addPacket(p)
conn.notify(protocol.sendPartitionTable(app.lptid, row_list))
del row_list[:]
if len(row_list) != 0:
p = protocol.sendPartitionTable(conn.getNextId(), app.lptid, row_list)
conn.addPacket(p)
conn.notify(protocol.sendPartitionTable(app.lptid, row_list))
# If this is a storage node, ask it to start.
if node.getNodeType() == STORAGE_NODE_TYPE:
conn.addPacket(protocol.startOperation(conn.getNextId()))
conn.notify(protocol.startOperation())
def handleAnnouncePrimaryMaster(self, conn, packet):
uuid = conn.getUUID()
......@@ -466,7 +452,7 @@ class ServiceEventHandler(MasterEventHandler):
return
tid = app.getNextTID()
app.finishing_transaction_dict[tid] = FinishingTransaction(conn)
conn.addPacket(protocol.answerNewTID(packet.getId(), tid))
conn.answer(protocol.answerNewTID(tid), packet)
def handleAskNewOIDs(self, conn, packet, num_oids):
uuid = conn.getUUID()
......@@ -475,14 +461,12 @@ class ServiceEventHandler(MasterEventHandler):
return
app = self.app
node = app.nm.getNodeByUUID(uuid)
if node.getNodeType() != CLIENT_NODE_TYPE:
self.handleUnexpectedPacket(conn, packet)
return
oid_list = app.getNewOIDList(num_oids)
conn.addPacket(protocol.answerNewOIDs(packet.getId(), oid_list))
conn.answer(protocol.answerNewOIDs(oid_list), packet)
def handleFinishTransaction(self, conn, packet, oid_list, tid):
uuid = conn.getUUID()
......@@ -518,9 +502,7 @@ class ServiceEventHandler(MasterEventHandler):
# Request locking data.
for c in app.em.getConnectionList():
if c.getUUID() in uuid_set:
msg_id = c.getNextId()
c.addPacket(protocol.lockInformation(msg_id, tid))
c.expectMessage(msg_id, timeout = 60)
c.ask(protocol.lockInformation(tid), timeout=60)
try:
t = app.finishing_transaction_dict[tid]
......@@ -564,17 +546,17 @@ class ServiceEventHandler(MasterEventHandler):
node = app.nm.getNodeByUUID(uuid)
if node.getNodeType() == CLIENT_NODE_TYPE:
if c is t.getConnection():
p = protocol.notifyTransactionFinished(
t.getMessageId(), tid)
# TODO: use connection.notify if possible
p = protocol.notifyTransactionFinished(tid)
p.setId(t.getMessageId())
c.addPacket(p)
else:
p = protocol.invalidateObjects(c.getNextId(),
t.getOIDList(), tid)
c.addPacket(p)
p = protocol.invalidateObjects(t.getOIDList(), tid)
c.notify(p)
elif node.getNodeType() == STORAGE_NODE_TYPE:
if uuid in t.getUUIDSet():
p = protocol.unlockInformation(c.getNextId(), tid)
c.addPacket(p)
p = protocol.unlockInformation(tid)
c.notify(p)
del app.finishing_transaction_dict[tid]
except KeyError:
# What is this?
......@@ -606,8 +588,7 @@ class ServiceEventHandler(MasterEventHandler):
return
app = self.app
p = protocol.answerLastIDs(packet.getId(), app.loid, app.ltid, app.lptid)
conn.addPacket(p)
conn.answer(protocol.answerLastIDs(app.loid, app.ltid, app.lptid), packet)
def handleAskUnfinishedTransactions(self, conn, packet):
uuid = conn.getUUID()
......@@ -616,9 +597,8 @@ class ServiceEventHandler(MasterEventHandler):
return
app = self.app
p = protocol.answerUnfinishedTransactions(packet.getId(),
app.finishing_transaction_dict.keys())
conn.addPacket(p)
p = protocol.answerUnfinishedTransactions(app.finishing_transaction_dict.keys())
conn.answer(p, packet)
def handleNotifyPartitionChanges(self, conn, packet, ptid, cell_list):
# This should be sent when a cell becomes up-to-date because
......
......@@ -92,13 +92,12 @@ class VerificationEventHandler(MasterEventHandler):
app = self.app
if node_type not in (MASTER_NODE_TYPE, STORAGE_NODE_TYPE, ADMIN_NODE_TYPE):
logging.info('reject a connection from a client')
conn.addPacket(protocol.notReady(packet.getId(), 'retry later'))
conn.answer(protocol.notReady('retry later'), packet)
conn.abort()
return
if name != app.name:
logging.error('reject an alien cluster')
conn.addPacket(protocol.protocolError(packet.getId(),
'invalid cluster name'))
conn.answer(protocol.protocolError('invalid cluster name'), packet)
conn.abort()
return
......@@ -142,8 +141,8 @@ class VerificationEventHandler(MasterEventHandler):
if node.getNodeType() != MASTER_NODE_TYPE or node_type != MASTER_NODE_TYPE:
# Error. This node uses the same server address as a master
# node.
conn.addPacket(protocol.protocolError(packet.getId(),
'invalid server address'))
conn.answer(protocol.protocolError(
'invalid server address'), packet)
conn.abort()
return
......@@ -155,8 +154,8 @@ class VerificationEventHandler(MasterEventHandler):
# This node has a different UUID.
if node.getState() == RUNNING_STATE:
# If it is still running, reject this node.
conn.addPacket(protocol.protocolError(packet.getId(),
'invalid server address'))
conn.answer(protocol.protocolError(
'invalid server address'), packet)
conn.abort()
return
else:
......@@ -173,8 +172,8 @@ class VerificationEventHandler(MasterEventHandler):
# This node has a different server address.
if node.getState() == RUNNING_STATE:
# If it is still running, reject this node.
conn.addPacket(protocol.protocolError(packet.getId(),
'invalid server address'))
conn.answer(protocol.protocolError(
'invalid server address'), packet)
conn.abort()
return
else:
......@@ -189,8 +188,8 @@ class VerificationEventHandler(MasterEventHandler):
# If this node is broken, reject it. Otherwise, assume that it is
# working again.
if node.getState() == BROKEN_STATE:
p = protocol.brokenNodeDisallowedError(packet.getId(), 'go away')
conn.addPacket(p)
p = protocol.brokenNodeDisallowedError('go away')
conn.answer(p, packet)
conn.abort()
return
else:
......@@ -200,10 +199,10 @@ class VerificationEventHandler(MasterEventHandler):
conn.setUUID(uuid)
p = protocol.acceptNodeIdentification(packet.getId(), MASTER_NODE_TYPE,
p = protocol.acceptNodeIdentification(MASTER_NODE_TYPE,
app.uuid, app.server[0], app.server[1],
app.num_partitions, app.num_replicas, uuid)
conn.addPacket(p)
conn.answer(p, packet)
# Next, the peer should ask a primary master node.
conn.expectMessage()
......@@ -218,8 +217,7 @@ class VerificationEventHandler(MasterEventHandler):
# Merely tell the peer that I am the primary master node.
# It is not necessary to send known master nodes, because
# I must send all node information immediately.
p = protocol.answerPrimaryMaster(packet.getId(), app.uuid, [])
conn.addPacket(p)
conn.answer(protocol.answerPrimaryMaster(app.uuid, []), packet)
# Send the information.
node_list = []
......@@ -232,11 +230,9 @@ class VerificationEventHandler(MasterEventHandler):
n.getUUID() or INVALID_UUID, n.getState()))
if len(node_list) == 10000:
# Ugly, but it is necessary to split a packet, if it is too big.
p = protocol.notifyNodeInformation(conn.getNextId(), node_list)
conn.addPacket(p)
conn.notify(protocol.notifyNodeInformation(node_list))
del node_list[:]
p = protocol.notifyNodeInformation(conn.getNextId(), node_list)
conn.addPacket(p)
conn.notify(protocol.notifyNodeInformation(node_list))
# If this is a storage node or an admin node, send the partition table.
node = app.nm.getNodeByUUID(uuid)
......@@ -246,12 +242,10 @@ class VerificationEventHandler(MasterEventHandler):
for offset in xrange(app.num_partitions):
row_list.append((offset, app.pt.getRow(offset)))
if len(row_list) == 1000:
p = protocol.sendPartitionTable(conn.getNextId(), app.lptid, row_list)
conn.addPacket(p)
conn.notify(protocol.sendPartitionTable(app.lptid, row_list))
del row_list[:]
if len(row_list) != 0:
p = protocol.sendPartitionTable(conn.getNextId(), app.lptid, row_list)
conn.addPacket(p)
conn.notify(protocol.sendPartitionTable(app.lptid, row_list))
def handleAnnouncePrimaryMaster(self, conn, packet):
uuid = conn.getUUID()
......
......@@ -346,16 +346,21 @@ class Packet(object):
if len(msg) < msg_len:
# Not enough.
return None
return cls(msg_id, msg_type, msg[PACKET_HEADER_SIZE:msg_len])
packet = cls(msg_type, msg[PACKET_HEADER_SIZE:msg_len])
packet.setId(msg_id)
return packet
def __init__(self, msg_id, msg_type, body=''):
self._id = msg_id
def __init__(self, msg_type, body=''):
self._id = None
self._type = msg_type
self._body = body
def getId(self):
return self._id
def setId(self, id):
self._id = id
def getType(self):
return self._type
......@@ -871,179 +876,179 @@ class Packet(object):
# Packet constructors
def _error(msg_id, error_code, error_message):
def _error(error_code, error_message):
body = pack('!HL', error_code, len(error_message)) + error_message
return Packet(msg_id, ERROR, body)
return Packet(ERROR, body)
def protocolError(msg_id, error_message):
return _error(msg_id, PROTOCOL_ERROR_CODE, 'protocol error: ' + error_message)
def protocolError(error_message):
return _error(PROTOCOL_ERROR_CODE, 'protocol error: ' + error_message)
def internalError(msg_id, error_message):
return _error(msg_id, INTERNAL_ERROR_CODE, 'internal error: ' + error_message)
def internalError(error_message):
return _error(INTERNAL_ERROR_CODE, 'internal error: ' + error_message)
def notReady(msg_id, error_message):
return _error(msg_id, NOT_READY_CODE, 'not ready: ' + error_message)
def notReady(error_message):
return _error(NOT_READY_CODE, 'not ready: ' + error_message)
def brokenNodeDisallowedError(msg_id, error_message):
return _error(msg_id, BROKEN_NODE_DISALLOWED_CODE,
def brokenNodeDisallowedError(error_message):
return _error(BROKEN_NODE_DISALLOWED_CODE,
'broken node disallowed error: ' + error_message)
def oidNotFound(msg_id, error_message):
return _error(msg_id, OID_NOT_FOUND_CODE, 'oid not found: ' + error_message)
def oidNotFound(error_message):
return _error(OID_NOT_FOUND_CODE, 'oid not found: ' + error_message)
def tidNotFound(msg_id, error_message):
return _error(msg_id, TID_NOT_FOUND_CODE, 'tid not found: ' + error_message)
def tidNotFound(error_message):
return _error(TID_NOT_FOUND_CODE, 'tid not found: ' + error_message)
def ping(msg_id):
return Packet(msg_id, PING)
def ping():
return Packet(PING)
def pong(msg_id):
return Packet(msg_id, PONG)
def pong():
return Packet(PONG)
def requestNodeIdentification(msg_id, node_type, uuid, ip_address, port, name):
def requestNodeIdentification(node_type, uuid, ip_address, port, name):
body = pack('!LLH16s4sHL', PROTOCOL_VERSION[0], PROTOCOL_VERSION[1],
node_type, uuid, inet_aton(ip_address), port, len(name)) + name
return Packet(msg_id, REQUEST_NODE_IDENTIFICATION, body)
return Packet(REQUEST_NODE_IDENTIFICATION, body)
def acceptNodeIdentification(msg_id, node_type, uuid, ip_address,
def acceptNodeIdentification(node_type, uuid, ip_address,
port, num_partitions, num_replicas, your_uuid):
body = pack('!H16s4sHLL16s', node_type, uuid,
inet_aton(ip_address), port,
num_partitions, num_replicas, your_uuid)
return Packet(msg_id, ACCEPT_NODE_IDENTIFICATION, body)
return Packet(ACCEPT_NODE_IDENTIFICATION, body)
def askPrimaryMaster(msg_id):
return Packet(msg_id, ASK_PRIMARY_MASTER)
def askPrimaryMaster():
return Packet(ASK_PRIMARY_MASTER)
def answerPrimaryMaster(msg_id, primary_uuid, known_master_list):
def answerPrimaryMaster(primary_uuid, known_master_list):
body = [primary_uuid, pack('!L', len(known_master_list))]
for master in known_master_list:
body.append(pack('!4sH16s', inet_aton(master[0]), master[1], master[2]))
body = ''.join(body)
return Packet(msg_id, ANSWER_PRIMARY_MASTER, body)
return Packet(ANSWER_PRIMARY_MASTER, body)
def announcePrimaryMaster(msg_id):
return Packet(msg_id, ANNOUNCE_PRIMARY_MASTER)
def announcePrimaryMaster():
return Packet(ANNOUNCE_PRIMARY_MASTER)
def reelectPrimaryMaster(msg_id):
return Packet(msg_id, REELECT_PRIMARY_MASTER)
def reelectPrimaryMaster():
return Packet(REELECT_PRIMARY_MASTER)
def notifyNodeInformation(msg_id, node_list):
def notifyNodeInformation(node_list):
body = [pack('!L', len(node_list))]
for node_type, ip_address, port, uuid, state in node_list:
body.append(pack('!H4sH16sH', node_type, inet_aton(ip_address), port,
uuid, state))
body = ''.join(body)
return Packet(msg_id, NOTIFY_NODE_INFORMATION, body)
return Packet(NOTIFY_NODE_INFORMATION, body)
def askLastIDs(msg_id):
return Packet(msg_id, ASK_LAST_IDS)
def askLastIDs():
return Packet(ASK_LAST_IDS)
def answerLastIDs(msg_id, loid, ltid, lptid):
return Packet(msg_id, ANSWER_LAST_IDS, loid + ltid + lptid)
def answerLastIDs(loid, ltid, lptid):
return Packet(ANSWER_LAST_IDS, loid + ltid + lptid)
def askPartitionTable(msg_id, offset_list):
def askPartitionTable(offset_list):
body = [pack('!L', len(offset_list))]
for offset in offset_list:
body.append(pack('!L', offset))
body = ''.join(body)
return Packet(msg_id, ASK_PARTITION_TABLE, body)
return Packet(ASK_PARTITION_TABLE, body)
def answerPartitionTable(msg_id, ptid, row_list):
def answerPartitionTable(ptid, row_list):
body = [pack('!8sL', ptid, len(row_list))]
for offset, cell_list in row_list:
body.append(pack('!LL', offset, len(cell_list)))
for uuid, state in cell_list:
body.append(pack('!16sH', uuid, state))
body = ''.join(body)
return Packet(msg_id, ANSWER_PARTITION_TABLE, body)
return Packet(ANSWER_PARTITION_TABLE, body)
def sendPartitionTable(msg_id, ptid, row_list):
def sendPartitionTable(ptid, row_list):
body = [pack('!8sL', ptid, len(row_list))]
for offset, cell_list in row_list:
body.append(pack('!LL', offset, len(cell_list)))
for uuid, state in cell_list:
body.append(pack('!16sH', uuid, state))
body = ''.join(body)
return Packet(msg_id, SEND_PARTITION_TABLE, body)
return Packet(SEND_PARTITION_TABLE, body)
def notifyPartitionChanges(msg_id, ptid, cell_list):
def notifyPartitionChanges(ptid, cell_list):
body = [pack('!8sL', ptid, len(cell_list))]
for offset, uuid, state in cell_list:
body.append(pack('!L16sH', offset, uuid, state))
body = ''.join(body)
return Packet(msg_id, NOTIFY_PARTITION_CHANGES, body)
return Packet(NOTIFY_PARTITION_CHANGES, body)
def startOperation(msg_id):
return Packet(msg_id, START_OPERATION)
def startOperation():
return Packet(START_OPERATION)
def stopOperation(msg_id):
return Packet(msg_id, STOP_OPERATION)
def stopOperation():
return Packet(STOP_OPERATION)
def askUnfinishedTransactions(msg_id):
return Packet(msg_id, ASK_UNFINISHED_TRANSACTIONS)
def askUnfinishedTransactions():
return Packet(ASK_UNFINISHED_TRANSACTIONS)
def answerUnfinishedTransactions(msg_id, tid_list):
def answerUnfinishedTransactions(tid_list):
body = [pack('!L', len(tid_list))]
body.extend(tid_list)
body = ''.join(body)
return Packet(msg_id, ANSWER_UNFINISHED_TRANSACTIONS, body)
return Packet(ANSWER_UNFINISHED_TRANSACTIONS, body)
def askObjectPresent(msg_id, oid, tid):
return Packet(msg_id, ASK_OBJECT_PRESENT, oid + tid)
def askObjectPresent(oid, tid):
return Packet(ASK_OBJECT_PRESENT, oid + tid)
def answerObjectPresent(msg_id, oid, tid):
return Packet(msg_id, ANSWER_OBJECT_PRESENT, oid + tid)
def answerObjectPresent(oid, tid):
return Packet(ANSWER_OBJECT_PRESENT, oid + tid)
def deleteTransaction(msg_id, tid):
return Packet(msg_id, DELETE_TRANSACTION, tid)
def deleteTransaction(tid):
return Packet(DELETE_TRANSACTION, tid)
def commitTransaction(msg_id, tid):
return Packet(msg_id, COMMIT_TRANSACTION, tid)
def commitTransaction(tid):
return Packet(COMMIT_TRANSACTION, tid)
def askNewTID(msg_id):
return Packet(msg_id, ASK_NEW_TID)
def askNewTID():
return Packet(ASK_NEW_TID)
def answerNewTID(msg_id, tid):
return Packet(msg_id, ANSWER_NEW_TID, tid)
def answerNewTID(tid):
return Packet(ANSWER_NEW_TID, tid)
def askNewOIDs(msg_id, num_oids):
return Packet(msg_id, ASK_NEW_OIDS, pack('!H', num_oids))
def askNewOIDs(num_oids):
return Packet(ASK_NEW_OIDS, pack('!H', num_oids))
def answerNewOIDs(msg_id, oid_list):
def answerNewOIDs(oid_list):
body = [pack('!H', len(oid_list))]
body.extend(oid_list)
body = ''.join(body)
return Packet(msg_id, ANSWER_NEW_OIDS, body)
return Packet(ANSWER_NEW_OIDS, body)
def finishTransaction(msg_id, oid_list, tid):
def finishTransaction(oid_list, tid):
body = [pack('!8sL', tid, len(oid_list))]
body.extend(oid_list)
body = ''.join(body)
return Packet(msg_id, FINISH_TRANSACTION, body)
return Packet(FINISH_TRANSACTION, body)
def notifyTransactionFinished(msg_id, tid):
return Packet(msg_id, NOTIFY_TRANSACTION_FINISHED, tid)
def notifyTransactionFinished(tid):
return Packet(NOTIFY_TRANSACTION_FINISHED, tid)
def lockInformation(msg_id, tid):
return Packet(msg_id, LOCK_INFORMATION, tid)
def lockInformation(tid):
return Packet(LOCK_INFORMATION, tid)
def notifyInformationLocked(msg_id, tid):
return Packet(msg_id, NOTIFY_INFORMATION_LOCKED, tid)
def notifyInformationLocked(tid):
return Packet(NOTIFY_INFORMATION_LOCKED, tid)
def invalidateObjects(msg_id, oid_list, tid):
def invalidateObjects(oid_list, tid):
body = [pack('!8sL', tid, len(oid_list))]
body.extend(oid_list)
body = ''.join(body)
return Packet(msg_id, INVALIDATE_OBJECTS, body)
return Packet(INVALIDATE_OBJECTS, body)
def unlockInformation(msg_id, tid):
return Packet(msg_id, UNLOCK_INFORMATION, tid)
def unlockInformation(tid):
return Packet(UNLOCK_INFORMATION, tid)
def abortTransaction(msg_id, tid):
return Packet(msg_id, ABORT_TRANSACTION, tid)
def abortTransaction(tid):
return Packet(ABORT_TRANSACTION, tid)
def askStoreTransaction(msg_id, tid, user, desc, ext, oid_list):
def askStoreTransaction(tid, user, desc, ext, oid_list):
user_len = len(user)
desc_len = len(desc)
ext_len = len(ext)
......@@ -1053,66 +1058,66 @@ def askStoreTransaction(msg_id, tid, user, desc, ext, oid_list):
body.append(ext)
body.extend(oid_list)
body = ''.join(body)
return Packet(msg_id, ASK_STORE_TRANSACTION, body)
return Packet(ASK_STORE_TRANSACTION, body)
def answerStoreTransaction(msg_id, tid):
return Packet(msg_id, ANSWER_STORE_TRANSACTION, tid)
def answerStoreTransaction(tid):
return Packet(ANSWER_STORE_TRANSACTION, tid)
def askStoreObject(msg_id, oid, serial, compression, checksum, data, tid):
def askStoreObject(oid, serial, compression, checksum, data, tid):
body = pack('!8s8s8sBLL', oid, serial, tid, compression,
checksum, len(data)) + data
return Packet(msg_id, ASK_STORE_OBJECT, body)
return Packet(ASK_STORE_OBJECT, body)
def answerStoreObject(msg_id, conflicting, oid, serial):
def answerStoreObject(conflicting, oid, serial):
body = pack('!B8s8s', conflicting, oid, serial)
return Packet(msg_id, ANSWER_STORE_OBJECT, body)
return Packet(ANSWER_STORE_OBJECT, body)
def askObject(msg_id, oid, serial, tid):
return Packet(msg_id, ASK_OBJECT, pack('!8s8s8s', oid, serial, tid))
def askObject(oid, serial, tid):
return Packet(ASK_OBJECT, pack('!8s8s8s', oid, serial, tid))
def answerObject(msg_id, oid, serial_start, serial_end, compression,
def answerObject(oid, serial_start, serial_end, compression,
checksum, data):
body = pack('!8s8s8sBLL', oid, serial_start, serial_end,
compression, checksum, len(data)) + data
return Packet(msg_id, ANSWER_OBJECT, body)
return Packet(ANSWER_OBJECT, body)
def askTIDs(msg_id, first, last, partition):
return Packet(msg_id, ASK_TIDS, pack('!QQL', first, last, partition))
def askTIDs(first, last, partition):
return Packet(ASK_TIDS, pack('!QQL', first, last, partition))
def answerTIDs(msg_id, tid_list):
def answerTIDs(tid_list):
body = [pack('!L', len(tid_list))]
body.extend(tid_list)
body = ''.join(body)
return Packet(msg_id, ANSWER_TIDS, body)
return Packet(ANSWER_TIDS, body)
def askTransactionInformation(msg_id, tid):
return Packet(msg_id, ASK_TRANSACTION_INFORMATION, pack('!8s', tid))
def askTransactionInformation(tid):
return Packet(ASK_TRANSACTION_INFORMATION, pack('!8s', tid))
def answerTransactionInformation(msg_id, tid, user, desc, ext, oid_list):
def answerTransactionInformation(tid, user, desc, ext, oid_list):
body = [pack('!8sHHHL', tid, len(user), len(desc), len(ext), len(oid_list))]
body.append(user)
body.append(desc)
body.append(ext)
body.extend(oid_list)
body = ''.join(body)
return Packet(msg_id, ANSWER_TRANSACTION_INFORMATION, body)
return Packet(ANSWER_TRANSACTION_INFORMATION, body)
def askObjectHistory(msg_id, oid, first, last):
return Packet(msg_id, ASK_OBJECT_HISTORY, pack('!8sQQ', oid, first, last))
def askObjectHistory(oid, first, last):
return Packet(ASK_OBJECT_HISTORY, pack('!8sQQ', oid, first, last))
def answerObjectHistory(msg_id, oid, history_list):
def answerObjectHistory(oid, history_list):
body = [pack('!8sL', oid, len(history_list))]
# history_list is a list of tuple (serial, size)
for history_tuple in history_list:
body.append(pack('!8sL', history_tuple[0], history_tuple[1]))
body = ''.join(body)
return Packet(msg_id, ANSWER_OBJECT_HISTORY, body)
return Packet(ANSWER_OBJECT_HISTORY, body)
def askOIDs(msg_id, first, last, partition):
return Packet(msg_id, ASK_OIDS, pack('!QQL', first, last, partition))
def askOIDs(first, last, partition):
return Packet(ASK_OIDS, pack('!QQL', first, last, partition))
def answerOIDs(msg_id, oid_list):
def answerOIDs(oid_list):
body = [pack('!L', len(oid_list))]
body.extend(oid_list)
body = ''.join(body)
return Packet(msg_id, ANSWER_OIDS, body)
return Packet(ANSWER_OIDS, body)
......@@ -37,11 +37,9 @@ class BootstrapEventHandler(StorageEventHandler):
# Should not happen.
raise RuntimeError('connection completed while not trying to connect')
msg_id = conn.getNextId()
p = protocol.requestNodeIdentification(msg_id, STORAGE_NODE_TYPE, app.uuid,
p = protocol.requestNodeIdentification(STORAGE_NODE_TYPE, app.uuid,
app.server[0], app.server[1], app.name)
conn.addPacket(p)
conn.expectMessage(msg_id)
conn.ask(p)
StorageEventHandler.connectionCompleted(self, conn)
def connectionFailed(self, conn):
......@@ -115,13 +113,12 @@ class BootstrapEventHandler(StorageEventHandler):
app = self.app
if node_type != MASTER_NODE_TYPE:
logging.info('reject a connection from a non-master')
conn.addPacket(protocol.notReady(packet.getId(), 'retry later'))
conn.answer(protocol.notReady('retry later'), packet)
conn.abort()
return
if name != app.name:
logging.error('reject an alien cluster')
conn.addPacket(protocol.protocolError(packet.getId(),
'invalid cluster name'))
conn.answer(protocol.protocolError('invalid cluster name'), packet)
conn.abort()
return
......@@ -134,8 +131,8 @@ class BootstrapEventHandler(StorageEventHandler):
# If this node is broken, reject it.
if node.getUUID() == uuid:
if node.getState() == BROKEN_STATE:
p = protocol.brokenNodeDisallowedError(packet.getId(), 'go away')
conn.addPacket(p)
p = protocol.brokenNodeDisallowedError('go away')
conn.answer(p, packet)
conn.abort()
return
......@@ -143,10 +140,9 @@ class BootstrapEventHandler(StorageEventHandler):
node.setUUID(uuid)
conn.setUUID(uuid)
p = protocol.acceptNodeIdentification(packet.getId(), STORAGE_NODE_TYPE,
app.uuid, app.server[0], app.server[1],
0, 0, uuid)
conn.addPacket(p)
p = protocol.acceptNodeIdentification(STORAGE_NODE_TYPE, app.uuid,
app.server[0], app.server[1], 0, 0, uuid)
conn.answer(p, packet)
# Now the master node should know that I am not the right one.
conn.abort()
......@@ -199,9 +195,7 @@ class BootstrapEventHandler(StorageEventHandler):
node.setUUID(uuid)
# Ask a primary master.
msg_id = conn.getNextId()
conn.addPacket(protocol.askPrimaryMaster(msg_id))
conn.expectMessage(msg_id)
conn.ask(protocol.askPrimaryMaster())
def handleAnswerPrimaryMaster(self, conn, packet, primary_uuid,
known_master_list):
......
......@@ -139,8 +139,8 @@ class OperationEventHandler(StorageEventHandler):
app = self.app
if name != app.name:
logging.error('reject an alien cluster')
conn.addPacket(protocol.protocolError(packet.getId(),
'invalid cluster name'))
p = protocol.protocolError('invalid cluster name')
conn.answer(p, packet)
conn.abort()
return
......@@ -156,16 +156,15 @@ class OperationEventHandler(StorageEventHandler):
# If I do not know such a node, and it is not even a master
# node, simply reject it.
logging.error('reject an unknown node %s', dump(uuid))
conn.addPacket(protocol.notReady(packet.getId(),
'unknown node'))
conn.answer(protocol.notReady('unknown node'), packet)
conn.abort()
return
else:
# If this node is broken, reject it.
if node.getUUID() == uuid:
if node.getState() == BROKEN_STATE:
p = protocol.brokenNodeDisallowedError(packet.getId(), 'go away')
conn.addPacket(p)
p = protocol.brokenNodeDisallowedError('go away')
conn.answer(p, packet)
conn.abort()
return
......@@ -173,11 +172,10 @@ class OperationEventHandler(StorageEventHandler):
node.setUUID(uuid)
conn.setUUID(uuid)
p = protocol.acceptNodeIdentification(packet.getId(), STORAGE_NODE_TYPE,
app.uuid, app.server[0], app.server[1],
app.num_partitions, app.num_replicas,
uuid)
conn.addPacket(p)
p = protocol.acceptNodeIdentification(STORAGE_NODE_TYPE, app.uuid,
app.server[0], app.server[1], app.num_partitions,
app.num_replicas, uuid)
conn.answer(p, packet)
if node_type == MASTER_NODE_TYPE:
conn.abort()
......@@ -256,11 +254,10 @@ class OperationEventHandler(StorageEventHandler):
t = app.dm.getTransaction(tid)
if t is None:
p = protocol.tidNotFound(packet.getId(), '%s does not exist' % dump(tid))
p = protocol.tidNotFound('%s does not exist' % dump(tid))
else:
p = protocol.answerTransactionInformation(packet.getId(), tid,
t[1], t[2], t[3], t[0])
conn.addPacket(p)
p = protocol.answerTransactionInformation(tid, t[1], t[2], t[3], t[0])
conn.answer(p, packet)
def handleAskObjectPresent(self, conn, packet, oid, tid):
self.handleUnexpectedPacket(conn, packet)
......@@ -284,7 +281,7 @@ class OperationEventHandler(StorageEventHandler):
except KeyError:
pass
conn.addPacket(protocol.notifyInformationLocked(packet.getId(), tid))
conn.answer(protocol.notifyInformationLocked(tid), packet)
else:
self.handleUnexpectedPacket(conn, packet)
......@@ -328,19 +325,18 @@ class OperationEventHandler(StorageEventHandler):
next_serial = INVALID_SERIAL
logging.debug('oid = %s, serial = %s, next_serial = %s',
dump(oid), dump(serial), dump(next_serial))
p = protocol.answerObject(packet.getId(), oid, serial, next_serial,
p = protocol.answerObject(oid, serial, next_serial,
compression, checksum, data)
else:
logging.debug('oid = %s not found', dump(oid))
p = protocol.oidNotFound(packet.getId(), '%s does not exist' % dump(oid))
conn.addPacket(p)
p = protocol.oidNotFound('%s does not exist' % dump(oid))
conn.answer(p, packet)
def handleAskTIDs(self, conn, packet, first, last, partition):
# This method is complicated, because I must return TIDs only
# about usable partitions assigned to me.
if first >= last:
conn.addPacket(protocol.protocolError(packet.getId(),
'invalid offsets'))
conn.answer(protocol.protocolError( 'invalid offsets'), packet)
return
app = self.app
......@@ -359,20 +355,19 @@ class OperationEventHandler(StorageEventHandler):
tid_list = app.dm.getTIDList(first, last - first,
app.num_partitions, partition_list)
conn.addPacket(protocol.answerTIDs(packet.getId(), tid_list))
conn.answer(protocol.answerTIDs(tid_list), packet)
def handleAskObjectHistory(self, conn, packet, oid, first, last):
if first >= last:
conn.addPacket(protocol.protocolError(packet.getId(),
'invalid offsets'))
conn.answer(protocol.protocolError( 'invalid offsets'), packet)
return
app = self.app
history_list = app.dm.getObjectHistory(oid, first, last - first)
if history_list is None:
history_list = []
conn.addPacket(protocol.answerObjectHistory(packet.getId(), oid,
history_list))
p = protocol.answerObjectHistory(oid, history_list)
conn.answer(p, packet)
def handleAskStoreTransaction(self, conn, packet, tid, user, desc,
ext, oid_list):
......@@ -385,7 +380,7 @@ class OperationEventHandler(StorageEventHandler):
t = app.transaction_dict.setdefault(tid, TransactionInformation(uuid))
t.addTransaction(oid_list, user, desc, ext)
conn.addPacket(protocol.answerStoreTransaction(packet.getId(), tid))
conn.answer(protocol.answerStoreTransaction(tid), packet)
def handleAskStoreObject(self, conn, packet, oid, serial,
compression, checksum, data, tid):
......@@ -406,8 +401,8 @@ class OperationEventHandler(StorageEventHandler):
# If a newer transaction already locks this object,
# do not try to resolve a conflict, so return immediately.
logging.info('unresolvable conflict in %s', dump(oid))
conn.addPacket(protocol.answerStoreObject(packet.getId(), 1,
oid, locking_tid))
p = protocol.answerStoreObject(1, oid, locking_tid)
conn.answer(p, packet)
return
# Next, check if this is generated from the latest revision.
......@@ -416,14 +411,14 @@ class OperationEventHandler(StorageEventHandler):
last_serial = history_list[0][0]
if last_serial != serial:
logging.info('resolvable conflict in %s', dump(oid))
conn.addPacket(protocol.answerStoreObject(packet.getId(), 1,
oid, last_serial))
p = protocol.answerStoreObject(1, oid, last_serial)
conn.answer(p, packet)
return
# Now store the object.
t = app.transaction_dict.setdefault(tid, TransactionInformation(uuid))
t.addObject(oid, compression, checksum, data)
conn.addPacket(protocol.answerStoreObject(packet.getId(), 0,
oid, serial))
p = protocol.answerStoreObject(0, oid, serial)
conn.answer(p, packet)
app.store_lock_dict[oid] = tid
def handleAbortTransaction(self, conn, packet, tid):
......@@ -467,8 +462,7 @@ class OperationEventHandler(StorageEventHandler):
# This method is complicated, because I must return OIDs only
# about usable partitions assigned to me.
if first >= last:
conn.addPacket(protocol.protocolError(packet.getId(),
'invalid offsets'))
conn.answer(protocol.protocolError( 'invalid offsets'), packet)
return
app = self.app
......@@ -487,4 +481,4 @@ class OperationEventHandler(StorageEventHandler):
oid_list = app.dm.getOIDList(first, last - first,
app.num_partitions, partition_list)
conn.addPacket(protocol.answerOIDs(packet.getId(), oid_list))
conn.answer(protocol.answerOIDs(oid_list), packet)
......@@ -89,27 +89,20 @@ class ReplicationEventHandler(StorageEventHandler):
present_tid_list = app.dm.getTIDListPresent(tid_list)
tid_set = set(tid_list) - set(present_tid_list)
for tid in tid_set:
msg_id = conn.getNextId()
p = protocol.askTransactionInformation(msg_id, tid)
conn.addPacket(p)
conn.expectMessage(msg_id, timeout = 300)
conn.ask(protocol.askTransactionInformation(tid), timeout=300)
# And, ask more TIDs.
app.replicator.tid_offset += 1000
offset = app.replicator.tid_offset
msg_id = conn.getNextId()
p = protocol.askTIDs(msg_id, offset, offset + 1000,
p = protocol.askTIDs(offset, offset + 1000,
app.replicator.current_partition.getRID())
conn.addPacket(p)
conn.expectMessage(msg_id, timeout = 300)
conn.ask(p, timeout=300)
else:
# If no more TID, a replication of transactions is finished.
# So start to replicate objects now.
msg_id = conn.getNextId()
p = protocol.askOIDs(msg_id, 0, 1000,
p = protocol.askOIDs(0, 1000,
app.replicator.current_partition.getRID())
conn.addPacket(p)
conn.expectMessage(msg_id, timeout = 300)
conn.ask(p, timeout=300)
app.replicator.oid_offset = 0
def handleAnswerTransactionInformation(self, conn, packet, tid,
......@@ -129,10 +122,7 @@ class ReplicationEventHandler(StorageEventHandler):
if oid_list:
# Pick one up, and ask the history.
oid = oid_list.pop()
msg_id = conn.getNextId()
p = protocol.askObjectHistory(msg_id, oid, 0, 1000)
conn.addPacket(p)
conn.expectMessage(msg_id, timeout = 300)
conn.ask(protocol.askObjectHistory(oid, 0, 1000), timeout=300)
app.replicator.serial_offset = 0
app.replicator.oid_list = oid_list
else:
......@@ -151,38 +141,28 @@ class ReplicationEventHandler(StorageEventHandler):
present_serial_list = app.dm.getSerialListPresent(oid, serial_list)
serial_set = set(serial_list) - set(present_serial_list)
for serial in serial_set:
msg_id = conn.getNextId()
p = protocol.askObject(msg_id, oid, serial, INVALID_TID)
conn.addPacket(p)
conn.expectMessage(msg_id, timeout = 300)
conn.ask(protocol.askObject(oid, serial, INVALID_TID), timeout=300)
# And, ask more serials.
app.replicator.serial_offset += 1000
offset = app.replicator.serial_offset
msg_id = conn.getNextId()
p = protocol.askObjectHistory(msg_id, oid, offset, offset + 1000)
conn.addPacket(p)
conn.expectMessage(msg_id, timeout = 300)
p = protocol.askObjectHistory(oid, offset, offset + 1000)
conn.ask(p, timeout=300)
else:
# This OID is finished. So advance to next.
oid_list = app.replicator.oid_list
if oid_list:
# If I have more pending OIDs, pick one up.
oid = oid_list.pop()
msg_id = conn.getNextId()
p = protocol.askObjectHistory(msg_id, oid, 0, 1000)
conn.addPacket(p)
conn.expectMessage(msg_id, timeout = 300)
conn.ask(protocol.askObjectHistory(oid, 0, 1000), timeout=300)
app.replicator.serial_offset = 0
else:
# Otherwise, acquire more OIDs.
app.replicator.oid_offset += 1000
offset = app.replicator.oid_offset
msg_id = conn.getNextId()
p = protocol.askOIDs(msg_id, offset, offset + 1000,
app.replicator.current_partition.getRID())
conn.addPacket(p)
conn.expectMessage(msg_id, timeout = 300)
conn.ask(p, timeout=300)
def handleAnswerObject(self, conn, packet, oid, serial_start,
serial_end, compression, checksum, data):
......@@ -284,9 +264,7 @@ class Replicator(object):
def _askCriticalTID(self):
conn = self.primary_master_connection
msg_id = conn.getNextId()
conn.addPacket(protocol.askLastIDs(msg_id))
conn.expectMessage(msg_id)
conn.ask(protocol.askLastIDs())
self.critical_tid_dict[msg_id] = self.new_partition_dict.values()
self.partition_dict.update(self.new_partition_dict)
self.new_partition_dict = {}
......@@ -300,9 +278,7 @@ class Replicator(object):
def _askUnfinishedTIDs(self):
conn = self.primary_master_connection
msg_id = conn.getNextId()
conn.addPacket(protocol.askUnfinishedTransactions(msg_id))
conn.expectMessage(msg_id)
conn.ask(protocol.askUnfinishedTransactions())
self.waiting_for_unfinished_tids = True
def _startReplication(self):
......@@ -334,17 +310,13 @@ class Replicator(object):
self.current_connection = ClientConnection(app.em, handler,
addr = addr,
connector_handler = app.connector_handler)
msg_id = self.current_connection.getNextId()
p = protocol.requestNodeIdentification(msg_id, STORAGE_NODE_TYPE, app.uuid,
p = protocol.requestNodeIdentification(STORAGE_NODE_TYPE, app.uuid,
app.server[0], app.server[1], app.name)
self.current_connection.addPacket(p)
self.current_connection.expectMessage(msg_id)
self.current_connection.ask(p)
self.tid_offset = 0
msg_id = self.current_connection.getNextId()
p = protocol.askTIDs(msg_id, 0, 1000, self.current_partition.getRID())
self.current_connection.addPacket(p)
self.current_connection.expectMessage(msg_id, timeout = 300)
p = protocol.askTIDs(0, 1000, self.current_partition.getRID())
self.current_connection.ask(p, timeout=300)
self.replication_done = False
......@@ -354,12 +326,9 @@ class Replicator(object):
self.partition_dict.pop(self.current_partition.getRID())
# Notify to a primary master node that my cell is now up-to-date.
conn = self.primary_master_connection
p = protocol.notifyPartitionChanges(conn.getNextId(),
app.ptid,
[(self.current_partition.getRID(),
app.uuid,
UP_TO_DATE_STATE)])
conn.addPacket(p)
p = protocol.notifyPartitionChanges( app.ptid,
[(self.current_partition.getRID(), app.uuid, UP_TO_DATE_STATE)])
conn.send(p)
except ValueError:
pass
self.current_partition = None
......
......@@ -69,13 +69,13 @@ class VerificationEventHandler(StorageEventHandler):
app = self.app
if node_type != MASTER_NODE_TYPE:
logging.info('reject a connection from a non-master')
conn.addPacket(protocol.notReady(packet.getId(), 'retry later'))
conn.answer(protocol.notReady('retry later'), packet)
conn.abort()
return
if name != app.name:
logging.error('reject an alien cluster')
conn.addPacket(protocol.protocolError(packet.getId(),
'invalid cluster name'))
conn.answer(protocol.protocolError(
'invalid cluster name'), packet)
conn.abort()
return
......@@ -88,8 +88,8 @@ class VerificationEventHandler(StorageEventHandler):
# If this node is broken, reject it.
if node.getUUID() == uuid:
if node.getState() == BROKEN_STATE:
p = protocol.brokenNodeDisallowedError(packet.getId(), 'go away')
conn.addPacket(p)
p = protocol.brokenNodeDisallowedError('go away')
conn.answer(p, packet)
conn.abort()
return
......@@ -97,11 +97,10 @@ class VerificationEventHandler(StorageEventHandler):
node.setUUID(uuid)
conn.setUUID(uuid)
p = protocol.acceptNodeIdentification(packet.getId(), STORAGE_NODE_TYPE,
app.uuid, app.server[0], app.server[1],
app.num_partitions, app.num_replicas,
uuid)
conn.addPacket(p)
p = protocol.acceptNodeIdentification(STORAGE_NODE_TYPE, app.uuid,
app.server[0], app.server[1], app.num_partitions,
app.num_replicas, uuid)
conn.answer(p, packet)
# Now the master node should know that I am not the right one.
conn.abort()
......@@ -128,8 +127,8 @@ class VerificationEventHandler(StorageEventHandler):
app = self.app
oid = app.dm.getLastOID() or INVALID_OID
tid = app.dm.getLastTID() or INVALID_TID
p = protocol.answerLastIDs(packet.getId(), oid, tid, app.ptid)
conn.addPacket(p)
p = protocol.answerLastIDs(oid, tid, app.ptid)
conn.answer(p, packet)
else:
self.handleUnexpectedPacket(conn, packet)
......@@ -147,13 +146,12 @@ class VerificationEventHandler(StorageEventHandler):
pass
row_list.append((offset, row))
except IndexError:
p = protocol.protocolError(packet.getId(),
'invalid partition table offset')
conn.addPacket(p)
p = protocol.protocolError( 'invalid partition table offset')
conn.answer(p, packer)
return
p = protocol.answerPartitionTable(packet.getId(), app.ptid, row_list)
conn.addPacket(p)
p = protocol.answerPartitionTable(app.ptid, row_list)
conn.answer(p, packet)
else:
self.handleUnexpectedPacket(conn, packet)
......@@ -236,8 +234,8 @@ class VerificationEventHandler(StorageEventHandler):
if not conn.isServerConnection():
app = self.app
tid_list = app.dm.getUnfinishedTIDList()
p = protocol.answerUnfinishedTransactions(packet.getId(), tid_list)
conn.addPacket(p)
p = protocol.answerUnfinishedTransactions(tid_list)
conn.answer(p, packet)
else:
self.handleUnexpectedPacket(conn, packet)
......@@ -252,21 +250,20 @@ class VerificationEventHandler(StorageEventHandler):
t = app.dm.getTransaction(tid)
if t is None:
p = protocol.tidNotFound(packet.getId(), '%s does not exist' % dump(tid))
p = protocol.tidNotFound('%s does not exist' % dump(tid))
else:
p = protocol.answerTransactionInformation(packet.getId(), tid,
t[1], t[2], t[3], t[0])
conn.addPacket(p)
p = protocol.answerTransactionInformation(tid, t[1], t[2], t[3], t[0])
conn.answer(p, packet)
def handleAskObjectPresent(self, conn, packet, oid, tid):
if not conn.isServerConnection():
app = self.app
if app.dm.objectPresent(oid, tid):
p = protocol.answerObjectPresent(packet.getId(), oid, tid)
p = protocol.answerObjectPresent(oid, tid)
else:
p = protocol.oidNotFound(packet.getId(),
p = protocol.oidNotFound(
'%s:%s do not exist' % (dump(oid), dump(tid)))
conn.addPacket(p)
conn.answer(p, packet)
else:
self.handleUnexpectedPacket(conn, packet)
......
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