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

Change replicas number lower bound to zero instead of one for consistency.

Update tests and default configuration too.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@437 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 3a8db361
...@@ -28,7 +28,7 @@ class ConfigurationManager: ...@@ -28,7 +28,7 @@ class ConfigurationManager:
'server' : '127.0.0.1', 'server' : '127.0.0.1',
'connector' : 'SocketConnector', 'connector' : 'SocketConnector',
'master_nodes' : '', 'master_nodes' : '',
'replicas' : '1', 'replicas' : '0',
'partitions' : '1009', 'partitions' : '1009',
'name' : 'main'} 'name' : 'main'}
......
...@@ -82,8 +82,8 @@ class Application(object): ...@@ -82,8 +82,8 @@ class Application(object):
def run(self): def run(self):
"""Make sure that the status is sane and start a loop.""" """Make sure that the status is sane and start a loop."""
if self.num_replicas <= 0: if self.num_replicas < 0:
raise RuntimeError, 'replicas must be more than zero' raise RuntimeError, 'replicas must be a positive integer'
if self.num_partitions <= 0: if self.num_partitions <= 0:
raise RuntimeError, 'partitions must be more than zero' raise RuntimeError, 'partitions must be more than zero'
if len(self.name) == 0: if len(self.name) == 0:
......
...@@ -102,7 +102,7 @@ class PartitionTable(object): ...@@ -102,7 +102,7 @@ class PartitionTable(object):
# Take it into account that the number of storage nodes may be less than the # Take it into account that the number of storage nodes may be less than the
# number of replicas. # number of replicas.
repeats = min(self.nr, len(node_list)) repeats = min(self.nr + 1, len(node_list))
index = 0 index = 0
for offset in xrange(self.np): for offset in xrange(self.np):
row = [] row = []
...@@ -308,7 +308,7 @@ class PartitionTable(object): ...@@ -308,7 +308,7 @@ class PartitionTable(object):
if skip: if skip:
continue continue
if num_cells < self.nr: if num_cells <= self.nr:
row.append(Cell(node, OUT_OF_DATE_STATE)) row.append(Cell(node, OUT_OF_DATE_STATE))
cell_list.append((offset, node.getUUID(), OUT_OF_DATE_STATE)) cell_list.append((offset, node.getUUID(), OUT_OF_DATE_STATE))
node_count += 1 node_count += 1
...@@ -374,7 +374,7 @@ class PartitionTable(object): ...@@ -374,7 +374,7 @@ class PartitionTable(object):
if len(out_of_date_cell_list) == 0 and feeding_cell is not None: if len(out_of_date_cell_list) == 0 and feeding_cell is not None:
removed_cell_list.append(feeding_cell) removed_cell_list.append(feeding_cell)
ideal_num = self.nr ideal_num = self.nr + 1
while len(out_of_date_cell_list) + len(up_to_date_cell_list) > ideal_num: while len(out_of_date_cell_list) + len(up_to_date_cell_list) > ideal_num:
# This row contains too many cells. # This row contains too many cells.
if len(up_to_date_cell_list) > 1: if len(up_to_date_cell_list) > 1:
...@@ -411,7 +411,7 @@ class PartitionTable(object): ...@@ -411,7 +411,7 @@ class PartitionTable(object):
for cell in row: for cell in row:
if cell.getState() != FEEDING_STATE: if cell.getState() != FEEDING_STATE:
num_cells += 1 num_cells += 1
while num_cells < self.nr: while num_cells <= self.nr:
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
......
...@@ -602,7 +602,7 @@ class testPartitionTable(unittest.TestCase): ...@@ -602,7 +602,7 @@ class testPartitionTable(unittest.TestCase):
# 2 : sn1, sn4 # 2 : sn1, sn4
# 3 : sn1, sn5 # 3 : sn1, sn5
num_partitions = 4 num_partitions = 4
num_replicas = 2 num_replicas = 1
pt = PartitionTable(num_partitions, num_replicas) pt = PartitionTable(num_partitions, num_replicas)
# node most used is out of date, just dropped # node most used is out of date, just dropped
pt.setCell(0, sn1, OUT_OF_DATE_STATE) pt.setCell(0, sn1, OUT_OF_DATE_STATE)
...@@ -755,7 +755,7 @@ class testPartitionTable(unittest.TestCase): ...@@ -755,7 +755,7 @@ class testPartitionTable(unittest.TestCase):
def test_16_make(self): def test_16_make(self):
num_partitions = 5 num_partitions = 5
num_replicas = 2 num_replicas = 1
pt = PartitionTable(num_partitions, num_replicas) pt = PartitionTable(num_partitions, num_replicas)
# add nodes # add nodes
uuid1 = self.getNewUUID() uuid1 = self.getNewUUID()
...@@ -834,7 +834,7 @@ class testPartitionTable(unittest.TestCase): ...@@ -834,7 +834,7 @@ class testPartitionTable(unittest.TestCase):
# 3 : sn1(up), sn2(up), sn3(up), sn4(up) -> only 3 cell must remain # 3 : sn1(up), sn2(up), sn3(up), sn4(up) -> only 3 cell must remain
# 4 : sn1(up), sn5(up) -> one more cell must be added # 4 : sn1(up), sn5(up) -> one more cell must be added
num_partitions = 5 num_partitions = 5
num_replicas = 3 num_replicas = 2
pt = PartitionTable(num_partitions, num_replicas) pt = PartitionTable(num_partitions, num_replicas)
# part 0 # part 0
pt.setCell(0, sn1, DISCARDED_STATE) pt.setCell(0, sn1, DISCARDED_STATE)
......
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