HBASE-3676 Update region server load for AssignmentManager through regionServerReport()

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1083992 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2011-03-21 22:13:38 +00:00
parent 9d93ccc938
commit c4fb32cc22
5 changed files with 34 additions and 19 deletions

View File

@ -84,6 +84,8 @@ Release 0.91.0 - Unreleased
HBASE-3657 reduce copying of HRegionInfo's (Ted Yu via Stack)
HBASE-3422 Balancer will try to rebalance thousands of regions in one go;
needs an upper bound added (Ted Yu via Stack)
HBASE-3676 Update region server load for AssignmentManager through
regionServerReport() (Ted Yu via Stack)
TASK
HBASE-3559 Move report of split to master OFF the heartbeat channel

View File

@ -22,9 +22,9 @@ package org.apache.hadoop.hbase;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.TreeMap;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Strings;
@ -47,7 +47,7 @@ public class HServerLoad implements WritableComparable<HServerLoad> {
/** the maximum allowable size of the heap, in MB */
private int maxHeapMB;
/** per-region load metrics */
private ArrayList<RegionLoad> regionLoad = new ArrayList<RegionLoad>();
private Map<byte[], RegionLoad> regionLoad = new TreeMap<byte[], RegionLoad>(Bytes.BYTES_COMPARATOR);
/**
* Encapsulates per-region loading metrics.
@ -86,8 +86,7 @@ public class HServerLoad implements WritableComparable<HServerLoad> {
*/
public RegionLoad(final byte[] name, final int stores,
final int storefiles, final int storefileSizeMB,
final int memstoreSizeMB, final int storefileIndexSizeMB,
final long requestsCount) {
final int memstoreSizeMB, final int storefileIndexSizeMB,final long requestsCount) {
this.name = name;
this.stores = stores;
this.storefiles = storefiles;
@ -282,7 +281,9 @@ public class HServerLoad implements WritableComparable<HServerLoad> {
*/
public HServerLoad(final HServerLoad hsl) {
this(hsl.numberOfRequests, hsl.usedHeapMB, hsl.maxHeapMB);
this.regionLoad.addAll(hsl.regionLoad);
for (Map.Entry<byte[], RegionLoad> e : hsl.regionLoad.entrySet()) {
this.regionLoad.put(e.getKey(), e.getValue());
}
}
/**
@ -387,8 +388,8 @@ public class HServerLoad implements WritableComparable<HServerLoad> {
/**
* @return region load metrics
*/
public Collection<RegionLoad> getRegionsLoad() {
return Collections.unmodifiableCollection(regionLoad);
public Map<byte[], RegionLoad> getRegionsLoad() {
return Collections.unmodifiableMap(regionLoad);
}
/**
@ -396,7 +397,7 @@ public class HServerLoad implements WritableComparable<HServerLoad> {
*/
public int getStorefiles() {
int count = 0;
for (RegionLoad info: regionLoad)
for (RegionLoad info: regionLoad.values())
count += info.getStorefiles();
return count;
}
@ -406,7 +407,7 @@ public class HServerLoad implements WritableComparable<HServerLoad> {
*/
public int getStorefileSizeInMB() {
int count = 0;
for (RegionLoad info: regionLoad)
for (RegionLoad info: regionLoad.values())
count += info.getStorefileSizeMB();
return count;
}
@ -416,7 +417,7 @@ public class HServerLoad implements WritableComparable<HServerLoad> {
*/
public int getMemStoreSizeInMB() {
int count = 0;
for (RegionLoad info: regionLoad)
for (RegionLoad info: regionLoad.values())
count += info.getMemStoreSizeMB();
return count;
}
@ -426,7 +427,7 @@ public class HServerLoad implements WritableComparable<HServerLoad> {
*/
public int getStorefileIndexSizeInMB() {
int count = 0;
for (RegionLoad info: regionLoad)
for (RegionLoad info: regionLoad.values())
count += info.getStorefileIndexSizeMB();
return count;
}
@ -466,7 +467,7 @@ public class HServerLoad implements WritableComparable<HServerLoad> {
*/
public void addRegionInfo(final HServerLoad.RegionLoad load) {
this.numberOfRegions++;
this.regionLoad.add(load);
this.regionLoad.put(load.getName(), load);
}
/**
@ -483,7 +484,7 @@ public class HServerLoad implements WritableComparable<HServerLoad> {
final int storefiles, final int storefileSizeMB,
final int memstoreSizeMB, final int storefileIndexSizeMB,
final long requestsCount) {
this.regionLoad.add(new HServerLoad.RegionLoad(name, stores, storefiles,
this.regionLoad.put(name, new HServerLoad.RegionLoad(name, stores, storefiles,
storefileSizeMB, memstoreSizeMB, storefileIndexSizeMB, requestsCount));
}
@ -497,7 +498,7 @@ public class HServerLoad implements WritableComparable<HServerLoad> {
for (int i = 0; i < numberOfRegions; i++) {
RegionLoad rl = new RegionLoad();
rl.readFields(in);
regionLoad.add(rl);
regionLoad.put(rl.getName(), rl);
}
}
@ -506,8 +507,8 @@ public class HServerLoad implements WritableComparable<HServerLoad> {
out.writeInt(usedHeapMB);
out.writeInt(maxHeapMB);
out.writeInt(numberOfRegions);
for (int i = 0; i < numberOfRegions; i++)
regionLoad.get(i).write(out);
for (RegionLoad rl: regionLoad.values())
rl.write(out);
}
// Comparable

View File

@ -93,7 +93,7 @@ public class AvroUtil {
asl.numberOfRegions = hsl.getNumberOfRegions();
asl.numberOfRequests = hsl.getNumberOfRequests();
Collection<HServerLoad.RegionLoad> regionLoads = hsl.getRegionsLoad();
Collection<HServerLoad.RegionLoad> regionLoads = hsl.getRegionsLoad().values();
Schema s = Schema.createArray(ARegionLoad.SCHEMA$);
GenericData.Array<ARegionLoad> aregionLoads = null;
if (regionLoads != null) {

View File

@ -326,6 +326,18 @@ public class ServerManager {
// No more piggyback messages on heartbeats for other stuff
return msgs;
}
/**
* Make server load accessible to AssignmentManager
* @param serverName
* @return
* @throws HServerLoad if serverName is known
*/
HServerLoad getLoad(String serverName) {
HServerInfo hsi = this.onlineServers.get(serverName);
if (hsi == null) return null;
return hsi.getLoad();
}
/**
* @param serverName

View File

@ -82,7 +82,7 @@ public class StorageClusterStatusResource extends ResourceBase {
info.getStartCode(), load.getUsedHeapMB(),
load.getMaxHeapMB());
node.setRequests(load.getNumberOfRequests());
for (HServerLoad.RegionLoad region: load.getRegionsLoad()) {
for (HServerLoad.RegionLoad region: load.getRegionsLoad().values()) {
node.addRegion(region.getName(), region.getStores(),
region.getStorefiles(), region.getStorefileSizeMB(),
region.getMemStoreSizeMB(), region.getStorefileIndexSizeMB());