diff --git a/src/main/java/org/apache/hadoop/hbase/HServerLoad.java b/src/main/java/org/apache/hadoop/hbase/HServerLoad.java index efa7e0e..05ff4b9 100644 --- a/src/main/java/org/apache/hadoop/hbase/HServerLoad.java +++ b/src/main/java/org/apache/hadoop/hbase/HServerLoad.java @@ -65,6 +65,8 @@ public class HServerLoad implements WritableComparable { private int memstoreSizeMB; /** the current total size of storefile indexes for the region, in MB */ private int storefileIndexSizeMB; + /** the current total request made to region */ + private long requestsCount; /** * Constructor, for Writable @@ -80,16 +82,19 @@ public class HServerLoad implements WritableComparable { * @param storefileSizeMB * @param memstoreSizeMB * @param storefileIndexSizeMB + * @param requestsCount */ public RegionLoad(final byte[] name, final int stores, final int storefiles, final int storefileSizeMB, - final int memstoreSizeMB, final int storefileIndexSizeMB) { + final int memstoreSizeMB, final int storefileIndexSizeMB, + final long requestsCount) { this.name = name; this.stores = stores; this.storefiles = storefiles; this.storefileSizeMB = storefileSizeMB; this.memstoreSizeMB = memstoreSizeMB; this.storefileIndexSizeMB = storefileIndexSizeMB; + this.requestsCount = requestsCount; } // Getters @@ -143,6 +148,13 @@ public class HServerLoad implements WritableComparable { return storefileIndexSizeMB; } + /** + * @return the number of requests made to region + */ + public long getRequestsCount() { + return requestsCount; + } + // Setters /** @@ -181,6 +193,13 @@ public class HServerLoad implements WritableComparable { this.storefileIndexSizeMB = storefileIndexSizeMB; } + /** + * @param requestsCount the number of requests to region + */ + public void setRequestsCount(long requestsCount) { + this.requestsCount = requestsCount; + } + // Writable public void readFields(DataInput in) throws IOException { int namelen = in.readInt(); @@ -191,6 +210,7 @@ public class HServerLoad implements WritableComparable { this.storefileSizeMB = in.readInt(); this.memstoreSizeMB = in.readInt(); this.storefileIndexSizeMB = in.readInt(); + this.requestsCount = in.readLong(); } public void write(DataOutput out) throws IOException { @@ -201,6 +221,7 @@ public class HServerLoad implements WritableComparable { out.writeInt(storefileSizeMB); out.writeInt(memstoreSizeMB); out.writeInt(storefileIndexSizeMB); + out.writeLong(requestsCount); } /** @@ -218,6 +239,8 @@ public class HServerLoad implements WritableComparable { Integer.valueOf(this.memstoreSizeMB)); sb = Strings.appendKeyValue(sb, "storefileIndexSizeMB", Integer.valueOf(this.storefileIndexSizeMB)); + sb = Strings.appendKeyValue(sb, "requestsCount", + Long.valueOf(this.requestsCount)); return sb.toString(); } } @@ -452,14 +475,16 @@ public class HServerLoad implements WritableComparable { * @param storefiles * @param memstoreSizeMB * @param storefileIndexSizeMB + * @param requestsCount * @deprecated Use {@link #addRegionInfo(RegionLoad)} */ @Deprecated public void addRegionInfo(final byte[] name, final int stores, final int storefiles, final int storefileSizeMB, - final int memstoreSizeMB, final int storefileIndexSizeMB) { + final int memstoreSizeMB, final int storefileIndexSizeMB, + final long requestsCount) { this.regionLoad.add(new HServerLoad.RegionLoad(name, stores, storefiles, - storefileSizeMB, memstoreSizeMB, storefileIndexSizeMB)); + storefileSizeMB, memstoreSizeMB, storefileIndexSizeMB, requestsCount)); } // Writable diff --git a/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java b/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java index d073b87..d30e3f8 100644 --- a/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ b/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -87,7 +87,6 @@ import org.apache.hadoop.hbase.util.FSUtils; import org.apache.hadoop.hbase.util.Pair; import org.apache.hadoop.hbase.util.Writables; import org.apache.hadoop.io.Writable; -import org.apache.hadoop.util.Progressable; import org.apache.hadoop.util.StringUtils; import com.google.common.collect.Lists; @@ -162,6 +161,9 @@ public class HRegion implements HeapSize { // , Writable{ final AtomicLong memstoreSize = new AtomicLong(0); + // Isn't this slow? Can't we use lockless counters? St.Ack 20110310 + final AtomicLong requestsCount = new AtomicLong(0); + /** * The directory for the table this region is part of. * This directory contains the directory for this region. @@ -434,6 +436,11 @@ public class HRegion implements HeapSize { // , Writable{ return this.regionInfo; } + /** @return requestsCount for this region */ + public long getRequestsCount() { + return this.requestsCount.get(); + } + /** @return true if region is closed */ public boolean isClosed() { return this.closed.get(); @@ -3186,7 +3193,7 @@ public class HRegion implements HeapSize { // , Writable{ } public static final long FIXED_OVERHEAD = ClassSize.align( - (4 * Bytes.SIZEOF_LONG) + Bytes.SIZEOF_BOOLEAN + + (5 * Bytes.SIZEOF_LONG) + Bytes.SIZEOF_BOOLEAN + (21 * ClassSize.REFERENCE) + ClassSize.OBJECT + Bytes.SIZEOF_INT); public static final long DEEP_OVERHEAD = ClassSize.align(FIXED_OVERHEAD + @@ -3340,6 +3347,7 @@ public class HRegion implements HeapSize { // , Writable{ throw new NotServingRegionException(regionInfo.getRegionNameAsString() + " is closed"); } + this.requestsCount.incrementAndGet(); } /** diff --git a/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java b/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java index b9e9a7e..47256e1 100644 --- a/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java +++ b/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java @@ -50,7 +50,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.locks.ReentrantReadWriteLock; -import com.google.common.collect.Lists; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; @@ -76,7 +75,6 @@ import org.apache.hadoop.hbase.Stoppable; import org.apache.hadoop.hbase.UnknownRowLockException; import org.apache.hadoop.hbase.UnknownScannerException; import org.apache.hadoop.hbase.YouAreDeadException; -import org.apache.hadoop.hbase.HConstants.OperationStatusCode; import org.apache.hadoop.hbase.catalog.CatalogTracker; import org.apache.hadoop.hbase.catalog.MetaEditor; import org.apache.hadoop.hbase.catalog.RootLocationEditor; @@ -137,6 +135,7 @@ import org.apache.hadoop.net.DNS; import org.apache.zookeeper.KeeperException; import com.google.common.base.Function; +import com.google.common.collect.Lists; /** * HRegionServer makes a set of HRegions available to clients. It checks in with @@ -908,6 +907,7 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler, int storefileSizeMB = 0; int memstoreSizeMB = (int) (r.memstoreSize.get() / 1024 / 1024); int storefileIndexSizeMB = 0; + long requestsCount = r.requestsCount.get(); synchronized (r.stores) { stores += r.stores.size(); for (Store store : r.stores.values()) { @@ -916,8 +916,8 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler, storefileIndexSizeMB += (int) (store.getStorefilesIndexSize() / 1024 / 1024); } } - return new HServerLoad.RegionLoad(name, stores, storefiles, - storefileSizeMB, memstoreSizeMB, storefileIndexSizeMB); + return new HServerLoad.RegionLoad(name,stores, storefiles, + storefileSizeMB, memstoreSizeMB, storefileIndexSizeMB, requestsCount); } /** @@ -1156,11 +1156,13 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler, int stores = 0; int storefiles = 0; long memstoreSize = 0; + long requestsCount = 0; long storefileIndexSize = 0; synchronized (this.onlineRegions) { for (Map.Entry e : this.onlineRegions.entrySet()) { HRegion r = e.getValue(); memstoreSize += r.memstoreSize.get(); + requestsCount += r.requestsCount.get(); synchronized (r.stores) { stores += r.stores.size(); for (Map.Entry ee : r.stores.entrySet()) { @@ -1174,6 +1176,7 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler, this.metrics.stores.set(stores); this.metrics.storefiles.set(storefiles); this.metrics.memstoreSizeMB.set((int) (memstoreSize / (1024 * 1024))); + this.metrics.requestsCount.set(requestsCount); this.metrics.storefileIndexSizeMB .set((int) (storefileIndexSize / (1024 * 1024))); this.metrics.compactionQueueSize.set(compactSplitThread diff --git a/src/main/java/org/apache/hadoop/hbase/regionserver/SplitTransaction.java b/src/main/java/org/apache/hadoop/hbase/regionserver/SplitTransaction.java index ddb619f..0a92a57 100644 --- a/src/main/java/org/apache/hadoop/hbase/regionserver/SplitTransaction.java +++ b/src/main/java/org/apache/hadoop/hbase/regionserver/SplitTransaction.java @@ -500,6 +500,7 @@ class SplitTransaction { HRegion r = HRegion.newHRegion(this.parent.getTableDir(), this.parent.getLog(), fs, this.parent.getConf(), hri, flusher); + r.requestsCount.set(this.parent.getRequestsCount() / 2); HRegion.moveInitialFilesIntoPlace(fs, regionDir, r.getRegionDir()); return r; } diff --git a/src/main/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetrics.java b/src/main/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetrics.java index 8e79aca..7353e85 100644 --- a/src/main/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetrics.java +++ b/src/main/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetrics.java @@ -128,6 +128,11 @@ public class RegionServerMetrics implements Updater { public final MetricsIntValue storefiles = new MetricsIntValue("storefiles", registry); /** + * Count of storefiles open on the regionserver. + */ + public final MetricsLongValue requestsCount = new MetricsLongValue("requestsCount", registry); + + /** * Sum of all the storefile index sizes in this regionserver in MB */ public final MetricsIntValue storefileIndexSizeMB = @@ -243,6 +248,7 @@ public class RegionServerMetrics implements Updater { this.storefiles.pushMetric(this.metricsRecord); this.storefileIndexSizeMB.pushMetric(this.metricsRecord); this.memstoreSizeMB.pushMetric(this.metricsRecord); + this.requestsCount.pushMetric(this.metricsRecord); this.regions.pushMetric(this.metricsRecord); this.requests.pushMetric(this.metricsRecord); this.compactionQueueSize.pushMetric(this.metricsRecord); @@ -345,6 +351,8 @@ public class RegionServerMetrics implements Updater { Integer.valueOf(this.storefileIndexSizeMB.get())); sb = Strings.appendKeyValue(sb, "memstoreSize", Integer.valueOf(this.memstoreSizeMB.get())); + sb = Strings.appendKeyValue(sb, "requestsCount", + Long.valueOf(this.requestsCount.get())); sb = Strings.appendKeyValue(sb, "compactionQueueSize", Integer.valueOf(this.compactionQueueSize.get())); sb = Strings.appendKeyValue(sb, "flushQueueSize",