Skip to content

feat(cache): stamp S3 content ETag onto disk copy at write time#326

Open
worstell wants to merge 1 commit into
worstell/pinned-range-servingfrom
worstell/snapshot-disk-pin-stamp
Open

feat(cache): stamp S3 content ETag onto disk copy at write time#326
worstell wants to merge 1 commit into
worstell/pinned-range-servingfrom
worstell/snapshot-disk-pin-stamp

Conversation

@worstell

Copy link
Copy Markdown
Contributor

Stacks on #324.

A tiered Create feeds the same byte stream to disk and S3, but only an S3-backed Open backfill persisted the content ETag onto the disk copy. So freshly generated disk entries weren't pinnable, and pinned ranges proxied through S3 until a backfill happened to run — defeating disk-first range serving for hot repos.

This captures S3's ETag from PutObject and stamps it onto the disk copy when the tiered writer closes. Both tiers were written from the same bytes, so the ETag is valid for the disk copy and it serves pinned ranges immediately. Stamping is best effort: a failure only falls pinned reads back to S3, and a disk ETag that doesn't match the authoritative S3 pin simply misses to S3.

A tiered Create writes the same byte stream to disk and S3, but only an
S3-backed Open backfill persisted the content ETag, so freshly generated
disk entries weren't pinnable and pinned ranges proxied through S3 until a
backfill ran. Capture S3's ETag from PutObject and stamp it onto the disk
copy on Close, so the disk tier serves pinned ranges immediately. Best
effort: a stamp failure only falls pinned reads back to S3.
@worstell worstell marked this pull request as ready for review June 18, 2026 00:51
@worstell worstell requested a review from a team as a code owner June 18, 2026 00:51
@worstell worstell requested review from alecthomas and removed request for a team June 18, 2026 00:51

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 275cdcd5cb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/cache/disk.go
w.headers = http.Header{}
}
w.headers.Set(ContentETagHeader, etag)
return errors.WithStack(w.disk.db.set(w.key, w.namespace, w.expiresAt, w.headers))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Guard ETag stamps against replaced disk entries

When two tiered Creates for the same key close concurrently, the first disk writer can commit its file, wait for its S3 upload, and then run this stamp after a later writer has already renamed a different file over w.path. Because this only checks that some file exists before rewriting metadata with this writer's S3 ETag, it can attach an old pin to newer disk bytes; a client holding the old pin would then be served the wrong range from disk instead of falling through to S3 and getting ErrPinStale. The stamp needs a generation/same-file check, or it must happen while the disk commit is still known to be the current entry.

Useful? React with 👍 / 👎.

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.

1 participant