Skip to content
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

Correct dist-toolchain cache invalidation #554

Closed
chmanchester opened this issue Oct 22, 2019 · 4 comments
Closed

Correct dist-toolchain cache invalidation #554

chmanchester opened this issue Oct 22, 2019 · 4 comments

Comments

@chmanchester
Copy link
Contributor

A user reported needing to delete the dist-client cache directory locally when moving between rust toolchain versions to correct a version mismatch between local and the distributed builder. We should determine the circumstances where this might happen and correct it.

@luser
Copy link
Contributor

luser commented Oct 23, 2019

The dist client has this concept of "weak toolchain hashes" which are an easy-to-compute hash of some parts of the toolchain:

// Local machine mapping from 'weak' hashes to strong toolchain hashes
// - Weak hashes are what sccache uses to determine if a compiler has changed
// on the local machine - they're fast and 'good enough' (assuming we trust
// the local machine), but not safe if other users can update the cache.
// - Strong hashes (or 'archive ids') are the hash of the complete compiler contents that
// will be sent over the wire for use in distributed compilation - it is assumed
// that if two of them match, the contents of a compiler archive cannot
// have been tampered with
weak_map: Mutex<HashMap<String, String>>,

It uses those to lookup whether it has already packaged a toolchain, and during packaging it generates a stronger hash from all the files in the toolchain archive, which is what it uses to talk about toolchains with the build server.

For the Rust compiler the weak hash is actually pretty good, it includes the compiler_shlibs_digests that get calculated when sccache finds a Rust compiler (the hashes of all the shared libraries in $(rustc --print=sysroot)/lib, or /bin on Windows):

sccache/src/compiler/rust.rs

Lines 1003 to 1011 in 6371211

let mut m = Digest::new();
// Hash inputs:
// 1. A version
m.update(CACHE_VERSION);
// 2. compiler_shlibs_digests
for d in compiler_shlibs_digests {
m.update(d.as_bytes());
}
let weak_toolchain_key = m.clone().finish();

The weak map gets persisted as ~/.cache/sccache-dist-client/client/weak_map.json on Linux so it should be possible to have someone send you that file if they hit this again.

It's also possible that this is related to #87 will not do the right thing if someone uses rustup to point the same rustc binary at a different actual version of rustc during the lifetime of a server process, since the server caches compiler info purely based on path + mtime:

//TODO: properly handle rustup overrides. Currently this will

@chmanchester
Copy link
Contributor Author

This seems like #87

@chmanchester
Copy link
Contributor Author

On further inspection, there's the override case to handle, but also the simpler case of a binary path like .rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc getting an update that we fail to detect. Re-opening this issue to handle the latter.

@chmanchester chmanchester reopened this Nov 1, 2019
@luser
Copy link
Contributor

luser commented Nov 1, 2019

That seems like it ought to be handled properly? The sccache server caches compiler info by path + mtime, so if a compiler gets updated that ought to invalidate the cache.

chmanchester added a commit to chmanchester/sccache that referenced this issue Jan 15, 2020
… compiler info.

The hash for rust compilations do not currently take the dist archive into
account, meaning that updates to the dist archive may require clearing the
cache to purge old compiled artifacts. This takes the dist archive into
account when hashing rust compiles by hashing it when constructing a rust
compiler instance. It also takes the dist archive and its mtime into account
when caching compiler info in order to account for swapping out archives
without re-starting the local daemon.

Fixes mozilla#554
chmanchester added a commit to chmanchester/sccache that referenced this issue Feb 4, 2020
… compiler info.

The hash for rust compilations do not currently take the dist archive into
account, meaning that updates to the dist archive may require clearing the
cache to purge old compiled artifacts. This takes the dist archive into
account when hashing rust compiles by hashing it when constructing a rust
compiler instance. It also takes the dist archive and its mtime into account
when caching compiler info in order to account for swapping out archives
without re-starting the local daemon.

Fixes mozilla#554
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

No branches or pull requests

2 participants