Skip to content

Conversation

@calebzulawski
Copy link
Contributor

My initial implementation of garbage collection for #18. It seems to work but it could use more testing.

calebzulawski added a commit to CACI-International/cpp-toolchain that referenced this pull request Mar 4, 2025
@calebzulawski
Copy link
Contributor Author

I am seeing some odd errors, like:

Failed to save: Unable to reserve cache with key setup-bazel-1-darwin-disk-MY_CACHE_KEY-e211a56abda1473b71bb15b46a58c96b588692bd155524ecbb2bdb23e5547203, another job may be creating this cache.

I don't actually have conflicting jobs (as far as I can tell), so not sure what's going on.

@calebzulawski calebzulawski force-pushed the feature/disk-cache branch 3 times, most recently from ecb896b to da63002 Compare March 7, 2025 21:53
@calebzulawski
Copy link
Contributor Author

It turns out, according to actions/toolkit#658, you can't actually update an existing key. The only option is creating a new key, so I add a unique identifier to the end, and restore it via a prefix match.

@p0deje
Copy link
Member

p0deje commented Mar 11, 2025

@calebzulawski please ping me for review/testing once you're happy with implementation

@calebzulawski
Copy link
Contributor Author

@p0deje sorry for all the churn, I can clean up the history if you'd like, but I think this is good to go.

A quick summary of changes:

  • Garbage collect disk and repository caches
    • These caches are keyed by the hash of their contents rather than BUILD files etc
    • Contents are sorted by mtime, removing the oldest files until the cache is under the size maximum
    • A future change could also add an age maximum
  • Add cache-prefix argument that affects all caches (this replaces non-bool values for disk-cache, too)


const bazeliskVersion = core.getInput('bazelisk-version')
const cachePrefix = core.getInput('cache-prefix')
const cacheVersion = core.getInput('cache-version')
Copy link
Member

Choose a reason for hiding this comment

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

I suppose we can drop this input and move it to cache-prefix instead.

Copy link
Contributor Author

@calebzulawski calebzulawski Mar 17, 2025

Choose a reason for hiding this comment

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

What's the purpose of this input? If the prefix is user-configurable, is it necessary at all? Should the default still have 1 in it?

config.js Outdated
`${moduleRoot}/WORKSPACE.bzlmod`,
`${moduleRoot}/WORKSPACE`
]
const repositoryCacheEnabled = core.getBooleanInput('repository-cache')
Copy link
Member

Choose a reason for hiding this comment

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

Let's add a core.warning when repository-cache is not a boolean. This would indicate that an old interface for using repository-cache with a path to a file is being used, and we can add a link to the release page with upgrade instructions (https://github.com/bazel-contrib/setup-bazel/releases/tag/0.15.0)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ended up adding a core.error, because ultimately the action will fail

const maxDiskCacheSize = core.getInput('max-disk-cache-size')
if (diskCacheEnabled) {
bazelrc.push(`common --disk_cache=${bazelDisk}`)
if (diskCacheName !== 'true') {
Copy link
Member

Choose a reason for hiding this comment

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

Let's add a core.warning when disk-cache is not a boolean. This would indicate that an old interface for using disk-cache with a cache name is being used, and we can add a link to the release page with upgrade instructions (https://github.com/bazel-contrib/setup-bazel/releases/tag/0.15.0)

required: false
default: ""
cache-prefix:
description: Key prefix for all caches
Copy link
Member

Choose a reason for hiding this comment

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

Let's clarify it's only used for disk/repository cache, not bazlisk/external.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The way I implemented it, all of the caches use this prefix, including bazelisk and external. This resolves #73

@p0deje
Copy link
Member

p0deje commented Mar 15, 2025

After trying to use it in Selenium (SeleniumHQ/selenium#15427), I believe we might need to separate inputs for prefixes for repository and disk caches. The main reason is that I see lots of similar repository caches for matrix jobs, and the Selenium project would benefit from having a single repository cache (GC'ed) while keeping disk caches separate for each job.

@calebzulawski
Copy link
Contributor Author

We could do that, but on cache misses you will continue to see the kinds of errors in #73, as each job tries to write the same cache. Alternatively, if they aren't actually completely identical caches (e.g. the jobs have slightly different use of dependencies), whichever job completes last will win out for the next run and might end up missing some of the dependencies. You could even end up with a dependency repeatedly purged because the job that completes last doesn't use it and doesn't update its mtime.

What about adding an input for additional restore prefixes, so those jobs could share caches rather than have a cache miss?

@p0deje
Copy link
Member

p0deje commented May 27, 2025

@calebzulawski Sorry for the delay, it's been a crazy couple of months and I couldn't keep up with all the OSS projects I have on me. I'll go through our conversation and PR again to see where we left off.

@calebzulawski
Copy link
Contributor Author

No worries, thanks!

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.

2 participants