Skip to content

Commit

Permalink
HBASE-26809: Report client backoff time for server overloaded (#4729)
Browse files Browse the repository at this point in the history
Co-authored-by: Briana Augenreich <[email protected]>
Signed-off-by: Duo Zhang <[email protected]>
  • Loading branch information
briaugenreich and Briana Augenreich authored Sep 1, 2022
1 parent 10d85f3 commit 308cd72
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,11 @@ private void tryResubmit(Stream<Action> actions, int tries, boolean immediately,
} else {
delayNs = getPauseTime(pauseNsToUse, tries - 1);
}

if (isServerOverloaded) {
Optional<MetricsConnection> metrics = conn.getConnectionMetrics();
metrics.ifPresent(m -> m.incrementServerOverloadedBackoffTime(delayNs, TimeUnit.NANOSECONDS));
}
retryTimer.newTimeout(t -> groupAndSend(actions, tries + 1), delayNs, TimeUnit.NANOSECONDS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ private void tryScheduleRetry(Throwable error) {
delayNs = getPauseTime(pauseNsToUse, tries - 1);
}
tries++;
if (HBaseServerException.isServerOverloaded(error)) {
Optional<MetricsConnection> metrics = conn.getConnectionMetrics();
metrics.ifPresent(m -> m.incrementServerOverloadedBackoffTime(delayNs, TimeUnit.NANOSECONDS));
}
retryTimer.newTimeout(t -> doCall(), delayNs, TimeUnit.NANOSECONDS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ class AsyncScanSingleRegionRpcRetryingCaller {

private final Runnable completeWhenNoMoreResultsInRegion;

private final AsyncConnectionImpl conn;

private final CompletableFuture<Boolean> future;

private final HBaseRpcController controller;
Expand Down Expand Up @@ -318,6 +320,7 @@ public AsyncScanSingleRegionRpcRetryingCaller(Timer retryTimer, AsyncConnectionI
long pauseNsForServerOverloaded, int maxAttempts, long scanTimeoutNs, long rpcTimeoutNs,
int startLogErrorsCnt) {
this.retryTimer = retryTimer;
this.conn = conn;
this.scan = scan;
this.scanMetrics = scanMetrics;
this.scannerId = scannerId;
Expand Down Expand Up @@ -441,6 +444,11 @@ private void onError(Throwable error) {
return;
}
tries++;

if (HBaseServerException.isServerOverloaded(error)) {
Optional<MetricsConnection> metrics = conn.getConnectionMetrics();
metrics.ifPresent(m -> m.incrementServerOverloadedBackoffTime(delayNs, TimeUnit.NANOSECONDS));
}
retryTimer.newTimeout(t -> call(), delayNs, TimeUnit.NANOSECONDS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ public Counter newMetric(Class<?> clazz, String name, String scope) {
protected final Histogram numActionsPerServerHist;
protected final Counter nsLookups;
protected final Counter nsLookupsFailed;
protected final Timer overloadedBackoffTimer;

// dynamic metrics

Expand Down Expand Up @@ -376,6 +377,8 @@ protected Ratio getRatio() {
registry.histogram(name(MetricsConnection.class, "numActionsPerServer", scope));
this.nsLookups = registry.counter(name(this.getClass(), NS_LOOKUPS, scope));
this.nsLookupsFailed = registry.counter(name(this.getClass(), NS_LOOKUPS_FAILED, scope));
this.overloadedBackoffTimer =
registry.timer(name(this.getClass(), "overloadedBackoffDurationMs", scope));

this.reporter = JmxReporter.forRegistry(this.registry).build();
this.reporter.start();
Expand Down Expand Up @@ -449,6 +452,11 @@ public void incrDelayRunnersAndUpdateDelayInterval(long interval) {
this.runnerStats.updateDelayInterval(interval);
}

/** Update the overloaded backoff time **/
public void incrementServerOverloadedBackoffTime(long time, TimeUnit timeUnit) {
overloadedBackoffTimer.update(time, timeUnit);
}

/**
* Get a metric for {@code key} from {@code map}, or create it with {@code factory}.
*/
Expand Down

0 comments on commit 308cd72

Please sign in to comment.