Index: src/main/java/org/apache/hadoop/hbase/HServerLoad.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/HServerLoad.java (revision 1080346) +++ src/main/java/org/apache/hadoop/hbase/HServerLoad.java (working copy) @@ -65,6 +65,8 @@ 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,18 @@ * @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 @@ -142,6 +146,13 @@ public int getStorefileIndexSizeMB() { return storefileIndexSizeMB; } + + /** + * @return the number of requests made to region + */ + public long getRequestsCount() { + return requestsCount; + } // Setters @@ -181,6 +192,13 @@ 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 +209,7 @@ 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 +220,7 @@ out.writeInt(storefileSizeMB); out.writeInt(memstoreSizeMB); out.writeInt(storefileIndexSizeMB); + out.writeLong(requestsCount); } /** @@ -218,6 +238,8 @@ 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 +474,16 @@ * @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 Index: src/main/java/org/apache/hadoop/hbase/regionserver/SplitTransaction.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/regionserver/SplitTransaction.java (revision 1080346) +++ src/main/java/org/apache/hadoop/hbase/regionserver/SplitTransaction.java (working copy) @@ -542,7 +542,7 @@ this.splitdir, hri); HRegion r = HRegion.newHRegion(this.parent.getTableDir(), this.parent.getLog(), fs, this.parent.getConf(), - hri, rsServices); + hri, rsServices, this.parent.getRequestCount()/2); HRegion.moveInitialFilesIntoPlace(fs, regionDir, r.getRegionDir()); return r; } Index: src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java (revision 1080346) +++ src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java (working copy) @@ -901,6 +901,7 @@ 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()) { @@ -909,8 +910,8 @@ 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); } /** @@ -1149,11 +1150,13 @@ 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()) { @@ -1167,6 +1170,7 @@ 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 Index: src/main/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetrics.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetrics.java (revision 1080346) +++ src/main/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetrics.java (working copy) @@ -128,6 +128,11 @@ 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 @@ 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 @@ 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", Index: src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java (revision 1080346) +++ src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java (working copy) @@ -43,6 +43,7 @@ import java.util.TreeSet; import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.locks.ReentrantReadWriteLock; @@ -173,7 +174,7 @@ // private byte [] name = null; final AtomicLong memstoreSize = new AtomicLong(0); - + final AtomicLong requestsCount = new AtomicLong(0); /** * The directory for the table this region is part of. * This directory contains the directory for this region. @@ -295,6 +296,13 @@ */ public HRegion(Path tableDir, HLog log, FileSystem fs, Configuration conf, HRegionInfo regionInfo, RegionServerServices rsServices) { + this(tableDir, log, fs, conf, regionInfo, rsServices, 0); + } + /* + * @param reqCount The initial request count the new region should carry + */ + public HRegion(Path tableDir, HLog log, FileSystem fs, Configuration conf, + HRegionInfo regionInfo, RegionServerServices rsServices, long reqCount) { this.tableDir = tableDir; this.comparator = regionInfo.getComparator(); this.log = log; @@ -302,6 +303,7 @@ this.conf = conf; this.regionInfo = regionInfo; this.rsServices = rsServices; + this.requestsCount.set(reqCount); this.threadWakeFrequency = conf.getLong(HConstants.THREAD_WAKE_FREQUENCY, 10 * 1000); String encodedNameStr = this.regionInfo.getEncodedName(); @@ -451,6 +453,11 @@ } /** @return requestsCount for this region */ + public long getRequestCount() { + return this.requestsCount.get(); + } + + /** @return a HRegionInfo object for this region */ public HRegionInfo getRegionInfo() { return this.regionInfo; @@ -2604,6 +2618,15 @@ public static HRegion newHRegion(Path tableDir, HLog log, FileSystem fs, Configuration conf, HRegionInfo regionInfo, RegionServerServices rsServices) { + return newHRegion(tableDir, log, fs, conf, regionInfo, rsServices, 0); + } + + /* + * @param requestCount The initial request count the new region should carry + */ + public static HRegion newHRegion(Path tableDir, HLog log, FileSystem fs, + Configuration conf, HRegionInfo regionInfo, + RegionServerServices rsServices, long requestCount) { try { @SuppressWarnings("unchecked") Class regionClass = @@ -2611,9 +2618,10 @@ Constructor c = regionClass.getConstructor(Path.class, HLog.class, FileSystem.class, - Configuration.class, HRegionInfo.class, RegionServerServices.class); + Configuration.class, HRegionInfo.class, RegionServerServices.class, long.class); - return c.newInstance(tableDir, log, fs, conf, regionInfo, rsServices); + HRegion r = c.newInstance(tableDir, log, fs, conf, regionInfo, rsServices, requestCount); + return r; } catch (Throwable e) { // todo: what should I throw here? throw new IllegalStateException("Could not instantiate a region instance.", e); @@ -2644,7 +2652,7 @@ HRegion region = HRegion.newHRegion(tableDir, new HLog(fs, new Path(regionDir, HConstants.HREGION_LOGDIR_NAME), new Path(regionDir, HConstants.HREGION_OLDLOGDIR_NAME), conf), - fs, conf, info, null); + fs, conf, info, null, 0); region.initialize(); return region; } @@ -2694,7 +2702,7 @@ Path dir = HTableDescriptor.getTableDir(FSUtils.getRootDir(conf), info.getTableDesc().getName()); HRegion r = HRegion.newHRegion(dir, wal, FileSystem.get(conf), conf, info, - rsServices); + rsServices, 0); return r.openHRegion(reporter); } @@ -2961,7 +2969,7 @@ LOG.debug("Files for new region"); listPaths(fs, newRegionDir); } - HRegion dstRegion = HRegion.newHRegion(tableDir, log, fs, conf, newRegionInfo, null); + HRegion dstRegion = HRegion.newHRegion(tableDir, log, fs, conf, newRegionInfo, null, a.getRequestCount()+b.getRequestCount()); dstRegion.initialize(); dstRegion.compactStores(); if (LOG.isDebugEnabled()) { @@ -3370,7 +3378,7 @@ } public static final long FIXED_OVERHEAD = ClassSize.align( - (4 * Bytes.SIZEOF_LONG) + ClassSize.ARRAY + + (5 * Bytes.SIZEOF_LONG) + ClassSize.ARRAY + (24 * ClassSize.REFERENCE) + ClassSize.OBJECT + Bytes.SIZEOF_INT); public static final long DEEP_OVERHEAD = ClassSize.align(FIXED_OVERHEAD + @@ -3523,10 +3531,10 @@ String metaStr = Bytes.toString(HConstants.META_TABLE_NAME); // Currently expects tables have one region only. if (p.getName().startsWith(rootStr)) { - region = HRegion.newHRegion(p, log, fs, c, HRegionInfo.ROOT_REGIONINFO, null); + region = HRegion.newHRegion(p, log, fs, c, HRegionInfo.ROOT_REGIONINFO, null, 0); } else if (p.getName().startsWith(metaStr)) { region = HRegion.newHRegion(p, log, fs, c, HRegionInfo.FIRST_META_REGIONINFO, - null); + null, 0); } else { throw new IOException("Not a known catalog table: " + p.toString()); } @@ -3634,6 +3642,7 @@ throw new NotServingRegionException(regionInfo.getRegionNameAsString() + " is closed"); } + this.requestsCount.incrementAndGet(); } /**