@@ -108,7 +108,7 @@ pub struct CompactOrchestrator {
108
108
max_compaction_size : usize ,
109
109
max_partition_size : usize ,
110
110
// Populated during the compaction process
111
- cached_segments : Option < Vec < Segment > > ,
111
+ cached_segments : OnceCell < Vec < Segment > > ,
112
112
writers : OnceCell < (
113
113
RecordSegmentWriter ,
114
114
Box < DistributedHNSWSegmentWriter > ,
@@ -197,7 +197,7 @@ impl CompactOrchestrator {
197
197
result_channel,
198
198
max_compaction_size,
199
199
max_partition_size,
200
- cached_segments : None ,
200
+ cached_segments : OnceCell :: new ( ) ,
201
201
writers : OnceCell :: new ( ) ,
202
202
}
203
203
}
@@ -310,7 +310,7 @@ impl CompactOrchestrator {
310
310
} ,
311
311
} ;
312
312
313
- self . num_write_tasks = partitions. len ( ) as i32 ;
313
+ self . num_write_tasks = partitions. len ( ) as i32 * 3 ; // 3 different segment types
314
314
for partition in partitions. iter ( ) {
315
315
let operator = MaterializeLogOperator :: new ( ) ;
316
316
let input = MaterializeLogInput :: new (
@@ -426,17 +426,14 @@ impl CompactOrchestrator {
426
426
}
427
427
428
428
async fn get_all_segments ( & mut self ) -> Result < Vec < Segment > , GetSegmentsError > {
429
- if let Some ( segments) = & self . cached_segments {
430
- return Ok ( segments. clone ( ) ) ;
431
- }
432
-
433
- let segments = self
434
- . sysdb
435
- . get_segments ( None , None , None , self . collection_id )
436
- . await ?;
437
-
438
- self . cached_segments = Some ( segments. clone ( ) ) ;
439
- Ok ( segments)
429
+ self . cached_segments
430
+ . get_or_try_init ( || async {
431
+ self . sysdb
432
+ . get_segments ( None , None , None , self . collection_id )
433
+ . await
434
+ } )
435
+ . await
436
+ . cloned ( )
440
437
}
441
438
442
439
async fn get_segment (
0 commit comments