Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so dont bother with any of their useless mail servers here and just use oauth login instead. Thank the nice Russians for causing that. :)
Paste
Pasted as Ruby by Sebastian Bauer ( 15 years ago )
Index: src/main/ruby/shell/commands/rebalance.rb
===================================================================
--- src/main/ruby/shell/commands/rebalance.rb (revision 0)
+++ src/main/ruby/shell/commands/rebalance.rb (revision 0)
@@ -0,0 +1,35 @@
+#
+# Copyright 2010 The Apache Software Foundation
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+module Shell
+ module Commands
+ class Rebalance < Command
+ def help
+ return <<-EOF
+Rebalance server by region requests load
+EOF
+ end
+
+ def command()
+ admin.rebalance()
+ end
+ end
+ end
+end
Index: src/main/ruby/shell.rb
===================================================================
--- src/main/ruby/shell.rb (revision 1067865)
+++ src/main/ruby/shell.rb (working copy)
@@ -206,6 +206,7 @@
:full_name => 'GENERAL HBASE SHELL COMMANDS',
:commands => %w[
status
+ rebalance
version
]
)
Index: src/main/ruby/hbase/admin.rb
===================================================================
--- src/main/ruby/hbase/admin.rb (revision 1067865)
+++ src/main/ruby/hbase/admin.rb (working copy)
@@ -326,7 +326,31 @@
puts "#{status.getServers} servers, #{status.getDeadServers} dead, #{'%.4f' % status.getAverageLoad} average load"
end
end
-
+
+ def rebalance()
+ status = @admin.getClusterStatus()
+ server_names = Array.new
+ regions_table = Hash.new
+ @admin.balanceSwitch(false)
+ for server in status.getServerInfo()
+ server_names << server.getServerAddress().getHostname()
+ puts(" %s" % [ server.getServerAddress().getHostname() ])
+
+ for region in server.getLoad().getRegionsLoad()
+ r_str = "%s"%[region.getNameAsString()]
+ if not r_str =~ /^.META./ and not r_str =~ /^-ROOT-/
+ regions_table[region.getRequestsCount()] = r_str
+ end
+ end
+ end
+ regions_table.sort.reverse.each do|count,region|
+ server_names.push(server = server_names.shift)
+ puts "#{server}: #{count}: #{region}"
+ @admin.move(org.apache.hadoop.hbase.util.Bytes.toBytes(region.split(".")[1]), server ? org.apache.hadoop.hbase.util.Bytes.toBytes(server): nil)
+ end
+ @admin.balanceSwitch(true)
+ end
+
#----------------------------------------------------------------------------------------------
#
# Helper methods
Revise this Paste
Parent: 28529