Skip to content

Implement locking & co-ordination between cache cleans - #3644

Open
peterebden wants to merge 2 commits into
masterfrom
dir-cache-coordination
Open

peterebden wants to merge 2 commits into
masterfrom
dir-cache-coordination

Conversation

@peterebden

Copy link
Copy Markdown
Collaborator

Third and final part of #3629 , stacked on #3642

Implements a lockfile for the cache so if a clean is in progress, another process will see that and will not try to do it as well.
Also implements cleaning of stale lock files across the cache so they don't build up forever.

@peterebden
peterebden added this pull request to stack #3643 October 24, 2026 09:34
@peterebden peterebden linked an issue Oct 26, 2026 that may be closed by this pull request
Comment thread src/cache/dir_cache.go
func (cache *dirCache) Store(target *core.BuildTarget, key []byte, files []string) {
cacheDir := cache.getPath(target, key, "")
lockFile, err := core.AcquireExclusiveFileLock(cacheDir + ".lock")
lockFile, err := lockEntry(cacheDir, syscall.LOCK_EX)

@jwong-beep jwong-beep Oct 28, 2026 •

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.

Am I right that cacheDir sometimes isn't actually a directory but a file? I was a little confused by why you are writing a lock file under it but then delete the entire directory at line 48

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.

Yeah, there's a mode where it stores compressed tarballs for each entry. It mostly gets used for CI where we're more concerned about the cache's size.

I wonder sometimes if it's worth it though, it does add some complexity.

Comment thread src/cache/dir_cache.go Resolved
Comment thread src/cache/dir_cache.go Outdated
}
cache.clean(policy, freeSpace)
now := time.Now()
if err := os.WriteFile(timestampFile, nil, 0644); err != nil {

@jwong-beep jwong-beep Oct 28, 2026 •

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.

Should we write the timestamp into the file regardless? It's not using the timestamp in the name, it may be unintuitive to find out how to read the timestamp. Everyone knows how to use ls and cat, not everyone knows how to use stat.

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.

Yeah that's not a bad idea, might as well while we're writing the file anyway.

Base automatically changed from dir-cache-eviction-policy to master October 31, 2026 10:24
@peterebden
peterebden force-pushed the dir-cache-coordination branch from 06315c8 to 5fe0851 Compare October 31, 2026 10:24
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.

Improve performance with multiple plz-outs

2 participants