You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by la...@apache.org on 2013/03/05 04:20:05 UTC
svn commit: r1452648 - in
/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver:
HRegion.java HRegionServer.java SplitTransaction.java
metrics/OperationMetrics.java metrics/RegionMetricsStorage.java
Author: larsh
Date: Tue Mar 5 03:20:04 2013
New Revision: 1452648
URL: http://svn.apache.org/r1452648
Log:
HBASE-7818 add region level metrics readReqeustCount and writeRequestCount (Tianying Chang)
Modified:
hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/SplitTransaction.java
hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/metrics/OperationMetrics.java
hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/metrics/RegionMetricsStorage.java
Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java?rev=1452648&r1=1452647&r2=1452648&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java (original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java Tue Mar 5 03:20:04 2013
@@ -1040,7 +1040,7 @@ public class HRegion implements HeapSize
status.setStatus("Running coprocessor post-close hooks");
this.coprocessorHost.postClose(abort);
}
- this.opMetrics.closeMetrics();
+ this.opMetrics.closeMetrics(this.getRegionInfo().getEncodedName());
status.markComplete("Closed");
LOG.info("Closed " + this);
return result;
@@ -1688,6 +1688,7 @@ public class HRegion implements HeapSize
checkRow(row, "getClosestRowBefore");
startRegionOperation();
this.readRequestsCount.increment();
+ this.opMetrics.setReadRequestCountMetrics(this.readRequestsCount.get());
try {
Store store = getStore(family);
// get the closest key. (HStore.getRowKeyAtOrBefore can return null)
@@ -1734,6 +1735,7 @@ public class HRegion implements HeapSize
List<KeyValueScanner> additionalScanners) throws IOException {
startRegionOperation();
this.readRequestsCount.increment();
+ this.opMetrics.setReadRequestCountMetrics(this.readRequestsCount.get());
try {
// Verify families are all valid
prepareScanner(scan);
@@ -1801,6 +1803,7 @@ public class HRegion implements HeapSize
Integer lid = null;
startRegionOperation();
this.writeRequestsCount.increment();
+ this.opMetrics.setWriteRequestCountMetrics(this.writeRequestsCount.get());
try {
byte [] row = delete.getRow();
// If we did not pass an existing row lock, obtain a new one
@@ -1993,6 +1996,7 @@ public class HRegion implements HeapSize
checkResources();
startRegionOperation();
this.writeRequestsCount.increment();
+ this.opMetrics.setWriteRequestCountMetrics(this.writeRequestsCount.get());
try {
// We obtain a per-row lock, so other clients will block while one client
// performs an update. The read lock is released by the client calling
@@ -2093,6 +2097,7 @@ public class HRegion implements HeapSize
try {
if (!initialized) {
this.writeRequestsCount.increment();
+ this.opMetrics.setWriteRequestCountMetrics(this.writeRequestsCount.get());
doPreMutationHook(batchOp);
initialized = true;
}
@@ -2519,6 +2524,7 @@ public class HRegion implements HeapSize
startRegionOperation();
this.writeRequestsCount.increment();
+ this.opMetrics.setWriteRequestCountMetrics(this.writeRequestsCount.get());
try {
RowLock lock = isPut ? ((Put)w).getRowLock() : ((Delete)w).getRowLock();
Get get = new Get(row, lock);
@@ -3341,6 +3347,7 @@ public class HRegion implements HeapSize
public Integer obtainRowLock(final byte [] row) throws IOException {
startRegionOperation();
this.writeRequestsCount.increment();
+ this.opMetrics.setWriteRequestCountMetrics( this.writeRequestsCount.get());
try {
return internalObtainRowLock(row, true);
} finally {
@@ -3513,6 +3520,7 @@ public class HRegion implements HeapSize
startBulkRegionOperation(hasMultipleColumnFamilies(familyPaths));
try {
this.writeRequestsCount.increment();
+ this.opMetrics.setWriteRequestCountMetrics( this.writeRequestsCount.get());
// There possibly was a split that happend between when the split keys
// were gathered and before the HReiogn's write lock was taken. We need
@@ -3737,6 +3745,7 @@ public class HRegion implements HeapSize
}
startRegionOperation();
readRequestsCount.increment();
+ opMetrics.setReadRequestCountMetrics(readRequestsCount.get());
try {
// This could be a new thread from the last time we called next().
@@ -4555,8 +4564,14 @@ public class HRegion implements HeapSize
}
HRegion dstRegion = HRegion.newHRegion(tableDir, log, fs, conf,
newRegionInfo, a.getTableDesc(), null);
- dstRegion.readRequestsCount.set(a.readRequestsCount.get() + b.readRequestsCount.get());
- dstRegion.writeRequestsCount.set(a.writeRequestsCount.get() + b.writeRequestsCount.get());
+ long totalReadRequestCount = a.readRequestsCount.get() + b.readRequestsCount.get();
+ dstRegion.readRequestsCount.set(totalReadRequestCount);
+ dstRegion.opMetrics.setReadRequestCountMetrics(totalReadRequestCount);
+
+ long totalWriteRequestCount = a.writeRequestsCount.get() + b.writeRequestsCount.get();
+ dstRegion.writeRequestsCount.set(totalWriteRequestCount);
+ dstRegion.opMetrics.setWriteRequestCountMetrics(totalWriteRequestCount);
+
dstRegion.initialize();
dstRegion.compactStores();
if (LOG.isDebugEnabled()) {
@@ -4946,6 +4961,7 @@ public class HRegion implements HeapSize
// Lock row
startRegionOperation();
this.writeRequestsCount.increment();
+ this.opMetrics.setWriteRequestCountMetrics(this.writeRequestsCount.get());
try {
Integer lid = getLock(lockid, row, true);
lock(this.updatesLock.readLock());
@@ -5116,6 +5132,7 @@ public class HRegion implements HeapSize
// Lock row
startRegionOperation();
this.writeRequestsCount.increment();
+ this.opMetrics.setWriteRequestCountMetrics(this.writeRequestsCount.get());
try {
Integer lid = getLock(lockid, row, true);
lock(this.updatesLock.readLock());
@@ -5234,6 +5251,7 @@ public class HRegion implements HeapSize
long result = amount;
startRegionOperation();
this.writeRequestsCount.increment();
+ this.opMetrics.setWriteRequestCountMetrics(this.writeRequestsCount.get());
try {
Integer lid = obtainRowLock(row);
lock(this.updatesLock.readLock());
@@ -5619,6 +5637,24 @@ public class HRegion implements HeapSize
return coprocessorHost;
}
+ /*
+ * Set the read request count defined in opMetrics
+ * @param value absolute value of read request count
+ */
+ public void setOpMetricsReadRequestCount(long value)
+ {
+ this.opMetrics.setReadRequestCountMetrics(value);
+ }
+
+ /*
+ * Set the write request count defined in opMetrics
+ * @param value absolute value of write request count
+ */
+ public void setOpMetricsWriteRequestCount(long value)
+ {
+ this.opMetrics.setWriteRequestCountMetrics(value);
+ }
+
/** @param coprocessorHost the new coprocessor host */
public void setCoprocessorHost(final RegionCoprocessorHost coprocessorHost) {
this.coprocessorHost = coprocessorHost;
Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java?rev=1452648&r1=1452647&r2=1452648&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java (original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java Tue Mar 5 03:20:04 2013
@@ -2524,6 +2524,7 @@ public class HRegionServer implements HR
}
requestCount.addAndGet(i);
region.readRequestsCount.add(i);
+ region.setOpMetricsReadRequestCount(region.readRequestsCount.get());
} finally {
region.closeRegionOperation();
}
Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/SplitTransaction.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/SplitTransaction.java?rev=1452648&r1=1452647&r2=1452648&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/SplitTransaction.java (original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/SplitTransaction.java Tue Mar 5 03:20:04 2013
@@ -700,8 +700,12 @@ public class SplitTransaction {
HRegion r = HRegion.newHRegion(this.parent.getTableDir(),
this.parent.getLog(), fs, this.parent.getConf(),
hri, this.parent.getTableDesc(), rsServices);
- r.readRequestsCount.set(this.parent.getReadRequestsCount() / 2);
- r.writeRequestsCount.set(this.parent.getWriteRequestsCount() / 2);
+ long halfParentReadRequestCount = this.parent.getReadRequestsCount() / 2;
+ r.readRequestsCount.set(halfParentReadRequestCount);
+ r.setOpMetricsReadRequestCount(halfParentReadRequestCount);
+ long halfParentWriteRequest = this.parent.getWriteRequestsCount() / 2;
+ r.writeRequestsCount.set(halfParentWriteRequest);
+ r.setOpMetricsWriteRequestCount(halfParentWriteRequest);
HRegion.moveInitialFilesIntoPlace(fs, regionDir, r.getRegionDir());
return r;
}
Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/metrics/OperationMetrics.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/metrics/OperationMetrics.java?rev=1452648&r1=1452647&r2=1452648&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/metrics/OperationMetrics.java (original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/metrics/OperationMetrics.java Tue Mar 5 03:20:04 2013
@@ -46,6 +46,8 @@ public class OperationMetrics {
private static final String MULTIPUT_KEY = "multiput_";
private static final String MULTIDELETE_KEY = "multidelete_";
private static final String APPEND_KEY = "append_";
+ private static final String READREQUESTCOUNT_KEY = "readrequestcount";
+ private static final String WRITEREQUESTCOUNT_KEY = "writerequestcount";
/** Conf key controlling whether we should expose metrics.*/
private static final String CONF_KEY =
@@ -98,6 +100,27 @@ public class OperationMetrics {
this(null, null);
}
+ /*
+ * This is used in set the read request count that is going to be exposed to
+ * hadoop metric framework.
+ * @param value absolute value of read account
+ */
+ public void setReadRequestCountMetrics(long value) {
+ doSetNumericPersistentMetrics(READREQUESTCOUNT_KEY, value);
+ }
+
+ /*
+ * This is used in set the read request count that is going to be exposed to
+ * hadoop metric framework.
+ * @param value absolute value of write account
+ */
+ public void setWriteRequestCountMetrics(long value) {
+ doSetNumericPersistentMetrics(WRITEREQUESTCOUNT_KEY, value);
+ }
+
+ private void doSetNumericPersistentMetrics(String key, long value) {
+ RegionMetricsStorage.setNumericPersistentMetric(this.regionMetrixPrefix+key, value);
+ }
/**
* Update the stats associated with {@link HTable#put(java.util.List)}.
@@ -190,11 +213,15 @@ public class OperationMetrics {
doUpdateTimeVarying(columnFamilies, DELETE_KEY, value);
}
+
+
/**
- * This deletes all old metrics this instance has ever created or updated.
+ * This deletes all old non-persistent metrics this instance has ever created or updated.
+ * for persistent metrics, only delete for the region to be closed
+ * @param regionEncodedName the region that is to be closed
*/
- public void closeMetrics() {
- RegionMetricsStorage.clear();
+ public void closeMetrics(String regionEncodedName) {
+ RegionMetricsStorage.clear(regionEncodedName);
}
/**
Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/metrics/RegionMetricsStorage.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/metrics/RegionMetricsStorage.java?rev=1452648&r1=1452647&r2=1452648&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/metrics/RegionMetricsStorage.java (original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/metrics/RegionMetricsStorage.java Tue Mar 5 03:20:04 2013
@@ -20,6 +20,7 @@
package org.apache.hadoop.hbase.regionserver.metrics;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicInteger;
@@ -88,6 +89,9 @@ public class RegionMetricsStorage {
oldVal.getSecond().incrementAndGet(); // increment ops by 1
}
+ public static void setNumericPersistentMetric(String key, long amount) {
+ numericPersistentMetrics.put(key, new AtomicLong(amount));
+ }
public static void incrNumericPersistentMetric(String key, long amount) {
AtomicLong oldVal = numericPersistentMetrics.get(key);
if (oldVal == null) {
@@ -126,11 +130,18 @@ public class RegionMetricsStorage {
}
/**
- * Clear all copies of the metrics this stores.
+ * Clear the timevarying and numeric metrics for all regions in this region server
+ * Clear the numericPersistentMerics for only the region being closed.
*/
- public static void clear() {
+ public static void clear(String regionEncodedName) {
timeVaryingMetrics.clear();
numericMetrics.clear();
- numericPersistentMetrics.clear();
+ for (Entry<String, AtomicLong> entry : RegionMetricsStorage.getNumericPersistentMetrics().entrySet()) {
+ if (entry.getKey().contains(regionEncodedName))
+ {
+ String keyName = entry.getKey();
+ numericPersistentMetrics.remove(keyName);
+ }
+ }
}
}