Commit b3f868de authored by Aurel's avatar Aurel

store the number of replicas inside DB, thus we can create the

partition table if we get all necessaey information at bootstrap


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@458 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent a0a23d21
......@@ -34,6 +34,7 @@ from neo.storage.verification import VerificationEventHandler
from neo.storage.operation import OperationEventHandler
from neo.storage.replicator import Replicator
from neo.connector import getConnectorHandler
from neo.pt import PartitionTable
from neo.util import dump
class Application(object):
......@@ -79,7 +80,12 @@ class Application(object):
self.uuid = INVALID_UUID
self.num_partitions = dm.getNumPartitions()
self.num_replicas = dm.getNumReplicas()
if self.num_partitions is not None and self.num_replicas is not None:
# create a partition table
self.pt = PartitionTable(self.num_partitions, self.num_replicas)
name = dm.getName()
if name is None:
dm.setName(self.name)
......@@ -88,8 +94,8 @@ class Application(object):
self.ptid = dm.getPTID() # return ptid or INVALID_PTID
if self.ptid == INVALID_PTID:
dm.setPTID(self.ptid)
logging.info("loaded configuration from db : uuid = %s, ptid = %s, name = %s, np = %s" \
%(dump(self.uuid), dump(self.ptid), name, self.num_partitions))
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))
def loadPartitionTable(self):
"""Load a partition table from the database."""
......
......@@ -177,17 +177,16 @@ class BootstrapEventHandler(StorageEventHandler):
conn.close()
return
if app.num_partitions is None:
if app.num_partitions is None or app.num_replicas is None:
app.num_partitions = num_partitions
app.dm.setNumPartitions(app.num_partitions)
app.num_replicas = num_replicas
app.dm.setNumReplicas(app.num_replicas)
app.pt = PartitionTable(num_partitions, num_replicas)
app.loadPartitionTable()
app.ptid = app.dm.getPTID()
elif app.num_partitions != num_partitions:
raise RuntimeError('the number of partitions is inconsistent')
elif app.num_replicas != num_replicas:
raise RuntimeError('the number of replicas is inconsistent')
if your_uuid != INVALID_UUID and app.uuid != your_uuid:
# got an uuid from the primary master
......
......@@ -44,6 +44,15 @@ class DatabaseManager(object):
"""Store the number of partitions into a database."""
raise NotImplementedError('this method must be overridden')
def getNumReplicas(self):
"""Load the number of replicas from a database. If not present,
return None."""
raise NotImplementedError('this method must be overridden')
def setNumReplicas(self, num_partitions):
"""Store the number of replicas into a database."""
raise NotImplementedError('this method must be overridden')
def getName(self):
"""Load a name from a database. If not present, return None."""
raise NotImplementedError('this method must be overridden')
......
......@@ -211,6 +211,20 @@ class MySQLDatabaseManager(DatabaseManager):
raise
self.commit()
def getNumReplicas(self):
n = self.getConfiguration('replicas')
if n is not None:
return int(n)
def setNumReplicas(self, num_replicas):
self.begin()
try:
self.setConfiguration('replicas', num_replicas)
except:
self.rollback()
raise
self.commit()
def getName(self):
return self.getConfiguration('name')
......
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