-
Notifications
You must be signed in to change notification settings - Fork 172
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
Allow --metadata-ttl without --cache and set default with --cache to 60s #855
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3bb6968
Allow --metadata-ttl without --cache and set default with --cache to 60s
passaro 12f625e
PR feedback
passaro aaff4e7
Show 0 TTL warning in background mode
passaro c6c25c8
Update docs and changelog
passaro edc662b
Colorize warning with owo_colors
passaro fdb5976
Break items in the changelog
passaro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use std::{fmt::Display, num::ParseIntError, str::FromStr, time::Duration}; | ||
|
||
use thiserror::Error; | ||
|
||
/// User-configurable time-to-live (TTL) for metadata caching. | ||
#[derive(Debug, Clone, Copy)] | ||
pub enum TimeToLive { | ||
Minimal, | ||
Indefinite, | ||
Duration(Duration), | ||
} | ||
|
||
#[derive(Error, Debug)] | ||
pub enum TimeToLiveError { | ||
#[error("TTL must be a valid number of seconds, or 'indefinite', or 'minimal'")] | ||
InvalidInt(#[from] ParseIntError), | ||
#[error( | ||
"TTL must not be greater than {}s (~{} years), or be 'indefinite', or 'minimal'", | ||
TimeToLive::MAXIMUM_TTL_SECONDS, | ||
TimeToLive::MAXIMUM_TTL_YEARS | ||
)] | ||
TooLarge, | ||
} | ||
|
||
impl TimeToLive { | ||
const MINIMAL: &'static str = "minimal"; | ||
const INDEFINITE: &'static str = "indefinite"; | ||
|
||
// Set an upper bound that is practically "forever", but does not cause overflow | ||
// when added to `Instant::now()` (as `u64::MAX` would). | ||
const MAXIMUM_TTL_YEARS: u64 = 100; | ||
const MAXIMUM_TTL_SECONDS: u64 = Self::MAXIMUM_TTL_YEARS * 365 * 24 * 60 * 60; | ||
|
||
pub const INDEFINITE_DURATION: Duration = Duration::from_secs(Self::MAXIMUM_TTL_SECONDS); | ||
|
||
pub fn new_from_str(s: &str) -> Result<Self, TimeToLiveError> { | ||
match s { | ||
Self::MINIMAL => Ok(Self::Minimal), | ||
Self::INDEFINITE => Ok(Self::Indefinite), | ||
_ => { | ||
let seconds = s.parse()?; | ||
if seconds > Self::MAXIMUM_TTL_SECONDS { | ||
return Err(TimeToLiveError::TooLarge); | ||
} | ||
|
||
let duration = Duration::from_secs(seconds); | ||
Ok(Self::Duration(duration)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl Display for TimeToLive { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Self::Minimal => f.write_str(Self::MINIMAL), | ||
Self::Indefinite => f.write_str(Self::INDEFINITE), | ||
Self::Duration(duration) => write!(f, "{}s", duration.as_secs()), | ||
} | ||
} | ||
} | ||
|
||
impl FromStr for TimeToLive { | ||
type Err = TimeToLiveError; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
Self::new_from_str(s) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Maybe split this up because only part of it is breaking
New features
--metadata-ttl <seconds>
argument without also specifying--cache <directory>
, Mountpoint will cache file metadata in memory for up to the given TTL, but will not cache object data. The--metadata-ttl
argument also accepts two special values:minimal
to enable only the minimal necessary caching, andindefinite
to cache indefinitely. These modes can help accelerate workloads that touch many files but do not need to cache object data for re-use (for example, listing a directory and then reading each file within it once).Breaking changes
--metadata-ttl 0
setting is no longer supported and will be removed in a future release. The new--metadata-ttl minimal
has a similar effect, but behaves better when latency for S3 requests is high.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 also added a breaking change entry for the new default TTL with cache.