mononoke: allow different tier name for sharded filenodes

Summary:
This updates our configuration to allow using a different tier name for sharded filenodes.

One thing I'd like to call out is that we currently use the DB tier name in the keys generated by `CachingFilenodes`. Updating the tier name will therefore result in us dropping all our caches. Is this acceptable? If not, should we just continue using the old tier name.

Reviewed By: jsgf, StanislavGlebik

Differential Revision: D15243112

fbshipit-source-id: 3bfdcefcc823768f2964b4733e570e9cef57cebc
This commit is contained in:
Thomas Orozco 2019-05-08 10:51:34 -07:00 committed by Facebook Github Bot
parent e5cdd1a5da
commit 5e0f2d895a
3 changed files with 99 additions and 29 deletions

View File

@ -27,8 +27,7 @@ use futures_ext::{try_boxfuture, BoxFuture, FutureExt};
use glusterblob::Glusterblob;
use manifoldblob::ThriftManifoldBlob;
use memblob::EagerMemblob;
use metaconfig_types::RemoteBlobstoreArgs;
use metaconfig_types::{self, RepoType};
use metaconfig_types::{self, RemoteBlobstoreArgs, RepoType, ShardedFilenodesParams};
use mononoke_types::RepositoryId;
use multiplexedblob::MultiplexedBlobstore;
use prefixblob::PrefixBlobstore;
@ -112,12 +111,12 @@ pub fn open_blobrepo(
ref blobstores_args,
ref db_address,
write_lock_db_address: _,
ref filenode_shards,
ref sharded_filenodes,
} => new_remote(
logger,
blobstores_args,
db_address.clone(),
filenode_shards.clone(),
sharded_filenodes.clone(),
repoid,
myrouter_port,
bookmarks_cache_ttl,
@ -152,11 +151,59 @@ pub fn new_memblob_empty(
))
}
fn new_filenodes(
db_address: &String,
sharded_filenodes: Option<ShardedFilenodesParams>,
myrouter_port: Option<u16>,
) -> Result<CachingFilenodes> {
let (tier, filenodes) = match (sharded_filenodes, myrouter_port) {
(
Some(ShardedFilenodesParams {
shard_map,
shard_num,
}),
Some(port),
) => {
let conn = SqlFilenodes::with_sharded_myrouter(&shard_map, port, shard_num.into())?;
(shard_map, conn)
}
(
Some(ShardedFilenodesParams {
shard_map,
shard_num,
}),
None,
) => {
let conn = SqlFilenodes::with_sharded_raw_xdb(&shard_map, shard_num.into())?;
(shard_map, conn)
}
(None, Some(port)) => {
let conn = SqlFilenodes::with_myrouter(&db_address, port);
(db_address.clone(), conn)
}
(None, None) => {
let conn = SqlFilenodes::with_raw_xdb_tier(&db_address)?;
(db_address.clone(), conn)
}
};
let filenodes = CachingFilenodes::new(
Arc::new(filenodes),
cachelib::get_pool("filenodes").ok_or(Error::from(ErrorKind::MissingCachePool(
"filenodes".to_string(),
)))?,
"sqlfilenodes",
&tier,
);
Ok(filenodes)
}
pub fn new_remote(
logger: Logger,
args: &RemoteBlobstoreArgs,
db_address: String,
filenode_shards: Option<usize>,
sharded_filenodes: Option<ShardedFilenodesParams>,
repoid: RepositoryId,
myrouter_port: Option<u16>,
bookmarks_cache_ttl: Option<Duration>,
@ -248,24 +295,7 @@ pub fn new_remote(
))?);
let blobstore = Arc::new(new_cachelib_blobstore(blobstore, blob_pool, presence_pool));
let filenodes = match (filenode_shards, myrouter_port) {
(Some(shards), Some(myrouter_port)) => {
SqlFilenodes::with_sharded_myrouter(&db_address, myrouter_port, shards)?
}
(None, Some(myrouter_port)) => {
SqlFilenodes::with_myrouter(&db_address, myrouter_port)
}
(Some(shards), None) => SqlFilenodes::with_sharded_raw_xdb(&db_address, shards)?,
(None, None) => SqlFilenodes::with_raw_xdb_tier(&db_address)?,
};
let filenodes = CachingFilenodes::new(
Arc::new(filenodes),
cachelib::get_pool("filenodes").ok_or(Error::from(ErrorKind::MissingCachePool(
"filenodes".to_string(),
)))?,
"sqlfilenodes",
&db_address,
);
let filenodes = new_filenodes(&db_address, sharded_filenodes, myrouter_port)?;
let bookmarks: Arc<dyn Bookmarks> = {
let bookmarks = match myrouter_port {

View File

@ -24,7 +24,7 @@ use metaconfig_types::{
BlobstoreId, BookmarkOrRegex, BookmarkParams, Bundle2ReplayParams, CacheWarmupParams,
CommonConfig, GlusterArgs, HookBypass, HookConfig, HookManagerParams, HookParams, HookType,
LfsParams, ManifoldArgs, MysqlBlobstoreArgs, PushrebaseParams, RemoteBlobstoreArgs, RepoConfig,
RepoReadOnly, RepoType, WhitelistEntry,
RepoReadOnly, RepoType, ShardedFilenodesParams, WhitelistEntry,
};
use regex::Regex;
use toml;
@ -368,10 +368,28 @@ impl RepoConfigs {
}
};
let sharded_filenodes: Result<Option<ShardedFilenodesParams>> = this
.sharded_filenodes
.map(|params| {
let RawShardedFilenodesParams {
shard_map,
shard_num,
} = params;
let err =
ErrorKind::InvalidConfig("filenodes shard_num must be > 0".into());
let shard_num: Result<NonZeroUsize> =
NonZeroUsize::new(shard_num).ok_or(err.into());
Ok(ShardedFilenodesParams {
shard_map,
shard_num: shard_num?,
})
})
.transpose();
RepoType::BlobRemote {
blobstores_args,
db_address,
filenode_shards: this.filenode_shards,
sharded_filenodes: sharded_filenodes?,
write_lock_db_address,
}
}
@ -514,7 +532,6 @@ struct RawRepoConfig {
repoid: i32,
db_address: Option<String>,
write_lock_db_address: Option<String>,
filenode_shards: Option<usize>,
scuba_table: Option<String>,
blobstore_scuba_table: Option<String>,
delay_mean: Option<u64>,
@ -532,6 +549,7 @@ struct RawRepoConfig {
skiplist_index_blobstore_key: Option<String>,
remote_blobstore: Option<Vec<RawRemoteBlobstoreConfig>>,
bundle2_replay_params: Option<RawBundle2ReplayParams>,
sharded_filenodes: Option<RawShardedFilenodesParams>,
}
#[derive(Debug, Deserialize, Clone)]
@ -652,6 +670,13 @@ struct RawBundle2ReplayParams {
preserve_raw_bundle2: Option<bool>,
}
#[derive(Clone, Debug, Deserialize)]
#[serde(deny_unknown_fields)]
struct RawShardedFilenodesParams {
shard_map: String,
shard_num: usize,
}
#[cfg(test)]
mod test {
use super::*;
@ -743,6 +768,9 @@ mod test {
threshold = 1000
[bundle2_replay_params]
preserve_raw_bundle2 = true
[sharded_filenodes]
shard_map = "db_address_shards"
shard_num = 123
"#;
let www_content = r#"
path="/tmp/www"
@ -805,7 +833,10 @@ mod test {
repotype: RepoType::BlobRemote {
db_address: "db_address".into(),
blobstores_args,
filenode_shards: None,
sharded_filenodes: Some(ShardedFilenodesParams {
shard_map: "db_address_shards".into(),
shard_num: NonZeroUsize::new(123).unwrap(),
}),
write_lock_db_address: Some("write_lock_db_address".into()),
},
generation_cache_size: 1024 * 1024,

View File

@ -467,8 +467,8 @@ pub enum RepoType {
blobstores_args: RemoteBlobstoreArgs,
/// Identifies the SQL database to connect to.
db_address: String,
/// If present, the number of shards to spread filenodes across
filenode_shards: Option<usize>,
/// If present, sharding configuration for filenodes.
sharded_filenodes: Option<ShardedFilenodesParams>,
/// Address of the SQL database used to lock writes to a repo.
write_lock_db_address: Option<String>,
},
@ -480,3 +480,12 @@ pub struct Bundle2ReplayParams {
/// A flag specifying whether to preserve raw bundle2 contents in the blobstore
pub preserve_raw_bundle2: bool,
}
/// Storage setup for sharded filenodes
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct ShardedFilenodesParams {
/// Identifies the SQL database to connect to.
pub shard_map: String,
/// Number of shards to distribute filenodes across.
pub shard_num: NonZeroUsize,
}