diff options
Diffstat (limited to 'examples/stale_fid_checker.rb')
-rw-r--r-- | examples/stale_fid_checker.rb | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/examples/stale_fid_checker.rb b/examples/stale_fid_checker.rb index 77cb23d..2dab866 100644 --- a/examples/stale_fid_checker.rb +++ b/examples/stale_fid_checker.rb @@ -4,25 +4,38 @@ # * Ruby 1.9.2+ # * upstream MogileFS::Server 2.45 or later $stdout.sync = $stderr.sync = true +usage = <<EOF +Usage: #$0 -t TRACKERS" + +The output of this script can be piped to awk + curl to DELETE the files: +#$0 -t TRACKERS | awk '{system("curl -XDELETE "$3)}' +EOF + require 'uri' require 'optparse' require 'mogilefs' require 'net/http/persistent' Thread.abort_on_exception = true +MogileFS::VERSION <= "3.0.0" and + abort "Upgrade mogilefs-client (to a version that distributes this script)" \ + "MogileFS::Admin#each_fid is probably broken in this version" trackers = [] ARGV.options do |x| - x.banner = "Usage: #$0 -t TRACKERS" + x.banner = usage.strip x.separator '' x.on('-t', '--trackers=host1[,host2]', '--hosts=host1[,host2]', Array, 'hostnames/IP addresses of trackers') do |args| trackers = args end + + x.on('-h', '--help', 'Show this help message.') { puts x; exit } x.parse! end adm = MogileFS::Admin.new(:hosts => trackers) NHP = Net::HTTP::Persistent.new(File.basename($0)) +client = MogileFS::MogileFS.new(:hosts => trackers, :domain => "none") def start_perdev_thread(pfx) todo = Queue.new @@ -82,6 +95,12 @@ adm.each_fid do |fid| dev_map.each_value { |done| check(bad, curfid, done.shift) } next if bad.empty? + begin + info = client.file_debug(curfid) + abort "BUG: #{info.inspect} found!" if info["fid_dkey"] + rescue MogileFS::Backend::UnknownFidError + end + puts bad.join end end |