Skip to content

Commit

Permalink
chore: apply suggestions from CR
Browse files Browse the repository at this point in the history
  • Loading branch information
WenyXu committed Oct 18, 2023
1 parent d67801e commit 2fa46ed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 24 deletions.
30 changes: 9 additions & 21 deletions src/common/meta/src/kv_backend/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
// limitations under the License.

use std::any::Any;
use std::borrow::BorrowMut;
use std::collections::btree_map::Entry;
use std::collections::BTreeMap;
use std::fmt::{Display, Formatter};
use std::marker::PhantomData;
use std::ops::RangeBounds;
use std::sync::RwLock;

use async_trait::async_trait;
Expand Down Expand Up @@ -93,13 +95,13 @@ impl<T: ErrorExt + Send + Sync + 'static> KvBackend for MemoryKvBackend<T> {
let iter = kvs.range(range);

let mut more = false;
let mut counter = 0usize;
let mut took = 0;

let kvs = iter
.take_while(|_| {
let take = counter != limit as usize || limit == 0;
counter += 1;
more = counter > limit as usize && limit != 0;
let take = limit == 0 || took != limit;
took += 1;
more = limit > 0 && took > limit;

take
})
Expand Down Expand Up @@ -216,25 +218,11 @@ impl<T: ErrorExt + Send + Sync + 'static> KvBackend for MemoryKvBackend<T> {

let mut kvs = self.kvs.write().unwrap();

let keys = kvs
.range(range)
.map(|(key, _)| key.clone())
let prev_kvs = kvs
.extract_if(|key, _| range.contains(key))
.map(Into::into)
.collect::<Vec<_>>();

let mut prev_kvs = if prev_kv {
Vec::with_capacity(keys.len())
} else {
vec![]
};

for key in keys {
if let Some(value) = kvs.remove(&key) {
if prev_kv {
prev_kvs.push((key.clone(), value).into())
}
}
}

Ok(DeleteRangeResponse {
deleted: prev_kvs.len() as i64,
prev_kvs: if prev_kv { prev_kvs } else { vec![] },
Expand Down
4 changes: 1 addition & 3 deletions src/log-store/src/raft_engine/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ impl KvBackend for RaftEngineBackend {
} = req;

let (start_key, end_key) = match (start, end) {
(Included(start), Included(_)) => {
(Some(start.clone()), Some(get_next_prefix_key(&start)))
}
(Included(start), Included(end)) => (Some(start), Some(get_next_prefix_key(&end))),
(Unbounded, Unbounded) => (None, None),
(Included(start), Excluded(end)) => (Some(start), Some(end)),
(Included(start), Unbounded) => (Some(start), None),
Expand Down

0 comments on commit 2fa46ed

Please sign in to comment.