From 1a5b3487e5a38a4897a6461b3907cd6bde501e0c Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 8 Nov 2011 02:45:40 +0000 Subject: add support for the file_debug command This was added in MogileFS 2.45 --- lib/mogilefs/mogilefs.rb | 49 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) (limited to 'lib/mogilefs/mogilefs.rb') diff --git a/lib/mogilefs/mogilefs.rb b/lib/mogilefs/mogilefs.rb index ef01f5b..bbf8740 100644 --- a/lib/mogilefs/mogilefs.rb +++ b/lib/mogilefs/mogilefs.rb @@ -219,12 +219,13 @@ class MogileFS::MogileFS < MogileFS::Client [ keys, res['next_after'] ] end - # Used to return metadata about a file. Returns the domain, class, expected - # length, devcount, etc. Optionally device ids (not paths) can be returned as - # well if :devices is specified. + # Return metadata about a file as a hash. + # Returns the domain, class, expected length, devcount, etc. + # Optionally device ids (not paths) can be returned as + # well if :devices is specified and +true+. # - # Should be used for informational purposes, and not usually for dynamically - # serving files. + # This should only be used for informational purposes, and not usually + # for dynamically serving files. def file_info(key, args = nil) opts = { :domain => @domain, :key => key } args and devices = args[:devices] and opts[:devices] = devices ? 1 : 0 @@ -233,4 +234,42 @@ class MogileFS::MogileFS < MogileFS::Client devids = rv["devids"] and rv["devids"] = devids.split(/,/).map! { |x| x.to_i } rv end + + # Given an Integer +fid+ or String +key+ and domain, thorougly search + # the database for all occurences of a particular fid. + # + # Use this sparingly, this command hits the master database numerous + # times and is very expensive. This is not for production use, only + # troubleshooting and debugging. + # + # Searches for fid=666: + # + # client.file_debug(666) + # + # Search for key=foo using the default domain for this object: + # + # client.file_debug("foo") + # + # Search for key=foo in domain="bar": + # + # client.file_debug(:key => "foo", :domain => "bar") + # + def file_debug(args) + case args + when Integer then args = { "fid" => args } + when String then args = { "key" => args } + end + opts = { :domain => args[:domain] || @domain }.merge!(args) + + rv = @backend.file_debug(opts) + rv.each do |k,v| + case k + when /_(?:classid|devcount|dmid|fid|length| + nexttry|fromdevid|failcount|flags|devid|type)\z/x + rv[k] = v.to_i + when /devids\z/ + rv[k] = v.split(/,/).map! { |x| x.to_i } + end + end + end end -- cgit v1.2.3-24-ge0c7