Commit df47e5b1 authored by Julien Muchembled's avatar Julien Muchembled

client: optimize Storage.history() by not asking all storages systematically

parent 11473bff
...@@ -982,21 +982,17 @@ class Application(object): ...@@ -982,21 +982,17 @@ class Application(object):
return (tid, txn_list) return (tid, txn_list)
def history(self, oid, size=1, filter=None): def history(self, oid, size=1, filter=None):
queue = self._getThreadQueue()
# Get history informations for object first # Get history informations for object first
packet = Packets.AskObjectHistory(oid, 0, size) packet = Packets.AskObjectHistory(oid, 0, size)
for node, conn in self.cp.iterateForObject(oid, readable=True): for node, conn in self.cp.iterateForObject(oid, readable=True):
try: try:
conn.ask(packet, queue=queue) history_list = self._askStorage(conn, packet)
except ConnectionClosed: except ConnectionClosed:
continue continue
history_dict = {}
self.waitResponses(queue, history_dict)
# Now that we have object informations, get txn informations # Now that we have object informations, get txn informations
history_list = [] result = []
append = history_list.append # history_list is already sorted descending (by the storage)
for serial in sorted(history_dict.keys(), reverse=True): for serial, size in history_list:
size = history_dict[serial]
txn_info, txn_ext = self._getTransactionInformation(serial) txn_info, txn_ext = self._getTransactionInformation(serial)
# create history dict # create history dict
txn_info.pop('id') txn_info.pop('id')
...@@ -1006,9 +1002,9 @@ class Application(object): ...@@ -1006,9 +1002,9 @@ class Application(object):
txn_info['version'] = '' txn_info['version'] = ''
txn_info['size'] = size txn_info['size'] = size
if filter is None or filter(txn_info): if filter is None or filter(txn_info):
append(txn_info) result.append(txn_info)
self._insertMetadata(txn_info, txn_ext) self._insertMetadata(txn_info, txn_ext)
return history_list return result
@profiler_decorator @profiler_decorator
def importFrom(self, source, start, stop, tryToResolveConflict): def importFrom(self, source, start, stop, tryToResolveConflict):
......
...@@ -122,7 +122,7 @@ class StorageAnswersHandler(AnswerBaseHandler): ...@@ -122,7 +122,7 @@ class StorageAnswersHandler(AnswerBaseHandler):
def answerObjectHistory(self, conn, _, history_list): def answerObjectHistory(self, conn, _, history_list):
# history_list is a list of tuple (serial, size) # history_list is a list of tuple (serial, size)
self.app.getHandlerData().update(history_list) self.app.setHandlerData(history_list)
def oidNotFound(self, conn, message): def oidNotFound(self, conn, message):
# This can happen either when : # This can happen either when :
......
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