Separate remotely downloaded snapshot archives (#23510)

* seperate remotely downloaded snapshot archives

* add str const for snapshot download dir

* only walk remote sub directory

* move directory creation outside of loop

* move is_remote to traits

* clippy simplify

* clippy

* clippy

* add unittest

* fix local cluster tests

* look for remote snapshot archive in remote foler

* create remote dir in tests

* use snapshot download dir constant

* extract build_remote_dir fn

* fix build

* code review - walking snapshot archived dirs explicitly

* fix build

* fix build

* fix comments

* Update runtime/src/snapshot_utils.rs

Co-authored-by: Brooks Prumo <brooks@prumo.org>

* clippy

* borrow to avoid copy

Co-authored-by: Brooks Prumo <brooks@prumo.org>
This commit is contained in:
HaoranYi
2022-03-14 14:03:59 -05:00
committed by GitHub
parent 5ea6a1e500
commit 0c684721d8
5 changed files with 146 additions and 49 deletions

View File

@ -153,6 +153,20 @@ impl RpcRequestMiddleware {
tokio::fs::File::open(path).await
}
fn find_snapshot_file<P>(&self, stem: P) -> PathBuf
where
P: AsRef<Path>,
{
let root = &self.snapshot_config.as_ref().unwrap().snapshot_archives_dir;
let local_path = root.join(&stem);
if local_path.exists() {
local_path
} else {
// remote snapshot archive path
snapshot_utils::build_snapshot_archives_remote_dir(root).join(stem)
}
}
fn process_file_get(&self, path: &str) -> RequestMiddlewareAction {
let stem = path.split_at(1).1; // Drop leading '/' from path
let filename = {
@ -163,11 +177,7 @@ impl RpcRequestMiddleware {
}
_ => {
inc_new_counter_info!("rpc-get_snapshot", 1);
self.snapshot_config
.as_ref()
.unwrap()
.snapshot_archives_dir
.join(stem)
self.find_snapshot_file(stem)
}
}
};