diff options
author | Eric Wong <normalperson@yhbt.net> | 2011-11-18 10:50:25 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2011-11-18 10:59:41 +0000 |
commit | 1d891c7d0c300444c8327222fdee95cd3174c667 (patch) | |
tree | 1fe3e51d2d21c9dd129bba79e839274f96e9c723 | |
parent | 4074889c30690a3effef4fe49fa5a75f7d6c8e51 (diff) | |
download | mogilefs-client-1d891c7d0c300444c8327222fdee95cd3174c667.tar.gz |
Currently a no-op in MogileFS 2.55, but it was useful at one point in the past and may be in the future.
-rw-r--r-- | lib/mogilefs/admin.rb | 4 | ||||
-rw-r--r-- | lib/mogilefs/backend.rb | 32 | ||||
-rw-r--r-- | test/test_fresh.rb | 4 |
3 files changed, 40 insertions, 0 deletions
diff --git a/lib/mogilefs/admin.rb b/lib/mogilefs/admin.rb index 51d507d..1bba4a2 100644 --- a/lib/mogilefs/admin.rb +++ b/lib/mogilefs/admin.rb @@ -259,6 +259,10 @@ class MogileFS::Admin < MogileFS::Client rv end + def clear_cache + @backend.clear_cache + end + protected unless defined? $TESTING ## diff --git a/lib/mogilefs/backend.rb b/lib/mogilefs/backend.rb index f4c7254..b754bbc 100644 --- a/lib/mogilefs/backend.rb +++ b/lib/mogilefs/backend.rb @@ -312,6 +312,38 @@ class MogileFS::Backend "Invalid response from server: #{line.inspect}" end + # this command is special since the cache is per-tracker, so we connect + # to all backends and not just one + def clear_cache(types = %w(all)) + opts = {} + types.each { |type| opts[type] = 1 } + + sockets = @hosts.map do |host| + MogileFS::Socket.start(*(host.split(/:/))) rescue nil + end + sockets.compact! + + wpending = sockets + rpending = [] + request = make_request("clear_cache", opts) + while wpending[0] || rpending[0] + r = IO.select(rpending, wpending, nil, @timeout) or return + rpending -= r[0] + wpending -= r[1] + r[0].each { |io| io.timed_gets(0) rescue nil } + r[1].each do |io| + begin + io.timed_write(request, 0) + rpending << io + rescue + end + end + end + nil + ensure + sockets.each { |io| io.close } + end + # Returns a socket connected to a MogileFS tracker. def socket return @socket if @socket and not @socket.closed? diff --git a/test/test_fresh.rb b/test/test_fresh.rb index 9b279c6..4afed06 100644 --- a/test/test_fresh.rb +++ b/test/test_fresh.rb @@ -99,6 +99,10 @@ EOF assert_equal({"count" => 0}, @admin.replicate_now) end + def test_clear_cache + assert_nil @admin.clear_cache + end + def test_create_update_delete_class domain = "rbmogtest#{Time.now.strftime('%Y%m%d%H%M%S')}.#{uuid}" @admin.create_domain(domain) |