2021-03-12 18:57:37 +00:00
|
|
|
use core::borrow::Borrow;
|
2022-05-10 11:16:57 +00:00
|
|
|
use std::convert::TryInto;
|
2021-03-11 15:54:15 +00:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
use serde_bytes::ByteBuf;
|
2021-03-16 10:43:58 +00:00
|
|
|
use tokio::sync::Notify;
|
2021-03-11 15:54:15 +00:00
|
|
|
|
2022-06-08 08:01:44 +00:00
|
|
|
use garage_db as db;
|
|
|
|
|
2021-03-11 15:54:15 +00:00
|
|
|
use garage_util::data::*;
|
|
|
|
use garage_util::error::*;
|
2023-01-03 13:44:47 +00:00
|
|
|
use garage_util::migrate::Migrate;
|
2021-03-11 15:54:15 +00:00
|
|
|
|
2021-10-14 09:50:12 +00:00
|
|
|
use garage_rpc::system::System;
|
2021-03-16 17:42:33 +00:00
|
|
|
|
2021-05-02 21:13:08 +00:00
|
|
|
use crate::crdt::Crdt;
|
2021-10-28 10:49:37 +00:00
|
|
|
use crate::gc::GcTodoEntry;
|
2022-02-15 19:09:43 +00:00
|
|
|
use crate::metrics::*;
|
2021-03-16 10:43:58 +00:00
|
|
|
use crate::replication::*;
|
2021-03-11 17:28:03 +00:00
|
|
|
use crate::schema::*;
|
2022-05-10 11:16:57 +00:00
|
|
|
use crate::util::*;
|
2021-03-11 15:54:15 +00:00
|
|
|
|
2021-03-16 10:43:58 +00:00
|
|
|
pub struct TableData<F: TableSchema, R: TableReplication> {
|
2021-03-16 17:42:33 +00:00
|
|
|
system: Arc<System>,
|
2021-03-16 10:43:58 +00:00
|
|
|
|
2022-05-10 11:16:57 +00:00
|
|
|
pub instance: F,
|
|
|
|
pub replication: R,
|
2021-03-11 15:54:15 +00:00
|
|
|
|
2022-06-08 08:01:44 +00:00
|
|
|
pub store: db::Tree,
|
2021-03-16 10:43:58 +00:00
|
|
|
|
2022-06-08 08:01:44 +00:00
|
|
|
pub(crate) merkle_tree: db::Tree,
|
|
|
|
pub(crate) merkle_todo: db::Tree,
|
2021-03-16 10:43:58 +00:00
|
|
|
pub(crate) merkle_todo_notify: Notify,
|
2022-12-14 10:58:06 +00:00
|
|
|
|
|
|
|
pub(crate) insert_queue: db::Tree,
|
2023-09-21 13:37:28 +00:00
|
|
|
pub(crate) insert_queue_notify: Arc<Notify>,
|
2022-12-14 10:58:06 +00:00
|
|
|
|
2024-03-08 13:59:56 +00:00
|
|
|
pub(crate) gc_todo: db::Tree,
|
2022-02-15 19:09:43 +00:00
|
|
|
|
|
|
|
pub(crate) metrics: TableMetrics,
|
2021-03-11 15:54:15 +00:00
|
|
|
}
|
|
|
|
|
2023-01-03 14:08:37 +00:00
|
|
|
impl<F: TableSchema, R: TableReplication> TableData<F, R> {
|
2022-06-08 08:01:44 +00:00
|
|
|
pub fn new(system: Arc<System>, instance: F, replication: R, db: &db::Db) -> Arc<Self> {
|
2021-03-11 15:54:15 +00:00
|
|
|
let store = db
|
2023-05-09 19:49:34 +00:00
|
|
|
.open_tree(format!("{}:table", F::TABLE_NAME))
|
2021-03-11 15:54:15 +00:00
|
|
|
.expect("Unable to open DB tree");
|
|
|
|
|
2021-03-16 10:43:58 +00:00
|
|
|
let merkle_tree = db
|
2023-05-09 19:49:34 +00:00
|
|
|
.open_tree(format!("{}:merkle_tree", F::TABLE_NAME))
|
2021-03-11 15:54:15 +00:00
|
|
|
.expect("Unable to open DB Merkle tree tree");
|
2021-03-16 10:43:58 +00:00
|
|
|
let merkle_todo = db
|
2023-05-09 19:49:34 +00:00
|
|
|
.open_tree(format!("{}:merkle_todo", F::TABLE_NAME))
|
2021-03-16 10:43:58 +00:00
|
|
|
.expect("Unable to open DB Merkle TODO tree");
|
2021-03-11 15:54:15 +00:00
|
|
|
|
2022-12-14 10:58:06 +00:00
|
|
|
let insert_queue = db
|
2023-05-09 19:49:34 +00:00
|
|
|
.open_tree(format!("{}:insert_queue", F::TABLE_NAME))
|
2022-12-14 10:58:06 +00:00
|
|
|
.expect("Unable to open insert queue DB tree");
|
|
|
|
|
2021-03-12 18:57:37 +00:00
|
|
|
let gc_todo = db
|
2023-05-09 19:49:34 +00:00
|
|
|
.open_tree(format!("{}:gc_todo_v2", F::TABLE_NAME))
|
2022-12-14 10:58:06 +00:00
|
|
|
.expect("Unable to open GC DB tree");
|
2021-03-12 18:57:37 +00:00
|
|
|
|
2022-12-13 14:54:03 +00:00
|
|
|
let metrics = TableMetrics::new(
|
|
|
|
F::TABLE_NAME,
|
|
|
|
store.clone(),
|
|
|
|
merkle_tree.clone(),
|
|
|
|
merkle_todo.clone(),
|
|
|
|
gc_todo.clone(),
|
|
|
|
);
|
2022-02-15 19:09:43 +00:00
|
|
|
|
2021-03-11 17:28:03 +00:00
|
|
|
Arc::new(Self {
|
2021-03-16 17:42:33 +00:00
|
|
|
system,
|
2021-03-11 15:54:15 +00:00
|
|
|
instance,
|
2021-03-16 10:43:58 +00:00
|
|
|
replication,
|
2021-03-11 15:54:15 +00:00
|
|
|
store,
|
2021-03-16 10:43:58 +00:00
|
|
|
merkle_tree,
|
|
|
|
merkle_todo,
|
|
|
|
merkle_todo_notify: Notify::new(),
|
2022-12-14 10:58:06 +00:00
|
|
|
insert_queue,
|
2023-09-21 13:37:28 +00:00
|
|
|
insert_queue_notify: Arc::new(Notify::new()),
|
2021-03-12 18:57:37 +00:00
|
|
|
gc_todo,
|
2022-02-15 19:09:43 +00:00
|
|
|
metrics,
|
2021-03-11 15:54:15 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read functions
|
|
|
|
|
|
|
|
pub fn read_entry(&self, p: &F::P, s: &F::S) -> Result<Option<ByteBuf>, Error> {
|
|
|
|
let tree_key = self.tree_key(p, s);
|
2023-05-09 19:49:34 +00:00
|
|
|
if let Some(bytes) = self.store.get(tree_key)? {
|
2021-03-11 15:54:15 +00:00
|
|
|
Ok(Some(ByteBuf::from(bytes.to_vec())))
|
|
|
|
} else {
|
|
|
|
Ok(None)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn read_range(
|
|
|
|
&self,
|
2022-05-10 11:16:57 +00:00
|
|
|
partition_key: &F::P,
|
|
|
|
start: &Option<F::S>,
|
|
|
|
filter: &Option<F::Filter>,
|
|
|
|
limit: usize,
|
|
|
|
enumeration_order: EnumerationOrder,
|
|
|
|
) -> Result<Vec<Arc<ByteBuf>>, Error> {
|
|
|
|
let partition_hash = partition_key.hash();
|
|
|
|
match enumeration_order {
|
|
|
|
EnumerationOrder::Forward => {
|
|
|
|
let first_key = match start {
|
|
|
|
None => partition_hash.to_vec(),
|
|
|
|
Some(sk) => self.tree_key(partition_key, sk),
|
|
|
|
};
|
2022-06-08 08:01:44 +00:00
|
|
|
let range = self.store.range(first_key..)?;
|
2022-05-10 11:16:57 +00:00
|
|
|
self.read_range_aux(partition_hash, range, filter, limit)
|
|
|
|
}
|
|
|
|
EnumerationOrder::Reverse => match start {
|
|
|
|
Some(sk) => {
|
|
|
|
let last_key = self.tree_key(partition_key, sk);
|
2022-06-08 08:01:44 +00:00
|
|
|
let range = self.store.range_rev(..=last_key)?;
|
2022-05-10 11:16:57 +00:00
|
|
|
self.read_range_aux(partition_hash, range, filter, limit)
|
|
|
|
}
|
|
|
|
None => {
|
|
|
|
let mut last_key = partition_hash.to_vec();
|
|
|
|
let lower = u128::from_be_bytes(last_key[16..32].try_into().unwrap());
|
|
|
|
last_key[16..32].copy_from_slice(&u128::to_be_bytes(lower + 1));
|
2022-06-08 08:01:44 +00:00
|
|
|
let range = self.store.range_rev(..last_key)?;
|
2022-05-10 11:16:57 +00:00
|
|
|
self.read_range_aux(partition_hash, range, filter, limit)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-09 19:49:34 +00:00
|
|
|
fn read_range_aux(
|
2022-05-10 11:16:57 +00:00
|
|
|
&self,
|
|
|
|
partition_hash: Hash,
|
2023-05-09 19:49:34 +00:00
|
|
|
range: db::ValueIter,
|
2021-03-11 15:54:15 +00:00
|
|
|
filter: &Option<F::Filter>,
|
|
|
|
limit: usize,
|
|
|
|
) -> Result<Vec<Arc<ByteBuf>>, Error> {
|
|
|
|
let mut ret = vec![];
|
2022-05-10 11:16:57 +00:00
|
|
|
for item in range {
|
2021-03-11 15:54:15 +00:00
|
|
|
let (key, value) = item?;
|
|
|
|
if &key[..32] != partition_hash.as_slice() {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
let keep = match filter {
|
|
|
|
None => true,
|
|
|
|
Some(f) => {
|
|
|
|
let entry = self.decode_entry(value.as_ref())?;
|
|
|
|
F::matches_filter(&entry, f)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if keep {
|
2022-06-08 08:01:44 +00:00
|
|
|
ret.push(Arc::new(ByteBuf::from(value)));
|
2021-03-11 15:54:15 +00:00
|
|
|
}
|
|
|
|
if ret.len() >= limit {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(ret)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mutation functions
|
2021-03-12 18:57:37 +00:00
|
|
|
// When changing this code, take care of propagating modifications correctly:
|
|
|
|
// - When an entry is modified or deleted, call the updated() function
|
|
|
|
// on the table instance
|
|
|
|
// - When an entry is modified or deleted, add it to the merkle updater's todo list.
|
|
|
|
// This has to be done atomically with the modification for the merkle updater
|
|
|
|
// to maintain consistency. The merkle updater must then be notified with todo_notify.
|
|
|
|
// - When an entry is updated to be a tombstone, add it to the gc_todo tree
|
|
|
|
|
|
|
|
pub(crate) fn update_many<T: Borrow<ByteBuf>>(&self, entries: &[T]) -> Result<(), Error> {
|
2021-03-11 15:54:15 +00:00
|
|
|
for update_bytes in entries.iter() {
|
2021-03-12 18:57:37 +00:00
|
|
|
self.update_entry(update_bytes.borrow().as_slice())?;
|
2021-03-11 15:54:15 +00:00
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn update_entry(&self, update_bytes: &[u8]) -> Result<(), Error> {
|
|
|
|
let update = self.decode_entry(update_bytes)?;
|
|
|
|
|
2023-01-10 10:01:49 +00:00
|
|
|
self.update_entry_with(
|
|
|
|
update.partition_key(),
|
|
|
|
update.sort_key(),
|
|
|
|
|_tx, ent| match ent {
|
|
|
|
Some(mut ent) => {
|
|
|
|
ent.merge(&update);
|
|
|
|
Ok(ent)
|
|
|
|
}
|
|
|
|
None => Ok(update.clone()),
|
|
|
|
},
|
|
|
|
)?;
|
2022-05-10 11:16:57 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn update_entry_with(
|
|
|
|
&self,
|
2022-12-14 09:48:49 +00:00
|
|
|
partition_key: &F::P,
|
|
|
|
sort_key: &F::S,
|
2023-01-10 10:01:49 +00:00
|
|
|
update_fn: impl Fn(&mut db::Transaction, Option<F::E>) -> db::TxOpResult<F::E>,
|
2022-05-10 11:16:57 +00:00
|
|
|
) -> Result<Option<F::E>, Error> {
|
2022-12-14 09:48:49 +00:00
|
|
|
let tree_key = self.tree_key(partition_key, sort_key);
|
|
|
|
|
2023-09-21 13:32:25 +00:00
|
|
|
let changed = self.store.db().transaction(|tx| {
|
2022-12-14 09:48:49 +00:00
|
|
|
let (old_entry, old_bytes, new_entry) = match tx.get(&self.store, &tree_key)? {
|
2022-02-10 11:33:29 +00:00
|
|
|
Some(old_bytes) => {
|
2022-06-08 08:01:44 +00:00
|
|
|
let old_entry = self.decode_entry(&old_bytes).map_err(db::TxError::Abort)?;
|
2023-09-21 13:32:25 +00:00
|
|
|
let new_entry = update_fn(tx, Some(old_entry.clone()))?;
|
2022-02-10 11:33:29 +00:00
|
|
|
(Some(old_entry), Some(old_bytes), new_entry)
|
2021-03-11 15:54:15 +00:00
|
|
|
}
|
2023-09-21 13:32:25 +00:00
|
|
|
None => (None, None, update_fn(tx, None)?),
|
2021-03-16 10:43:58 +00:00
|
|
|
};
|
|
|
|
|
2022-12-14 09:48:49 +00:00
|
|
|
// Changed can be true in two scenarios
|
|
|
|
// Scenario 1: the actual represented value changed,
|
|
|
|
// so of course the messagepack encoding changed as well
|
2022-02-10 11:33:29 +00:00
|
|
|
// Scenario 2: the value didn't change but due to a migration in the
|
2022-12-14 09:48:49 +00:00
|
|
|
// 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.
|
2023-01-03 13:44:47 +00:00
|
|
|
let new_bytes = new_entry
|
|
|
|
.encode()
|
2022-02-10 11:33:29 +00:00
|
|
|
.map_err(Error::RmpEncode)
|
2022-06-08 08:01:44 +00:00
|
|
|
.map_err(db::TxError::Abort)?;
|
2022-12-14 09:48:49 +00:00
|
|
|
let changed = Some(&new_bytes[..]) != old_bytes.as_deref();
|
2022-06-08 08:01:44 +00:00
|
|
|
drop(old_bytes);
|
2022-02-10 11:33:29 +00:00
|
|
|
|
2022-12-14 09:48:49 +00:00
|
|
|
if changed {
|
|
|
|
let new_bytes_hash = blake2sum(&new_bytes);
|
|
|
|
tx.insert(&self.merkle_todo, &tree_key, new_bytes_hash.as_slice())?;
|
|
|
|
tx.insert(&self.store, &tree_key, new_bytes)?;
|
2022-06-08 08:01:44 +00:00
|
|
|
|
|
|
|
self.instance
|
2023-09-21 13:32:25 +00:00
|
|
|
.updated(tx, old_entry.as_ref(), Some(&new_entry))?;
|
2022-06-08 08:01:44 +00:00
|
|
|
|
|
|
|
Ok(Some((new_entry, new_bytes_hash)))
|
2021-03-16 10:43:58 +00:00
|
|
|
} else {
|
|
|
|
Ok(None)
|
|
|
|
}
|
|
|
|
})?;
|
2021-03-11 15:54:15 +00:00
|
|
|
|
2022-06-08 08:01:44 +00:00
|
|
|
if let Some((new_entry, new_bytes_hash)) = changed {
|
2022-02-16 13:23:04 +00:00
|
|
|
self.metrics.internal_update_counter.add(1);
|
|
|
|
|
2021-03-12 18:57:37 +00:00
|
|
|
let is_tombstone = new_entry.is_tombstone();
|
2021-03-16 10:43:58 +00:00
|
|
|
self.merkle_todo_notify.notify_one();
|
2021-03-12 18:57:37 +00:00
|
|
|
if is_tombstone {
|
2021-03-16 17:42:33 +00:00
|
|
|
// We are only responsible for GC'ing this item if we are the
|
|
|
|
// "leader" of the partition, i.e. the first node in the
|
|
|
|
// set of nodes that replicates this partition.
|
|
|
|
// This avoids GC loops and does not change the termination properties
|
|
|
|
// of the GC algorithm, as in all cases GC is suspended if
|
|
|
|
// any node of the partition is unavailable.
|
|
|
|
let pk_hash = Hash::try_from(&tree_key[..32]).unwrap();
|
2023-11-14 13:28:16 +00:00
|
|
|
// TODO: this probably breaks when the layout changes
|
|
|
|
let nodes = self.replication.storage_nodes(&pk_hash);
|
2021-03-16 17:42:33 +00:00
|
|
|
if nodes.first() == Some(&self.system.id) {
|
2022-12-14 09:48:49 +00:00
|
|
|
GcTodoEntry::new(tree_key, new_bytes_hash).save(&self.gc_todo)?;
|
2021-03-16 17:42:33 +00:00
|
|
|
}
|
2021-03-12 18:57:37 +00:00
|
|
|
}
|
2021-03-11 15:54:15 +00:00
|
|
|
|
2022-05-10 11:16:57 +00:00
|
|
|
Ok(Some(new_entry))
|
|
|
|
} else {
|
|
|
|
Ok(None)
|
|
|
|
}
|
2021-03-11 15:54:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn delete_if_equal(self: &Arc<Self>, k: &[u8], v: &[u8]) -> Result<bool, Error> {
|
2022-06-08 08:01:44 +00:00
|
|
|
let removed = self
|
|
|
|
.store
|
|
|
|
.db()
|
2023-09-21 13:32:25 +00:00
|
|
|
.transaction(|tx| match tx.get(&self.store, k)? {
|
2022-06-08 08:01:44 +00:00
|
|
|
Some(cur_v) if cur_v == v => {
|
2022-12-14 09:48:49 +00:00
|
|
|
let old_entry = self.decode_entry(v).map_err(db::TxError::Abort)?;
|
|
|
|
|
2022-06-08 08:01:44 +00:00
|
|
|
tx.remove(&self.store, k)?;
|
|
|
|
tx.insert(&self.merkle_todo, k, vec![])?;
|
|
|
|
|
2023-09-21 13:32:25 +00:00
|
|
|
self.instance.updated(tx, Some(&old_entry), None)?;
|
2022-06-08 08:01:44 +00:00
|
|
|
Ok(true)
|
2021-03-11 15:54:15 +00:00
|
|
|
}
|
2022-06-08 08:01:44 +00:00
|
|
|
_ => Ok(false),
|
|
|
|
})?;
|
2021-03-11 15:54:15 +00:00
|
|
|
|
|
|
|
if removed {
|
2022-02-16 13:23:04 +00:00
|
|
|
self.metrics.internal_delete_counter.add(1);
|
2021-03-16 10:43:58 +00:00
|
|
|
self.merkle_todo_notify.notify_one();
|
2021-03-11 15:54:15 +00:00
|
|
|
}
|
|
|
|
Ok(removed)
|
|
|
|
}
|
|
|
|
|
2021-03-12 20:52:19 +00:00
|
|
|
pub(crate) fn delete_if_equal_hash(
|
|
|
|
self: &Arc<Self>,
|
|
|
|
k: &[u8],
|
|
|
|
vhash: Hash,
|
|
|
|
) -> Result<bool, Error> {
|
2022-06-08 08:01:44 +00:00
|
|
|
let removed = self
|
|
|
|
.store
|
|
|
|
.db()
|
2023-09-21 13:32:25 +00:00
|
|
|
.transaction(|tx| match tx.get(&self.store, k)? {
|
2022-06-08 08:01:44 +00:00
|
|
|
Some(cur_v) if blake2sum(&cur_v[..]) == vhash => {
|
2022-12-14 09:48:49 +00:00
|
|
|
let old_entry = self.decode_entry(&cur_v[..]).map_err(db::TxError::Abort)?;
|
|
|
|
|
2022-06-08 08:01:44 +00:00
|
|
|
tx.remove(&self.store, k)?;
|
|
|
|
tx.insert(&self.merkle_todo, k, vec![])?;
|
|
|
|
|
2023-09-21 13:32:25 +00:00
|
|
|
self.instance.updated(tx, Some(&old_entry), None)?;
|
2022-06-08 08:01:44 +00:00
|
|
|
Ok(true)
|
2021-03-12 18:57:37 +00:00
|
|
|
}
|
2022-06-08 08:01:44 +00:00
|
|
|
_ => Ok(false),
|
|
|
|
})?;
|
2021-03-12 18:57:37 +00:00
|
|
|
|
2022-06-08 08:01:44 +00:00
|
|
|
if removed {
|
|
|
|
self.metrics.internal_delete_counter.add(1);
|
2021-03-16 10:43:58 +00:00
|
|
|
self.merkle_todo_notify.notify_one();
|
2021-03-12 18:57:37 +00:00
|
|
|
}
|
2022-06-08 08:01:44 +00:00
|
|
|
Ok(removed)
|
2021-03-12 18:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-12-14 10:58:06 +00:00
|
|
|
// ---- Insert queue functions ----
|
|
|
|
|
|
|
|
pub(crate) fn queue_insert(
|
|
|
|
&self,
|
|
|
|
tx: &mut db::Transaction,
|
|
|
|
ins: &F::E,
|
|
|
|
) -> db::TxResult<(), Error> {
|
|
|
|
let tree_key = self.tree_key(ins.partition_key(), ins.sort_key());
|
|
|
|
|
|
|
|
let new_entry = match tx.get(&self.insert_queue, &tree_key)? {
|
|
|
|
Some(old_v) => {
|
|
|
|
let mut entry = self.decode_entry(&old_v).map_err(db::TxError::Abort)?;
|
|
|
|
entry.merge(ins);
|
2023-01-03 13:44:47 +00:00
|
|
|
entry.encode()
|
2022-12-14 10:58:06 +00:00
|
|
|
}
|
2023-01-03 13:44:47 +00:00
|
|
|
None => ins.encode(),
|
2022-12-14 10:58:06 +00:00
|
|
|
};
|
2022-12-14 15:16:55 +00:00
|
|
|
let new_entry = new_entry
|
|
|
|
.map_err(Error::RmpEncode)
|
|
|
|
.map_err(db::TxError::Abort)?;
|
2022-12-14 10:58:06 +00:00
|
|
|
tx.insert(&self.insert_queue, &tree_key, new_entry)?;
|
2023-09-21 13:37:28 +00:00
|
|
|
|
|
|
|
let notif = self.insert_queue_notify.clone();
|
|
|
|
tx.on_commit(move || notif.notify_one());
|
2022-12-14 10:58:06 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2021-03-12 18:57:37 +00:00
|
|
|
// ---- Utility functions ----
|
|
|
|
|
2022-05-10 11:16:57 +00:00
|
|
|
pub fn tree_key(&self, p: &F::P, s: &F::S) -> Vec<u8> {
|
2023-05-09 10:38:55 +00:00
|
|
|
[p.hash().as_slice(), s.sort_key()].concat()
|
2021-03-11 15:54:15 +00:00
|
|
|
}
|
|
|
|
|
2022-05-10 11:16:57 +00:00
|
|
|
pub fn decode_entry(&self, bytes: &[u8]) -> Result<F::E, Error> {
|
2023-01-03 13:44:47 +00:00
|
|
|
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);
|
2021-03-11 15:54:15 +00:00
|
|
|
}
|
2023-01-03 13:44:47 +00:00
|
|
|
Err(Error::Message(format!(
|
|
|
|
"Unable to decode entry of {}",
|
|
|
|
F::TABLE_NAME
|
|
|
|
)))
|
|
|
|
}
|
2021-03-11 15:54:15 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-15 18:51:16 +00:00
|
|
|
|
2022-06-08 08:01:44 +00:00
|
|
|
pub fn gc_todo_len(&self) -> Result<usize, Error> {
|
2024-03-08 13:59:56 +00:00
|
|
|
Ok(self.gc_todo.len()?)
|
2021-03-15 18:51:16 +00:00
|
|
|
}
|
2021-03-11 15:54:15 +00:00
|
|
|
}
|