Refactor how things are migrated #461

Merged
lx merged 9 commits from format-migration into main 2023-01-03 15:28:25 +00:00
4 changed files with 18 additions and 17 deletions
Showing only changes of commit a54b67740d - Show all commits

View file

@ -14,7 +14,7 @@ use tokio::sync::{mpsc, watch};
use garage_util::background::*;
use garage_util::data::*;
use garage_util::encode::nonversioned_encode;
use garage_util::encode::{nonversioned_encode, debug_serialize};
use garage_util::error::{Error, OkOrMessage};
use garage_rpc::ring::*;

View file

@ -140,19 +140,3 @@ pub fn fasthash(data: &[u8]) -> FastHash {
pub fn gen_uuid() -> Uuid {
rand::thread_rng().gen::<[u8; 32]>().into()
}
/// Serialize to JSON, truncating long result
pub fn debug_serialize<T: Serialize>(x: T) -> String {
match serde_json::to_string(&x) {
Ok(ss) => {
if ss.len() > 100 {
// TODO this can panic if 100 is not a codepoint boundary, but inside a 2 Bytes
// (or more) codepoint
ss[..100].to_string()
} else {
ss
}
}
Err(e) => format!("<JSON serialization error: {}>", e),
}
}

View file

@ -24,3 +24,19 @@ where
{
rmp_serde::decode::from_read_ref::<_, T>(bytes)
}
/// Serialize to JSON, truncating long result
pub fn debug_serialize<T: Serialize>(x: T) -> String {
match serde_json::to_string(&x) {
Ok(ss) => {
if ss.len() > 100 {
// TODO this can panic if 100 is not a codepoint boundary, but inside a 2 Bytes
// (or more) codepoint
ss[..100].to_string()
} else {
ss
}
}
Err(e) => format!("<JSON serialization error: {}>", e),
}
}

View file

@ -7,6 +7,7 @@ use err_derive::Error;
use serde::{de::Visitor, Deserialize, Deserializer, Serialize, Serializer};
use crate::data::*;
use crate::encode::debug_serialize;
/// Regroup all Garage errors
#[derive(Debug, Error)]