Commit 04287e68 authored by Vincent Pelletier's avatar Vincent Pelletier

Factorise transaction information retrieval.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2561 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 19b611da
...@@ -1023,37 +1023,8 @@ class Application(object): ...@@ -1023,37 +1023,8 @@ class Application(object):
if txn is not self.local_var.txn: if txn is not self.local_var.txn:
raise StorageTransactionError(self, undone_tid) raise StorageTransactionError(self, undone_tid)
# First get transaction information from a storage node. txn_info, txn_ext = self._getTransactionInformation(undone_tid)
cell_list = self._getCellListForTID(undone_tid, readable=True) oid_list = txn_info['oids']
shuffle(cell_list)
cell_list.sort(key=self.cp.getCellSortKey)
packet = Packets.AskTransactionInformation(undone_tid)
getConnForCell = self.cp.getConnForCell
for cell in cell_list:
conn = getConnForCell(cell)
if conn is None:
continue
self.local_var.txn_info = 0
self.local_var.txn_ext = 0
try:
self._askStorage(conn, packet)
except ConnectionClosed:
continue
except NEOStorageNotFoundError:
# Tid not found, try with next node
neo.logging.warning('Transaction %s was not found on node %s',
dump(undone_tid), self.nm.getByAddress(conn.getAddress()))
continue
if isinstance(self.local_var.txn_info, dict):
break
else:
raise NEOStorageError('undo failed')
else:
raise NEOStorageError('undo failed')
oid_list = self.local_var.txn_info['oids']
# Regroup objects per partition, to ask a minimum set of storage. # Regroup objects per partition, to ask a minimum set of storage.
partition_oid_dict = {} partition_oid_dict = {}
...@@ -1070,6 +1041,7 @@ class Application(object): ...@@ -1070,6 +1041,7 @@ class Application(object):
# is) # is)
getCellList = pt.getCellList getCellList = pt.getCellList
getCellSortKey = self.cp.getCellSortKey getCellSortKey = self.cp.getCellSortKey
getConnForCell = self.cp.getConnForCell
queue = self.local_var.queue queue = self.local_var.queue
undo_object_tid_dict = self.local_var.undo_object_tid_dict = {} undo_object_tid_dict = self.local_var.undo_object_tid_dict = {}
for partition, oid_list in partition_oid_dict.iteritems(): for partition, oid_list in partition_oid_dict.iteritems():
...@@ -1131,23 +1103,22 @@ class Application(object): ...@@ -1131,23 +1103,22 @@ class Application(object):
cell_list = self._getCellListForTID(tid, readable=True) cell_list = self._getCellListForTID(tid, readable=True)
shuffle(cell_list) shuffle(cell_list)
cell_list.sort(key=self.cp.getCellSortKey) cell_list.sort(key=self.cp.getCellSortKey)
packet = Packets.AskTransactionInformation(tid)
getConnForCell = self.cp.getConnForCell
for cell in cell_list: for cell in cell_list:
conn = self.cp.getConnForCell(cell) conn = getConnForCell(cell)
if conn is not None: if conn is None:
self.local_var.txn_info = 0 continue
self.local_var.txn_ext = 0
try: try:
self._askStorage(conn, self._askStorage(conn, packet)
Packets.AskTransactionInformation(tid))
except ConnectionClosed: except ConnectionClosed:
continue continue
if isinstance(self.local_var.txn_info, dict): except NEOStorageNotFoundError:
# TID not found
continue
break break
if self.local_var.txn_info in (-1, 0): else:
# TID not found at all raise NEOStorageError('Transaction %r not found' % (tid, ))
raise NeoException, 'Data inconsistency detected: ' \
'transaction info for TID %r could not ' \
'be found' % (tid, )
return (self.local_var.txn_info, self.local_var.txn_ext) return (self.local_var.txn_info, self.local_var.txn_ext)
...@@ -1268,38 +1239,17 @@ class Application(object): ...@@ -1268,38 +1239,17 @@ class Application(object):
# Now that we have object informations, get txn informations # Now that we have object informations, get txn informations
history_list = [] history_list = []
for serial, size in self.local_var.history[1]: for serial, size in self.local_var.history[1]:
self._getCellListForTID(serial, readable=True) txn_info, txn_ext = self._getTransactionInformation(serial)
shuffle(cell_list)
cell_list.sort(key=self.cp.getCellSortKey)
for cell in cell_list:
conn = self.cp.getConnForCell(cell)
if conn is None:
continue
# ask transaction information
self.local_var.txn_info = None
try:
self._askStorage(conn,
Packets.AskTransactionInformation(serial))
except ConnectionClosed:
continue
except NEOStorageNotFoundError:
# TID not found
continue
if isinstance(self.local_var.txn_info, dict):
break
# create history dict # create history dict
self.local_var.txn_info.pop('id') txn_info.pop('id')
self.local_var.txn_info.pop('oids') txn_info.pop('oids')
self.local_var.txn_info.pop('packed') txn_info.pop('packed')
self.local_var.txn_info['tid'] = serial txn_info['tid'] = serial
self.local_var.txn_info['version'] = '' txn_info['version'] = ''
self.local_var.txn_info['size'] = size txn_info['size'] = size
if filter is None or filter(self.local_var.txn_info): if filter is None or filter(txn_info):
history_list.append(self.local_var.txn_info) history_list.append(txn_info)
self._insertMetadata(self.local_var.txn_info, self._insertMetadata(txn_info, txn_ext)
self.local_var.txn_ext)
return history_list return history_list
......
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