mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-06 13:02:55 +00:00
Turn GenericRemoteStorage into just a newtype around 'Arc<dyn RemoteStorage>'
We had a pattern like this:
match remote_storage {
GenericRemoteStorage::Local(storage) => {
let source = storage.remote_object_id(&file_path)?;
...
storage
.function(&source, ...)
.await
},
GenericRemoteStorage::S3(storage) => {
... exact same code as for the Local case ...
},
This removes the code duplication, by allowing you to call the functions
directly on GenericRemoteStorage.
Also change RemoveObjectId to be just a type alias for String. Now that
the callers of GenericRemoteStorage functions don't know whether they're
dealing with the LocalFs or S3 implementation, RemoveObjectId must be the
same type for both.
This commit is contained in:
committed by
Dmitry Rodionov
parent
171385ac14
commit
35b4816f09
@@ -127,7 +127,8 @@ async fn wal_backup_launcher_main_loop(
|
||||
let conf_ = conf.clone();
|
||||
REMOTE_STORAGE.get_or_init(|| {
|
||||
conf_.remote_storage.as_ref().map(|c| {
|
||||
GenericRemoteStorage::new(conf_.workdir, c).expect("failed to create remote storage")
|
||||
GenericRemoteStorage::from_config(conf_.workdir, c)
|
||||
.expect("failed to create remote storage")
|
||||
})
|
||||
});
|
||||
|
||||
@@ -417,7 +418,11 @@ fn get_segments(start: Lsn, end: Lsn, seg_size: usize) -> Vec<Segment> {
|
||||
static REMOTE_STORAGE: OnceCell<Option<GenericRemoteStorage>> = OnceCell::new();
|
||||
|
||||
async fn backup_object(source_file: &Path, size: usize) -> Result<()> {
|
||||
let storage = REMOTE_STORAGE.get().expect("failed to get remote storage");
|
||||
let storage = REMOTE_STORAGE
|
||||
.get()
|
||||
.expect("failed to get remote storage")
|
||||
.as_ref()
|
||||
.unwrap();
|
||||
|
||||
let file = tokio::io::BufReader::new(File::open(&source_file).await.with_context(|| {
|
||||
format!(
|
||||
@@ -427,9 +432,7 @@ async fn backup_object(source_file: &Path, size: usize) -> Result<()> {
|
||||
})?);
|
||||
|
||||
storage
|
||||
.as_ref()
|
||||
.expect("Storage should be initialized by launcher at this point.")
|
||||
.upload_storage_object(file, size, source_file)
|
||||
.upload_storage_object(Box::new(file), size, source_file)
|
||||
.await
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user