From 17128d5b73c8ad12f45c3888eded5d7a96a5e46a Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 29 Jun 2012 20:26:12 +0000 Subject: admin: add change_device_weight command This feature uses the "set_weight" command to change device weights and has a part of the MogileFS protocol for many years, now. --- lib/mogilefs/admin.rb | 10 ++++++++++ lib/mogilefs/backend.rb | 1 + test/test_fresh.rb | 6 ++++++ 3 files changed, 17 insertions(+) diff --git a/lib/mogilefs/admin.rb b/lib/mogilefs/admin.rb index 19f6858..2b3540a 100644 --- a/lib/mogilefs/admin.rb +++ b/lib/mogilefs/admin.rb @@ -283,6 +283,16 @@ class MogileFS::Admin < MogileFS::Client ! @backend.set_state(:host => host, :device => device, :state => state).nil? end + ## + # Changes the device weight of +device+ on +host+ to +weight+. + # +weight+ should be a non-negative Integer. Devices with higher + # +weight+ values are more likely to be chosen for reads and writes. + def change_device_weight(host, device, weight) + raise MogileFS::ReadOnlyError if readonly? + opts = { :host => host, :device => device, :weight => weight } + ! @backend.set_weight(opts).nil? + end + # reschedules all deferred replication, returns a hash with the number # of files rescheduled: # diff --git a/lib/mogilefs/backend.rb b/lib/mogilefs/backend.rb index f578257..f694623 100644 --- a/lib/mogilefs/backend.rb +++ b/lib/mogilefs/backend.rb @@ -125,6 +125,7 @@ class MogileFS::Backend add_command :update_host add_command :delete_host add_command :set_state + add_command :set_weight add_command :replicate_now def shutdown_unlocked(do_raise = false) # :nodoc: diff --git a/test/test_fresh.rb b/test/test_fresh.rb index 41c30ef..f20aacc 100644 --- a/test/test_fresh.rb +++ b/test/test_fresh.rb @@ -6,6 +6,12 @@ class TestMogFresh < Test::Unit::TestCase alias setup setup_mogilefs alias teardown teardown_mogilefs + def test_change_device_weight + add_host_device_domain + assert_equal true, @admin.change_device_weight("me", 1, 50) + assert_equal 50, @admin.get_devices(1)[0]["weight"] + end + def test_list_keys_invalid_domain add_host_device_domain domain = @domain + ".non-existent" -- cgit v1.2.3-24-ge0c7