HBASE-8172 Fix ./bin/*.rb scripts or remove them

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1461163 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2013-03-26 15:03:37 +00:00
parent 56fd88fff6
commit fbf0b65205
3 changed files with 19 additions and 32 deletions

View File

@ -34,7 +34,7 @@ zk = ZooKeeperWatcher.new(config, 'get-active-master', nil)
begin begin
master_address = ZKUtil.getData(zk, zk.masterAddressZNode) master_address = ZKUtil.getData(zk, zk.masterAddressZNode)
if master_address if master_address
puts ServerName.parseVersionedServerName(master_address).getHostname() puts ServerName.parseFrom(master_address).getHostname()
else else
puts 'Master not running' puts 'Master not running'
end end

View File

@ -32,25 +32,18 @@ import org.apache.hadoop.hbase.client.Scan
import org.apache.hadoop.hbase.client.HTable import org.apache.hadoop.hbase.client.HTable
import org.apache.hadoop.hbase.client.HConnectionManager import org.apache.hadoop.hbase.client.HConnectionManager
import org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter; import org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter;
import org.apache.hadoop.hbase.HServerAddress
import org.apache.hadoop.hbase.util.Bytes import org.apache.hadoop.hbase.util.Bytes
import org.apache.hadoop.hbase.util.Writables import org.apache.hadoop.hbase.util.Writables
import org.apache.hadoop.conf.Configuration import org.apache.hadoop.conf.Configuration
import org.apache.commons.logging.Log import org.apache.commons.logging.Log
import org.apache.commons.logging.LogFactory import org.apache.commons.logging.LogFactory
import org.apache.hadoop.hbase.protobuf.ProtobufUtil
import org.apache.hadoop.hbase.ServerName
import org.apache.hadoop.hbase.HRegionInfo
# Name of this script # Name of this script
NAME = "region_mover" NAME = "region_mover"
# Get root table reference
def getRootTable(config)
# Keep meta reference in ruby global
if not $ROOT
$ROOT = HTable.new(config, HConstants::ROOT_TABLE_NAME)
end
return $ROOT
end
# Get meta table reference # Get meta table reference
def getMetaTable(config) def getMetaTable(config)
# Keep meta reference in ruby global # Keep meta reference in ruby global
@ -93,24 +86,20 @@ end
# Get servername that is up in .META.; this is hostname + port + startcode comma-delimited. # Get servername that is up in .META.; this is hostname + port + startcode comma-delimited.
# Can return nil # Can return nil
def getServerNameForRegion(admin, r) def getServerNameForRegion(admin, r)
if r.isRootRegion() if r.isMetaRegion()
# Hack # Hack
tracker = org.apache.hadoop.hbase.zookeeper.RootRegionTracker.new(admin.getConnection().getZooKeeperWatcher(), RubyAbortable.new()) tracker = org.apache.hadoop.hbase.zookeeper.MetaRegionTracker.new(admin.getConnection().getZooKeeperWatcher(), RubyAbortable.new())
tracker.start() tracker.start()
while not tracker.isLocationAvailable() while not tracker.isLocationAvailable()
sleep 0.1 sleep 0.1
end end
# Make a fake servername by appending ',' # Make a fake servername by appending ','
rootServer = tracker.getRootRegionLocation().toString() + "," metaServer = tracker.getMetaRegionLocation().toString() + ","
tracker.stop() tracker.stop()
return rootServer return metaServer
end end
table = nil table = nil
if r.isMetaRegion() table = getMetaTable(admin.getConfiguration())
table = getRootTable(admin.getConfiguration())
else
table = getMetaTable(admin.getConfiguration())
end
g = Get.new(r.getRegionName()) g = Get.new(r.getRegionName())
g.addColumn(HConstants::CATALOG_FAMILY, HConstants::SERVER_QUALIFIER) g.addColumn(HConstants::CATALOG_FAMILY, HConstants::SERVER_QUALIFIER)
g.addColumn(HConstants::CATALOG_FAMILY, HConstants::STARTCODE_QUALIFIER) g.addColumn(HConstants::CATALOG_FAMILY, HConstants::STARTCODE_QUALIFIER)
@ -259,10 +248,8 @@ end
# Now get list of regions on targetServer # Now get list of regions on targetServer
def getRegions(config, servername) def getRegions(config, servername)
connection = HConnectionManager::getConnection(config) connection = HConnectionManager::getConnection(config);
parts = servername.split(',') return ProtobufUtil::getOnlineRegions(connection.getAdmin(ServerName.new(servername)));
rs = connection.getHRegionConnection(parts[0], parts[1].to_i)
return rs.getOnlineRegions()
end end
def deleteFile(filename) def deleteFile(filename)
@ -280,8 +267,7 @@ def writeFile(filename, regions)
dos.writeInt(regions.size()) dos.writeInt(regions.size())
# Write actual region names. # Write actual region names.
for r in regions for r in regions
bytes = Writables.getBytes(r) Bytes.writeByteArray(dos, r.toByteArray())
Bytes.writeByteArray(dos, bytes)
end end
dos.close() dos.close()
end end
@ -298,7 +284,7 @@ def readFile(filename)
regions = java.util.ArrayList.new(count) regions = java.util.ArrayList.new(count)
index = 0 index = 0
while index < count while index < count
regions.add(Writables.getHRegionInfo(Bytes.readByteArray(dis))) regions.add(HRegionInfo.parseFromOrNull(Bytes.readByteArray(dis)))
index = index + 1 index = index + 1
end end
dis.close() dis.close()

View File

@ -53,7 +53,8 @@ import org.apache.hadoop.hbase.client.HTable
import org.apache.hadoop.hbase.client.Scan import org.apache.hadoop.hbase.client.Scan
import org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter import org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter
import org.apache.hadoop.hbase.util.Bytes import org.apache.hadoop.hbase.util.Bytes
import org.apache.hadoop.hbase.util.Writables import org.apache.hadoop.hbase.HRegionInfo
import org.apache.hadoop.hbase.client.MetaScanner
# disable debug logging on this script for clarity # disable debug logging on this script for clarity
log_level = org.apache.log4j.Level::ERROR log_level = org.apache.log4j.Level::ERROR
@ -114,7 +115,7 @@ while iter.hasNext
# Gone too far, break # Gone too far, break
break break
end end
region = Writables.getHRegionInfo result.getValue(INFO, REGION_INFO) region = HRegionInfo.getHRegionInfo result
if not region.isOffline if not region.isOffline
# only include regions that should be online # only include regions that should be online
meta_count += 1 meta_count += 1
@ -122,9 +123,9 @@ while iter.hasNext
end end
scanner.close scanner.close
# If we're trying to see the status of all HBase tables, we need to include the # If we're trying to see the status of all HBase tables, we need to include the
# -ROOT- & .META. tables, that are not included in our scan # .META. table, that is not included in our scan
if $tablename.nil? if $tablename.nil?
meta_count += 2 meta_count += 1
end end
# query the master to see how many regions are on region servers # query the master to see how many regions are on region servers
@ -135,7 +136,7 @@ while true
if $tablename.nil? if $tablename.nil?
server_count = admin.getClusterStatus().getRegionsCount() server_count = admin.getClusterStatus().getRegionsCount()
else else
server_count = $tableq.getRegionsInfo().size() server_count = MetaScanner::allTableRegions(config,$tablename.to_java_bytes,false).size()
end end
print "Region Status: #{server_count} / #{meta_count}\n" print "Region Status: #{server_count} / #{meta_count}\n"
if SHOULD_WAIT and server_count < meta_count if SHOULD_WAIT and server_count < meta_count