Introduce the RetryPolicy abstraction#2
Draft
stIncMale wants to merge 5 commits into
Draft
Conversation
1483625 to
4a1aa2b
Compare
759cbbf to
d62866c
Compare
f1cf803 to
8cacb8c
Compare
JAVA-6229
8cacb8c to
48ee5ca
Compare
JAVA-6229
JAVA-6229
JAVA-6229
48ee5ca to
69ad9b4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR existed for demonstration purposes. The actual PR is mongodb#2004.
Notable changes:
LoopState->LoopControl.RetryState->RetryControl.onAttemptFailureOperatorandretryPredicateinRetryState->RetryControlwere replaced byRetryPolicy.onAttemptFailure.retryPredicateis now called on every failed attempt, unlike previously, where onlyonAttemptFailureOperatorwas called on every failed attempt. As a result, we no longer need to callCommandOperationHelper.addRetryableLabelOrGetWriteAttemptFailureNotToBeRetried->SpecRetryPolicy.decideRetryableAndAddRetryableWriteErrorLabelIfNeededexplicitly inMixedBulkWriteOperation/ClientBulkWriteOperation, or useAsyncOperationHelper.addingRetryableLabelCallback/CommandOperationHelper.addRetryableWriteErrorLabelinAsyncOperationHelper.executeRetryableWriteAsync/SyncOperationHelper.executeRetryableWrite.RetryingAsyncCallbackSupplier,RetryingSyncSupplierno longer passErrors toadvanceOrThrow.RetryingSyncSupplierpassesExceptions toadvanceOrThrowas is, without wrapping them inRuntimeException. Wrapping is done byRetryState->RetryControl, and only if that checkedExceptionhas to be thrown.AttachmentKeyand the related methods and implementations were deleted. Instead,SpecRetryPolicynow exposes methods with more specific semantics and more specific assertions guarding their usage.AttachmentKeyscommandDescriptionSupplier->SpecRetryPolicy.onCommandinstead ofretryableWriteCommandFlag&maxWireVersion->SpecRetryPolicy.onWriteRetryRequirementscommand-> was not needed at all, and was replaced with a localMutableValue<BsonDocument>variable.SpecRetryPolicyimplements both read and write retry logic, the methodsAsyncOperationHelper.decorateReadWithRetriesAsync/decorateWriteWithRetriesAsyncandSyncOperationHelper.decorateReadWithRetries/decorateWriteWithRetrieswere replaced with a single methodAsyncOperationHelper.decorateWithRetriesAsyncandSyncOperationHelper.decorateWithRetriesrespectively.RetryState->RetryControl.doWhileDisabled/doWhileDisabledAsyncwas introduced to replace the brokenClientBulkWriteOperation.doWithRetriesDisabled/doWithRetriesDisabledAsync.AsyncOperationhelper.executeRetryableWriteAsyncwas rewritten with thebeginAsyncAPI. Now it is an even more straightforward translation ofSyncOperationHelper.executeRetryableWrite.RetryState->RetryControl.breakAndCompleteIfRetryAnd, and use only thebreakAndThrowIfRetryAndmethod in both sync and async code.RetryState->RetryControl.breakAndThrowIfRetryAndis now used only to break from a retry attempt based on the information that could not have been available before the attempt start. The only such information is the information about the server selected, which is checked by theOperationHelper.canRetryWrite->isServerWriteRetryRequirementsMetmethod.RetryState->RetryControl.breakAndThrowIfRetryAndis now used only by writes.BulkWriteBatchgetRetryWrites->isWriteRetryRequirementsMetisRetryable->isCommandWriteRetryRequirementsMetOperationHelperisRetryableWrite->isNonCommandWriteRetryRequirementsMetcanRetryWrite->isServerWriteRetryRequirementsMetCommandOperationHelperonRetryableReadAttemptFailure-> became part ofSpecRetryPolicy.onAttemptFailurechooseRetryableReadException->SpecRetryPolicy.decideReadProspectiveFailedResultonRetryableWriteAttemptFailure-> became part ofSpecRetryPolicy.onAttemptFailurechooseRetryableWriteException->SpecRetryPolicy.decideWriteProspectiveFailedResultinitialRetryState->createSpecRetryControlloggingShouldAttemptToRetryRead-> became part ofSpecRetryPolicy.onAttemptFailure,isRetryableReadError.loggingShouldAttemptToRetryWriteAndAddRetryableLabel-> became part ofSpecRetryPolicy.onAttemptFailureaddRetryableLabelOrGetWriteAttemptFailureNotToBeRetried->SpecRetryPolicy.decideRetryableAndAddRetryableWriteErrorLabelIfNeededisRetryableWriteCommand->isWriteRetryRequirementsMetdecideRetryableAndAddRetryableWriteErrorLabel-> became part ofSpecRetryPolicy.decideRetryableAndAddRetryableWriteErrorLabelIfNeededaddRetryableWriteErrorLabel->addRetryableWriteErrorLabelIfNeededlogRetryCommand->SpecRetryPolicy.onAttemptStartlogUnableToRetryCommand->SpecRetryPolicy.logUnableToRetryError(also,SpecRetryPolicy.logUnableToRetryMaxAttemptsReachedwas added)JAVA-6229