diff options
author | Eric Wong <normalperson@yhbt.net> | 2011-11-08 02:45:40 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2011-11-08 02:45:40 +0000 |
commit | 1a5b3487e5a38a4897a6461b3907cd6bde501e0c (patch) | |
tree | ed354bc6398343262ea104b1d2f718dd080e5a37 /lib/mogilefs/mogilefs.rb | |
parent | fd5098ba0825d5ee603265a40e8c62b97191b7b6 (diff) | |
download | mogilefs-client-1a5b3487e5a38a4897a6461b3907cd6bde501e0c.tar.gz |
This was added in MogileFS 2.45
Diffstat (limited to 'lib/mogilefs/mogilefs.rb')
-rw-r--r-- | lib/mogilefs/mogilefs.rb | 49 |
1 files changed, 44 insertions, 5 deletions
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 |