Add ability to get the latest incremental snapshot via RPC (#23788)
This commit is contained in:
parent
ae76fe2bd7
commit
739e43ba58
|
@ -50,6 +50,8 @@ use {
|
||||||
tokio_util::codec::{BytesCodec, FramedRead},
|
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;
|
const LARGEST_ACCOUNTS_CACHE_DURATION: u64 = 60 * 60 * 2;
|
||||||
|
|
||||||
pub struct JsonRpcService {
|
pub struct JsonRpcService {
|
||||||
|
@ -227,16 +229,37 @@ impl RequestMiddleware for RpcRequestMiddleware {
|
||||||
trace!("request uri: {}", request.uri());
|
trace!("request uri: {}", request.uri());
|
||||||
|
|
||||||
if let Some(ref snapshot_config) = self.snapshot_config {
|
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
|
// 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_utils::get_highest_full_snapshot_archive_info(
|
||||||
&snapshot_config.snapshot_archives_dir,
|
&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!(
|
RpcRequestMiddleware::redirect(&format!(
|
||||||
"/{}",
|
"/{}",
|
||||||
full_snapshot_archive_info
|
snapshot_archive_info
|
||||||
.path()
|
.path
|
||||||
.file_name()
|
.file_name()
|
||||||
.unwrap_or_else(|| std::ffi::OsStr::new(""))
|
.unwrap_or_else(|| std::ffi::OsStr::new(""))
|
||||||
.to_str()
|
.to_str()
|
||||||
|
|
Loading…
Reference in New Issue