diff options
-rw-r--r-- | lib/mogilefs/admin.rb | 25 | ||||
-rw-r--r-- | test/test_mogilefs_integration.rb | 16 |
2 files changed, 29 insertions, 12 deletions
diff --git a/lib/mogilefs/admin.rb b/lib/mogilefs/admin.rb index 926b6cf..6d5db24 100644 --- a/lib/mogilefs/admin.rb +++ b/lib/mogilefs/admin.rb @@ -5,18 +5,18 @@ class MogileFS::Admin < MogileFS::Client ## - # Enumerates fids using #list_fids. + # Enumerates fids using #list_fids. Returns the number of valid fids + # processed def each_fid - low = 0 - - max = get_stats('fids')['fids']['max'] - - 0.step max, 100 do |high| - fids = list_fids low, high + low = -1 + rv = 0 + begin + fids = list_fids(low + 1) fids.each { |fid| yield fid } - low = high + 1 - end + rv += fids.size + end while last = fids[-1] and low = last["fid"] + rv end ## @@ -73,7 +73,7 @@ class MogileFS::Admin < MogileFS::Client end ## - # Returns an Array of fid Hashes from +from_fid+ to +to_fid+. + # Returns an Array of fid Hashes from +from_fid+, limited to +count+ # # admin.list_fids 0, 100 # @@ -92,10 +92,11 @@ class MogileFS::Admin < MogileFS::Client # "length"=>9, # "key"=>"new_new_key"}] - def list_fids(from_fid, to_fid) + def list_fids(from_fid, count = 100) to_i = { "fid" => true, "devcount" => true, "length" => true } + # :to is now :count internally in mogilefsd clean('fid_count', 'fid_', - @backend.list_fids(:from => from_fid, :to => to_fid), true, to_i) + @backend.list_fids(:from => from_fid, :to => count), true, to_i) end ## diff --git a/test/test_mogilefs_integration.rb b/test/test_mogilefs_integration.rb index 610b899..4bc8e27 100644 --- a/test/test_mogilefs_integration.rb +++ b/test/test_mogilefs_integration.rb @@ -146,4 +146,20 @@ class TestMogileFSIntegration < TestMogIntegration end end end + + # TODO: move this to a fresh instance + def test_admin_each_fid + admin = MogileFS::Admin.new(:hosts => @trackers) + seen = {} + count = admin.each_fid do |info| + seen[info["fid"]] = true + assert_kind_of Integer, info["fid"] + assert_kind_of Integer, info["length"] + assert_kind_of Integer, info["devcount"] + assert_kind_of String, info["key"] + assert_kind_of String, info["class"] + assert_kind_of String, info["domain"] + end + assert_equal count, seen.size + end if ENV["TEST_EXPENSIVE"] end |