Commit dfcf454d authored by Aurel's avatar Aurel

add handler to manage newOIDList

use new protocol for NodeIdentification
plus fix some variable,import


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@43 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 0569958a
...@@ -7,7 +7,7 @@ from struct import pack, unpack ...@@ -7,7 +7,7 @@ from struct import pack, unpack
from neo.config import ConfigurationManager from neo.config import ConfigurationManager
from neo.protocol import Packet, ProtocolError, \ from neo.protocol import Packet, ProtocolError, \
RUNNING_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, BROKEN_STATE, \ RUNNING_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, BROKEN_STATE, \
INVALID_UUID, INVALID_OID, INVALID_TID, INVALID_PTID INVALID_UUID, INVALID_OID, INVALID_TID, INVALID_PTID, CLIENT_NODE_TYPE
from neo.node import NodeManager, MasterNode, StorageNode, ClientNode from neo.node import NodeManager, MasterNode, StorageNode, ClientNode
from neo.event import EventManager from neo.event import EventManager
from neo.util import dump from neo.util import dump
...@@ -240,7 +240,7 @@ class Application(object): ...@@ -240,7 +240,7 @@ class Application(object):
for conn in em.getConnectionList(): for conn in em.getConnectionList():
if isinstance(conn, ClientConnection): if isinstance(conn, ClientConnection):
# Still not closed. # Still not closed.
closed = Falsed closed = False
break break
if time() > t + 10: if time() > t + 10:
...@@ -673,7 +673,7 @@ class Application(object): ...@@ -673,7 +673,7 @@ class Application(object):
"""I play a secondary role, thus only wait for a primary master to fail.""" """I play a secondary role, thus only wait for a primary master to fail."""
logging.info('play the secondary role') logging.info('play the secondary role')
handler = SecondaryEventHandler() handler = SecondaryEventHandler(self)
em = self.em em = self.em
nm = self.nm nm = self.nm
...@@ -728,3 +728,9 @@ class Application(object): ...@@ -728,3 +728,9 @@ class Application(object):
def getPartition(self, oid_or_tid): def getPartition(self, oid_or_tid):
return unpack('!Q', oid_or_tid)[0] % self.num_partitions return unpack('!Q', oid_or_tid)[0] % self.num_partitions
def getNewOidList(self, num_oid):
return [self.getNextOid() for i in xrange(n)]
...@@ -71,7 +71,8 @@ class ElectionEventHandler(MasterEventHandler): ...@@ -71,7 +71,8 @@ class ElectionEventHandler(MasterEventHandler):
MasterEventHandler.packetReceived(self, conn, packet) MasterEventHandler.packetReceived(self, conn, packet)
def handleAcceptNodeIdentification(self, conn, packet, node_type, def handleAcceptNodeIdentification(self, conn, packet, node_type,
uuid, ip_address, port): uuid, ip_address, port, num_partitions,
num_replicas):
if isinstance(conn, ClientConnection): if isinstance(conn, ClientConnection):
app = self.app app = self.app
node = app.nm.getNodeByServer(conn.getAddress()) node = app.nm.getNodeByServer(conn.getAddress())
...@@ -137,10 +138,10 @@ class ElectionEventHandler(MasterEventHandler): ...@@ -137,10 +138,10 @@ class ElectionEventHandler(MasterEventHandler):
# is old. So ignore it. # is old. So ignore it.
pass pass
else: else:
if node.getUUID() == primary_uuid: if primary_node.getUUID() == primary_uuid:
# Whatever the situation is, I trust this master. # Whatever the situation is, I trust this master.
app.primary = False app.primary = False
app.primary_master_node = node app.primary_master_node = primary_node
else: else:
if app.uuid < uuid: if app.uuid < uuid:
# I lost. # I lost.
...@@ -190,7 +191,8 @@ class ElectionEventHandler(MasterEventHandler): ...@@ -190,7 +191,8 @@ class ElectionEventHandler(MasterEventHandler):
p = Packet() p = Packet()
p.acceptNodeIdentification(packet.getId(), MASTER_NODE_TYPE, p.acceptNodeIdentification(packet.getId(), MASTER_NODE_TYPE,
app.uuid, app.server[0], app.server[1]) app.uuid, app.server[0], app.server[1],
app.num_partitions, app.num_replicas)
conn.addPacket(p) conn.addPacket(p)
# Next, the peer should ask a primary master node. # Next, the peer should ask a primary master node.
conn.expectMessage() conn.expectMessage()
......
...@@ -57,6 +57,10 @@ class MasterEventHandler(EventHandler): ...@@ -57,6 +57,10 @@ class MasterEventHandler(EventHandler):
logging.info('ignoring Ask New TID') logging.info('ignoring Ask New TID')
pass pass
def handleAskNewOIDList(self, conn, packet):
logging.info('ignoring Ask New OID List')
pass
def handleFinishTransaction(self, conn, packet, oid_list, tid): def handleFinishTransaction(self, conn, packet, oid_list, tid):
logging.info('ignoring Finish Transaction') logging.info('ignoring Finish Transaction')
pass pass
......
import logging import logging
from neo.protocol import MASTER_NODE_TYPE, \ from neo.protocol import MASTER_NODE_TYPE, \
RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \
STORAGE_NODE_TYPE
from neo.master.handler import MasterEventHandler from neo.master.handler import MasterEventHandler
from neo.exception import ElectionFailure from neo.exception import ElectionFailure
from neo.protocol import Packet, INVALID_UUID from neo.protocol import Packet, INVALID_UUID
from neo.node import ClientNode, StorageNode
from neo.util import dump from neo.util import dump
class RecoveryEventHandler(MasterEventHandler): class RecoveryEventHandler(MasterEventHandler):
...@@ -158,7 +160,8 @@ class RecoveryEventHandler(MasterEventHandler): ...@@ -158,7 +160,8 @@ class RecoveryEventHandler(MasterEventHandler):
p = Packet() p = Packet()
p.acceptNodeIdentification(packet.getId(), MASTER_NODE_TYPE, p.acceptNodeIdentification(packet.getId(), MASTER_NODE_TYPE,
app.uuid, app.server[0], app.server[1]) app.uuid, app.server[0], app.server[1],
app.num_partitions, app.num_replicas)
conn.addPacket(p) conn.addPacket(p)
# Next, the peer should ask a primary master node. # Next, the peer should ask a primary master node.
conn.expectMessage() conn.expectMessage()
......
...@@ -64,7 +64,8 @@ class SecondaryEventHandler(MasterEventHandler): ...@@ -64,7 +64,8 @@ class SecondaryEventHandler(MasterEventHandler):
p = Packet() p = Packet()
p.acceptNodeIdentification(packet.getId(), MASTER_NODE_TYPE, p.acceptNodeIdentification(packet.getId(), MASTER_NODE_TYPE,
app.uuid, app.server[0], app.server[1]) app.uuid, app.server[0], app.server[1],
app.num_partitions, app.num_replicas)
conn.addPacket(p) conn.addPacket(p)
# Next, the peer should ask a primary master node. # Next, the peer should ask a primary master node.
conn.expectMessage() conn.expectMessage()
......
...@@ -207,7 +207,8 @@ class ServiceEventHandler(MasterEventHandler): ...@@ -207,7 +207,8 @@ class ServiceEventHandler(MasterEventHandler):
p = Packet() p = Packet()
p.acceptNodeIdentification(packet.getId(), MASTER_NODE_TYPE, p.acceptNodeIdentification(packet.getId(), MASTER_NODE_TYPE,
app.uuid, app.server[0], app.server[1]) app.uuid, app.server[0], app.server[1],
app.num_partitions, app.num_replicas)
conn.addPacket(p) conn.addPacket(p)
# Next, the peer should ask a primary master node. # Next, the peer should ask a primary master node.
conn.expectMessage() conn.expectMessage()
...@@ -369,6 +370,22 @@ class ServiceEventHandler(MasterEventHandler): ...@@ -369,6 +370,22 @@ class ServiceEventHandler(MasterEventHandler):
tid = app.getNextTID() tid = app.getNextTID()
conn.addPacket(Packet().answerNewTID(packet.getId(), tid)) conn.addPacket(Packet().answerNewTID(packet.getId(), tid))
def handleAskNewOIDList(self, conn, packet, num_oid):
uuid = conn.getUUID()
if uuid is None:
self.handleUnexpectedPacket(conn, packet)
return
app = self.app
node = app.nm.getNodeByUUID(uuid)
if not isinstance(node, ClientNode):
self.handleUnexpectedPacket(conn, packet)
return
oid = app.getNextOIDList(num_oid)
conn.addPacket(Packet().answerNewOIDList(packet.getId(), num_oid, oid_list))
def handleFinishTransaction(self, conn, packet, oid_list, tid): def handleFinishTransaction(self, conn, packet, oid_list, tid):
uuid = conn.getUUID() uuid = conn.getUUID()
if uuid is None: if uuid is None:
......
...@@ -173,7 +173,8 @@ class VerificationEventHandler(MasterEventHandler): ...@@ -173,7 +173,8 @@ class VerificationEventHandler(MasterEventHandler):
p = Packet() p = Packet()
p.acceptNodeIdentification(packet.getId(), MASTER_NODE_TYPE, p.acceptNodeIdentification(packet.getId(), MASTER_NODE_TYPE,
app.uuid, app.server[0], app.server[1]) app.uuid, app.server[0], app.server[1],
app.num_partitions, app.num_replicas)
conn.addPacket(p) conn.addPacket(p)
# Next, the peer should ask a primary master node. # Next, the peer should ask a primary master node.
conn.expectMessage() conn.expectMessage()
......
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