HBASE-17205 Add a metric for the duration of region in transition

This commit is contained in:
Guanghao Zhang 2016-11-30 18:41:11 +08:00 committed by Matteo Bertozzi
parent eeaea4aea3
commit b3d8d06703
5 changed files with 54 additions and 2 deletions

View File

@ -176,6 +176,8 @@ public class RegionState {
private final HRegionInfo hri; private final HRegionInfo hri;
private final ServerName serverName; private final ServerName serverName;
private final State state; private final State state;
// The duration of region in transition
private long ritDuration;
public RegionState(HRegionInfo region, State state) { public RegionState(HRegionInfo region, State state) {
this(region, state, System.currentTimeMillis(), null); this(region, state, System.currentTimeMillis(), null);
@ -188,10 +190,16 @@ public class RegionState {
public RegionState(HRegionInfo region, public RegionState(HRegionInfo region,
State state, long stamp, ServerName serverName) { State state, long stamp, ServerName serverName) {
this(region, state, stamp, serverName, 0);
}
public RegionState(HRegionInfo region, State state, long stamp, ServerName serverName,
long ritDuration) {
this.hri = region; this.hri = region;
this.state = state; this.state = state;
this.stamp = stamp; this.stamp = stamp;
this.serverName = serverName; this.serverName = serverName;
this.ritDuration = ritDuration;
} }
public State getState() { public State getState() {
@ -210,6 +218,19 @@ public class RegionState {
return serverName; return serverName;
} }
public long getRitDuration() {
return ritDuration;
}
/**
* Update the duration of region in transition
* @param previousStamp previous RegionState's timestamp
*/
@InterfaceAudience.Private
void updateRitDuration(long previousStamp) {
this.ritDuration += (this.stamp - previousStamp);
}
/** /**
* PENDING_CLOSE (to be removed) is the same as CLOSING * PENDING_CLOSE (to be removed) is the same as CLOSING
*/ */

View File

@ -45,6 +45,7 @@ public interface MetricsAssignmentManagerSource extends BaseSource {
String RIT_COUNT_NAME = "ritCount"; String RIT_COUNT_NAME = "ritCount";
String RIT_COUNT_OVER_THRESHOLD_NAME = "ritCountOverThreshold"; String RIT_COUNT_OVER_THRESHOLD_NAME = "ritCountOverThreshold";
String RIT_OLDEST_AGE_NAME = "ritOldestAge"; String RIT_OLDEST_AGE_NAME = "ritOldestAge";
String RIT_DURATION_NAME = "ritDuration";
String ASSIGN_TIME_NAME = "assign"; String ASSIGN_TIME_NAME = "assign";
String BULK_ASSIGN_TIME_NAME = "bulkAssign"; String BULK_ASSIGN_TIME_NAME = "bulkAssign";
@ -72,4 +73,6 @@ public interface MetricsAssignmentManagerSource extends BaseSource {
* @param age age of the oldest RIT. * @param age age of the oldest RIT.
*/ */
void setRITOldestAge(long age); void setRITOldestAge(long age);
void updateRitDuration(long duration);
} }

View File

@ -31,6 +31,7 @@ public class MetricsAssignmentManagerSourceImpl
private MutableGaugeLong ritGauge; private MutableGaugeLong ritGauge;
private MutableGaugeLong ritCountOverThresholdGauge; private MutableGaugeLong ritCountOverThresholdGauge;
private MutableGaugeLong ritOldestAgeGauge; private MutableGaugeLong ritOldestAgeGauge;
private MetricHistogram ritDurationHisto;
private MetricHistogram assignTimeHisto; private MetricHistogram assignTimeHisto;
private MetricHistogram bulkAssignTimeHisto; private MetricHistogram bulkAssignTimeHisto;
@ -50,6 +51,7 @@ public class MetricsAssignmentManagerSourceImpl
ritOldestAgeGauge = metricsRegistry.newGauge(RIT_OLDEST_AGE_NAME, "", 0l); ritOldestAgeGauge = metricsRegistry.newGauge(RIT_OLDEST_AGE_NAME, "", 0l);
assignTimeHisto = metricsRegistry.newTimeHistogram(ASSIGN_TIME_NAME); assignTimeHisto = metricsRegistry.newTimeHistogram(ASSIGN_TIME_NAME);
bulkAssignTimeHisto = metricsRegistry.newTimeHistogram(BULK_ASSIGN_TIME_NAME); bulkAssignTimeHisto = metricsRegistry.newTimeHistogram(BULK_ASSIGN_TIME_NAME);
ritDurationHisto = metricsRegistry.newTimeHistogram(RIT_DURATION_NAME);
} }
@Override @Override
@ -73,4 +75,9 @@ public class MetricsAssignmentManagerSourceImpl
public void setRITOldestAge(long ritCount) { public void setRITOldestAge(long ritCount) {
ritOldestAgeGauge.set(ritCount); ritOldestAgeGauge.set(ritCount);
} }
@Override
public void updateRitDuration(long duration) {
ritDurationHisto.add(duration);
}
} }

View File

@ -64,4 +64,12 @@ public class MetricsAssignmentManager {
public void updateRITOldestAge(long timestamp) { public void updateRITOldestAge(long timestamp) {
assignmentManagerSource.setRITOldestAge(timestamp); assignmentManagerSource.setRITOldestAge(timestamp);
} }
/**
* update the duration metrics of region is transition
* @param duration
*/
public void updateRitDuration(long duration) {
assignmentManagerSource.updateRitDuration(duration);
}
} }

View File

@ -451,7 +451,15 @@ public class RegionStates {
updateRegionState(hri, State.OPEN, serverName, openSeqNum); updateRegionState(hri, State.OPEN, serverName, openSeqNum);
synchronized (this) { synchronized (this) {
regionsInTransition.remove(encodedName); RegionState regionState = regionsInTransition.remove(encodedName);
// When region is online and remove from regionsInTransition,
// update the RIT duration to assignment manager metrics
if (regionState != null && this.server.getAssignmentManager() != null) {
long ritDuration = System.currentTimeMillis() - regionState.getStamp()
+ regionState.getRitDuration();
this.server.getAssignmentManager().getAssignmentManagerMetrics()
.updateRitDuration(ritDuration);
}
ServerName oldServerName = regionAssignments.put(hri, serverName); ServerName oldServerName = regionAssignments.put(hri, serverName);
if (!serverName.equals(oldServerName)) { if (!serverName.equals(oldServerName)) {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
@ -1126,7 +1134,12 @@ public class RegionStates {
} }
synchronized (this) { synchronized (this) {
regionsInTransition.put(encodedName, regionState); RegionState oldRegionState = regionsInTransition.put(encodedName, regionState);
// When region transform old region state to new region state,
// accumulate the RIT duration to new region state.
if (oldRegionState != null) {
regionState.updateRitDuration(oldRegionState.getStamp());
}
putRegionState(regionState); putRegionState(regionState);
// For these states, region should be properly closed. // For these states, region should be properly closed.