Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HBASE-27684: add client metrics related to user region lock. #5081

Merged
merged 9 commits into from
Mar 21, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ public class ConnectionImplementation implements ClusterConnection, Closeable {

private ChoreService choreService;

private long userRegionLockHeldStartTime;

/**
* constructor
* @param conf Configuration object
Expand Down Expand Up @@ -1112,6 +1114,11 @@ rpcControllerFactory, getMetaLookupPool(), connectionConfig.getMetaReadRpcTimeou
ConnectionUtils.getPauseTime(pauseBase, tries), TimeUnit.MILLISECONDS);
}
} finally {
// update duration of the lock being held
vli02 marked this conversation as resolved.
Show resolved Hide resolved
if (metrics != null) {
metrics.updateUserRegionLockHeld(
EnvironmentEdgeManager.currentTime() - userRegionLockHeldStartTime);
}
userRegionLock.unlock();
}
try {
Expand All @@ -1126,9 +1133,21 @@ rpcControllerFactory, getMetaLookupPool(), connectionConfig.getMetaReadRpcTimeou
void takeUserRegionLock() throws IOException {
try {
long waitTime = connectionConfig.getMetaOperationTimeout();
long waitStartTime = 0;
if (metrics != null) {
shahrs87 marked this conversation as resolved.
Show resolved Hide resolved
metrics.updateUserRegionLockQueue(userRegionLock.getQueueLength());
waitStartTime = EnvironmentEdgeManager.currentTime();
}
if (!userRegionLock.tryLock(waitTime, TimeUnit.MILLISECONDS)) {
if (metrics != null) {
metrics.incrUserRegionLockTimeout();
}
throw new LockTimeoutException("Failed to get user region lock in" + waitTime + " ms. "
+ " for accessing meta region server.");
} else if (metrics != null) {
vli02 marked this conversation as resolved.
Show resolved Hide resolved
// successfully grabbed the lock, start timer of holding the lock
userRegionLockHeldStartTime = EnvironmentEdgeManager.currentTime();
metrics.updateUserRegionLockWaiting(userRegionLockHeldStartTime - waitStartTime);
}
} catch (InterruptedException ie) {
LOG.error("Interrupted while waiting for a lock", ie);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,10 @@ public Counter newMetric(Class<?> clazz, String name, String scope) {
private final Counter nsLookups;
private final Counter nsLookupsFailed;
private final Timer overloadedBackoffTimer;
private final Counter userRegionLockTimeoutCount;
private final Timer userRegionLockWaitingTimer;
private final Timer userRegionLockHeldTimer;
private final Histogram userRegionLockQueueHist;

// dynamic metrics

Expand Down Expand Up @@ -443,6 +447,15 @@ protected Ratio getRatio() {
this.nsLookups = registry.counter(name(this.getClass(), NS_LOOKUPS, scope));
this.nsLookupsFailed = registry.counter(name(this.getClass(), NS_LOOKUPS_FAILED, scope));

this.userRegionLockTimeoutCount =
registry.counter(name(this.getClass(), "userRegionLockTimeoutCount", scope));
this.userRegionLockWaitingTimer =
registry.timer(name(this.getClass(), "userRegionLockWaitingDurationMs", scope));
vli02 marked this conversation as resolved.
Show resolved Hide resolved
this.userRegionLockHeldTimer =
registry.timer(name(this.getClass(), "userRegionLockHeldDurationMs", scope));
this.userRegionLockQueueHist =
registry.histogram(name(MetricsConnection.class, "userRegionLockQueueLength", scope));

this.overloadedBackoffTimer =
registry.timer(name(this.getClass(), "overloadedBackoffDurationMs", scope));

Expand Down Expand Up @@ -598,6 +611,24 @@ public void incrementServerOverloadedBackoffTime(long time, TimeUnit timeUnit) {
overloadedBackoffTimer.update(time, timeUnit);
}

/** incr */
vli02 marked this conversation as resolved.
Show resolved Hide resolved
public void incrUserRegionLockTimeout() {
userRegionLockTimeoutCount.inc();
}

/** update */
public void updateUserRegionLockWaiting(long duration) {
userRegionLockWaitingTimer.update(duration, TimeUnit.MILLISECONDS);
}

public void updateUserRegionLockHeld(long duration) {
userRegionLockHeldTimer.update(duration, TimeUnit.MILLISECONDS);
}

public void updateUserRegionLockQueue(int count) {
userRegionLockQueueHist.update(count);
}

/** Return the connection count of the metrics within a scope */
public long getConnectionCount() {
return connectionCount.getCount();
Expand Down