Skip to content

Commit

Permalink
lazy initialized vnode count
Browse files Browse the repository at this point in the history
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
  • Loading branch information
BugenZhao committed Sep 19, 2024
1 parent 4bfd4e3 commit a516e1b
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/storage/hummock_sdk/src/table_watermark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,10 +536,12 @@ impl TableWatermarks {
debug!("clear stale table watermark below epoch {}", safe_epoch);
let mut result_epoch_watermark = Vec::with_capacity(self.watermarks.len());
let mut set_vnode: HashSet<VirtualNode> = HashSet::new();
let mut vnode_count: Option<usize> = None; // lazy initialized on first occurrence of vnode watermark
while let Some((epoch, _)) = self.watermarks.last() {
if *epoch >= safe_epoch {
let (epoch, watermarks) = self.watermarks.pop().expect("have check Some");
for watermark in watermarks.as_ref() {
vnode_count.get_or_insert_with(|| watermark.vnode_count());
for vnode in watermark.vnode_bitmap.iter_vnodes() {
set_vnode.insert(vnode);
}
Expand All @@ -555,6 +557,7 @@ impl TableWatermarks {
let mut new_vnode_watermarks = Vec::new();
for vnode_watermark in watermarks.as_ref() {
let mut new_set_vnode = Vec::new();
vnode_count.get_or_insert_with(|| vnode_watermark.vnode_count());
for vnode in vnode_watermark.vnode_bitmap.iter_vnodes() {
if set_vnode.insert(vnode) {
new_set_vnode.push(vnode);
Expand Down

0 comments on commit a516e1b

Please sign in to comment.