From d48dcc1d1e4679cf7dbd428fa4d2e7932f9839d3 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 12 Nov 2011 09:22:56 +0000 Subject: list_keys_verbose: preserve ordering with multiple queryworkers When multiple queryworkers are used in the tracker, it's possible to receive responses out-of-order. We need to hold onto responses while the pipeline is being processed and only make callbacks when they can be made in the order the keys were given to us in. --- lib/mogilefs/mogilefs.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'lib/mogilefs/mogilefs.rb') diff --git a/lib/mogilefs/mogilefs.rb b/lib/mogilefs/mogilefs.rb index 5f22152..cfbf082 100644 --- a/lib/mogilefs/mogilefs.rb +++ b/lib/mogilefs/mogilefs.rb @@ -250,10 +250,17 @@ class MogileFS::MogileFS < MogileFS::Client def list_keys_verbose(keys, block) # :nodoc: # emulate the MogileFS::Mysql interface, slowly... + ordered = keys.dup + ready = {} on_file_info = lambda do |info| Hash === info or raise info file_info_cleanup(info) - block.call(info["key"], info["length"], info["devcount"]) + + # deal with trackers with multiple queryworkers responding out-of-order + ready[info["key"]] = info + while info = ready.delete(ordered[0]) + block.call(ordered.shift, info["length"], info["devcount"]) + end end opts = { :domain => @domain } keys.each do |key| -- cgit v1.2.3-24-ge0c7