Skip to content

Commit ac0bacc

Browse files
committed
union find excluded ranges
1 parent 39f3380 commit ac0bacc

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

Cargo.lock

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ pyo3-log = "0.12.1"
125125
rancor = "0.1.0"
126126
rand = "0.9.0"
127127
rand_distr = "0.5"
128+
range_union_find = "0.5.0"
128129
ratatui = "0.29"
129130
rayon = "1.10.0"
130131
regex = "1.11.0"

vortex-layout/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ getrandom_v03 = { workspace = true }
2727
itertools = { workspace = true }
2828
log = { workspace = true }
2929
pin-project-lite = { workspace = true }
30+
range_union_find = { workspace = true }
3031
tokio = { workspace = true, features = ["sync"], optional = true }
3132
tracing = { workspace = true, optional = true }
3233
tracing-futures = { workspace = true, features = [

vortex-layout/src/segments.rs

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use std::collections::BTreeMap;
22
use std::fmt::Display;
3-
use std::ops::{Deref, Range};
3+
use std::ops::{Deref, Range, RangeBounds};
44
use std::sync::{Arc, RwLock};
55
use std::task::Poll;
66

77
use async_trait::async_trait;
88
use futures::channel::mpsc;
99
use futures::{SinkExt, Stream, StreamExt};
10+
use range_union_find::RangeUnionFind;
1011
use vortex_buffer::{Buffer, ByteBuffer};
1112
use vortex_error::{VortexExpect, VortexResult, vortex_err};
1213

@@ -119,6 +120,7 @@ impl SegmentCollector {
119120
RowRangePruner {
120121
store: self.store.clone(),
121122
cancellations_tx,
123+
excluded_ranges: Default::default(),
122124
},
123125
SegmentStream {
124126
store: self.store,
@@ -134,18 +136,29 @@ impl SegmentCollector {
134136
pub struct RowRangePruner {
135137
store: Arc<RwLock<SegmentStore>>,
136138
cancellations_tx: mpsc::UnboundedSender<SegmentId>,
139+
excluded_ranges: Arc<RwLock<RangeUnionFind<u64>>>,
137140
}
138141

139142
impl RowRangePruner {
140143
// Remove all segments fully encompassed by the given row range. Removals
141144
// of each matching segment is notified to the cancellation channel.
142145
pub async fn remove(&mut self, to_exclude: Range<u64>) -> VortexResult<()> {
146+
let to_exclude = {
147+
let mut excluded_ranges = self.excluded_ranges.write().vortex_expect("poisoned lock");
148+
excluded_ranges
149+
.insert_range(&to_exclude)
150+
.map_err(|e| vortex_err!("invalid range: {e}"))?;
151+
excluded_ranges
152+
.find_range_with_element(&to_exclude.start)
153+
.map_err(|_| vortex_err!("can not find range just inserted"))?
154+
};
155+
143156
let cancelled_segments: Vec<_> = {
144157
let mut store = self.store.write().vortex_expect("poisoned lock");
145158
let to_remove: Vec<_> = store
146159
.keys()
147-
.skip_while(|key| key.row_start < to_exclude.start)
148-
.take_while(|key| key.row_end <= to_exclude.end)
160+
.skip_while(|key| !to_exclude.contains(&key.row_start))
161+
.take_while(|key| to_exclude.contains(&key.row_end))
149162
.copied()
150163
.collect();
151164
to_remove

0 commit comments

Comments
 (0)