Skip to content

Commit

Permalink
chore: fix naming
Browse files Browse the repository at this point in the history
Signed-off-by: bsbds <[email protected]>
  • Loading branch information
bsbds committed Jun 11, 2024
1 parent f076025 commit dcc763b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
1 change: 0 additions & 1 deletion crates/xline/src/server/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
43 changes: 21 additions & 22 deletions crates/xline/src/storage/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl Index {
}
}

/// Creates a transaction
/// Creates a `IndexState`
pub(crate) fn state(&self) -> IndexState<'_> {
IndexState {
index_ref: self,
Expand Down Expand Up @@ -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<KeyRevision> {
let mut revs = Vec::new();
let mut del_keys = Vec::new();
Expand Down Expand Up @@ -238,7 +237,7 @@ impl Index {
}

/// Maps a closure to an entry
fn map_entry<F, R>(mut op: F) -> impl FnMut(Entry<Vec<u8>, RwLock<Vec<KeyRevision>>>) -> R
fn fmap_entry<F, R>(mut op: F) -> impl FnMut(Entry<Vec<u8>, RwLock<Vec<KeyRevision>>>) -> R
where
F: FnMut((&[u8], &[KeyRevision])) -> R,
{
Expand All @@ -248,15 +247,15 @@ where
}

/// Maps a closure to an entry value
fn map_value<F, R>(mut op: F) -> impl FnMut(Entry<Vec<u8>, RwLock<Vec<KeyRevision>>>) -> R
fn fmap_value<F, R>(mut op: F) -> impl FnMut(Entry<Vec<u8>, RwLock<Vec<KeyRevision>>>) -> R
where
F: FnMut(&[KeyRevision]) -> R,
{
move |entry: Entry<Vec<u8>, RwLock<Vec<KeyRevision>>>| entry.value().map_read(|revs| op(&revs))
}

/// Mutablely maps a closure to an entry value
fn map_value_mut<F, R>(mut op: F) -> impl FnMut(Entry<Vec<u8>, RwLock<Vec<KeyRevision>>>) -> R
fn fmap_value_mut<F, R>(mut op: F) -> impl FnMut(Entry<Vec<u8>, RwLock<Vec<KeyRevision>>>) -> R
where
F: FnMut(&mut Vec<KeyRevision>) -> R,
{
Expand All @@ -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(),
}
}
Expand All @@ -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"));
Expand All @@ -322,7 +321,7 @@ impl IndexOperate for Index {
fn prev_rev(&self, key: &[u8]) -> Option<KeyRevision> {
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<u8>, KeyRevision)>) {
Expand All @@ -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);
}),
);
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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)
}
Expand All @@ -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),
}
}

Expand Down Expand Up @@ -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");
}

Expand Down

0 comments on commit dcc763b

Please sign in to comment.