Commit 8f08613c authored by Grégory Wisniewski's avatar Grégory Wisniewski

As previous commits, use new Enum class for cell states.


git-svn-id: https://svn.erp5.org/repos/neo/trunk@1339 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 6d746894
...@@ -868,8 +868,8 @@ class Application(object): ...@@ -868,8 +868,8 @@ class Application(object):
last = first - last last = first - last
# First get a list of transactions from all storage nodes. # First get a list of transactions from all storage nodes.
# Each storage node will return TIDs only for UP_TO_DATE_STATE and # Each storage node will return TIDs only for UP_TO_DATE state and
# FEEDING_STATE cells # FEEDING state cells
pt = self._getPartitionTable() pt = self._getPartitionTable()
storage_node_list = pt.getNodeList() storage_node_list = pt.getNodeList()
......
...@@ -18,10 +18,9 @@ ...@@ -18,10 +18,9 @@
from neo import logging from neo import logging
from neo import protocol from neo import protocol
from neo.protocol import UP_TO_DATE_STATE, FEEDING_STATE, \ from neo.protocol import INTERNAL_ERROR_CODE
DISCARDED_STATE, OUT_OF_DATE_STATE, INTERNAL_ERROR_CODE from neo.protocol import UnexpectedPacketError, CellStates
from neo.master.handlers import BaseServiceHandler from neo.master.handlers import BaseServiceHandler
from neo.protocol import UnexpectedPacketError
from neo.exception import OperationFailure from neo.exception import OperationFailure
from neo.util import dump from neo.util import dump
...@@ -90,7 +89,7 @@ class StorageServiceHandler(BaseServiceHandler): ...@@ -90,7 +89,7 @@ class StorageServiceHandler(BaseServiceHandler):
new_cell_list = [] new_cell_list = []
for cell in cell_list: for cell in cell_list:
if cell[2] != UP_TO_DATE_STATE: if cell[2] != CellStates.UP_TO_DATE:
logging.warn('only up-to-date state should be sent') logging.warn('only up-to-date state should be sent')
continue continue
...@@ -104,7 +103,8 @@ class StorageServiceHandler(BaseServiceHandler): ...@@ -104,7 +103,8 @@ class StorageServiceHandler(BaseServiceHandler):
# check the storage said it is up to date for a partition it was assigne to # check the storage said it is up to date for a partition it was assigne to
for xcell in app.pt.getCellList(offset): for xcell in app.pt.getCellList(offset):
if xcell.getNode().getUUID() == node.getUUID() and \ if xcell.getNode().getUUID() == node.getUUID() and \
xcell.getState() not in (OUT_OF_DATE_STATE, UP_TO_DATE_STATE): xcell.getState() not in (CellStates.OUT_OF_DATE,
CellStates.UP_TO_DATE):
msg = "node %s telling that it is UP TO DATE for offset \ msg = "node %s telling that it is UP TO DATE for offset \
%s but where %s for that offset" % (dump(node.getUUID()), offset, %s but where %s for that offset" % (dump(node.getUUID()), offset,
xcell.getState()) xcell.getState())
...@@ -113,15 +113,15 @@ class StorageServiceHandler(BaseServiceHandler): ...@@ -113,15 +113,15 @@ class StorageServiceHandler(BaseServiceHandler):
return return
app.pt.setCell(offset, node, UP_TO_DATE_STATE) app.pt.setCell(offset, node, CellStates.UP_TO_DATE)
new_cell_list.append(cell) new_cell_list.append(cell)
# If the partition contains a feeding cell, drop it now. # If the partition contains a feeding cell, drop it now.
for feeding_cell in app.pt.getCellList(offset): for feeding_cell in app.pt.getCellList(offset):
if feeding_cell.getState() == FEEDING_STATE: if feeding_cell.getState() == CellStates.FEEDING:
app.pt.removeCell(offset, feeding_cell.getNode()) app.pt.removeCell(offset, feeding_cell.getNode())
new_cell_list.append((offset, feeding_cell.getUUID(), new_cell_list.append((offset, feeding_cell.getUUID(),
DISCARDED_STATE)) CellStates.DISCARDED))
break break
if new_cell_list: if new_cell_list:
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
import neo.pt import neo.pt
from struct import pack, unpack from struct import pack, unpack
from neo.protocol import OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE from neo.protocol import CellStates
class PartitionTable(neo.pt.PartitionTable): class PartitionTable(neo.pt.PartitionTable):
"""This class manages a partition table for the primary master node""" """This class manages a partition table for the primary master node"""
...@@ -88,12 +88,12 @@ class PartitionTable(neo.pt.PartitionTable): ...@@ -88,12 +88,12 @@ class PartitionTable(neo.pt.PartitionTable):
node_list = [c.getNode() for c in row] node_list = [c.getNode() for c in row]
n = self.findLeastUsedNode(node_list) n = self.findLeastUsedNode(node_list)
if n is not None: if n is not None:
row.append(neo.pt.Cell(n, OUT_OF_DATE_STATE)) row.append(neo.pt.Cell(n, CellStates.OUT_OF_DATE))
self.count_dict[n] += 1 self.count_dict[n] += 1
cell_list.append((offset, n.getUUID(), cell_list.append((offset, n.getUUID(),
OUT_OF_DATE_STATE)) CellStates.OUT_OF_DATE))
row.remove(cell) row.remove(cell)
cell_list.append((offset, uuid, DISCARDED_STATE)) cell_list.append((offset, uuid, CellStates.DISCARDED))
break break
try: try:
...@@ -134,8 +134,8 @@ class PartitionTable(neo.pt.PartitionTable): ...@@ -134,8 +134,8 @@ class PartitionTable(neo.pt.PartitionTable):
continue continue
if num_cells <= self.nr: if num_cells <= self.nr:
row.append(neo.pt.Cell(node, OUT_OF_DATE_STATE)) row.append(neo.pt.Cell(node, CellStates.OUT_OF_DATE))
cell_list.append((offset, node.getUUID(), OUT_OF_DATE_STATE)) cell_list.append((offset, node.getUUID(), CellStates.OUT_OF_DATE))
node_count += 1 node_count += 1
else: else:
if max_count - node_count > 1: if max_count - node_count > 1:
...@@ -144,18 +144,18 @@ class PartitionTable(neo.pt.PartitionTable): ...@@ -144,18 +144,18 @@ class PartitionTable(neo.pt.PartitionTable):
# out-of-date, just drop the node. # out-of-date, just drop the node.
row.remove(max_cell) row.remove(max_cell)
cell_list.append((offset, max_cell.getUUID(), cell_list.append((offset, max_cell.getUUID(),
DISCARDED_STATE)) CellStates.DISCARDED))
self.count_dict[max_cell.getNode()] -= 1 self.count_dict[max_cell.getNode()] -= 1
else: else:
# Otherwise, use it as a feeding cell for safety. # Otherwise, use it as a feeding cell for safety.
max_cell.setState(FEEDING_STATE) max_cell.setState(CellStates.FEEDING)
cell_list.append((offset, max_cell.getUUID(), cell_list.append((offset, max_cell.getUUID(),
FEEDING_STATE)) CellStates.FEEDING))
# Don't count a feeding cell. # Don't count a feeding cell.
self.count_dict[max_cell.getNode()] -= 1 self.count_dict[max_cell.getNode()] -= 1
row.append(neo.pt.Cell(node, OUT_OF_DATE_STATE)) row.append(neo.pt.Cell(node, CellStates.OUT_OF_DATE))
cell_list.append((offset, node.getUUID(), cell_list.append((offset, node.getUUID(),
OUT_OF_DATE_STATE)) CellStates.OUT_OF_DATE))
node_count += 1 node_count += 1
self.count_dict[node] = node_count self.count_dict[node] = node_count
...@@ -220,7 +220,7 @@ class PartitionTable(neo.pt.PartitionTable): ...@@ -220,7 +220,7 @@ class PartitionTable(neo.pt.PartitionTable):
row.remove(cell) row.remove(cell)
if not cell.isFeeding(): if not cell.isFeeding():
self.count_dict[cell.getNode()] -= 1 self.count_dict[cell.getNode()] -= 1
changed_cell_list.append((offset, cell.getUUID(), DISCARDED_STATE)) changed_cell_list.append((offset, cell.getUUID(), CellStates.DISCARDED))
# Add cells, if a row contains less than the number of replicas. # Add cells, if a row contains less than the number of replicas.
for offset, row in enumerate(self.partition_list): for offset, row in enumerate(self.partition_list):
...@@ -232,8 +232,8 @@ class PartitionTable(neo.pt.PartitionTable): ...@@ -232,8 +232,8 @@ class PartitionTable(neo.pt.PartitionTable):
node = self.findLeastUsedNode([cell.getNode() for cell in row]) node = self.findLeastUsedNode([cell.getNode() for cell in row])
if node is None: if node is None:
break break
row.append(neo.pt.Cell(node, OUT_OF_DATE_STATE)) row.append(neo.pt.Cell(node, CellStates.OUT_OF_DATE))
changed_cell_list.append((offset, node.getUUID(), OUT_OF_DATE_STATE)) changed_cell_list.append((offset, node.getUUID(), CellStates.OUT_OF_DATE))
self.count_dict[node] += 1 self.count_dict[node] += 1
num_cells += 1 num_cells += 1
...@@ -250,7 +250,7 @@ class PartitionTable(neo.pt.PartitionTable): ...@@ -250,7 +250,7 @@ class PartitionTable(neo.pt.PartitionTable):
for offset, row in enumerate(self.partition_list): for offset, row in enumerate(self.partition_list):
for cell in row: for cell in row:
if not cell.getNode().isRunning() and not cell.isOutOfDate(): if not cell.getNode().isRunning() and not cell.isOutOfDate():
cell.setState(OUT_OF_DATE_STATE) cell.setState(CellStates.OUT_OF_DATE)
cell_list.append((offset, cell.getUUID(), OUT_OF_DATE_STATE)) cell_list.append((offset, cell.getUUID(), CellStates.OUT_OF_DATE))
return cell_list return cell_list
...@@ -318,26 +318,21 @@ error_codes = OldEnum({ ...@@ -318,26 +318,21 @@ error_codes = OldEnum({
}) })
class ClusterStates(Enum): class ClusterStates(Enum):
BOOTING = Enum.Item(1) BOOTING = Enum.Item(1)
RECOVERING = Enum.Item(2) RECOVERING = Enum.Item(2)
VERIFYING = Enum.Item(3) VERIFYING = Enum.Item(3)
RUNNING = Enum.Item(4) RUNNING = Enum.Item(4)
STOPPING = Enum.Item(5) STOPPING = Enum.Item(5)
ClusterStates = ClusterStates() ClusterStates = ClusterStates()
class NodeTypes(Enum): class NodeTypes(Enum):
MASTER = Enum.Item(1) MASTER = Enum.Item(1)
STORAGE = Enum.Item(2) STORAGE = Enum.Item(2)
CLIENT = Enum.Item(3) CLIENT = Enum.Item(3)
ADMIN = Enum.Item(4) ADMIN = Enum.Item(4)
NodeTypes = NodeTypes() NodeTypes = NodeTypes()
class NodeStates(Enum): class NodeStates(Enum):
RUNNING = Enum.Item(1) RUNNING = Enum.Item(1)
TEMPORARILY_DOWN = Enum.Item(2) TEMPORARILY_DOWN = Enum.Item(2)
DOWN = Enum.Item(3) DOWN = Enum.Item(3)
...@@ -345,9 +340,15 @@ class NodeStates(Enum): ...@@ -345,9 +340,15 @@ class NodeStates(Enum):
HIDDEN = Enum.Item(5) HIDDEN = Enum.Item(5)
PENDING = Enum.Item(6) PENDING = Enum.Item(6)
UNKNOWN = Enum.Item(7) UNKNOWN = Enum.Item(7)
NodeStates = NodeStates() NodeStates = NodeStates()
class CellStates(Enum):
UP_TO_DATE = Enum.Item(1)
OUT_OF_DATE = Enum.Item(2)
FEEDING = Enum.Item(3)
DISCARDED = Enum.Item(4)
CellStates = CellStates()
# used for logging # used for logging
node_state_prefix_dict = { node_state_prefix_dict = {
NodeStates.RUNNING: 'R', NodeStates.RUNNING: 'R',
...@@ -359,20 +360,12 @@ node_state_prefix_dict = { ...@@ -359,20 +360,12 @@ node_state_prefix_dict = {
NodeStates.UNKNOWN: 'U', NodeStates.UNKNOWN: 'U',
} }
# Partition cell states.
cell_states = OldEnum({
'UP_TO_DATE_STATE': 0,
'OUT_OF_DATE_STATE': 1,
'FEEDING_STATE': 2,
'DISCARDED_STATE': 3,
})
# used for logging # used for logging
cell_state_prefix_dict = { cell_state_prefix_dict = {
UP_TO_DATE_STATE: 'U', CellStates.UP_TO_DATE: 'U',
OUT_OF_DATE_STATE: 'O', CellStates.OUT_OF_DATE: 'O',
FEEDING_STATE: 'F', CellStates.FEEDING: 'F',
DISCARDED_STATE: 'D', CellStates.DISCARDED: 'D',
} }
# Other constants. # Other constants.
...@@ -693,7 +686,7 @@ def _decodeAnswerPartitionTable(body): ...@@ -693,7 +686,7 @@ def _decodeAnswerPartitionTable(body):
for j in xrange(m): for j in xrange(m):
uuid, state = unpack('!16sH', body[index:index+18]) uuid, state = unpack('!16sH', body[index:index+18])
index += 18 index += 18
state = cell_states.get(state) state = CellStates.get(state)
uuid = _decodeUUID(uuid) uuid = _decodeUUID(uuid)
cell_list.append((uuid, state)) cell_list.append((uuid, state))
row_list.append((offset, tuple(cell_list))) row_list.append((offset, tuple(cell_list)))
...@@ -714,7 +707,7 @@ def _decodeSendPartitionTable(body): ...@@ -714,7 +707,7 @@ def _decodeSendPartitionTable(body):
for j in xrange(m): for j in xrange(m):
uuid, state = unpack('!16sH', body[index:index+18]) uuid, state = unpack('!16sH', body[index:index+18])
index += 18 index += 18
state = cell_states.get(state) state = CellStates.get(state)
uuid = _decodeUUID(uuid) uuid = _decodeUUID(uuid)
cell_list.append((uuid, state)) cell_list.append((uuid, state))
row_list.append((offset, tuple(cell_list))) row_list.append((offset, tuple(cell_list)))
...@@ -729,7 +722,7 @@ def _decodeNotifyPartitionChanges(body): ...@@ -729,7 +722,7 @@ def _decodeNotifyPartitionChanges(body):
cell_list = [] cell_list = []
for i in xrange(n): for i in xrange(n):
(offset, uuid, state) = unpack('!L16sH', body[12+i*22:34+i*22]) (offset, uuid, state) = unpack('!L16sH', body[12+i*22:34+i*22])
state = cell_states.get(state) state = CellStates.get(state)
uuid = _decodeUUID(uuid) uuid = _decodeUUID(uuid)
cell_list.append((offset, uuid, state)) cell_list.append((offset, uuid, state))
return ptid, cell_list return ptid, cell_list
...@@ -1012,7 +1005,7 @@ def _decodeAnswerPartitionList(body): ...@@ -1012,7 +1005,7 @@ def _decodeAnswerPartitionList(body):
for j in xrange(m): for j in xrange(m):
uuid, state = unpack('!16sH', body[index:index+18]) uuid, state = unpack('!16sH', body[index:index+18])
index += 18 index += 18
state = cell_states.get(state) state = CellStates.get(state)
uuid = _decodeUUID(uuid) uuid = _decodeUUID(uuid)
cell_list.append((uuid, state)) cell_list.append((uuid, state))
row_list.append((offset, tuple(cell_list))) row_list.append((offset, tuple(cell_list)))
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
from neo import logging from neo import logging
from neo import protocol from neo import protocol
from neo.protocol import CellStates
from neo.util import dump, u64 from neo.util import dump, u64
from neo.locking import RLock from neo.locking import RLock
...@@ -25,7 +26,7 @@ from neo.locking import RLock ...@@ -25,7 +26,7 @@ from neo.locking import RLock
class Cell(object): class Cell(object):
"""This class represents a cell in a partition table.""" """This class represents a cell in a partition table."""
def __init__(self, node, state = protocol.UP_TO_DATE_STATE): def __init__(self, node, state = CellStates.UP_TO_DATE):
self.node = node self.node = node
self.state = state self.state = state
...@@ -36,13 +37,13 @@ class Cell(object): ...@@ -36,13 +37,13 @@ class Cell(object):
self.state = state self.state = state
def isUpToDate(self): def isUpToDate(self):
return self.state == protocol.UP_TO_DATE_STATE return self.state == CellStates.UP_TO_DATE
def isOutOfDate(self): def isOutOfDate(self):
return self.state == protocol.OUT_OF_DATE_STATE return self.state == CellStates.OUT_OF_DATE
def isFeeding(self): def isFeeding(self):
return self.state == protocol.FEEDING_STATE return self.state == CellStates.FEEDING
def getNode(self): def getNode(self):
return self.node return self.node
...@@ -107,13 +108,13 @@ class PartitionTable(object): ...@@ -107,13 +108,13 @@ class PartitionTable(object):
def getCellList(self, offset, readable=False, writable=False): def getCellList(self, offset, readable=False, writable=False):
# allow all cell states # allow all cell states
state_set = set(protocol.cell_states.values()) state_set = set(CellStates.values())
if readable or writable: if readable or writable:
# except non readables # except non readables
state_set.remove(protocol.DISCARDED_STATE) state_set.remove(CellStates.DISCARDED)
if readable: if readable:
# except non writables # except non writables
state_set.remove(protocol.OUT_OF_DATE_STATE) state_set.remove(CellStates.OUT_OF_DATE)
allowed_states = tuple(state_set) allowed_states = tuple(state_set)
try: try:
return [cell for cell in self.partition_list[offset] \ return [cell for cell in self.partition_list[offset] \
...@@ -133,7 +134,7 @@ class PartitionTable(object): ...@@ -133,7 +134,7 @@ class PartitionTable(object):
return index % self.np return index % self.np
def setCell(self, offset, node, state): def setCell(self, offset, node, state):
if state == protocol.DISCARDED_STATE: if state == CellStates.DISCARDED:
return self.removeCell(offset, node) return self.removeCell(offset, node)
if node.isBroken() or node.isDown(): if node.isBroken() or node.isDown():
return return
...@@ -143,7 +144,7 @@ class PartitionTable(object): ...@@ -143,7 +144,7 @@ class PartitionTable(object):
if len(row) == 0: if len(row) == 0:
# Create a new row. # Create a new row.
row = [Cell(node, state), ] row = [Cell(node, state), ]
if state != protocol.FEEDING_STATE: if state != CellStates.FEEDING:
self.count_dict[node] += 1 self.count_dict[node] += 1
self.partition_list[offset] = row self.partition_list[offset] = row
...@@ -158,7 +159,7 @@ class PartitionTable(object): ...@@ -158,7 +159,7 @@ class PartitionTable(object):
self.count_dict[node] -= 1 self.count_dict[node] -= 1
break break
row.append(Cell(node, state)) row.append(Cell(node, state))
if state != protocol.FEEDING_STATE: if state != CellStates.FEEDING:
self.count_dict[node] += 1 self.count_dict[node] += 1
def removeCell(self, offset, node): def removeCell(self, offset, node):
...@@ -220,7 +221,7 @@ class PartitionTable(object): ...@@ -220,7 +221,7 @@ class PartitionTable(object):
DEBUG:root:pt: 00000009: U..U|.UU.|U..U|.UU.|U..U|.UU.|U..U|.UU.|U..U DEBUG:root:pt: 00000009: U..U|.UU.|U..U|.UU.|U..U|.UU.|U..U|.UU.|U..U
Here, there are 4 nodes in RUNNING state. Here, there are 4 nodes in RUNNING state.
The first partition has 2 replicas in UP_TO_DATE_STATE, on nodes 1 and The first partition has 2 replicas in UP_TO_DATE state, on nodes 1 and
2 (nodes 0 and 3 are displayed as unused for that partition by 2 (nodes 0 and 3 are displayed as unused for that partition by
displaying a dot). displaying a dot).
The 8-digits number on the left represents the number of the first The 8-digits number on the left represents the number of the first
......
...@@ -20,7 +20,7 @@ import sys ...@@ -20,7 +20,7 @@ import sys
from collections import deque from collections import deque
from neo import protocol from neo import protocol
from neo.protocol import NodeTypes from neo.protocol import NodeTypes, CellStates
from neo.node import NodeManager from neo.node import NodeManager
from neo.event import EventManager from neo.event import EventManager
from neo.storage.mysqldb import MySQLDatabaseManager from neo.storage.mysqldb import MySQLDatabaseManager
...@@ -132,7 +132,7 @@ class Application(object): ...@@ -132,7 +132,7 @@ class Application(object):
new_cell_list = [] new_cell_list = []
for offset, uuid, state in cell_list: for offset, uuid, state in cell_list:
# convert from int to Enum # convert from int to Enum
state = protocol.cell_states[state] state = CellStates[state]
# register unknown nodes # register unknown nodes
if self.nm.getByUUID(uuid) is None: if self.nm.getByUUID(uuid) is None:
self.nm.createStorage(uuid=uuid) self.nm.createStorage(uuid=uuid)
......
...@@ -18,8 +18,7 @@ ...@@ -18,8 +18,7 @@
from neo import logging from neo import logging
from neo.storage.handlers import BaseMasterHandler from neo.storage.handlers import BaseMasterHandler
from neo.protocol import DISCARDED_STATE, OUT_OF_DATE_STATE from neo.protocol import NodeTypes, NodeStates, CellStates
from neo.protocol import NodeTypes, NodeStates
class HiddenHandler(BaseMasterHandler): class HiddenHandler(BaseMasterHandler):
"""This class implements a generic part of the event handlers.""" """This class implements a generic part of the event handlers."""
...@@ -81,9 +80,9 @@ class HiddenHandler(BaseMasterHandler): ...@@ -81,9 +80,9 @@ class HiddenHandler(BaseMasterHandler):
for offset, uuid, state in cell_list: for offset, uuid, state in cell_list:
if uuid == app.uuid and app.replicator is not None: if uuid == app.uuid and app.replicator is not None:
# If this is for myself, this can affect replications. # If this is for myself, this can affect replications.
if state == DISCARDED_STATE: if state == CellStates.DISCARDED:
app.replicator.removePartition(offset) app.replicator.removePartition(offset)
elif state == OUT_OF_DATE_STATE: elif state == CellStates.OUT_OF_DATE:
app.replicator.addPartition(offset) app.replicator.addPartition(offset)
def handleStartOperation(self, conn, packet): def handleStartOperation(self, conn, packet):
......
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
from neo import logging from neo import logging
from neo import protocol from neo import protocol
from neo.protocol import CellStates
from neo.storage.handlers import BaseMasterHandler from neo.storage.handlers import BaseMasterHandler
from neo.protocol import DISCARDED_STATE, OUT_OF_DATE_STATE
from neo.exception import OperationFailure from neo.exception import OperationFailure
...@@ -52,9 +52,9 @@ class MasterOperationHandler(BaseMasterHandler): ...@@ -52,9 +52,9 @@ class MasterOperationHandler(BaseMasterHandler):
for offset, uuid, state in cell_list: for offset, uuid, state in cell_list:
if uuid == app.uuid and app.replicator is not None: if uuid == app.uuid and app.replicator is not None:
# If this is for myself, this can affect replications. # If this is for myself, this can affect replications.
if state == DISCARDED_STATE: if state == CellStates.DISCARDED:
app.replicator.removePartition(offset) app.replicator.removePartition(offset)
elif state == OUT_OF_DATE_STATE: elif state == CellStates.OUT_OF_DATE:
app.replicator.addPartition(offset) app.replicator.addPartition(offset)
def handleLockInformation(self, conn, packet, tid): def handleLockInformation(self, conn, packet, tid):
......
...@@ -25,7 +25,7 @@ from struct import pack, unpack ...@@ -25,7 +25,7 @@ from struct import pack, unpack
from neo.storage.database import DatabaseManager from neo.storage.database import DatabaseManager
from neo.exception import DatabaseFailure from neo.exception import DatabaseFailure
from neo.protocol import DISCARDED_STATE from neo.protocol import CellStates
from neo import util from neo import util
LOG_QUERIES = False LOG_QUERIES = False
...@@ -362,7 +362,7 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -362,7 +362,7 @@ class MySQLDatabaseManager(DatabaseManager):
q("""TRUNCATE pt""") q("""TRUNCATE pt""")
for offset, uuid, state in cell_list: for offset, uuid, state in cell_list:
uuid = e(util.dump(uuid)) uuid = e(util.dump(uuid))
if state == DISCARDED_STATE: if state == CellStates.DISCARDED:
q("""DELETE FROM pt WHERE rid = %d AND uuid = '%s'""" \ q("""DELETE FROM pt WHERE rid = %d AND uuid = '%s'""" \
% (offset, uuid)) % (offset, uuid))
else: else:
......
...@@ -20,8 +20,7 @@ from random import choice ...@@ -20,8 +20,7 @@ from random import choice
from neo.storage.handlers import replication from neo.storage.handlers import replication
from neo import protocol from neo import protocol
from neo.protocol import UP_TO_DATE_STATE, OUT_OF_DATE_STATE from neo.protocol import NodeTypes, NodeStates, CellStates
from neo.protocol import NodeTypes, NodeStates
from neo.connection import ClientConnection from neo.connection import ClientConnection
from neo.util import dump from neo.util import dump
...@@ -107,7 +106,7 @@ class Replicator(object): ...@@ -107,7 +106,7 @@ class Replicator(object):
partition_dict = {} partition_dict = {}
for offset in xrange(app.pt.getPartitions()): for offset in xrange(app.pt.getPartitions()):
for uuid, state in app.pt.getRow(offset): for uuid, state in app.pt.getRow(offset):
if uuid == app.uuid and state == OUT_OF_DATE_STATE: if uuid == app.uuid and state == CellStates.OUT_OF_DATE:
partition_dict[offset] = Partition(offset) partition_dict[offset] = Partition(offset)
return partition_dict return partition_dict
...@@ -197,7 +196,7 @@ class Replicator(object): ...@@ -197,7 +196,7 @@ class Replicator(object):
# Notify to a primary master node that my cell is now up-to-date. # Notify to a primary master node that my cell is now up-to-date.
conn = self.primary_master_connection conn = self.primary_master_connection
p = protocol.notifyPartitionChanges(app.pt.getID(), p = protocol.notifyPartitionChanges(app.pt.getID(),
[(self.current_partition.getRID(), app.uuid, UP_TO_DATE_STATE)]) [(self.current_partition.getRID(), app.uuid, CellStates.UP_TO_DATE)])
conn.notify(p) conn.notify(p)
except KeyError: except KeyError:
pass pass
......
...@@ -23,8 +23,7 @@ from neo.tests import NeoTestBase ...@@ -23,8 +23,7 @@ from neo.tests import NeoTestBase
from neo import protocol from neo import protocol
from neo.pt import PartitionTable from neo.pt import PartitionTable
from neo.protocol import UnexpectedPacketError, INVALID_UUID from neo.protocol import UnexpectedPacketError, INVALID_UUID
from neo.protocol import NodeTypes, NodeStates, INVALID_PTID, \ from neo.protocol import NodeTypes, NodeStates, CellStates, INVALID_PTID
UP_TO_DATE_STATE, FEEDING_STATE, DISCARDED_STATE
from neo.client.handlers import BaseHandler from neo.client.handlers import BaseHandler
from neo.client.handlers.master import PrimaryBootstrapHandler from neo.client.handlers.master import PrimaryBootstrapHandler
from neo.client.handlers.master import PrimaryNotificationsHandler, PrimaryAnswersHandler from neo.client.handlers.master import PrimaryNotificationsHandler, PrimaryAnswersHandler
...@@ -722,7 +721,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -722,7 +721,7 @@ class ClientHandlerTests(NeoTestBase):
conn = self.getConnection(uuid=test_master_uuid) conn = self.getConnection(uuid=test_master_uuid)
test_storage_uuid = self.getNewUUID() test_storage_uuid = self.getNewUUID()
# TODO: use realistic values # TODO: use realistic values
test_cell_list = [(0, test_storage_uuid, UP_TO_DATE_STATE)] test_cell_list = [(0, test_storage_uuid, CellStates.UP_TO_DATE)]
client_handler.handleNotifyPartitionChanges(conn, None, test_ptid + 1, test_cell_list) client_handler.handleNotifyPartitionChanges(conn, None, test_ptid + 1, test_cell_list)
# Check that a new node got added # Check that a new node got added
add_call_list = app.nm.mockGetNamedCalls('add') add_call_list = app.nm.mockGetNamedCalls('add')
...@@ -751,10 +750,10 @@ class ClientHandlerTests(NeoTestBase): ...@@ -751,10 +750,10 @@ class ClientHandlerTests(NeoTestBase):
client_handler = PrimaryNotificationsHandler(app, self.getDispatcher()) client_handler = PrimaryNotificationsHandler(app, self.getDispatcher())
conn = self.getConnection(uuid=uuid1) conn = self.getConnection(uuid=uuid1)
test_cell_list = [ test_cell_list = [
(0, uuid1, UP_TO_DATE_STATE), (0, uuid1, CellStates.UP_TO_DATE),
(0, uuid2, DISCARDED_STATE), (0, uuid2, CellStates.DISCARDED),
(0, uuid3, FEEDING_STATE), (0, uuid3, CellStates.FEEDING),
(0, uuid4, UP_TO_DATE_STATE), (0, uuid4, CellStates.UP_TO_DATE),
] ]
client_handler.handleNotifyPartitionChanges(conn, None, test_ptid + 1, test_cell_list) client_handler.handleNotifyPartitionChanges(conn, None, test_ptid + 1, test_cell_list)
# Check that the three last node got added # Check that the three last node got added
......
...@@ -15,8 +15,6 @@ ...@@ -15,8 +15,6 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
from neo.neoctl.neoctl import NeoCTL, NotReadyException
from neo import protocol
import os import os
import sys import sys
import time import time
...@@ -28,7 +26,8 @@ import unittest ...@@ -28,7 +26,8 @@ import unittest
import tempfile import tempfile
import traceback import traceback
from neo.protocol import ClusterStates, NodeTypes from neo.neoctl.neoctl import NeoCTL, NotReadyException
from neo.protocol import ClusterStates, NodeTypes, CellStates
from neo.client.Storage import Storage from neo.client.Storage import Storage
from neo.tests import getNewUUID from neo.tests import getNewUUID
from neo.util import dump from neo.util import dump
...@@ -411,7 +410,7 @@ class NEOCluster(object): ...@@ -411,7 +410,7 @@ class NEOCluster(object):
number_of_oudated = 0 number_of_oudated = 0
for row in row_list: for row in row_list:
for cell in row[1]: for cell in row[1]:
if cell[1] == protocol.OUT_OF_DATE_STATE: if cell[1] == CellStates.OUT_OF_DATE:
number_of_oudated += 1 number_of_oudated += 1
return number_of_oudated == number, number_of_oudated return number_of_oudated == number, number_of_oudated
self.expectCondition(callback, timeout, delay) self.expectCondition(callback, timeout, delay)
......
This diff is collapsed.
...@@ -22,7 +22,7 @@ from mock import Mock ...@@ -22,7 +22,7 @@ from mock import Mock
from struct import pack, unpack from struct import pack, unpack
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
from neo import protocol from neo import protocol
from neo.protocol import Packet, NodeTypes, NodeStates, INVALID_UUID from neo.protocol import Packet, NodeTypes, NodeStates, CellStates, INVALID_UUID
from neo.master.handlers.recovery import RecoveryHandler from neo.master.handlers.recovery import RecoveryHandler
from neo.master.app import Application from neo.master.app import Application
from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIFICATION, \ from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIFICATION, \
...@@ -39,11 +39,8 @@ from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIF ...@@ -39,11 +39,8 @@ from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIF
ABORT_TRANSACTION, ASK_STORE_TRANSACTION, ANSWER_STORE_TRANSACTION, \ ABORT_TRANSACTION, ASK_STORE_TRANSACTION, ANSWER_STORE_TRANSACTION, \
ASK_OBJECT, ANSWER_OBJECT, ASK_TIDS, ANSWER_TIDS, ASK_TRANSACTION_INFORMATION, \ ASK_OBJECT, ANSWER_OBJECT, ASK_TIDS, ANSWER_TIDS, ASK_TRANSACTION_INFORMATION, \
ANSWER_TRANSACTION_INFORMATION, ASK_OBJECT_HISTORY, ANSWER_OBJECT_HISTORY, \ ANSWER_TRANSACTION_INFORMATION, ASK_OBJECT_HISTORY, ANSWER_OBJECT_HISTORY, \
ASK_OIDS, ANSWER_OIDS, \ ASK_OIDS, ANSWER_OIDS, NOT_READY_CODE, OID_NOT_FOUND_CODE, TID_NOT_FOUND_CODE, \
NOT_READY_CODE, OID_NOT_FOUND_CODE, TID_NOT_FOUND_CODE, \ PROTOCOL_ERROR_CODE, BROKEN_NODE_DISALLOWED_CODE, INTERNAL_ERROR_CODE
PROTOCOL_ERROR_CODE, BROKEN_NODE_DISALLOWED_CODE, \
INTERNAL_ERROR_CODE, \
UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE
from neo.exception import OperationFailure, ElectionFailure from neo.exception import OperationFailure, ElectionFailure
from neo.tests import DoNothingConnector from neo.tests import DoNothingConnector
from neo.connection import ClientConnection from neo.connection import ClientConnection
...@@ -209,28 +206,28 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -209,28 +206,28 @@ class MasterRecoveryTests(NeoTestBase):
conn = self.getFakeConnection(uuid, self.storage_port) conn = self.getFakeConnection(uuid, self.storage_port)
self.assertNotEquals(self.app.target_uuid, uuid) self.assertNotEquals(self.app.target_uuid, uuid)
offset = 1 offset = 1
cell_list = [(offset, uuid, UP_TO_DATE_STATE)] cell_list = [(offset, uuid, CellStates.UP_TO_DATE)]
cells = self.app.pt.getRow(offset) cells = self.app.pt.getRow(offset)
for cell, state in cells: for cell, state in cells:
self.assertEquals(state, OUT_OF_DATE_STATE) self.assertEquals(state, CellStates.OUT_OF_DATE)
recovery.handleAnswerPartitionTable(conn, packet, None, cell_list) recovery.handleAnswerPartitionTable(conn, packet, None, cell_list)
cells = self.app.pt.getRow(offset) cells = self.app.pt.getRow(offset)
for cell, state in cells: for cell, state in cells:
self.assertEquals(state, OUT_OF_DATE_STATE) self.assertEquals(state, CellStates.OUT_OF_DATE)
# from target node, taken into account # from target node, taken into account
conn = self.getFakeConnection(uuid, self.storage_port) conn = self.getFakeConnection(uuid, self.storage_port)
self.assertNotEquals(self.app.target_uuid, uuid) self.assertNotEquals(self.app.target_uuid, uuid)
self.app.target_uuid = uuid self.app.target_uuid = uuid
self.assertEquals(self.app.target_uuid, uuid) self.assertEquals(self.app.target_uuid, uuid)
offset = 1 offset = 1
cell_list = [(offset, ((uuid, UP_TO_DATE_STATE,),),)] cell_list = [(offset, ((uuid, CellStates.UP_TO_DATE,),),)]
cells = self.app.pt.getRow(offset) cells = self.app.pt.getRow(offset)
for cell, state in cells: for cell, state in cells:
self.assertEquals(state, OUT_OF_DATE_STATE) self.assertEquals(state, CellStates.OUT_OF_DATE)
recovery.handleAnswerPartitionTable(conn, packet, None, cell_list) recovery.handleAnswerPartitionTable(conn, packet, None, cell_list)
cells = self.app.pt.getRow(offset) cells = self.app.pt.getRow(offset)
for cell, state in cells: for cell, state in cells:
self.assertEquals(state, UP_TO_DATE_STATE) self.assertEquals(state, CellStates.UP_TO_DATE)
# give a bad offset, must send error # give a bad offset, must send error
conn = self.getFakeConnection(uuid, self.storage_port) conn = self.getFakeConnection(uuid, self.storage_port)
self.assertEquals(self.app.target_uuid, uuid) self.assertEquals(self.app.target_uuid, uuid)
......
...@@ -23,15 +23,14 @@ from struct import pack, unpack ...@@ -23,15 +23,14 @@ from struct import pack, unpack
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
import neo.master import neo.master
from neo import protocol from neo import protocol
from neo.protocol import Packet, NodeTypes, NodeStates, INVALID_UUID from neo.protocol import Packet, NodeTypes, NodeStates, CellStates, INVALID_UUID
from neo.master.handlers.storage import StorageServiceHandler from neo.master.handlers.storage import StorageServiceHandler
from neo.master.app import Application from neo.master.app import Application
from neo.protocol import ERROR, PING, PONG, ANNOUNCE_PRIMARY_MASTER, \ from neo.protocol import ERROR, PING, PONG, ANNOUNCE_PRIMARY_MASTER, \
REELECT_PRIMARY_MASTER, NOTIFY_NODE_INFORMATION, \ REELECT_PRIMARY_MASTER, NOTIFY_NODE_INFORMATION, \
ASK_LAST_IDS, ANSWER_LAST_IDS, NOTIFY_PARTITION_CHANGES, \ ASK_LAST_IDS, ANSWER_LAST_IDS, NOTIFY_PARTITION_CHANGES, \
ASK_UNFINISHED_TRANSACTIONS, ASK_BEGIN_TRANSACTION, FINISH_TRANSACTION, \ ASK_UNFINISHED_TRANSACTIONS, ASK_BEGIN_TRANSACTION, FINISH_TRANSACTION, \
NOTIFY_INFORMATION_LOCKED, ASK_NEW_OIDS, ABORT_TRANSACTION, \ NOTIFY_INFORMATION_LOCKED, ASK_NEW_OIDS, ABORT_TRANSACTION
UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE
from neo.exception import OperationFailure, ElectionFailure from neo.exception import OperationFailure, ElectionFailure
class MasterStorageHandlerTests(NeoTestBase): class MasterStorageHandlerTests(NeoTestBase):
...@@ -137,7 +136,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -137,7 +136,7 @@ class MasterStorageHandlerTests(NeoTestBase):
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
sn = self.app.nm.getStorageList()[0] sn = self.app.nm.getStorageList()[0]
self.assertEquals(sn.getState(), BROKEN_STATE) self.assertEquals(sn.getState(), CellStates.BROKEN)
self.failUnless(ptid < self.app.pt.getID()) self.failUnless(ptid < self.app.pt.getID())
def test_06_handleAnswerLastIDs(self): def test_06_handleAnswerLastIDs(self):
...@@ -257,53 +256,54 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -257,53 +256,54 @@ class MasterStorageHandlerTests(NeoTestBase):
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
storage_uuid = self.identifyToMasterNode(port=self.storage_port+1) storage_uuid = self.identifyToMasterNode(port=self.storage_port+1)
offset = 1 offset = 1
cell_list = [(offset, uuid, FEEDING_STATE),] cell_list = [(offset, uuid, CellStates.FEEDING),]
cells = self.app.pt.getRow(offset) cells = self.app.pt.getRow(offset)
for cell, state in cells: for cell, state in cells:
self.assertEquals(state, OUT_OF_DATE_STATE) self.assertEquals(state, CellStates.OUT_OF_DATE)
service.handleNotifyPartitionChanges(conn, packet, self.app.pt.getID(), cell_list) service.handleNotifyPartitionChanges(conn, packet, self.app.pt.getID(), cell_list)
cells = self.app.pt.getRow(offset) cells = self.app.pt.getRow(offset)
for cell, state in cells: for cell, state in cells:
self.assertEquals(state, OUT_OF_DATE_STATE) self.assertEquals(state, CellStates.OUT_OF_DATE)
# send for another node, must not be take into account # send for another node, must not be take into account
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
offset = 1 offset = 1
cell_list = [(offset, storage_uuid, UP_TO_DATE_STATE),] cell_list = [(offset, storage_uuid, CellStates.UP_TO_DATE),]
cells = self.app.pt.getRow(offset) cells = self.app.pt.getRow(offset)
for cell, state in cells: for cell, state in cells:
self.assertEquals(state, OUT_OF_DATE_STATE) self.assertEquals(state, CellStates.OUT_OF_DATE)
service.handleNotifyPartitionChanges(conn, packet, self.app.pt.getID(), cell_list) service.handleNotifyPartitionChanges(conn, packet, self.app.pt.getID(), cell_list)
cells = self.app.pt.getRow(offset) cells = self.app.pt.getRow(offset)
for cell, state in cells: for cell, state in cells:
self.assertEquals(state, OUT_OF_DATE_STATE) self.assertEquals(state, CellStates.OUT_OF_DATE)
# send for itself, must be taken into account # send for itself, must be taken into account
# and the feeding node must be removed # and the feeding node must be removed
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
cell_list = [(offset, uuid, UP_TO_DATE_STATE),] cell_list = [(offset, uuid, CellStates.UP_TO_DATE),]
cells = self.app.pt.getRow(offset) cells = self.app.pt.getRow(offset)
for cell, state in cells: for cell, state in cells:
self.assertEquals(state, OUT_OF_DATE_STATE) self.assertEquals(state, CellStates.OUT_OF_DATE)
# mark the second storage node as feeding and say we are up to date # mark the second storage node as feeding and say we are up to date
# second node must go to discarded state and first one to up to date state # second node must go to discarded state and first one to up to date state
self.app.pt.setCell(offset, self.app.nm.getByUUID(storage_uuid), FEEDING_STATE) self.app.pt.setCell(offset, self.app.nm.getByUUID(storage_uuid),
cell_list = [(offset, uuid, UP_TO_DATE_STATE),] CellStates.FEEDING)
cell_list = [(offset, uuid, CellStates.UP_TO_DATE),]
cells = self.app.pt.getRow(offset) cells = self.app.pt.getRow(offset)
for cell, state in cells: for cell, state in cells:
if cell == storage_uuid: if cell == storage_uuid:
self.assertEquals(state, FEEDING_STATE) self.assertEquals(state, CellStates.FEEDING)
else: else:
self.assertEquals(state, OUT_OF_DATE_STATE) self.assertEquals(state, CellStates.OUT_OF_DATE)
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
service.handleNotifyPartitionChanges(conn, packet, self.app.pt.getID(), cell_list) service.handleNotifyPartitionChanges(conn, packet, self.app.pt.getID(), cell_list)
self.failUnless(lptid < self.app.pt.getID()) self.failUnless(lptid < self.app.pt.getID())
cells = self.app.pt.getRow(offset) cells = self.app.pt.getRow(offset)
for cell, state in cells: for cell, state in cells:
if cell == uuid: if cell == uuid:
self.assertEquals(state, UP_TO_DATE_STATE) self.assertEquals(state, CellStates.UP_TO_DATE)
else: else:
self.assertEquals(state, DISCARDED_STATE) self.assertEquals(state, CellStates.DISCARDED)
def test_15_peerBroken(self): def test_15_peerBroken(self):
......
...@@ -22,15 +22,14 @@ from mock import Mock ...@@ -22,15 +22,14 @@ from mock import Mock
from struct import pack, unpack from struct import pack, unpack
import neo import neo
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
from neo.protocol import Packet, NodeTypes, NodeStates, INVALID_UUID from neo.protocol import Packet, NodeTypes, NodeStates, CellStates, INVALID_UUID
from neo.master.handlers.verification import VerificationHandler from neo.master.handlers.verification import VerificationHandler
from neo.master.app import Application from neo.master.app import Application
from neo import protocol from neo import protocol
from neo.protocol import ERROR, ANNOUNCE_PRIMARY_MASTER, \ from neo.protocol import ERROR, ANNOUNCE_PRIMARY_MASTER, \
NOTIFY_NODE_INFORMATION, ANSWER_LAST_IDS, ANSWER_PARTITION_TABLE, \ NOTIFY_NODE_INFORMATION, ANSWER_LAST_IDS, ANSWER_PARTITION_TABLE, \
ANSWER_UNFINISHED_TRANSACTIONS, ANSWER_OBJECT_PRESENT, \ ANSWER_UNFINISHED_TRANSACTIONS, ANSWER_OBJECT_PRESENT, \
ANSWER_TRANSACTION_INFORMATION, OID_NOT_FOUND_CODE, TID_NOT_FOUND_CODE, \ ANSWER_TRANSACTION_INFORMATION, OID_NOT_FOUND_CODE, TID_NOT_FOUND_CODE
UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE
from neo.exception import OperationFailure, ElectionFailure, VerificationFailure from neo.exception import OperationFailure, ElectionFailure, VerificationFailure
from neo.tests import DoNothingConnector from neo.tests import DoNothingConnector
from neo.connection import ClientConnection from neo.connection import ClientConnection
......
...@@ -24,8 +24,8 @@ from neo import protocol ...@@ -24,8 +24,8 @@ from neo import protocol
from neo.pt import PartitionTable from neo.pt import PartitionTable
from neo.storage.app import Application from neo.storage.app import Application
from neo.storage.handlers.initialization import InitializationHandler from neo.storage.handlers.initialization import InitializationHandler
from neo.protocol import Packet, INVALID_UUID, \ from neo.protocol import Packet, CellStates, INVALID_UUID, \
UP_TO_DATE_STATE, INVALID_TID, PROTOCOL_ERROR_CODE INVALID_TID, PROTOCOL_ERROR_CODE
from neo.protocol import ACCEPT_NODE_IDENTIFICATION, REQUEST_NODE_IDENTIFICATION, \ from neo.protocol import ACCEPT_NODE_IDENTIFICATION, REQUEST_NODE_IDENTIFICATION, \
NOTIFY_PARTITION_CHANGES, STOP_OPERATION, ASK_LAST_IDS, ASK_PARTITION_TABLE, \ NOTIFY_PARTITION_CHANGES, STOP_OPERATION, ASK_LAST_IDS, ASK_PARTITION_TABLE, \
ANSWER_OBJECT_PRESENT, ASK_OBJECT_PRESENT, OID_NOT_FOUND_CODE, LOCK_INFORMATION, \ ANSWER_OBJECT_PRESENT, ASK_OBJECT_PRESENT, OID_NOT_FOUND_CODE, LOCK_INFORMATION, \
...@@ -108,9 +108,9 @@ class StorageInitializationHandlerTests(NeoTestBase): ...@@ -108,9 +108,9 @@ class StorageInitializationHandlerTests(NeoTestBase):
self.app.nm.createStorage(uuid=node_2) self.app.nm.createStorage(uuid=node_2)
self.app.nm.createStorage(uuid=node_3) self.app.nm.createStorage(uuid=node_3)
self.assertEqual(self.app.dm.getPartitionTable(), []) self.assertEqual(self.app.dm.getPartitionTable(), [])
row_list = [(0, ((node_1, UP_TO_DATE_STATE), (node_2, UP_TO_DATE_STATE))), row_list = [(0, ((node_1, CellStates.UP_TO_DATE), (node_2, CellStates.UP_TO_DATE))),
(1, ((node_3, UP_TO_DATE_STATE), (node_1, UP_TO_DATE_STATE))), (1, ((node_3, CellStates.UP_TO_DATE), (node_1, CellStates.UP_TO_DATE))),
(2, ((node_2, UP_TO_DATE_STATE), (node_3, UP_TO_DATE_STATE)))] (2, ((node_2, CellStates.UP_TO_DATE), (node_3, CellStates.UP_TO_DATE)))]
self.assertFalse(self.app.pt.filled()) self.assertFalse(self.app.pt.filled())
# send part of the table, won't be filled # send part of the table, won't be filled
self.verification.handleSendPartitionTable(conn, packet, 1, row_list[:1]) self.verification.handleSendPartitionTable(conn, packet, 1, row_list[:1])
......
...@@ -26,7 +26,7 @@ from neo.storage.app import Application ...@@ -26,7 +26,7 @@ from neo.storage.app import Application
from neo.storage.handlers.master import MasterOperationHandler from neo.storage.handlers.master import MasterOperationHandler
from neo.exception import PrimaryFailure, OperationFailure from neo.exception import PrimaryFailure, OperationFailure
from neo.pt import PartitionTable from neo.pt import PartitionTable
from neo import protocol from neo.protocol import CellStates
from neo.protocol import * from neo.protocol import *
class StorageMasterHandlerTests(NeoTestBase): class StorageMasterHandlerTests(NeoTestBase):
...@@ -115,9 +115,9 @@ class StorageMasterHandlerTests(NeoTestBase): ...@@ -115,9 +115,9 @@ class StorageMasterHandlerTests(NeoTestBase):
# cases : # cases :
uuid1, uuid2, uuid3 = [self.getNewUUID() for i in range(3)] uuid1, uuid2, uuid3 = [self.getNewUUID() for i in range(3)]
cells = ( cells = (
(0, uuid1, UP_TO_DATE_STATE), (0, uuid1, CellStates.UP_TO_DATE),
(1, uuid2, DISCARDED_STATE), (1, uuid2, CellStates.DISCARDED),
(2, uuid3, OUT_OF_DATE_STATE), (2, uuid3, CellStates.OUT_OF_DATE),
) )
# context # context
conn = Mock({ conn = Mock({
......
...@@ -19,8 +19,8 @@ import unittest, logging, os ...@@ -19,8 +19,8 @@ import unittest, logging, os
from mock import Mock from mock import Mock
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
from neo.storage.app import Application from neo.storage.app import Application
from neo.protocol import INVALID_PTID, INVALID_TID, \ from neo.protocol import CellStates, INVALID_PTID, INVALID_TID, \
INVALID_UUID, Packet, NOTIFY_NODE_INFORMATION, UP_TO_DATE_STATE INVALID_UUID, Packet, NOTIFY_NODE_INFORMATION
from neo.storage.mysqldb import p64, u64, MySQLDatabaseManager from neo.storage.mysqldb import p64, u64, MySQLDatabaseManager
from collections import deque from collections import deque
from neo.pt import PartitionTable from neo.pt import PartitionTable
...@@ -64,8 +64,8 @@ class StorageAppTests(NeoTestBase): ...@@ -64,8 +64,8 @@ class StorageAppTests(NeoTestBase):
client_uuid = self.getNewUUID() client_uuid = self.getNewUUID()
client = self.app.nm.createClient(uuid=client_uuid) client = self.app.nm.createClient(uuid=client_uuid)
self.app.pt.setCell(0, master, UP_TO_DATE_STATE) self.app.pt.setCell(0, master, CellStates.UP_TO_DATE)
self.app.pt.setCell(0, storage, UP_TO_DATE_STATE) self.app.pt.setCell(0, storage, CellStates.UP_TO_DATE)
self.assertEqual(len(self.app.pt.getNodeList()), 2) self.assertEqual(len(self.app.pt.getNodeList()), 2)
self.assertFalse(self.app.pt.filled()) self.assertFalse(self.app.pt.filled())
for x in xrange(num_partitions): for x in xrange(num_partitions):
...@@ -82,8 +82,8 @@ class StorageAppTests(NeoTestBase): ...@@ -82,8 +82,8 @@ class StorageAppTests(NeoTestBase):
self.assertFalse(self.app.pt.hasOffset(x)) self.assertFalse(self.app.pt.hasOffset(x))
# add some node # add some node
self.app.pt.setCell(0, master, UP_TO_DATE_STATE) self.app.pt.setCell(0, master, CellStates.UP_TO_DATE)
self.app.pt.setCell(0, storage, UP_TO_DATE_STATE) self.app.pt.setCell(0, storage, CellStates.UP_TO_DATE)
self.assertEqual(len(self.app.pt.getNodeList()), 2) self.assertEqual(len(self.app.pt.getNodeList()), 2)
self.assertFalse(self.app.pt.filled()) self.assertFalse(self.app.pt.filled())
for x in xrange(num_partitions): for x in xrange(num_partitions):
...@@ -95,15 +95,15 @@ class StorageAppTests(NeoTestBase): ...@@ -95,15 +95,15 @@ class StorageAppTests(NeoTestBase):
self.app.dm.setPTID(1) self.app.dm.setPTID(1)
self.app.dm.query('delete from pt;') self.app.dm.query('delete from pt;')
self.app.dm.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" % self.app.dm.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" %
(0, dump(client_uuid), UP_TO_DATE_STATE)) (0, dump(client_uuid), CellStates.UP_TO_DATE))
self.app.dm.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" % self.app.dm.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" %
(1, dump(client_uuid), UP_TO_DATE_STATE)) (1, dump(client_uuid), CellStates.UP_TO_DATE))
self.app.dm.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" % self.app.dm.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" %
(1, dump(storage_uuid), UP_TO_DATE_STATE)) (1, dump(storage_uuid), CellStates.UP_TO_DATE))
self.app.dm.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" % self.app.dm.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" %
(2, dump(storage_uuid), UP_TO_DATE_STATE)) (2, dump(storage_uuid), CellStates.UP_TO_DATE))
self.app.dm.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" % self.app.dm.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" %
(2, dump(master_uuid), UP_TO_DATE_STATE)) (2, dump(master_uuid), CellStates.UP_TO_DATE))
self.assertEqual(len(self.app.dm.getPartitionTable()), 5) self.assertEqual(len(self.app.dm.getPartitionTable()), 5)
self.app.pt.clear() self.app.pt.clear()
self.app.loadPartitionTable() self.app.loadPartitionTable()
......
...@@ -22,6 +22,7 @@ import MySQLdb ...@@ -22,6 +22,7 @@ import MySQLdb
from mock import Mock from mock import Mock
from neo.util import dump from neo.util import dump
from neo.protocol import * from neo.protocol import *
from neo.protocol import CellStates
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
from neo.exception import DatabaseFailure from neo.exception import DatabaseFailure
from neo.storage.mysqldb import MySQLDatabaseManager, p64, u64 from neo.storage.mysqldb import MySQLDatabaseManager, p64, u64
...@@ -329,32 +330,32 @@ class StorageMySQSLdbTests(NeoTestBase): ...@@ -329,32 +330,32 @@ class StorageMySQSLdbTests(NeoTestBase):
ptid = '1' ptid = '1'
uuid1, uuid2 = '\x00' * 15 + '\x01', '\x00' * 15 + '\x02' uuid1, uuid2 = '\x00' * 15 + '\x01', '\x00' * 15 + '\x02'
cells = ( cells = (
(0, uuid1, DISCARDED_STATE), (0, uuid1, CellStates.DISCARDED),
(1, uuid2, UP_TO_DATE_STATE), (1, uuid2, CellStates.UP_TO_DATE),
) )
self.db.setPTID(INVALID_PTID) self.db.setPTID(INVALID_PTID)
# empty table -> insert for second cell # empty table -> insert for second cell
self.db.changePartitionTable(ptid, cells) self.db.changePartitionTable(ptid, cells)
result = self.db.query('select rid, uuid, state from pt') result = self.db.query('select rid, uuid, state from pt')
self.assertEquals(len(result), 1) self.assertEquals(len(result), 1)
self.assertEquals(result[0], (1, dump(uuid2), 0)) self.assertEquals(result[0], (1, dump(uuid2), 1))
self.assertEquals(self.db.getPTID(), ptid) self.assertEquals(self.db.getPTID(), ptid)
# delete previous entries for a DISCARDED_STATE node # delete previous entries for a CellStates.DISCARDEDnode
self.db.query("delete from pt") self.db.query("delete from pt")
args = (0, dump(uuid1), DISCARDED_STATE) args = (0, dump(uuid1), CellStates.DISCARDED)
self.db.query('insert into pt (rid, uuid, state) values (%d, "%s", %d)' % args) self.db.query('insert into pt (rid, uuid, state) values (%d, "%s", %d)' % args)
result = self.db.query('select rid, uuid, state from pt') result = self.db.query('select rid, uuid, state from pt')
self.assertEquals(len(result), 1) self.assertEquals(len(result), 1)
self.assertEquals(result[0], (0, dump(uuid1), 3)) self.assertEquals(result[0], (0, dump(uuid1), 4))
self.assertEquals(self.db.getPTID(), ptid) self.assertEquals(self.db.getPTID(), ptid)
self.db.changePartitionTable(ptid, cells) self.db.changePartitionTable(ptid, cells)
result = self.db.query('select rid, uuid, state from pt') result = self.db.query('select rid, uuid, state from pt')
self.assertEquals(len(result), 1) self.assertEquals(len(result), 1)
self.assertEquals(result[0], (1, dump(uuid2), 0)) self.assertEquals(result[0], (1, dump(uuid2), 1))
self.assertEquals(self.db.getPTID(), ptid) self.assertEquals(self.db.getPTID(), ptid)
# raise exception (config not set), check rollback # raise exception (config not set), check rollback
self.db.query("drop table config") # will generate the exception self.db.query("drop table config") # will generate the exception
args = (0, uuid1, DISCARDED_STATE) args = (0, uuid1, CellStates.DISCARDED)
self.db.query('insert into pt (rid, uuid, state) values (%d, "%s", %d)' % args) self.db.query('insert into pt (rid, uuid, state) values (%d, "%s", %d)' % args)
self.assertRaises(MySQLdb.ProgrammingError, self.assertRaises(MySQLdb.ProgrammingError,
self.db.changePartitionTable, ptid, cells) self.db.changePartitionTable, ptid, cells)
...@@ -367,34 +368,34 @@ class StorageMySQSLdbTests(NeoTestBase): ...@@ -367,34 +368,34 @@ class StorageMySQSLdbTests(NeoTestBase):
ptid = '1' ptid = '1'
uuid1, uuid2 = '\x00' * 15 + '\x01', '\x00' * 15 + '\x02' uuid1, uuid2 = '\x00' * 15 + '\x01', '\x00' * 15 + '\x02'
cells = ( cells = (
(0, uuid1, DISCARDED_STATE), (0, uuid1, CellStates.DISCARDED),
(1, uuid2, UP_TO_DATE_STATE), (1, uuid2, CellStates.UP_TO_DATE),
) )
self.db.setPTID(INVALID_PTID) self.db.setPTID(INVALID_PTID)
# not empty table, reset -> clean table first # not empty table, reset -> clean table first
args = (0, uuid2, UP_TO_DATE_STATE) args = (0, uuid2, CellStates.UP_TO_DATE)
self.db.query('insert into pt (rid, uuid, state) values (%d, "%s", %d)' % args) self.db.query('insert into pt (rid, uuid, state) values (%d, "%s", %d)' % args)
self.db.setPartitionTable(ptid, cells) self.db.setPartitionTable(ptid, cells)
result = self.db.query('select rid, uuid, state from pt') result = self.db.query('select rid, uuid, state from pt')
self.assertEquals(len(result), 1) self.assertEquals(len(result), 1)
self.assertEquals(result[0], (1, dump(uuid2), 0)) self.assertEquals(result[0], (1, dump(uuid2), 1))
self.assertEquals(self.db.getPTID(), ptid) self.assertEquals(self.db.getPTID(), ptid)
# delete previous entries for a DISCARDED_STATE node # delete previous entries for a CellStates.DISCARDEDnode
self.db.query("delete from pt") self.db.query("delete from pt")
args = (0, uuid1, DISCARDED_STATE) args = (0, uuid1, CellStates.DISCARDED)
self.db.query('insert into pt (rid, uuid, state) values (%d, "%s", %d)' % args) self.db.query('insert into pt (rid, uuid, state) values (%d, "%s", %d)' % args)
result = self.db.query('select rid, uuid, state from pt') result = self.db.query('select rid, uuid, state from pt')
self.assertEquals(len(result), 1) self.assertEquals(len(result), 1)
self.assertEquals(result[0], (0, uuid1, 3)) self.assertEquals(result[0], (0, uuid1, 4))
self.assertEquals(self.db.getPTID(), ptid) self.assertEquals(self.db.getPTID(), ptid)
self.db.setPartitionTable(ptid, cells) self.db.setPartitionTable(ptid, cells)
result = self.db.query('select rid, uuid, state from pt') result = self.db.query('select rid, uuid, state from pt')
self.assertEquals(len(result), 1) self.assertEquals(len(result), 1)
self.assertEquals(result[0], (1, dump(uuid2), 0)) self.assertEquals(result[0], (1, dump(uuid2), 1))
self.assertEquals(self.db.getPTID(), ptid) self.assertEquals(self.db.getPTID(), ptid)
# raise exception (config not set), check rollback # raise exception (config not set), check rollback
self.db.query("drop table config") # will generate the exception self.db.query("drop table config") # will generate the exception
args = (0, uuid1, DISCARDED_STATE) args = (0, uuid1, CellStates.DISCARDED)
self.db.query('insert into pt (rid, uuid, state) values (%d, "%s", %d)' % args) self.db.query('insert into pt (rid, uuid, state) values (%d, "%s", %d)' % args)
self.assertRaises(MySQLdb.ProgrammingError, self.assertRaises(MySQLdb.ProgrammingError,
self.db.setPartitionTable, ptid, cells) self.db.setPartitionTable, ptid, cells)
......
...@@ -24,15 +24,10 @@ from neo import protocol ...@@ -24,15 +24,10 @@ from neo import protocol
from neo.pt import PartitionTable from neo.pt import PartitionTable
from neo.storage.app import Application from neo.storage.app import Application
from neo.storage.handlers.verification import VerificationHandler from neo.storage.handlers.verification import VerificationHandler
from neo.protocol import Packet, INVALID_UUID, \ from neo.protocol import Packet, CellStates, NodeTypes, INVALID_OID, INVALID_TID
UP_TO_DATE_STATE, INVALID_OID, INVALID_TID, PROTOCOL_ERROR_CODE from neo.protocol import NOTIFY_PARTITION_CHANGES, STOP_OPERATION, \
from neo.protocol import ACCEPT_NODE_IDENTIFICATION, REQUEST_NODE_IDENTIFICATION, \ ASK_OBJECT_PRESENT, OID_NOT_FOUND_CODE, TID_NOT_FOUND_CODE, \
NOTIFY_PARTITION_CHANGES, STOP_OPERATION, ASK_LAST_IDS, ASK_PARTITION_TABLE, \ ASK_TRANSACTION_INFORMATION, COMMIT_TRANSACTION, ASK_UNFINISHED_TRANSACTIONS
ANSWER_OBJECT_PRESENT, ASK_OBJECT_PRESENT, OID_NOT_FOUND_CODE, LOCK_INFORMATION, \
UNLOCK_INFORMATION, TID_NOT_FOUND_CODE, ASK_TRANSACTION_INFORMATION, \
COMMIT_TRANSACTION, ASK_UNFINISHED_TRANSACTIONS, SEND_PARTITION_TABLE
from neo.protocol import ERROR, BROKEN_NODE_DISALLOWED_CODE, ASK_PRIMARY_MASTER
from neo.protocol import ANSWER_PRIMARY_MASTER, NodeTypes
from neo.exception import PrimaryFailure, OperationFailure from neo.exception import PrimaryFailure, OperationFailure
from neo.storage.mysqldb import MySQLDatabaseManager, p64, u64 from neo.storage.mysqldb import MySQLDatabaseManager, p64, u64
...@@ -164,7 +159,7 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -164,7 +159,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
address=("127.7.9.9", 1), address=("127.7.9.9", 1),
uuid=self.getNewUUID() uuid=self.getNewUUID()
) )
self.app.pt.setCell(1, node, UP_TO_DATE_STATE) self.app.pt.setCell(1, node, CellStates.UP_TO_DATE)
self.assertTrue(self.app.pt.hasOffset(1)) self.assertTrue(self.app.pt.hasOffset(1))
conn = Mock({"getUUID" : uuid, conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port), "getAddress" : ("127.0.0.1", self.client_port),
...@@ -194,7 +189,7 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -194,7 +189,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
}) })
packet = Packet(msg_type=NOTIFY_PARTITION_CHANGES) packet = Packet(msg_type=NOTIFY_PARTITION_CHANGES)
new_uuid = self.getNewUUID() new_uuid = self.getNewUUID()
cell = (0, new_uuid, UP_TO_DATE_STATE) cell = (0, new_uuid, CellStates.UP_TO_DATE)
self.app.nm.createStorage(uuid=new_uuid) self.app.nm.createStorage(uuid=new_uuid)
self.app.pt = PartitionTable(1, 1) self.app.pt = PartitionTable(1, 1)
self.app.dm = Mock({ }) self.app.dm = Mock({ })
......
This diff is collapsed.
...@@ -19,7 +19,7 @@ import unittest, os ...@@ -19,7 +19,7 @@ import unittest, os
from mock import Mock from mock import Mock
from neo import protocol from neo import protocol
from neo.protocol import * from neo.protocol import *
from neo.protocol import NodeTypes, NodeStates from neo.protocol import NodeTypes, NodeStates, CellStates
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
from neo.util import getNextTID from neo.util import getNextTID
from time import time, gmtime from time import time, gmtime
...@@ -176,9 +176,9 @@ class ProtocolTests(NeoTestBase): ...@@ -176,9 +176,9 @@ class ProtocolTests(NeoTestBase):
uuid1 = self.getNewUUID() uuid1 = self.getNewUUID()
uuid2 = self.getNewUUID() uuid2 = self.getNewUUID()
uuid3 = self.getNewUUID() uuid3 = self.getNewUUID()
cell_list = [(0, ((uuid1, UP_TO_DATE_STATE), (uuid2, OUT_OF_DATE_STATE))), cell_list = [(0, ((uuid1, CellStates.UP_TO_DATE), (uuid2, CellStates.OUT_OF_DATE))),
(43, ((uuid2, OUT_OF_DATE_STATE),(uuid3, DISCARDED_STATE))), (43, ((uuid2, CellStates.OUT_OF_DATE),(uuid3, CellStates.DISCARDED))),
(124, ((uuid1, DISCARDED_STATE), (uuid3, UP_TO_DATE_STATE)))] (124, ((uuid1, CellStates.DISCARDED), (uuid3, CellStates.UP_TO_DATE)))]
p = protocol.answerPartitionTable(ptid, cell_list) p = protocol.answerPartitionTable(ptid, cell_list)
pptid, p_cell_list = p.decode() pptid, p_cell_list = p.decode()
self.assertEqual(pptid, ptid) self.assertEqual(pptid, ptid)
...@@ -189,9 +189,9 @@ class ProtocolTests(NeoTestBase): ...@@ -189,9 +189,9 @@ class ProtocolTests(NeoTestBase):
uuid1 = self.getNewUUID() uuid1 = self.getNewUUID()
uuid2 = self.getNewUUID() uuid2 = self.getNewUUID()
uuid3 = self.getNewUUID() uuid3 = self.getNewUUID()
cell_list = [(0, ((uuid1, UP_TO_DATE_STATE), (uuid2, OUT_OF_DATE_STATE))), cell_list = [(0, ((uuid1, CellStates.UP_TO_DATE), (uuid2, CellStates.OUT_OF_DATE))),
(43, ((uuid2, OUT_OF_DATE_STATE),(uuid3, DISCARDED_STATE))), (43, ((uuid2, CellStates.OUT_OF_DATE),(uuid3, CellStates.DISCARDED))),
(124, ((uuid1, DISCARDED_STATE), (uuid3, UP_TO_DATE_STATE)))] (124, ((uuid1, CellStates.DISCARDED), (uuid3, CellStates.UP_TO_DATE)))]
p = protocol.answerPartitionTable(ptid, cell_list) p = protocol.answerPartitionTable(ptid, cell_list)
pptid, p_cell_list = p.decode() pptid, p_cell_list = p.decode()
self.assertEqual(pptid, ptid) self.assertEqual(pptid, ptid)
...@@ -202,9 +202,9 @@ class ProtocolTests(NeoTestBase): ...@@ -202,9 +202,9 @@ class ProtocolTests(NeoTestBase):
uuid1 = self.getNewUUID() uuid1 = self.getNewUUID()
uuid2 = self.getNewUUID() uuid2 = self.getNewUUID()
uuid3 = self.getNewUUID() uuid3 = self.getNewUUID()
cell_list = [(0, uuid1, UP_TO_DATE_STATE), cell_list = [(0, uuid1, CellStates.UP_TO_DATE),
(43, uuid2, OUT_OF_DATE_STATE), (43, uuid2, CellStates.OUT_OF_DATE),
(124, uuid1, DISCARDED_STATE)] (124, uuid1, CellStates.DISCARDED)]
p = protocol.notifyPartitionChanges(ptid, p = protocol.notifyPartitionChanges(ptid,
cell_list) cell_list)
pptid, p_cell_list = p.decode() pptid, p_cell_list = p.decode()
......
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