-
Notifications
You must be signed in to change notification settings - Fork 374
Confirm a restore with the server once its blob is verified #4323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
87bd2d3
Confirm a restore with the server once its blob is verified- #4323
ss1909 9591c6c
Bound confirmRestoreSucceeded's retry loop, fix TotalDuration ordering
ss1909 26b572c
Merge branch 'main' into a-1775-refresh-expiry-after-blob-verified
ss1909 b6c388e
Merge branch 'main' into a-1775-refresh-expiry-after-blob-verified
ss1909 2620314
Add regression tests for best-effort confirm behaviour
ss1909 94bb086
Merge branch 'main' into a-1775-refresh-expiry-after-blob-verified
ss1909 be234e3
Merge branch 'main' into a-1775-refresh-expiry-after-blob-verified
ss1909 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -330,12 +330,18 @@ func (c *client) Restore(ctx context.Context, cacheID string) (RestoreResult, er | |
| } | ||
|
|
||
| result.CacheRestored = true | ||
|
|
||
| // The restore is now fully verified (downloaded, digest-checked, and | ||
| // extracted) — confirm it with the server so retention refreshes off a | ||
| // restore that's actually known to be good. | ||
| confirmed := c.confirmRestoreSucceeded(ctx, retrieveResp) | ||
| result.TotalDuration = time.Since(startTime) | ||
|
|
||
| // Add result attributes to span | ||
| span.SetAttributes( | ||
| attribute.Bool("cache.hit", result.CacheHit), | ||
| attribute.Bool("cache.restored", result.CacheRestored), | ||
| attribute.Bool("cache.confirmed", confirmed), | ||
| attribute.Int64("cache.archive_size_bytes", result.Archive.Size), | ||
| attribute.Int64("cache.written_bytes", result.Archive.WrittenBytes), | ||
| attribute.Int64("cache.written_entries", result.Archive.WrittenEntries), | ||
|
|
@@ -390,6 +396,66 @@ func (c *client) invalidateStaleEntry(ctx context.Context, retrieveResp api.Cach | |
| return existed | ||
| } | ||
|
|
||
| // confirmRestoreTimeout bounds the entire confirmRestoreSucceeded retry loop. | ||
| // Confirmation is best-effort and non-essential to a successful restore, so it | ||
| // must not be allowed to hold up job startup for anywhere near the API | ||
| // client's per-attempt timeout multiplied by roko's max attempts. | ||
| const confirmRestoreTimeout = 5 * time.Second | ||
|
|
||
| // confirmRestoreSucceeded tells the server this restore's blob was verified, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please shorten some of these code comments? This one for example could just be: |
||
| // so the registry can safely refresh the entry's retention now rather than | ||
| // when retrieve first served it, before the blob was known to be good. | ||
| // | ||
| // Skipped for a fallback match — mirrors the backend's own (now-removed) | ||
| // `unless entry_result.fallback_used?` bump guard: a fallback hit means the | ||
| // entry was saved under a shorter key sequence, and refreshing it would | ||
| // reset the clock on an entry the caller didn't explicitly target. | ||
| // | ||
| // Best-effort: never fails the build. The whole retry loop is bounded by | ||
| // confirmRestoreTimeout, not just each individual attempt — retrieve's exact-match | ||
| // success path (unlike the failure path invalidateStaleEntry handles) runs on | ||
| // every cache hit, so a network partition here must not be able to stall an | ||
| // otherwise-successful, latency-sensitive restore by using up 5 full client | ||
| // timeouts. | ||
| func (c *client) confirmRestoreSucceeded(ctx context.Context, retrieveResp api.CacheEntryRetrieveResp) bool { | ||
| if retrieveResp.Fallback { | ||
| return false | ||
| } | ||
| if len(retrieveResp.TargetPaths) == 0 || len(retrieveResp.CacheKey) == 0 { | ||
| slog.Warn("cannot confirm cache restore: retrieve response missing resolved address") | ||
| return false | ||
| } | ||
|
|
||
| ctx, cancel := context.WithTimeout(ctx, confirmRestoreTimeout) | ||
| defer cancel() | ||
|
|
||
| req := api.CacheEntryConfirmReq{ | ||
| TargetPaths: retrieveResp.TargetPaths, | ||
| CacheKey: retrieveResp.CacheKey, | ||
| Scopes: retrieveResp.Scopes, | ||
| } | ||
| err := roko.NewRetrier( | ||
| roko.WithMaxAttempts(5), | ||
|
buildsworth-bk-app[bot] marked this conversation as resolved.
|
||
| roko.WithStrategy(roko.ExponentialSubsecond(500*time.Millisecond)), | ||
| roko.WithJitter(), | ||
| ).DoWithContext(ctx, func(r *roko.Retrier) error { | ||
| _, apiResp, err := c.api.CacheEntryConfirm(ctx, c.registry, req) | ||
| if api.BreakOnNonRetryable(r, apiResp, err) { | ||
| return err | ||
| } | ||
| if err != nil { | ||
| slog.Warn("cache restore confirmation failed, retrying", "err", err, "retrier", r.String()) | ||
| return err | ||
| } | ||
| return nil | ||
| }) | ||
| if err != nil { | ||
| slog.Warn("cache restore confirmation failed", "registry", c.registry, "err", err) | ||
| return false | ||
| } | ||
| return true | ||
| } | ||
|
|
||
| // missCompleteMessage builds the progress text for a stale-entry miss, | ||
| // distinguishing an actual deletion from a no-op so callers aren't told an | ||
| // entry was invalidated when it wasn't. | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.