mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 16:57:49 +03:00
mononoke: allow binaries to specify a default for cachelib-only-blobstore
Summary: Reduces boilerplate for binaries usually run in this mode, notably the walker Reviewed By: ikostia Differential Revision: D25216883 fbshipit-source-id: e31d2a6aec7da3baafd8bcf208cf79cc696752c0
This commit is contained in:
parent
54bda6537d
commit
591363e1c4
@ -10,14 +10,15 @@ use clap::{App, Arg, ArgMatches};
|
||||
use fbinit::FacebookInit;
|
||||
use once_cell::sync::{Lazy, OnceCell};
|
||||
|
||||
use crate::args::MononokeMatches;
|
||||
use crate::args::{bool_as_str, MononokeMatches, BOOL_VALUES};
|
||||
|
||||
const CACHE_SIZE_GB: &str = "cache-size-gb";
|
||||
const USE_TUPPERWARE_SHRINKER: &str = "use-tupperware-shrinker";
|
||||
const MAX_PROCESS_SIZE: &str = "max-process-size";
|
||||
const MIN_PROCESS_SIZE: &str = "min-process-size";
|
||||
const SKIP_CACHING: &str = "skip-caching";
|
||||
const CACHELIB_ONLY_BLOBSTORE: &str = "cachelib-only-blobstore";
|
||||
const CACHELIB_ONLY_BLOBSTORE_OLD: &str = "cachelib-only-blobstore";
|
||||
const CACHELIB_ONLY_BLOBSTORE_NEW: &str = "blobstore-cachelib-only";
|
||||
const CACHELIB_SHARDS: &str = "cachelib-shards";
|
||||
|
||||
const PHASES_CACHE_SIZE: &str = "phases-cache-size";
|
||||
@ -117,9 +118,17 @@ pub(crate) fn add_cachelib_args<'a, 'b>(
|
||||
.help("do not init cachelib and disable caches (useful for tests)"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(CACHELIB_ONLY_BLOBSTORE)
|
||||
.long(CACHELIB_ONLY_BLOBSTORE)
|
||||
.help("do not init memcache for blobstore"),
|
||||
Arg::with_name(CACHELIB_ONLY_BLOBSTORE_OLD)
|
||||
.long(CACHELIB_ONLY_BLOBSTORE_OLD)
|
||||
.help("do not init memcache for blobstore. DEPRECATED, prefer --blobstore-cachelib-only=true"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(CACHELIB_ONLY_BLOBSTORE_NEW)
|
||||
.long(CACHELIB_ONLY_BLOBSTORE_NEW)
|
||||
.possible_values(BOOL_VALUES)
|
||||
.default_value(bool_as_str(defaults.blobstore_cachelib_only))
|
||||
.takes_value(true)
|
||||
.help("whether to run without memcache for blobstore"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(CACHELIB_SHARDS)
|
||||
@ -140,10 +149,22 @@ pub(crate) fn parse_cachelib_shards<'a>(matches: &ArgMatches<'a>) -> usize {
|
||||
pub(crate) fn parse_caching<'a>(matches: &ArgMatches<'a>) -> Caching {
|
||||
if matches.is_present(SKIP_CACHING) {
|
||||
Caching::Disabled
|
||||
} else if matches.is_present(CACHELIB_ONLY_BLOBSTORE) {
|
||||
} else if matches.is_present(CACHELIB_ONLY_BLOBSTORE_OLD) {
|
||||
Caching::CachelibOnlyBlobstore(parse_cachelib_shards(matches))
|
||||
} else {
|
||||
Caching::Enabled(parse_cachelib_shards(matches))
|
||||
let cachelib_only = matches
|
||||
.value_of(CACHELIB_ONLY_BLOBSTORE_NEW)
|
||||
.map_or(false, |v| {
|
||||
v.parse().unwrap_or_else(|_| {
|
||||
panic!("Provided {} is not bool", CACHELIB_ONLY_BLOBSTORE_NEW)
|
||||
})
|
||||
});
|
||||
|
||||
if cachelib_only {
|
||||
Caching::CachelibOnlyBlobstore(parse_cachelib_shards(matches))
|
||||
} else {
|
||||
Caching::Enabled(parse_cachelib_shards(matches))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -238,6 +259,7 @@ pub struct CachelibSettings {
|
||||
pub blob_cache_size: Option<usize>,
|
||||
pub phases_cache_size: Option<usize>,
|
||||
pub expected_item_size_bytes: Option<usize>,
|
||||
pub blobstore_cachelib_only: bool,
|
||||
}
|
||||
|
||||
impl Default for CachelibSettings {
|
||||
@ -256,6 +278,7 @@ impl Default for CachelibSettings {
|
||||
blob_cache_size: None,
|
||||
phases_cache_size: None,
|
||||
expected_item_size_bytes: None,
|
||||
blobstore_cachelib_only: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -995,11 +995,11 @@ fn add_mysql_options_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
|
||||
)
|
||||
}
|
||||
|
||||
fn bool_as_str(v: bool) -> &'static str {
|
||||
pub(crate) fn bool_as_str(v: bool) -> &'static str {
|
||||
if v { "true" } else { "false" }
|
||||
}
|
||||
|
||||
const BOOL_VALUES: &[&str] = &["false", "true"];
|
||||
pub(crate) const BOOL_VALUES: &[&str] = &["false", "true"];
|
||||
|
||||
fn add_blobstore_args<'a, 'b>(
|
||||
app: App<'a, 'b>,
|
||||
@ -1088,7 +1088,7 @@ fn add_blobstore_args<'a, 'b>(
|
||||
.arg(
|
||||
Arg::with_name(READONLY_STORAGE_OLD_ARG)
|
||||
.long(READONLY_STORAGE_OLD_ARG)
|
||||
.help("Error on any attempts to write to storage (deprecated, use --with-readonly-storage=<true|false>)"),
|
||||
.help("Error on any attempts to write to storage. DEPRECATED, prefer --with-readonly-storage=<true|false>"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(READONLY_STORAGE_NEW_ARG)
|
||||
|
@ -40,6 +40,7 @@ fn main(fb: FacebookInit) -> Result<(), Error> {
|
||||
let app_name = "walker";
|
||||
let cachelib_defaults = CachelibSettings {
|
||||
cache_size: 2 * 1024 * 1024 * 1024,
|
||||
blobstore_cachelib_only: true,
|
||||
..Default::default()
|
||||
};
|
||||
let matches = setup::setup_toplevel_app(app_name, cachelib_defaults.clone()).get_matches();
|
||||
|
Loading…
Reference in New Issue
Block a user