Commit bfd70ac2 authored by Vincent Pelletier's avatar Vincent Pelletier

Factorise code asking storage nodes and waiting for all responses.

Also, factorises packet creation.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2214 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 1e050aa8
...@@ -44,6 +44,21 @@ class VerificationManager(BaseServiceHandler): ...@@ -44,6 +44,21 @@ class VerificationManager(BaseServiceHandler):
self._uuid_dict = {} self._uuid_dict = {}
self._object_present = False self._object_present = False
def _askStorageNodesAndWait(self, packet, node_list):
poll = self.app.em.poll
operational = self.app.pt.operational
uuid_dict = self._uuid_dict
uuid_dict.clear()
for node in node_list:
uuid_dict[node.getUUID()] = False
node.ask(packet)
while True:
poll(1)
if not operational():
raise VerificationFailure
if False not in uuid_dict.values():
break
def getHandler(self): def getHandler(self):
return self return self
...@@ -93,17 +108,8 @@ class VerificationManager(BaseServiceHandler): ...@@ -93,17 +108,8 @@ class VerificationManager(BaseServiceHandler):
logging.info('start to verify data') logging.info('start to verify data')
# Gather all unfinished transactions. # Gather all unfinished transactions.
for node in self.app.nm.getIdentifiedList(): self._askStorageNodesAndWait(Packets.AskUnfinishedTransactions(),
if node.isStorage(): [x for x in self.app.nm.getIdentifiedList() if x.isStorage()])
self._uuid_dict[node.getUUID()] = False
node.ask(Packets.AskUnfinishedTransactions())
while True:
em.poll(1)
if not self.app.pt.operational():
raise VerificationFailure
if False not in self._uuid_dict.values():
break
# Gather OIDs for each unfinished TID, and verify whether the # Gather OIDs for each unfinished TID, and verify whether the
# transaction can be finished or must be aborted. This could be # transaction can be finished or must be aborted. This could be
...@@ -137,26 +143,17 @@ class VerificationManager(BaseServiceHandler): ...@@ -137,26 +143,17 @@ class VerificationManager(BaseServiceHandler):
uuid_set.update(uuid_list) uuid_set.update(uuid_list)
# Gather OIDs. # Gather OIDs.
self._uuid_dict = {} node_list = self.app.nm.getIdentifiedList(pool_set=uuid_list)
for node in self.app.nm.getIdentifiedList(pool_set=uuid_list): if len(node_list) == 0:
self._uuid_dict[node.getUUID()] = False
node.ask(Packets.AskTransactionInformation(tid))
if len(self._uuid_dict) == 0:
raise VerificationFailure raise VerificationFailure
self._askStorageNodesAndWait(Packets.AskTransactionInformation(tid),
while True: node_list)
em.poll(1)
if not self.app.pt.operational():
raise VerificationFailure
if False not in self._uuid_dict.values():
break
if self._oid_set is None or len(self._oid_set) == 0: if self._oid_set is None or len(self._oid_set) == 0:
# Not commitable. # Not commitable.
return None return None
# Verify that all objects are present. # Verify that all objects are present.
for oid in self._oid_set: for oid in self._oid_set:
self._uuid_dict.clear()
partition = self.app.pt.getPartition(oid) partition = self.app.pt.getPartition(oid)
object_uuid_list = [cell.getUUID() for cell \ object_uuid_list = [cell.getUUID() for cell \
in self.app.pt.getCellList(partition, readable=True)] in self.app.pt.getCellList(partition, readable=True)]
...@@ -165,17 +162,8 @@ class VerificationManager(BaseServiceHandler): ...@@ -165,17 +162,8 @@ class VerificationManager(BaseServiceHandler):
uuid_set.update(object_uuid_list) uuid_set.update(object_uuid_list)
self._object_present = True self._object_present = True
for node in nm.getIdentifiedList(pool_set=object_uuid_list): self._askStorageNodesAndWait(Packets.AskObjectPresent(oid, tid),
self._uuid_dict[node.getUUID()] = False nm.getIdentifiedList(pool_set=object_uuid_list))
node.ask(Packets.AskObjectPresent(oid, tid))
while True:
em.poll(1)
if not self.app.pt.operational():
raise VerificationFailure
if False not in self._uuid_dict.values():
break
if not self._object_present: if not self._object_present:
# Not commitable. # Not commitable.
return None return None
......
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