mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-15 09:22:55 +00:00
use a pub type for simulated errors
This commit is contained in:
committed by
Joonas Koivunen
parent
ba92668e37
commit
4feb12548b
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user