about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-11-18 23:14:08 +0000
committerEric Wong <normalperson@yhbt.net>2011-11-18 23:16:32 +0000
commit2ff4eacf708a3f2e42140a34568bf3792c063618 (patch)
treecb9c90d0cdb8beee15306fc4121fb636f7d2c6ec
parente6edebe4288c98827e723d75fe9fea4c1a0b013f (diff)
downloadmogilefs-client-2ff4eacf708a3f2e42140a34568bf3792c063618.tar.gz
The +to+ arg of list_fids is now actually +count+ internally
because gaps may appear in an auto-incrementing FID range
(due to deleted files).  We also have a default +count+ of
100 (matches the internal MogileFS default).
-rw-r--r--lib/mogilefs/admin.rb25
-rw-r--r--test/test_mogilefs_integration.rb16
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