diff options
author | Alex Auvolat <alex@adnab.me> | 2022-02-24 14:59:49 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-03-14 10:54:25 +0100 |
commit | 2377a92f6b64165be84f53722f30c21e9c8a0b3e (patch) | |
tree | 4a45feb7bd73bd541cc5f8552423cb9d46c8e26d /src/table | |
parent | 203e8d2c345dabee56e31aebf88b706df5aa72e5 (diff) | |
download | garage-2377a92f6b64165be84f53722f30c21e9c8a0b3e.tar.gz garage-2377a92f6b64165be84f53722f30c21e9c8a0b3e.zip |
Add wrapper over sled tree to count items (used for big queues)
Diffstat (limited to 'src/table')
-rw-r--r-- | src/table/data.rs | 4 | ||||
-rw-r--r-- | src/table/gc.rs | 5 | ||||
-rw-r--r-- | src/table/metrics.rs | 8 |
3 files changed, 13 insertions, 4 deletions
diff --git a/src/table/data.rs b/src/table/data.rs index 4293e395..ff7965f5 100644 --- a/src/table/data.rs +++ b/src/table/data.rs @@ -7,6 +7,7 @@ use tokio::sync::Notify; use garage_util::data::*; use garage_util::error::*; +use garage_util::sled_counter::SledCountedTree; use garage_rpc::system::System; @@ -27,7 +28,7 @@ pub struct TableData<F: TableSchema, R: TableReplication> { pub(crate) merkle_tree: sled::Tree, pub(crate) merkle_todo: sled::Tree, pub(crate) merkle_todo_notify: Notify, - pub(crate) gc_todo: sled::Tree, + pub(crate) gc_todo: SledCountedTree, pub(crate) metrics: TableMetrics, } @@ -52,6 +53,7 @@ where let gc_todo = db .open_tree(&format!("{}:gc_todo_v2", F::TABLE_NAME)) .expect("Unable to open DB tree"); + let gc_todo = SledCountedTree::new(gc_todo); let metrics = TableMetrics::new(F::TABLE_NAME, merkle_todo.clone(), gc_todo.clone()); diff --git a/src/table/gc.rs b/src/table/gc.rs index 8d0a5bef..2a05b6ae 100644 --- a/src/table/gc.rs +++ b/src/table/gc.rs @@ -14,6 +14,7 @@ use tokio::sync::watch; use garage_util::data::*; use garage_util::error::*; +use garage_util::sled_counter::SledCountedTree; use garage_util::time::*; use garage_rpc::system::System; @@ -362,7 +363,7 @@ impl GcTodoEntry { } /// Saves the GcTodoEntry in the gc_todo tree - pub(crate) fn save(&self, gc_todo_tree: &sled::Tree) -> Result<(), Error> { + pub(crate) fn save(&self, gc_todo_tree: &SledCountedTree) -> Result<(), Error> { gc_todo_tree.insert(self.todo_table_key(), self.value_hash.as_slice())?; Ok(()) } @@ -372,7 +373,7 @@ impl GcTodoEntry { /// This is usefull to remove a todo entry only under the condition /// that it has not changed since the time it was read, i.e. /// what we have to do is still the same - pub(crate) fn remove_if_equal(&self, gc_todo_tree: &sled::Tree) -> Result<(), Error> { + pub(crate) fn remove_if_equal(&self, gc_todo_tree: &SledCountedTree) -> Result<(), Error> { let _ = gc_todo_tree.compare_and_swap::<_, _, Vec<u8>>( &self.todo_table_key()[..], Some(self.value_hash), diff --git a/src/table/metrics.rs b/src/table/metrics.rs index 548bf0d6..752a2a6d 100644 --- a/src/table/metrics.rs +++ b/src/table/metrics.rs @@ -1,5 +1,7 @@ use opentelemetry::{global, metrics::*, KeyValue}; +use garage_util::sled_counter::SledCountedTree; + /// TableMetrics reference all counter used for metrics pub struct TableMetrics { pub(crate) _merkle_todo_len: ValueObserver<u64>, @@ -17,7 +19,11 @@ pub struct TableMetrics { pub(crate) sync_items_received: Counter<u64>, } impl TableMetrics { - pub fn new(table_name: &'static str, merkle_todo: sled::Tree, gc_todo: sled::Tree) -> Self { + pub fn new( + table_name: &'static str, + merkle_todo: sled::Tree, + gc_todo: SledCountedTree, + ) -> Self { let meter = global::meter(table_name); TableMetrics { _merkle_todo_len: meter |