Skip to content

Commit d02cc16

Browse files
sjuddConvex, Inc.
authored andcommitted
Pass segments to compact as owned (#26445)
GitOrigin-RevId: 8abe89ec131e710d1266bab5d3b693ebea90c932
1 parent cd40166 commit d02cc16

File tree

4 files changed

+15
-19
lines changed

4 files changed

+15
-19
lines changed

crates/database/src/index_workers/index_meta.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ pub trait SearchIndex: Clone + Debug {
137137
searcher: Arc<dyn Searcher>,
138138
search_storage: Arc<dyn Storage>,
139139
config: &Self::DeveloperConfig,
140-
segments: &Vec<&Self::Segment>,
140+
segments: Vec<Self::Segment>,
141141
) -> anyhow::Result<Self::Segment>;
142142
}
143143

crates/database/src/index_workers/search_compactor.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl<RT: Runtime, T: SearchIndexConfigParser> SearchIndexCompactor<RT, T> {
204204
log_compaction_total_segments(total_compacted_segments, Self::search_type());
205205

206206
let new_segment = self
207-
.compact(&job.developer_config, &segments_to_compact)
207+
.compact(&job.developer_config, segments_to_compact.clone())
208208
.await?;
209209
let stats = new_segment.statistics()?;
210210

@@ -216,11 +216,7 @@ impl<RT: Runtime, T: SearchIndexConfigParser> SearchIndexCompactor<RT, T> {
216216
job.index_id,
217217
job.index_name,
218218
snapshot_ts,
219-
segments_to_compact
220-
.clone()
221-
.into_iter()
222-
.cloned()
223-
.collect_vec(),
219+
segments_to_compact.clone(),
224220
new_segment.clone(),
225221
*SEARCH_WORKER_PASSIVE_PAGES_PER_SECOND,
226222
)
@@ -304,9 +300,13 @@ impl<RT: Runtime, T: SearchIndexConfigParser> SearchIndexCompactor<RT, T> {
304300
developer_config: &'a <T::IndexType as SearchIndex>::DeveloperConfig,
305301
compaction_config: &CompactionConfig,
306302
) -> anyhow::Result<(
307-
Vec<&'a <T::IndexType as SearchIndex>::Segment>,
303+
Vec<<T::IndexType as SearchIndex>::Segment>,
308304
CompactionReason,
309305
)> {
306+
fn to_owned<R: Clone>(borrowed: Vec<&R>) -> Vec<R> {
307+
borrowed.into_iter().cloned().collect_vec()
308+
}
309+
310310
let segments_and_sizes = segments
311311
.iter()
312312
.map(|segment| Ok((segment, segment.total_size_bytes(developer_config)?)))
@@ -327,7 +327,7 @@ impl<RT: Runtime, T: SearchIndexConfigParser> SearchIndexCompactor<RT, T> {
327327
let compact_small =
328328
Self::max_compactable_segments(small_segments, developer_config, compaction_config)?;
329329
if let Some(compact_small) = compact_small {
330-
return Ok((compact_small, CompactionReason::SmallSegments));
330+
return Ok((to_owned(compact_small), CompactionReason::SmallSegments));
331331
}
332332
// Next check to see if we have too many larger segments and if so, compact
333333
// them.
@@ -341,7 +341,7 @@ impl<RT: Runtime, T: SearchIndexConfigParser> SearchIndexCompactor<RT, T> {
341341
compaction_config,
342342
)?;
343343
if let Some(compact_large) = compact_large {
344-
return Ok((compact_large, CompactionReason::LargeSegments));
344+
return Ok((to_owned(compact_large), CompactionReason::LargeSegments));
345345
}
346346

347347
// Finally check to see if any individual segment has a large number of deleted
@@ -361,7 +361,7 @@ impl<RT: Runtime, T: SearchIndexConfigParser> SearchIndexCompactor<RT, T> {
361361
})?
362362
.map(|(segment, _)| vec![segment]);
363363
if let Some(compact_deletes) = compact_deletes {
364-
return Ok((compact_deletes, CompactionReason::Deletes));
364+
return Ok((to_owned(compact_deletes), CompactionReason::Deletes));
365365
}
366366
tracing::trace!(
367367
"Found no segments to compact, segments: {:#?}",
@@ -396,7 +396,7 @@ impl<RT: Runtime, T: SearchIndexConfigParser> SearchIndexCompactor<RT, T> {
396396
async fn compact(
397397
&self,
398398
developer_config: &<T::IndexType as SearchIndex>::DeveloperConfig,
399-
segments: &Vec<&<T::IndexType as SearchIndex>::Segment>,
399+
segments: Vec<<T::IndexType as SearchIndex>::Segment>,
400400
) -> anyhow::Result<<T::IndexType as SearchIndex>::Segment> {
401401
let total_segment_size_bytes: u64 = segments
402402
.iter()

crates/database/src/text_index_worker/text_meta.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,15 +276,13 @@ impl SearchIndex for TextSearchIndex {
276276
searcher: Arc<dyn Searcher>,
277277
search_storage: Arc<dyn Storage>,
278278
_config: &Self::DeveloperConfig,
279-
segments: &Vec<&Self::Segment>,
279+
segments: Vec<Self::Segment>,
280280
) -> anyhow::Result<Self::Segment> {
281281
searcher
282282
.execute_text_compaction(
283283
search_storage,
284284
segments
285-
.clone()
286285
.into_iter()
287-
.cloned()
288286
.map(FragmentedTextStorageKeys::from)
289287
.collect(),
290288
)

crates/database/src/vector_index_worker/vector_meta.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,10 @@ impl SearchIndex for VectorSearchIndex {
280280
searcher: Arc<dyn Searcher>,
281281
search_storage: Arc<dyn Storage>,
282282
config: &Self::DeveloperConfig,
283-
segments: &Vec<&Self::Segment>,
283+
segments: Vec<Self::Segment>,
284284
) -> anyhow::Result<Self::Segment> {
285285
let protos: Vec<pb::searchlight::FragmentedVectorSegmentPaths> = segments
286-
.iter()
287-
.cloned()
288-
.cloned()
286+
.into_iter()
289287
.map(|segment| segment.to_paths_proto())
290288
.collect::<anyhow::Result<Vec<_>>>()?;
291289
searcher

0 commit comments

Comments
 (0)