Skip to content

Commit 2c4f1e5

Browse files
committed
Expiry time for backoff cache entry.
1 parent 4843256 commit 2c4f1e5

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

rls/src/main/java/io/grpc/rls/CachingRlsLbClient.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,8 @@ private BackoffCacheEntry createBackOffEntry(
439439
ChannelLogLevel.DEBUG,
440440
"[RLS Entry {0}] Transition to back off: status={1}, delayNanos={2}",
441441
request, status, delayNanos);
442-
BackoffCacheEntry entry = new BackoffCacheEntry(request, status, backoffPolicy);
442+
BackoffCacheEntry entry = new BackoffCacheEntry(request, status, backoffPolicy,
443+
ticker.read() + delayNanos * 2);
443444
// Lock is held, so the task can't execute before the assignment
444445
entry.scheduledFuture = scheduledExecutorService.schedule(
445446
() -> refreshBackoffEntry(entry), delayNanos, TimeUnit.NANOSECONDS);
@@ -762,12 +763,15 @@ private static final class BackoffCacheEntry extends CacheEntry {
762763

763764
private final Status status;
764765
private final BackoffPolicy backoffPolicy;
766+
private final long expiryTimeNanos;
765767
private Future<?> scheduledFuture;
766768

767-
BackoffCacheEntry(RouteLookupRequest request, Status status, BackoffPolicy backoffPolicy) {
769+
BackoffCacheEntry(RouteLookupRequest request, Status status, BackoffPolicy backoffPolicy,
770+
long expiryTimeNanos) {
768771
super(request);
769772
this.status = checkNotNull(status, "status");
770773
this.backoffPolicy = checkNotNull(backoffPolicy, "backoffPolicy");
774+
this.expiryTimeNanos = expiryTimeNanos;
771775
}
772776

773777
Status getStatus() {
@@ -780,8 +784,8 @@ int getSizeBytes() {
780784
}
781785

782786
@Override
783-
boolean isExpired(long now) {
784-
return scheduledFuture.isDone();
787+
boolean isExpired(long nowNanos) {
788+
return nowNanos > expiryTimeNanos;
785789
}
786790

787791
@Override

0 commit comments

Comments
 (0)