Skip to content

MLE-27388 Refactor: Cutting down on duplicated retry code#1914

Merged
rjrudin merged 1 commit intodevelopfrom
feature/27388-retry
Mar 3, 2026
Merged

MLE-27388 Refactor: Cutting down on duplicated retry code#1914
rjrudin merged 1 commit intodevelopfrom
feature/27388-retry

Conversation

@rjrudin
Copy link
Contributor

@rjrudin rjrudin commented Mar 2, 2026

Had Copilot add a RetryContext to get rid of a bunch of duplication (in 9 places) so that debug logging can then be added.

Not merging this yet, just want to see the tests run first.

@github-actions
Copy link

github-actions bot commented Mar 2, 2026

Copyright Validation Results
Total: 2 | Passed: 2 | Failed: 0 | Skipped: 0 | at: 2026-03-03 15:21:29 UTC | commit: e8642cb

✅ Valid Files

  • marklogic-client-api/src/main/java/com/marklogic/client/impl/OkHttpServices.java
  • marklogic-client-api/src/main/java/com/marklogic/client/impl/RetryContext.java

✅ All files have valid copyright headers!

@rjrudin
Copy link
Contributor Author

rjrudin commented Mar 3, 2026

Closing, just wanted to see the tests pass.

Added RetryContext and tossed in some debug logging, but that may change a bit in the next PR. This gets rid of 9 occurrences of the same code and also means that logging for the retry-50x can be done in a single place now.
@rjrudin rjrudin force-pushed the feature/27388-retry branch from 603153e to e8642cb Compare March 3, 2026 14:04
@rjrudin rjrudin changed the title MLE-27388 Draft: Refactored the retry-on-50x logic MLE-27388 Refactor: Cutting down on duplicated retry code Mar 3, 2026
@rjrudin rjrudin marked this pull request as ready for review March 3, 2026 15:21
Copilot AI review requested due to automatic review settings March 3, 2026 15:21
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a small retry helper to reduce duplicated retry-loop code in OkHttpServices, with the goal of centralizing retry state (attempt count, elapsed time, and delay calculation) so it’s easier to add consistent debug logging later.

Changes:

  • Added a new RetryContext helper to track retry attempt count, elapsed time, and next sleep delay.
  • Refactored multiple retry loops in OkHttpServices to use RetryContext instead of local startTime/nextDelay/retry variables.
  • Centralized the “max retries exceeded” exception construction (and checkFirstRequest callback) into RetryContext.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
marklogic-client-api/src/main/java/com/marklogic/client/impl/RetryContext.java New helper class encapsulating retry loop state, sleep, delay computation, and max-retry failure throwing.
marklogic-client-api/src/main/java/com/marklogic/client/impl/OkHttpServices.java Replaces repeated retry-loop state variables with RetryContext across multiple HTTP operation implementations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +56 to +60
void throwIfMaxRetriesExceeded(int status) {
if (retryableStatusCodes.contains(status)) {
if (onMaxRetriesCallback != null) {
onMaxRetriesCallback.run();
}
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throwIfMaxRetriesExceeded is named as if it always throws, but it silently no-ops when status is not in retryableStatusCodes. This makes the method easy to misuse in the future (callers may assume it always throws). Consider either removing the internal status check (and always throwing) or renaming the method to reflect the conditional behavior (and/or returning a boolean indicating whether it threw).

Copilot uses AI. Check for mistakes.
try {
retryContext.sleepIfNeeded();
} catch (InterruptedException e) {
// Ignore interruption
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catching InterruptedException and ignoring it clears the thread's interrupted status, which can make it harder for callers/executors to stop work promptly. Consider restoring the interrupt flag via Thread.currentThread().interrupt() (and ideally exiting the retry loop) so interruption can be honored.

Suggested change
// Ignore interruption
Thread.currentThread().interrupt();
break;

Copilot uses AI. Check for mistakes.
@rjrudin rjrudin merged commit aaa7c20 into develop Mar 3, 2026
11 checks passed
@rjrudin rjrudin deleted the feature/27388-retry branch March 3, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants