Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: stackoverflow issue when there are lots of empty slots in mem_store #558

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 32 additions & 29 deletions crates/kv-store/src/mem_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,43 +386,46 @@ where
{
type Item = (Bytes, Bytes);
fn next(&mut self) -> Option<Self::Item> {
if self.current_sstable.is_none() {
if let Some((k, v)) = self.sst.next() {
self.current_sstable = Some((k, v));
loop {
if self.current_sstable.is_none() {
if let Some((k, v)) = self.sst.next() {
self.current_sstable = Some((k, v));
}
}
}

if self.current_mem.is_none() && self.back_mem.is_some() {
std::mem::swap(&mut self.back_mem, &mut self.current_mem);
}
let ans = match (&self.current_mem, &self.current_sstable) {
(Some((mem_key, _)), Some((iter_key, _))) => match mem_key.cmp(iter_key) {
Ordering::Less => self.current_mem.take().inspect(|_kv| {
if self.current_mem.is_none() && self.back_mem.is_some() {
std::mem::swap(&mut self.back_mem, &mut self.current_mem);
}
let ans = match (&self.current_mem, &self.current_sstable) {
(Some((mem_key, _)), Some((iter_key, _))) => match mem_key.cmp(iter_key) {
Ordering::Less => self.current_mem.take().inspect(|_kv| {
self.current_mem = self.mem.next();
}),
Ordering::Equal => {
self.current_sstable.take();
self.current_mem.take().inspect(|_kv| {
self.current_mem = self.mem.next();
})
}
Ordering::Greater => self.current_sstable.take(),
},
(Some(_), None) => self.current_mem.take().inspect(|_kv| {
self.current_mem = self.mem.next();
}),
Ordering::Equal => {
self.current_sstable.take();
self.current_mem.take().inspect(|_kv| {
self.current_mem = self.mem.next();
})
}
Ordering::Greater => self.current_sstable.take(),
},
(Some(_), None) => self.current_mem.take().inspect(|_kv| {
self.current_mem = self.mem.next();
}),
(None, Some(_)) => self.current_sstable.take(),
(None, None) => None,
};
(None, Some(_)) => self.current_sstable.take(),
(None, None) => None,
};

if self.filter_empty {
if let Some((_k, v)) = &ans {
if v.is_empty() {
return self.next();
if self.filter_empty {
if let Some((_k, v)) = &ans {
if v.is_empty() {
continue;
}
}
}

return ans;
}
ans
}
}

Expand Down
Loading