-
Notifications
You must be signed in to change notification settings - Fork 566
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
Implement read-only local cache #2048
Conversation
storage.put_preprocessor_cache_entry( | ||
|
||
if let Err(e) = storage.put_preprocessor_cache_entry( | ||
preprocessor_key, | ||
preprocessor_cache_entry, | ||
)?; | ||
) { | ||
debug!("Failed to update preprocessor cache: {}", e); | ||
update_failed = true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm unsure about this behavior. It's based on how compiler.rs
handles errors.
Realistically, errors shouldn't be used here, but it seems to be how it's handled with GCS read-only, so I did it the same way. I thought about changing it, but I'd like to hear the input about someone more knowledgeable about sccache's internals first. Storage::check()
seems to be a great candidate, although it only seems to be used for a print and is very expensive for GCS (which could be changed, of course).
storage | ||
.put_preprocessor_cache_entry(&preprocessor_key, preprocessor_cache_entry)?; | ||
|
||
if let Err(e) = storage | ||
.put_preprocessor_cache_entry(&preprocessor_key, preprocessor_cache_entry) | ||
{ | ||
debug!("Failed to update preprocessor cache: {}", e); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
src/cache/gcs.rs
Outdated
impl From<config::CacheRWMode> for RWMode { | ||
fn from(value: config::CacheRWMode) -> Self { | ||
match value { | ||
config::CacheRWMode::ReadOnly => RWMode::ReadOnly, | ||
config::CacheRWMode::ReadWrite => RWMode::ReadWrite, | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few different types like this that have the same purpose. Should they be consolidated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've merged two of them together, although there's still CacheModeConfig
and CacheMode
, which do effectively the same thing.
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #2048 +/- ##
==========================================
- Coverage 30.86% 30.85% -0.02%
==========================================
Files 51 52 +1
Lines 19653 19889 +236
Branches 9455 9620 +165
==========================================
+ Hits 6066 6136 +70
- Misses 7852 7911 +59
- Partials 5735 5842 +107 ☔ View full report in Codecov by Sentry. |
docs/Local.md
Outdated
|
||
## Read-only cache mode | ||
|
||
By default, the local cache operates in read/write mode. The `SCCACHE_LOCAL_RW_MODE` environment variable can be set to `READ_ONLY` (or `READ_WRITE`) to modify this behavior. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you please detail in which case someone might want to use READ_ONLY
thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you please detail in which case someone might want to use READ_ONLY thanks
Done, let me know if that's what you want. For a more specific use case, see the linked issue. I'm using sccache to speed up build times for untrusted (and short-lived) build tasks, where new items can't be added as they may not be valid, but caching commonly used libraries can still speed up build times immensely. Read-only is not being used as a security feature, as build tasks are already isolated correctly, but to reduce useless disk consumption.
Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
@@ -130,6 +133,11 @@ impl Storage for DiskCache { | |||
// We should probably do this on a background thread if we're going to buffer | |||
// everything in memory... | |||
trace!("DiskCache::finish_put({})", key); | |||
|
|||
if self.rw_mode == CacheMode::ReadOnly { | |||
return Err(anyhow!("Cannot write to a read-only cache")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you please add a test to trigger this error ? thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you please add a test to trigger this error ? thanks
@sylvestre Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you please check for the error message string too ?
thanks
I'm not sure why the integration tests are failing. The only change I made (since they succeeded) was asserting the errors' messages and running rustfmt. |
rate limiting on github, not your fault :) |
thanks for your pr! |
This allows the local cache to be set as read-only (similar to GCS read-only) when the
SCCACHE_LOCAL_RW_MODE
environment variable is set toREAD_ONLY
(or the corresponding config option).Closes #1852.