Re: [PR] fix(store-client): stop retrying after DEADLINE_EXCEEDED and honour thread interrupts in NodeTxExecutor [hugegraph]
bitflicker64 commented on code in PR #3204:
URL: https://github.com/apache/hugegraph/pull/3204#discussion_r4004358083
##
hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/client/NodeTxExecutor.java:
##
@@ -373,35 +391,75 @@ boolean ifAnyTrue(Supplier>> nodeStreamSuppl
}
Optional retryingInvoke(Supplier supplier) {
+boolean[] deadlineRetried = {false};
return IntStream.rangeClosed(0, NODE_MAX_RETRYING_TIMES).boxed()
.map(
i -> {
+if
(Thread.currentThread().isInterrupted()) {
+// The caller (e.g. a REST worker
hitting
+// restserver.request_timeout) gave
up: stop
+// retrying instead of holding its
thread.
+// InterruptedException as the root
cause: the
+// server's task cancel path
recognises it
+// (HugeException.isInterrupted()).
+throw HgStoreClientException.of(
+"Interrupted before retry " +
i,
+new InterruptedException());
+}
T buffer = null;
try {
buffer = supplier.get();
} catch (Throwable t) {
-if (i + 1 <= NODE_MAX_RETRYING_TIMES) {
-try {
-int sleepTime;
-// The first three times try
once every second
-if (i < 3) {
-sleepTime = 1;
-} else {
-// Subsequent incremental
-sleepTime = i - 1;
-}
-log.info("Waiting {} seconds "
+
- "for the next try.",
- sleepTime);
-Thread.sleep(sleepTime *
1000L);
-} catch (InterruptedException e) {
-log.error("Failed to sleep",
e);
+Failure failure = classify(t);
+if (failure != Failure.DEADLINE) {
+// a different failure in between
means the
+// next deadline is not "in a row"
again
+deadlineRetried[0] = false;
Review Comment:
⚠️ Resetting the budget here lets one call block on up to six full
deadlines, not two.
Evidence:
- The loop makes 11 attempts (`rangeClosed(0, NODE_MAX_RETRYING_TIMES)`).
With D, X, D, X, ... D, where X is any fast retryable failure, every D gets
retried: 6 × `grpc.timeout.seconds` (600 s on defaults) plus about 38 s of
backoff.
- That pattern is reachable. The DEADLINE sends NOT_WORK without the node
(`NotifyingExecutor.java:249-254`), which reloads partition leaders. While raft
is still electing, or PD still lists the stalled store, the next attempt can
fail quickly with NOT_LEADER, a partition fault or UNAVAILABLE. That resets
this flag, and the attempt after it waits on the stalled store again.
- The description gives the bound as 2 × deadline + backoff. That holds only
for back-to-back deadlines. The request-timeout interrupt still frees REST
workers, but callers that are never interrupted (Gremlin jobs without
`evaluationTimeout`, background tasks) can be held for about 10 minutes again.
Could you bound deadlines per `retryingInvoke` call instead, e.g. count
DEADLINE failures and stop at the second one even if something else failed in
between? The javadoc on `Failure` and
`testDeadlineBudgetResetsAfterAnotherFailure` would need updating to match.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
-
To unsubscribe, e-mail:
Re: [PR] fix(store-client): stop retrying after DEADLINE_EXCEEDED and honour thread interrupts in NodeTxExecutor [hugegraph]
SebastianGruza commented on code in PR #3204:
URL: https://github.com/apache/hugegraph/pull/3204#discussion_r3995606936
##
hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/client/NodeTxExecutor.java:
##
@@ -373,35 +398,70 @@ boolean ifAnyTrue(Supplier>> nodeStreamSuppl
}
Optional retryingInvoke(Supplier supplier) {
+boolean[] deadlineRetried = {false};
return IntStream.rangeClosed(0, NODE_MAX_RETRYING_TIMES).boxed()
.map(
i -> {
+if
(Thread.currentThread().isInterrupted()) {
+// The caller (e.g. a REST worker
hitting
+// restserver.request_timeout) gave
up: stop
+// retrying instead of holding its
thread.
+// InterruptedException as the root
cause: the
+// server's task cancel path
recognises it
+// (HugeException.isInterrupted()).
+throw HgStoreClientException.of(
+"Interrupted before retry " +
i,
+new InterruptedException());
+}
T buffer = null;
try {
buffer = supplier.get();
} catch (Throwable t) {
-if (i + 1 <= NODE_MAX_RETRYING_TIMES) {
-try {
-int sleepTime;
-// The first three times try
once every second
-if (i < 3) {
-sleepTime = 1;
-} else {
-// Subsequent incremental
-sleepTime = i - 1;
-}
-log.info("Waiting {} seconds "
+
- "for the next try.",
- sleepTime);
-Thread.sleep(sleepTime *
1000L);
-} catch (InterruptedException e) {
-log.error("Failed to sleep",
e);
+Failure failure = classify(t);
+if (failure == Failure.FATAL) {
+// The caller's thread was
interrupted or the
+// call was cancelled: fail fast.
+log.warn("Not retrying after: {}",
+ t.getMessage(), t);
+throw HgStoreClientException.of(
+t.getMessage(), t);
+}
+if (failure == Failure.DEADLINE) {
+// One retry: the NOT_WORK notice
sent for the
+// failed RPC reloads the
partition leaders, so
+// the next attempt can reach a
new leader. A
+// second deadline in a row would
only wait the
+// full deadline again on the same
stalled store.
+if (deadlineRetried[0]) {
+log.warn("Not retrying a
second deadline: {}",
+ t.getMessage(), t);
+throw
HgStoreClientException.of(
+t.getMessage(), t);
}
-} else {
+deadlineRetried[0] = true;
+log.warn("Deadline exceeded,
retrying once in " +
Review Comment:
Done — the description now describes `classify()` / `Failure` with the
single deadline retry (and the reset after a different failure from 35e0a6d),
and I re-ran the SIGSTOP measurement at `35e0a6d` instead of annotating: with
one deadline retry the REST outage under the 1
Re: [PR] fix(store-client): stop retrying after DEADLINE_EXCEEDED and honour thread interrupts in NodeTxExecutor [hugegraph]
SebastianGruza commented on code in PR #3204:
URL: https://github.com/apache/hugegraph/pull/3204#discussion_r3995591672
##
hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/client/NodeTxExecutor.java:
##
@@ -129,35 +136,7 @@ void doCommit() {
if (!allSuccess.get()) {
throw HgStoreClientException.of(msg);
}
-AtomicReference throwable = new AtomicReference<>();
-Collection sessions = this.sessions.values();
-sessions.parallelStream().forEach(e -> {
-if (e.isTx()) {
-try {
-e.commit();
-} catch (Throwable t) {
-throwable.compareAndSet(null, t);
-allSuccess.set(false);
-}
-}
-});
-if (!allSuccess.get()) {
-if (isTx) {
-try {
-
sessions.stream().forEach(HgStoreSession::rollback);
-} catch (Exception e) {
-
-}
-}
-Throwable cause = throwable.get();
-if (cause.getCause() != null) {
-cause = cause.getCause();
-}
-if (cause instanceof HgStoreClientException) {
-throw (HgStoreClientException) cause;
-}
-throw HgStoreClientException.of(cause);
-}
+this.commitSessions(this.sessions.values());
Review Comment:
Done in 35e0a6d — `allSuccess`, the unreachable throw and the unused `msg`
constant are gone (the `doAction()` return value was never wired into that gate
before either, so nothing changes behaviourally).
##
hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/client/NodeTxExecutor.java:
##
@@ -373,35 +398,70 @@ boolean ifAnyTrue(Supplier>> nodeStreamSuppl
}
Optional retryingInvoke(Supplier supplier) {
+boolean[] deadlineRetried = {false};
return IntStream.rangeClosed(0, NODE_MAX_RETRYING_TIMES).boxed()
.map(
i -> {
+if
(Thread.currentThread().isInterrupted()) {
+// The caller (e.g. a REST worker
hitting
+// restserver.request_timeout) gave
up: stop
+// retrying instead of holding its
thread.
+// InterruptedException as the root
cause: the
+// server's task cancel path
recognises it
+// (HugeException.isInterrupted()).
+throw HgStoreClientException.of(
+"Interrupted before retry " +
i,
+new InterruptedException());
+}
T buffer = null;
try {
buffer = supplier.get();
} catch (Throwable t) {
-if (i + 1 <= NODE_MAX_RETRYING_TIMES) {
-try {
-int sleepTime;
-// The first three times try
once every second
-if (i < 3) {
-sleepTime = 1;
-} else {
-// Subsequent incremental
-sleepTime = i - 1;
-}
-log.info("Waiting {} seconds "
+
- "for the next try.",
- sleepTime);
-Thread.sleep(sleepTime *
1000L);
-} catch (InterruptedException e) {
-log.error("Failed to sleep",
e);
+Failure failure = classify(t);
+if (failure == Failure.FATAL) {
+// The caller's thread was
interrupted or the
+// call was cancelled: fail fast.
+
Re: [PR] fix(store-client): stop retrying after DEADLINE_EXCEEDED and honour thread interrupts in NodeTxExecutor [hugegraph]
bitflicker64 commented on code in PR #3204:
URL: https://github.com/apache/hugegraph/pull/3204#discussion_r3995474168
##
hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/client/NodeTxExecutor.java:
##
@@ -373,35 +398,70 @@ boolean ifAnyTrue(Supplier>> nodeStreamSuppl
}
Optional retryingInvoke(Supplier supplier) {
+boolean[] deadlineRetried = {false};
return IntStream.rangeClosed(0, NODE_MAX_RETRYING_TIMES).boxed()
.map(
i -> {
+if
(Thread.currentThread().isInterrupted()) {
+// The caller (e.g. a REST worker
hitting
+// restserver.request_timeout) gave
up: stop
+// retrying instead of holding its
thread.
+// InterruptedException as the root
cause: the
+// server's task cancel path
recognises it
+// (HugeException.isInterrupted()).
+throw HgStoreClientException.of(
+"Interrupted before retry " +
i,
+new InterruptedException());
+}
T buffer = null;
try {
buffer = supplier.get();
} catch (Throwable t) {
-if (i + 1 <= NODE_MAX_RETRYING_TIMES) {
-try {
-int sleepTime;
-// The first three times try
once every second
-if (i < 3) {
-sleepTime = 1;
-} else {
-// Subsequent incremental
-sleepTime = i - 1;
-}
-log.info("Waiting {} seconds "
+
- "for the next try.",
- sleepTime);
-Thread.sleep(sleepTime *
1000L);
-} catch (InterruptedException e) {
-log.error("Failed to sleep",
e);
+Failure failure = classify(t);
+if (failure == Failure.FATAL) {
+// The caller's thread was
interrupted or the
+// call was cancelled: fail fast.
+log.warn("Not retrying after: {}",
+ t.getMessage(), t);
+throw HgStoreClientException.of(
+t.getMessage(), t);
+}
+if (failure == Failure.DEADLINE) {
+// One retry: the NOT_WORK notice
sent for the
+// failed RPC reloads the
partition leaders, so
+// the next attempt can reach a
new leader. A
+// second deadline in a row would
only wait the
+// full deadline again on the same
stalled store.
+if (deadlineRetried[0]) {
+log.warn("Not retrying a
second deadline: {}",
+ t.getMessage(), t);
+throw
HgStoreClientException.of(
+t.getMessage(), t);
}
-} else {
+deadlineRetried[0] = true;
+log.warn("Deadline exceeded,
retrying once in " +
Review Comment:
⚠️ The PR description still describes the pre-`b588aa88` behaviour, so the
numbers reviewers and the squash commit message will carry are wrong for this
head.
Evidence:
- The body says "Do not retry a failure whose cause chain carries
`Status.Code.DEADLINE_EXCEEDED` …
Re: [PR] fix(store-client): stop retrying after DEADLINE_EXCEEDED and honour thread interrupts in NodeTxExecutor [hugegraph]
bitflicker64 commented on code in PR #3204:
URL: https://github.com/apache/hugegraph/pull/3204#discussion_r3987157390
##
hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/client/NodeTxExecutor.java:
##
@@ -411,6 +448,40 @@ Optional retryingInvoke(Supplier supplier) {
}
+/**
+ * Retry only failures that a fresh attempt can plausibly fix (a transport
error, a
+ * leader change). A DEADLINE_EXCEEDED would wait the full deadline again,
a CANCELLED
+ * means the caller's thread was interrupted; neither is retried, also
when it is one of
+ * several failures of a parallel commit.
+ */
+static boolean isRetryable(Throwable t) {
+return isRetryable(t, Collections.newSetFromMap(new
IdentityHashMap<>()));
+}
+
+private static boolean isRetryable(Throwable t, Set seen) {
+Throwable c = t;
+while (c != null && seen.add(c)) {
+if (c instanceof InterruptedException) {
+return false;
+}
+if (c instanceof StatusRuntimeException) {
+Status.Code code = ((StatusRuntimeException)
c).getStatus().getCode();
+if (code == Status.Code.DEADLINE_EXCEEDED || code ==
Status.Code.CANCELLED) {
Review Comment:
⚠️ Not retrying `DEADLINE_EXCEEDED` also drops a leader-failover recovery.
The Javadoc's reasoning (a retry waits the full deadline again) holds when the
retry goes to the same store, which is not the case once the partition leader
has moved. This corrects my earlier summary, which only looked at node eviction.
Evidence:
- Every RPC error sends a `NOT_WORK` notice
(`NotifyingExecutor.java:117-123`, `:244-255`).
`HgStoreNodePartitionerImpl.notice()` then calls
`pdClient.invalidPartitionCache()` (`HgStoreNodePartitionerImpl.java:190-195`),
which reloads shard-group leaders from PD right away
(`ClientCache.java:220-230`, `:178-186`).
- The retried `doCommit()` supplier re-runs `doAction()` for every entry
(`NodeTxExecutor.java:132-135`), so it routes against the reloaded leaders
(`NodeTxSessionProxy.java:731-734`, `:862-866`).
- A new raft leader is elected after the 3 s election timeout
(`HgStoreEngineOptions.java:91`) and pushes its shard group to PD
(`PartitionEngine.java:605-681`), well inside the 100 s default
`grpc.timeout.seconds` (`HgStoreClientConfig.java:30`).
So with replicated partitions, attempt 1 used to reach the new leader; now
the call fails after attempt 0. Interrupted REST workers still stop after one
deadline either way, but callers with no timeout that interrupts them (async
jobs are only interrupted on cancel) lose the recovery. Was the SIGSTOP cluster
at the shipped `default-shard-count: 1`
(`hugegraph-pd/hg-pd-dist/src/assembly/static/conf/application.yml:95`)? With 3
replicas the before run should have recovered on attempt 1.
Requested change: allow at most one `DEADLINE_EXCEEDED` retry per
`retryingInvoke()` call (keep `CANCELLED` and `InterruptedException`
non-retryable), update the Javadoc to match, and make
`testDeadlineExceededIsNotRetried` expect two attempts.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
Re: [PR] fix(store-client): stop retrying after DEADLINE_EXCEEDED and honour thread interrupts in NodeTxExecutor [hugegraph]
SebastianGruza commented on code in PR #3204:
URL: https://github.com/apache/hugegraph/pull/3204#discussion_r3991513090
##
hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/client/NodeTxExecutor.java:
##
@@ -373,35 +398,65 @@ boolean ifAnyTrue(Supplier>> nodeStreamSuppl
}
Optional retryingInvoke(Supplier supplier) {
+boolean[] deadlineRetried = {false};
return IntStream.rangeClosed(0, NODE_MAX_RETRYING_TIMES).boxed()
.map(
i -> {
+if
(Thread.currentThread().isInterrupted()) {
+// The caller (e.g. a REST worker
hitting
+// restserver.request_timeout) gave
up: stop
+// retrying instead of holding its
thread.
+throw HgStoreClientException.of(
Review Comment:
Done in 172b2d0 — both exits now have an `InterruptedException` as the root
cause (`HgStoreClientException.of("Interrupted before retry " + i, new
InterruptedException())`; in the sleep handler the `InterruptedException` is
the cause and the store failure `t` is attached to it as suppressed).
`testInterruptStopsRetrying` and `testInterruptBeforeCallSkipsTheAttempt`
assert the root cause, the first one also the suppressed store failure. 10/10
locally.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
Re: [PR] fix(store-client): stop retrying after DEADLINE_EXCEEDED and honour thread interrupts in NodeTxExecutor [hugegraph]
bitflicker64 commented on code in PR #3204:
URL: https://github.com/apache/hugegraph/pull/3204#discussion_r3990841696
##
hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/client/NodeTxExecutor.java:
##
@@ -373,35 +398,65 @@ boolean ifAnyTrue(Supplier>> nodeStreamSuppl
}
Optional retryingInvoke(Supplier supplier) {
+boolean[] deadlineRetried = {false};
return IntStream.rangeClosed(0, NODE_MAX_RETRYING_TIMES).boxed()
.map(
i -> {
+if
(Thread.currentThread().isInterrupted()) {
+// The caller (e.g. a REST worker
hitting
+// restserver.request_timeout) gave
up: stop
+// retrying instead of holding its
thread.
+throw HgStoreClientException.of(
Review Comment:
🧹 Two of the new interrupt exits drop the `InterruptedException`, so the
server cannot tell them apart from a store failure.
Evidence:
- `:409-410` throws `HgStoreClientException.of("Interrupted before retry " +
i)` with no cause. `:456-458` uses the store failure `t` as the cause and
discards `e`. Neither has an `InterruptedException` as its root cause.
- The FATAL path keeps one. A blocking stub on an interrupted thread fails
with `CANCELLED`, and the `InterruptedException` is its cause: grpc-stub 1.39.0
`ClientCalls.blockingUnaryCall` calls `call.cancel("Thread interrupted", e)`.
- `HugeException.isInterrupted()` only checks the root cause
(`HugeException.java:56-61`). `HugeTask.fail()` relies on it so that a
cancelled task is not recorded as failed (`HugeTask.java:351-355`). Take a task
that is cancelled while its thread is between store calls or in the retry
sleep. It now logs a WARN with a stack trace. If the worker reaches `fail()`
before `cancel()` sets CANCELLED (`:323` interrupts, `:336` sets the status),
the task is stored as FAILED and `cancel()` returns false, so
`DistributedTaskScheduler.cancel()` does not save CANCELLED (`:317-321`).
Before this change the loop swallowed the interrupt and carried on, so this
path did not exist.
Requested change: make `InterruptedException` the root cause on both exits.
For example, use `HgStoreClientException.of("Interrupted before retry " + i,
new InterruptedException())`. In the sleep handler, use
`HgStoreClientException.of("Interrupted while waiting to retry: " +
t.getMessage(), e)` and attach `t` with `addSuppressed`. Then extend
`testInterruptStopsRetrying` and `testInterruptBeforeCallSkipsTheAttempt` to
assert the root cause.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
Re: [PR] fix(store-client): stop retrying after DEADLINE_EXCEEDED and honour thread interrupts in NodeTxExecutor [hugegraph]
SebastianGruza commented on code in PR #3204:
URL: https://github.com/apache/hugegraph/pull/3204#discussion_r3988128307
##
hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/client/NodeTxExecutor.java:
##
@@ -411,6 +448,40 @@ Optional retryingInvoke(Supplier supplier) {
}
+/**
+ * Retry only failures that a fresh attempt can plausibly fix (a transport
error, a
+ * leader change). A DEADLINE_EXCEEDED would wait the full deadline again,
a CANCELLED
+ * means the caller's thread was interrupted; neither is retried, also
when it is one of
+ * several failures of a parallel commit.
+ */
+static boolean isRetryable(Throwable t) {
+return isRetryable(t, Collections.newSetFromMap(new
IdentityHashMap<>()));
+}
+
+private static boolean isRetryable(Throwable t, Set seen) {
+Throwable c = t;
+while (c != null && seen.add(c)) {
+if (c instanceof InterruptedException) {
+return false;
+}
+if (c instanceof StatusRuntimeException) {
+Status.Code code = ((StatusRuntimeException)
c).getStatus().getCode();
+if (code == Status.Code.DEADLINE_EXCEEDED || code ==
Status.Code.CANCELLED) {
Review Comment:
Agreed, and yes — the SIGSTOP cluster runs with the shipped
`default-shard-count: 1`, so it never had a leader to fail over to; with
replicas the first retry would indeed have reached the new leader. Done in
b588aa8: `retryingInvoke()` now classifies a failure as FATAL (interrupt,
`CANCELLED`: never retried), DEADLINE (retried exactly once per call, then
failed on a second deadline in a row) or RETRYABLE (unchanged); suppressed
failures of a parallel commit are classified as well and the most severe class
wins. Javadoc updated. Tests: `testDeadlineExceededIsRetriedExactlyOnce`
expects two attempts, `testDeadlineThenNewLeaderSucceeds` covers the failover
case, the mixed-commit test now expects two attempts, `testClassifyFailures`
replaces the old `isRetryable` test. 10/10 locally on JDK 17.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
Re: [PR] fix(store-client): stop retrying after DEADLINE_EXCEEDED and honour thread interrupts in NodeTxExecutor [hugegraph]
SebastianGruza commented on code in PR #3204:
URL: https://github.com/apache/hugegraph/pull/3204#discussion_r3984259105
##
hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/client/NodeTxExecutor.java:
##
@@ -376,32 +378,44 @@ Optional retryingInvoke(Supplier supplier) {
return IntStream.rangeClosed(0, NODE_MAX_RETRYING_TIMES).boxed()
.map(
i -> {
+if
(Thread.currentThread().isInterrupted()) {
+// The caller (e.g. a REST worker
hitting
+// restserver.request_timeout) gave
up: stop
+// retrying instead of holding its
thread.
+throw HgStoreClientException.of(
+"Interrupted before retry " +
i);
+}
T buffer = null;
try {
buffer = supplier.get();
} catch (Throwable t) {
-if (i + 1 <= NODE_MAX_RETRYING_TIMES) {
-try {
-int sleepTime;
-// The first three times try
once every second
-if (i < 3) {
-sleepTime = 1;
-} else {
-// Subsequent incremental
-sleepTime = i - 1;
-}
-log.info("Waiting {} seconds "
+
- "for the next try.",
- sleepTime);
-Thread.sleep(sleepTime *
1000L);
-} catch (InterruptedException e) {
-log.error("Failed to sleep",
e);
-}
-} else {
+if (i + 1 > NODE_MAX_RETRYING_TIMES) {
log.error(maxTryMsg, t);
throw HgStoreClientException.of(
t.getMessage(), t);
}
+if (!isRetryable(t)) {
Review Comment:
Done in 8adf522. `commitSessions()` now collects every session failure in a
`ConcurrentLinkedQueue` and throws one `HgStoreClientException` (first failure
unwrapped one level as before, the others attached as suppressed);
`isRetryable()` walks the suppressed failures as well as the cause chain
(identity-set guarded against cycles), so one `DEADLINE_EXCEEDED` among several
failures makes the attempt non-retryable regardless of which partition reported
first. Tests: `testMixedCommitFailuresAreNotRetried` (two sessions,
`UNAVAILABLE` + `DEADLINE_EXCEEDED` thrown fresh on every call, exactly one
attempt, both sessions rolled back, one suppressed) and
`testAllRetryableCommitFailuresAreRetried`.
##
hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/client/NodeTxExecutor.java:
##
@@ -376,32 +378,44 @@ Optional retryingInvoke(Supplier supplier) {
return IntStream.rangeClosed(0, NODE_MAX_RETRYING_TIMES).boxed()
.map(
i -> {
+if
(Thread.currentThread().isInterrupted()) {
+// The caller (e.g. a REST worker
hitting
+// restserver.request_timeout) gave
up: stop
+// retrying instead of holding its
thread.
+throw HgStoreClientException.of(
+"Interrupted before retry " +
i);
+}
T buffer = null;
try {
buffer = supplier.get();
} catch (Throwable t) {
-if (i + 1 <= NODE_MAX_RETRYING_TIMES) {
-try {
-int sleepTime;
-// The first three times try
once
Re: [PR] fix(store-client): stop retrying after DEADLINE_EXCEEDED and honour thread interrupts in NodeTxExecutor [hugegraph]
bitflicker64 commented on code in PR #3204:
URL: https://github.com/apache/hugegraph/pull/3204#discussion_r3982450791
##
hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/client/NodeTxExecutor.java:
##
@@ -376,32 +378,44 @@ Optional retryingInvoke(Supplier supplier) {
return IntStream.rangeClosed(0, NODE_MAX_RETRYING_TIMES).boxed()
.map(
i -> {
+if
(Thread.currentThread().isInterrupted()) {
+// The caller (e.g. a REST worker
hitting
+// restserver.request_timeout) gave
up: stop
+// retrying instead of holding its
thread.
+throw HgStoreClientException.of(
+"Interrupted before retry " +
i);
+}
T buffer = null;
try {
buffer = supplier.get();
} catch (Throwable t) {
-if (i + 1 <= NODE_MAX_RETRYING_TIMES) {
-try {
-int sleepTime;
-// The first three times try
once every second
-if (i < 3) {
-sleepTime = 1;
-} else {
-// Subsequent incremental
-sleepTime = i - 1;
-}
-log.info("Waiting {} seconds "
+
- "for the next try.",
- sleepTime);
-Thread.sleep(sleepTime *
1000L);
-} catch (InterruptedException e) {
-log.error("Failed to sleep",
e);
-}
-} else {
+if (i + 1 > NODE_MAX_RETRYING_TIMES) {
log.error(maxTryMsg, t);
throw HgStoreClientException.of(
t.getMessage(), t);
}
+if (!isRetryable(t)) {
+// A deadline or a cancellation
will not
+// get better by waiting the full
deadline
+// again; fail fast and let the
caller decide.
+log.warn("Not retrying after: {}",
Review Comment:
🧹 This log drops the throwable, on what this change makes the *common*
failure path.
Evidence:
- `log.warn("Not retrying after: {}", t.getMessage())` passes only the
message, so nothing reaches the logger's throwable slot.
- The branch four lines up keeps it: `log.error(maxTryMsg, t)` (`:393`).
Before this PR that was the only place a store failure was logged with its
cause chain; after it, a stalled node takes this branch on the first attempt
and never reaches `:393`, so the nested `StatusRuntimeException` and its stack
trace are no longer in the server log at all.
Requested change: `log.warn("Not retrying after: {}", t.getMessage(), t);` —
slf4j appends a trailing `Throwable` argument as the cause.
##
hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/client/NodeTxExecutor.java:
##
@@ -376,32 +378,44 @@ Optional retryingInvoke(Supplier supplier) {
return IntStream.rangeClosed(0, NODE_MAX_RETRYING_TIMES).boxed()
.map(
i -> {
+if
(Thread.currentThread().isInterrupted()) {
+// The caller (e.g. a REST worker
hitting
+// restserver.request_timeout) gave
up: stop
+// retrying instead of holding its
thread.
+throw HgStoreClientException.of(
+"Interrupted before retry " +
i);
+}
T buffer = null;
try {
