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

Delete num_partitions and num_replicas attributes on storage application object

and use those of PartitionTable (or DatabaseManager if required).


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@851 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 1643a9bd
......@@ -43,8 +43,6 @@ class Application(object):
def __init__(self, file, section, reset = False):
config = ConfigurationManager(file, section)
self.num_partitions = None
self.num_replicas = None
self.name = config.getName()
logging.debug('the name is %s', self.name)
self.connector_handler = getConnectorHandler(config.getConnector())
......@@ -87,12 +85,14 @@ class Application(object):
if self.uuid is None:
self.uuid = INVALID_UUID
self.num_partitions = dm.getNumPartitions()
self.num_replicas = dm.getNumReplicas()
num_partitions = dm.getNumPartitions()
num_replicas = dm.getNumReplicas()
if self.num_partitions is not None and self.num_replicas is not None:
if num_partitions is not None and num_replicas is not None:
if num_partitions <= 0:
raise RuntimeError, 'partitions must be more than zero'
# create a partition table
self.pt = PartitionTable(self.num_partitions, self.num_replicas)
self.pt = PartitionTable(num_partitions, num_replicas)
name = dm.getName()
if name is None:
......@@ -103,7 +103,7 @@ class Application(object):
if self.ptid == INVALID_PTID:
dm.setPTID(self.ptid)
logging.info("loaded configuration from db : uuid = %s, ptid = %s, name = %s, np = %s, nr = %s" \
%(dump(self.uuid), dump(self.ptid), name, self.num_partitions, self.num_replicas))
%(dump(self.uuid), dump(self.ptid), name, num_partitions, num_replicas))
def loadPartitionTable(self):
"""Load a partition table from the database."""
......@@ -126,8 +126,6 @@ class Application(object):
def run(self):
"""Make sure that the status is sane and start a loop."""
if self.num_partitions is not None and self.num_partitions <= 0:
raise RuntimeError, 'partitions must be more than zero'
if len(self.name) == 0:
raise RuntimeError, 'cluster name must be non-empty'
......@@ -200,10 +198,8 @@ class Application(object):
if pt is None or pt.getReplicas() != num_replicas:
# changing number of replicas is not an issue
self.num_partitions = num_partitions
self.num_replicas = num_replicas
self.dm.setNumPartitions(self.num_partitions)
self.dm.setNumReplicas(self.num_replicas)
self.dm.setNumPartitions(num_partitions)
self.dm.setNumReplicas(num_replicas)
self.pt = PartitionTable(num_partitions, num_replicas)
self.loadPartitionTable()
self.ptid = self.dm.getPTID()
......
......@@ -190,7 +190,7 @@ class BaseClientAndStorageOperationHandler(BaseStorageHandler):
# Collect all usable partitions for me.
getCellList = app.pt.getCellList
partition_list = []
for offset in xrange(app.num_partitions):
for offset in xrange(app.pt.getPartitions()):
for cell in getCellList(offset, readable=True):
if cell.getUUID() == app.uuid:
partition_list.append(offset)
......@@ -199,7 +199,7 @@ class BaseClientAndStorageOperationHandler(BaseStorageHandler):
partition_list = [partition]
tid_list = app.dm.getTIDList(first, last - first,
app.num_partitions, partition_list)
app.pt.getPartitions(), partition_list)
conn.answer(protocol.answerTIDs(tid_list), packet)
def handleAskObjectHistory(self, conn, packet, oid, first, last):
......
......@@ -64,7 +64,7 @@ class IdentificationHandler(BaseStorageHandler):
node.setUUID(uuid)
# FIXME: here we should use pt.getPartitions() and pt.getReplicas()
args = (STORAGE_NODE_TYPE, app.uuid, app.server[0], app.server[1],
app.num_partitions, app.num_replicas, uuid)
app.dm.getPartitions(), app.dm.getReplicas(), uuid)
# accept the identification and trigger an event
conn.answer(protocol.acceptNodeIdentification(*args), packet)
handler.connectionCompleted(conn)
......
......@@ -58,7 +58,7 @@ class InitializationHandler(BaseMasterHandler):
# If the table is filled, I assume that the table is ready
# to use. Thus install it into the database for persistency.
cell_list = []
for offset in xrange(app.num_partitions):
for offset in xrange(app.pt.getPartitions()):
for cell in pt.getCellList(offset):
cell_list.append((offset, cell.getUUID(),
cell.getState()))
......
......@@ -45,7 +45,7 @@ class StorageOperationHandler(BaseClientAndStorageOperationHandler):
# Collect all usable partitions for me.
getCellList = app.pt.getCellList
partition_list = []
for offset in xrange(app.num_partitions):
for offset in xrange(app.pt.getPartitions()):
for cell in getCellList(offset, readable=True):
if cell.getUUID() == app.uuid:
partition_list.append(offset)
......@@ -53,6 +53,6 @@ class StorageOperationHandler(BaseClientAndStorageOperationHandler):
else:
partition_list = [partition]
oid_list = app.dm.getOIDList(first, last - first,
app.num_partitions, partition_list)
app.pt.getPartitions(), partition_list)
conn.answer(protocol.answerOIDs(oid_list), packet)
......@@ -104,7 +104,7 @@ class Replicator(object):
def _getOutdatedPartitionList(self):
app = self.app
partition_dict = {}
for offset in xrange(app.num_partitions):
for offset in xrange(app.pt.getPartitions()):
for uuid, state in app.pt.getRow(offset):
if uuid == app.uuid and state == OUT_OF_DATE_STATE:
partition_dict[offset] = Partition(offset)
......
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