From 4feb12548bb7dff6c98aadbebd033796ab89a113 Mon Sep 17 00:00:00 2001 From: Joonas Koivunen Date: Wed, 6 Sep 2023 17:09:40 +0300 Subject: [PATCH] use a pub type for simulated errors --- libs/remote_storage/src/lib.rs | 6 +++++- libs/remote_storage/src/simulate_failures.rs | 18 ++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/libs/remote_storage/src/lib.rs b/libs/remote_storage/src/lib.rs index a92b87632b..f329a1a537 100644 --- a/libs/remote_storage/src/lib.rs +++ b/libs/remote_storage/src/lib.rs @@ -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 diff --git a/libs/remote_storage/src/simulate_failures.rs b/libs/remote_storage/src/simulate_failures.rs index 6d6a5c1d24..9bc51cb378 100644 --- a/libs/remote_storage/src/simulate_failures.rs +++ b/libs/remote_storage/src/simulate_failures.rs @@ -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), 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(