use a pub type for simulated errors

This commit is contained in:
Joonas Koivunen
2023-09-06 17:09:40 +03:00
committed by Joonas Koivunen
parent ba92668e37
commit 4feb12548b
2 changed files with 19 additions and 5 deletions

View File

@@ -25,7 +25,11 @@ use tokio::io;
use toml_edit::Item;
use tracing::info;
pub use self::{local_fs::LocalFs, s3_bucket::S3Bucket, simulate_failures::UnreliableWrapper};
pub use self::{
local_fs::LocalFs,
s3_bucket::S3Bucket,
simulate_failures::{SimulatedError, UnreliableWrapper},
};
/// How many different timelines can be processed simultaneously when synchronizing layers with the remote storage.
/// During regular work, pageserver produces one layer file per timeline checkpoint, with bursts of concurrency

View File

@@ -18,7 +18,7 @@ pub struct UnreliableWrapper {
}
/// Used to identify retries of different unique operation.
#[derive(Debug, Hash, Eq, PartialEq)]
#[derive(Debug, Hash, Eq, PartialEq, Clone)]
enum RemoteOp {
ListPrefixes(Option<RemotePath>),
Upload(RemotePath),
@@ -59,13 +59,12 @@ impl UnreliableWrapper {
e.remove();
Ok(attempts_before_this)
} else {
let error =
anyhow::anyhow!("simulated failure of remote operation {:?}", e.key());
let error = anyhow::anyhow!(SimulatedError(e.key().to_owned()));
Err(DownloadError::Other(error))
}
}
Entry::Vacant(e) => {
let error = anyhow::anyhow!("simulated failure of remote operation {:?}", e.key());
let error = anyhow::anyhow!(SimulatedError(e.key().to_owned()));
e.insert(1);
Err(DownloadError::Other(error))
}
@@ -80,6 +79,17 @@ impl UnreliableWrapper {
}
}
#[derive(Debug)]
pub struct SimulatedError(RemoteOp);
impl std::fmt::Display for SimulatedError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "simulated failure of remote operation {:?}", self.0)
}
}
impl std::error::Error for SimulatedError {}
#[async_trait::async_trait]
impl RemoteStorage for UnreliableWrapper {
async fn list_prefixes(