Skip to content

feat: cache SHA384 entries - #298

Merged
niemeyer merged 8 commits into
canonical:mainfrom
upils:cache-bins
Jun 16, 2026
Merged

niemeyer merged 8 commits into
canonical:mainfrom
upils:cache-bins

Conversation

@upils

@upils upils commented May 22, 2026 •

Copy link
Copy Markdown
Collaborator
  • Have you signed the CLA?

The Binstore only publishes SHA3-384 hashes for bins. This PR enables storing entries in the cache using
SHA3-384 hashes, so it can store bins. Consumers of the cache package must now explicitly select the
algorithm to be used to create/write/read an entry.

@upils
upils requested a review from Copilot June 1, 2026 12:56

Copilot AI 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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR extends the internal cache to support multiple hashing algorithms (SHA-256 and SHA3-384) and updates callers/tests to specify which algorithm to use.

Changes:

  • Introduced hashAlgo with SHA-256 and SHA3-384 support, plus hash construction via newHash.
  • Updated cache APIs (Create, Write, Open, Read) to take an algorithm parameter and adjusted archive fetch code accordingly.
  • Added a test verifying SHA3-384 entries are isolated from SHA-256 entries.

Reviewed changes

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

File Description
internal/cache/cache.go Adds multi-algorithm hashing support, updates cache APIs, and expires entries across algorithm directories.
internal/cache/cache_test.go Updates tests to pass the algorithm and adds SHA3-384 isolation coverage.
internal/archive/archive.go Updates cache usage in archive fetch path to specify SHA-256 algorithm.

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

Comment thread internal/cache/cache.go Resolved
Comment thread internal/cache/cache.go Resolved
Comment thread internal/cache/cache.go Resolved
Comment thread internal/cache/cache.go Resolved
Comment thread internal/cache/cache.go Resolved
Signed-off-by: Paul Mars <[email protected]>
@upils upils changed the title feat: cache SHA3-384 entries feat: cache SHA384 entries Jun 15, 2026

@niemeyer niemeyer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Underlying logic is good, thanks. Needs polishing in terms of terminology.

Comment thread internal/cache/cache.go Outdated

const (
SHA256 hashAlgo = "sha256"
SHA384 hashAlgo = "sha384"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Public values/functions/etc with private types is an anti pattern.

Also, this already had a name, right above: digestKind. Note how the entire public API below talks about a "digest", not a "hash". The hash is the internal Go types and values used to construct them locally. The overall PR needs to be fixed to make the terminology clear and less conflicting.

Note that if you want to change everything to be "hash", I'm fine with that too. We just cannot sit in the middle and use both terms with no clear lines. If you do that, please don't use "algo" as there are better terms that are naturally short.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Public values/functions/etc with private types is an anti pattern.

The type is now exported.

Also, this already had a name, right above: digestKind. Note how the entire public API below talks about a "digest", not a "hash". The hash is the internal Go types and values used to construct them locally. The overall PR needs to be fixed to make the terminology clear and less conflicting.

Note that if you want to change everything to be "hash", I'm fine with that too. We just cannot sit in the middle and use both terms with no clear lines. If you do that, please don't use "algo" as there are better terms that are naturally short.

I reworked it to use the existing digestKind term. I wanted to avoid a refactoring of the package in this PR.

Comment thread internal/cache/cache.go Outdated
err := os.MkdirAll(filepath.Join(c.Dir, digestKind), 0755)
h, err := newHash(algo)
if err != nil {
return &Writer{err: fmt.Errorf("internal error: %v", err)}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This function got a call with a piece of data that is coming from a place it has no idea, and then it also got an error that it has no idea about, because it has not inspected it, from a different function. How does it know it's an internal error?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This function was bringing more confusion than anything and was a unnecessary level of indirection. I inlined it. This is now more obvious why this is an internal error.

Comment thread internal/cache/cache.go Outdated
var file *os.File
if digest == "" {
file, err = os.CreateTemp(c.filePath(""), "tmp.*")
file, err = os.CreateTemp(filepath.Join(c.Dir, string(algo)), "tmp.*")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is the pattern from the existing code not working?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good catch. The existing pattern still works. I fixed it.

@niemeyer niemeyer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks nice now, thanks!

@niemeyer
niemeyer merged commit 23fc7e4 into canonical:main Jun 16, 2026
18 checks passed
@ROCKsBot

ROCKsBot commented Jun 16, 2026 •

Copy link
Copy Markdown
Command Mean [s] Min [s] Max [s] Relative
BASE 14.269 ± 0.071 14.179 14.398 1.00
HEAD 14.462 ± 0.102 14.292 14.650 1.01 ± 0.01

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.

4 participants