From dcc763bb748531998f31c184cecd992fed1b8c62 Mon Sep 17 00:00:00 2001 From: bsbds <69835502+bsbds@users.noreply.github.com> Date: Tue, 11 Jun 2024 18:05:19 +0800 Subject: [PATCH] chore: fix naming Signed-off-by: bsbds <69835502+bsbds@users.noreply.github.com> --- crates/xline/src/server/command.rs | 1 - crates/xline/src/storage/index.rs | 43 +++++++++++++++--------------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/crates/xline/src/server/command.rs b/crates/xline/src/server/command.rs index 8024b17a6..999cc1ebe 100644 --- a/crates/xline/src/server/command.rs +++ b/crates/xline/src/server/command.rs @@ -368,7 +368,6 @@ where } }; ops.append(&mut wr_ops); - println!("flush ops: {ops:?}"); let _key_revisions = self.persistent.flush_ops(ops)?; self.lease_storage.mark_lease_synced(wrapper); if !quota_enough { diff --git a/crates/xline/src/storage/index.rs b/crates/xline/src/storage/index.rs index a26459e9f..b6cbbabdc 100644 --- a/crates/xline/src/storage/index.rs +++ b/crates/xline/src/storage/index.rs @@ -60,7 +60,7 @@ impl Index { } } - /// Creates a transaction + /// Creates a `IndexState` pub(crate) fn state(&self) -> IndexState<'_> { IndexState { index_ref: self, @@ -195,10 +195,9 @@ impl Index { )); }); } - - /// Compact a `KeyRevision` by removing the versions with smaller or equal - /// revision than the given atRev except the largest one (If the largest one is - /// a tombstone, it will not be kept). + /// Compact a KeyRevision by removing all versions smaller than or equal to the + /// given atRev, except for the largest one. Note that if the largest version + /// is a tombstone, it will also be removed. pub(super) fn compact(&self, at_rev: i64) -> Vec { let mut revs = Vec::new(); let mut del_keys = Vec::new(); @@ -238,7 +237,7 @@ impl Index { } /// Maps a closure to an entry -fn map_entry(mut op: F) -> impl FnMut(Entry, RwLock>>) -> R +fn fmap_entry(mut op: F) -> impl FnMut(Entry, RwLock>>) -> R where F: FnMut((&[u8], &[KeyRevision])) -> R, { @@ -248,7 +247,7 @@ where } /// Maps a closure to an entry value -fn map_value(mut op: F) -> impl FnMut(Entry, RwLock>>) -> R +fn fmap_value(mut op: F) -> impl FnMut(Entry, RwLock>>) -> R where F: FnMut(&[KeyRevision]) -> R, { @@ -256,7 +255,7 @@ where } /// Mutablely maps a closure to an entry value -fn map_value_mut(mut op: F) -> impl FnMut(Entry, RwLock>>) -> R +fn fmap_value_mut(mut op: F) -> impl FnMut(Entry, RwLock>>) -> R where F: FnMut(&mut Vec) -> R, { @@ -271,18 +270,18 @@ impl IndexOperate for Index { RangeType::OneKey => self .inner .get(key) - .and_then(map_value(|revs| Index::get_revision(revs, revision))) + .and_then(fmap_value(|revs| Index::get_revision(revs, revision))) .map(|rev| vec![rev]) .unwrap_or_default(), RangeType::AllKeys => self .inner .iter() - .filter_map(map_value(|revs| Index::get_revision(revs, revision))) + .filter_map(fmap_value(|revs| Index::get_revision(revs, revision))) .collect(), RangeType::Range => self .inner .range(KeyRange::new(key, range_end)) - .filter_map(map_value(|revs| Index::get_revision(revs, revision))) + .filter_map(fmap_value(|revs| Index::get_revision(revs, revision))) .collect(), } } @@ -299,7 +298,7 @@ impl IndexOperate for Index { let _ignore = self.inner.insert(key, RwLock::new(vec![new_rev])); (new_rev, None) }, - map_value_mut(|revisions| { + fmap_value_mut(|revisions| { let last = *revisions .last() .unwrap_or_else(|| unreachable!("empty revision list")); @@ -322,7 +321,7 @@ impl IndexOperate for Index { fn prev_rev(&self, key: &[u8]) -> Option { self.inner .get(key) - .and_then(map_value(|revs| revs.last().copied())) + .and_then(fmap_value(|revs| revs.last().copied())) } fn insert(&self, key_revisions: Vec<(Vec, KeyRevision)>) { @@ -331,7 +330,7 @@ impl IndexOperate for Index { || { let _ignore = self.inner.insert(key, RwLock::new(vec![revision])); }, - map_value_mut(|revs| { + fmap_value_mut(|revs| { revs.push(revision); }), ); @@ -351,7 +350,7 @@ impl IndexOperate for Index { .inner .get(key) .into_iter() - .filter_map(map_value_mut(|revs| { + .filter_map(fmap_value_mut(|revs| { Index::gen_del_revision(revs, revision, sub_revision) })) .collect(); @@ -404,7 +403,7 @@ impl IndexState<'_> { let index = &self.index_ref.inner; while let Some((key, state_revs)) = self.state.lock().pop_first() { let entry = index.get_or_insert(key, RwLock::default()); - map_value_mut(|revs| { + fmap_value_mut(|revs| { revs.extend_from_slice(&state_revs); })(entry); } @@ -424,7 +423,7 @@ impl IndexState<'_> { let index = &self.index_ref.inner; let mut result = index .get(key) - .map(map_value(<[KeyRevision]>::to_vec)) + .map(fmap_value(<[KeyRevision]>::to_vec)) .unwrap_or_default(); if let Some(revs) = state.get(key) { result.extend_from_slice(revs); @@ -439,7 +438,7 @@ impl IndexState<'_> { let state = self.state.lock(); for (key, value) in index .range(range.clone()) - .map(map_entry(|(k, v)| (k.to_vec(), v.to_vec()))) + .map(fmap_entry(|(k, v)| (k.to_vec(), v.to_vec()))) .chain(state.range(range).map(|(k, v)| (k.clone(), v.clone()))) { let entry = map.entry(key.clone()).or_default(); @@ -455,7 +454,7 @@ impl IndexState<'_> { let state = self.state.lock(); for (key, value) in index .iter() - .map(map_entry(|(k, v)| (k.to_vec(), v.to_vec()))) + .map(fmap_entry(|(k, v)| (k.to_vec(), v.to_vec()))) .chain(state.clone().into_iter()) { let entry = map.entry(key.clone()).or_default(); @@ -575,7 +574,7 @@ impl IndexOperate for IndexState<'_> { (new_rev, last) } (Some(e), btree_map::Entry::Vacant(se)) => { - let (new_rev, last) = map_value(next_rev)(e); + let (new_rev, last) = fmap_value(next_rev)(e); let _ignore = se.insert(vec![new_rev]); (new_rev, last) } @@ -589,7 +588,7 @@ impl IndexOperate for IndexState<'_> { match (index.get(key), state.get(key)) { (None, None) => None, (None | Some(_), Some(revs)) => revs.last().copied(), - (Some(e), None) => map_value(|revs| revs.last().copied())(e), + (Some(e), None) => fmap_value(|revs| revs.last().copied())(e), } } @@ -634,7 +633,7 @@ mod test { index .inner .get(key.as_ref()) - .map(map_value(|revs| assert_eq!(revs, expected_values))) + .map(fmap_value(|revs| assert_eq!(revs, expected_values))) .expect("index entry should not be None"); }