Add ability to get the latest incremental snapshot via RPC (#23788)

This commit is contained in:
DimAn 2022-03-21 19:48:49 +03:00 committed by GitHub
parent ae76fe2bd7
commit 739e43ba58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 5 deletions

View File

@ -50,6 +50,8 @@ use {
tokio_util::codec::{BytesCodec, FramedRead},
};
const FULL_SNAPSHOT_REQUEST_PATH: &str = "/snapshot.tar.bz2";
const INCREMENTAL_SNAPSHOT_REQUEST_PATH: &str = "/incremental-snapshot.tar.bz2";
const LARGEST_ACCOUNTS_CACHE_DURATION: u64 = 60 * 60 * 2;
pub struct JsonRpcService {
@ -227,16 +229,37 @@ impl RequestMiddleware for RpcRequestMiddleware {
trace!("request uri: {}", request.uri());
if let Some(ref snapshot_config) = self.snapshot_config {
if request.uri().path() == "/snapshot.tar.bz2" {
if request.uri().path() == FULL_SNAPSHOT_REQUEST_PATH
|| request.uri().path() == INCREMENTAL_SNAPSHOT_REQUEST_PATH
{
// Convenience redirect to the latest snapshot
return if let Some(full_snapshot_archive_info) =
let full_snapshot_archive_info =
snapshot_utils::get_highest_full_snapshot_archive_info(
&snapshot_config.snapshot_archives_dir,
) {
);
let snapshot_archive_info =
if let Some(full_snapshot_archive_info) = full_snapshot_archive_info {
if request.uri().path() == FULL_SNAPSHOT_REQUEST_PATH {
Some(full_snapshot_archive_info.snapshot_archive_info().clone())
} else {
snapshot_utils::get_highest_incremental_snapshot_archive_info(
&snapshot_config.snapshot_archives_dir,
full_snapshot_archive_info.slot(),
)
.map(|incremental_snapshot_archive_info| {
incremental_snapshot_archive_info
.snapshot_archive_info()
.clone()
})
}
} else {
None
};
return if let Some(snapshot_archive_info) = snapshot_archive_info {
RpcRequestMiddleware::redirect(&format!(
"/{}",
full_snapshot_archive_info
.path()
snapshot_archive_info
.path
.file_name()
.unwrap_or_else(|| std::ffi::OsStr::new(""))
.to_str()