mirror of
https://github.com/deuxfleurs-org/garage.git
synced 2026-08-06 04:47:42 +00:00
Improve CLI, adapt tests, update documentation
This commit is contained in:
+5
-11
@@ -6,8 +6,8 @@ use std::path::PathBuf;
|
||||
use serde::de::Error as SerdeError;
|
||||
use serde::{de, Deserialize};
|
||||
|
||||
use netapp::NodeID;
|
||||
use netapp::util::parse_and_resolve_peer_addr;
|
||||
use netapp::NodeID;
|
||||
|
||||
use crate::error::Error;
|
||||
|
||||
@@ -46,10 +46,6 @@ pub struct Config {
|
||||
/// Consul service name to use
|
||||
pub consul_service_name: Option<String>,
|
||||
|
||||
/// Max number of concurrent RPC request
|
||||
#[serde(default = "default_max_concurrent_rpc_requests")]
|
||||
pub max_concurrent_rpc_requests: usize,
|
||||
|
||||
/// Sled cache size, in bytes
|
||||
#[serde(default = "default_sled_cache_capacity")]
|
||||
pub sled_cache_capacity: u64,
|
||||
@@ -91,9 +87,6 @@ fn default_sled_cache_capacity() -> u64 {
|
||||
fn default_sled_flush_every_ms() -> u64 {
|
||||
2000
|
||||
}
|
||||
fn default_max_concurrent_rpc_requests() -> usize {
|
||||
12
|
||||
}
|
||||
fn default_block_size() -> usize {
|
||||
1048576
|
||||
}
|
||||
@@ -117,10 +110,11 @@ where
|
||||
let mut ret = vec![];
|
||||
|
||||
for peer in <Vec<&str>>::deserialize(deserializer)? {
|
||||
let (pubkey, addrs) = parse_and_resolve_peer_addr(peer)
|
||||
.ok_or_else(|| D::Error::custom(format!("Unable to parse or resolve peer: {}", peer)))?;
|
||||
let (pubkey, addrs) = parse_and_resolve_peer_addr(peer).ok_or_else(|| {
|
||||
D::Error::custom(format!("Unable to parse or resolve peer: {}", peer))
|
||||
})?;
|
||||
for ip in addrs {
|
||||
ret.push((pubkey.clone(), ip));
|
||||
ret.push((pubkey, ip));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -93,9 +93,9 @@ impl From<netapp::NodeID> for FixedBytes32 {
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<netapp::NodeID> for FixedBytes32 {
|
||||
fn into(self) -> netapp::NodeID {
|
||||
netapp::NodeID::from_slice(self.as_slice()).unwrap()
|
||||
impl From<FixedBytes32> for netapp::NodeID {
|
||||
fn from(bytes: FixedBytes32) -> netapp::NodeID {
|
||||
netapp::NodeID::from_slice(bytes.as_slice()).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+37
-2
@@ -47,8 +47,14 @@ pub enum Error {
|
||||
#[error(display = "Timeout")]
|
||||
Timeout,
|
||||
|
||||
#[error(display = "Too many errors: {:?}", _0)]
|
||||
TooManyErrors(Vec<String>),
|
||||
#[error(
|
||||
display = "Could not reach quorum of {}. {} of {} request succeeded, others returned errors: {:?}",
|
||||
_0,
|
||||
_1,
|
||||
_2,
|
||||
_3
|
||||
)]
|
||||
Quorum(usize, usize, usize, Vec<String>),
|
||||
|
||||
#[error(display = "Bad RPC: {}", _0)]
|
||||
BadRpc(String),
|
||||
@@ -81,6 +87,35 @@ impl<T> From<tokio::sync::mpsc::error::SendError<T>> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a str> for Error {
|
||||
fn from(v: &'a str) -> Error {
|
||||
Error::Message(v.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for Error {
|
||||
fn from(v: String) -> Error {
|
||||
Error::Message(v)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ErrorContext<T, E> {
|
||||
fn err_context<C: std::borrow::Borrow<str>>(self, ctx: C) -> Result<T, Error>;
|
||||
}
|
||||
|
||||
impl<T, E> ErrorContext<T, E> for Result<T, E>
|
||||
where
|
||||
E: std::fmt::Display,
|
||||
{
|
||||
#[inline]
|
||||
fn err_context<C: std::borrow::Borrow<str>>(self, ctx: C) -> Result<T, Error> {
|
||||
match self {
|
||||
Ok(x) => Ok(x),
|
||||
Err(e) => Err(Error::Message(format!("{}\n{}", ctx.borrow(), e))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Custom serialization for our error type, for use in RPC.
|
||||
// Errors are serialized as a string of their Display representation.
|
||||
// Upon deserialization, they all become a RemoteError with the
|
||||
|
||||
Reference in New Issue
Block a user