Line data Source code
1 : //! Helper functions to delete files from remote storage with a RemoteStorage
2 : use anyhow::Context;
3 : use std::path::Path;
4 : use tracing::debug;
5 :
6 : use remote_storage::GenericRemoteStorage;
7 :
8 : use crate::{
9 : config::PageServerConf,
10 : tenant::{remote_timeline_client::remote_path, Generation},
11 : };
12 :
13 9987 : pub(super) async fn delete_layer<'a>(
14 9987 : conf: &'static PageServerConf,
15 9987 : storage: &'a GenericRemoteStorage,
16 9987 : local_layer_path: &'a Path,
17 9987 : generation: Generation,
18 9987 : ) -> anyhow::Result<()> {
19 9987 : fail::fail_point!("before-delete-layer", |_| {
20 0 : anyhow::bail!("failpoint before-delete-layer")
21 9987 : });
22 0 : debug!("Deleting layer from remote storage: {local_layer_path:?}",);
23 :
24 9987 : let path_to_delete = remote_path(conf, local_layer_path, generation)?;
25 :
26 : // We don't want to print an error if the delete failed if the file has
27 : // already been deleted. Thankfully, in this situation S3 already
28 : // does not yield an error. While OS-provided local file system APIs do yield
29 : // errors, we avoid them in the `LocalFs` wrapper.
30 9987 : storage
31 9987 : .delete(&path_to_delete)
32 30629 : .await
33 9987 : .with_context(|| format!("delete remote layer from storage at {path_to_delete:?}"))
34 9987 : }
|