feat: aborted-transaction retry policy and client integration#18
Open
mlwelles wants to merge 1 commit into
Open
feat: aborted-transaction retry policy and client integration#18mlwelles wants to merge 1 commit into
mlwelles wants to merge 1 commit into
Conversation
21760f3 to
67c0b31
Compare
There was a problem hiding this comment.
2 issues found across 2 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="retry.go">
<violation number="1" location="retry.go:46">
P2: MaxDelay cap is applied before jitter, so actual backoff can exceed the configured maximum. The `MaxDelay` field is documented as capping the backoff so "No single delay exceeds this," but the `delay()` method applies the cap before adding positive jitter, allowing the final delay to exceed `MaxDelay`.</violation>
<violation number="2" location="retry.go:77">
P2: Negative `MaxRetries` can skip the loop entirely and trigger the panic path.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
|
|
||
| // delay computes the backoff duration for a given attempt (0-indexed). | ||
| // Formula: min(BaseDelay * 2^attempt, MaxDelay) + random(0, delay * Jitter) | ||
| func (p RetryPolicy) delay(attempt int) time.Duration { |
There was a problem hiding this comment.
P2: MaxDelay cap is applied before jitter, so actual backoff can exceed the configured maximum. The MaxDelay field is documented as capping the backoff so "No single delay exceeds this," but the delay() method applies the cap before adding positive jitter, allowing the final delay to exceed MaxDelay.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At retry.go, line 46:
<comment>MaxDelay cap is applied before jitter, so actual backoff can exceed the configured maximum. The `MaxDelay` field is documented as capping the backoff so "No single delay exceeds this," but the `delay()` method applies the cap before adding positive jitter, allowing the final delay to exceed `MaxDelay`.</comment>
<file context>
@@ -0,0 +1,96 @@
+
+// delay computes the backoff duration for a given attempt (0-indexed).
+// Formula: min(BaseDelay * 2^attempt, MaxDelay) + random(0, delay * Jitter)
+func (p RetryPolicy) delay(attempt int) time.Duration {
+ d := p.BaseDelay * time.Duration(1<<uint(attempt))
+ if d > p.MaxDelay {
</file context>
| // return client.Insert(ctx, &entity) | ||
| // }) | ||
| func (c client) WithRetry(ctx context.Context, policy RetryPolicy, fn func() error) error { | ||
| for attempt := range policy.MaxRetries + 1 { |
There was a problem hiding this comment.
P2: Negative MaxRetries can skip the loop entirely and trigger the panic path.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At retry.go, line 77:
<comment>Negative `MaxRetries` can skip the loop entirely and trigger the panic path.</comment>
<file context>
@@ -0,0 +1,96 @@
+// return client.Insert(ctx, &entity)
+// })
+func (c client) WithRetry(ctx context.Context, policy RetryPolicy, fn func() error) error {
+ for attempt := range policy.MaxRetries + 1 {
+ err := fn()
+ if err == nil {
</file context>
Add RetryPolicy / DefaultRetryPolicy and a runner that re-executes a function on aborted Dgraph transactions with exponential backoff (retry.go), exposed on the client via a WithRetry method.
67c0b31 to
b477c28
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.
Adds a retry layer for aborted Dgraph transactions:
RetryPolicy/DefaultRetryPolicyand a runner with exponential backoff (retry.go).Client.WithRetry(ctx, policy, fn)method.Self-contained:
retry.go+ theWithRetryinterface method onClient; builds and tests green. The bulk-loader PR (#19) stacks on this.Part of a series upstreaming work from a downstream fork; opened for review/discussion.