diff options
author | Alex Auvolat <alex@adnab.me> | 2023-01-03 14:44:47 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2023-01-03 14:44:47 +0100 |
commit | cdb2a591e9d393d24ab5c49bb905b0589b193299 (patch) | |
tree | 10c95206d0bd7b30c1fcd14ccc188be374cb1066 /src/table/data.rs | |
parent | 582b0761790b7958a3ba10c4b549b466997d2dcd (diff) | |
download | garage-cdb2a591e9d393d24ab5c49bb905b0589b193299.tar.gz garage-cdb2a591e9d393d24ab5c49bb905b0589b193299.zip |
Refactor how things are migrated
Diffstat (limited to 'src/table/data.rs')
-rw-r--r-- | src/table/data.rs | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/src/table/data.rs b/src/table/data.rs index 40856b02..f93ed00d 100644 --- a/src/table/data.rs +++ b/src/table/data.rs @@ -10,6 +10,7 @@ use garage_db::counted_tree_hack::CountedTree; use garage_util::data::*; use garage_util::error::*; +use garage_util::migrate::Migrate; use garage_rpc::system::System; @@ -219,7 +220,8 @@ where // data format, the messagepack encoding changed. In this case, // we also have to write the migrated value in the table and update // the associated Merkle tree entry. - let new_bytes = rmp_to_vec_all_named(&new_entry) + let new_bytes = new_entry + .encode() .map_err(Error::RmpEncode) .map_err(db::TxError::Abort)?; let changed = Some(&new_bytes[..]) != old_bytes.as_deref(); @@ -329,9 +331,9 @@ where Some(old_v) => { let mut entry = self.decode_entry(&old_v).map_err(db::TxError::Abort)?; entry.merge(ins); - rmp_to_vec_all_named(&entry) + entry.encode() } - None => rmp_to_vec_all_named(ins), + None => ins.encode(), }; let new_entry = new_entry .map_err(Error::RmpEncode) @@ -351,18 +353,18 @@ where } pub fn decode_entry(&self, bytes: &[u8]) -> Result<F::E, Error> { - match rmp_serde::decode::from_read_ref::<_, F::E>(bytes) { - Ok(x) => Ok(x), - Err(e) => match F::try_migrate(bytes) { - Some(x) => Ok(x), - None => { - warn!("Unable to decode entry of {}: {}", F::TABLE_NAME, e); - for line in hexdump::hexdump_iter(bytes) { - debug!("{}", line); - } - Err(e.into()) + match F::E::decode(bytes) { + Some(x) => Ok(x), + None => { + error!("Unable to decode entry of {}", F::TABLE_NAME); + for line in hexdump::hexdump_iter(bytes) { + debug!("{}", line); } - }, + Err(Error::Message(format!( + "Unable to decode entry of {}", + F::TABLE_NAME + ))) + } } } |