about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rw-r--r--lib/mogilefs/admin.rb10
-rw-r--r--lib/mogilefs/backend.rb1
-rw-r--r--test/test_fresh.rb6
3 files changed, 17 insertions, 0 deletions
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"