Skip to content

Commit

Permalink
Fix possible race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
codetheweb committed Dec 27, 2024
1 parent 6f627fb commit 220a7ee
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions rust/worker/src/execution/orchestration/compact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ impl CompactOrchestrator {

async fn dispatch_segment_writer_commit(
&mut self,
segment_writer: ChromaSegmentWriter<'static>, // todo
segment_writer: ChromaSegmentWriter<'static>,
self_address: Box<
dyn ReceiverForMessage<
TaskResult<CommitSegmentWriterOutput, CommitSegmentWriterOperatorError>,
Expand Down Expand Up @@ -753,16 +753,14 @@ impl Handler<TaskResult<MaterializeLogsResult, MaterializeLogOperatorError>>
message: TaskResult<MaterializeLogsResult, MaterializeLogOperatorError>,
ctx: &crate::system::ComponentContext<CompactOrchestrator>,
) {
self.num_uncompleted_materialization_tasks -= 1;

let materialized_result = match self.ok_or_terminate(message.into_inner(), ctx) {
Some(result) => result,
None => return,
};

if materialized_result.is_empty() {
// We check the number of remaining materialization tasks to prevent a race condition
if self.num_uncompleted_materialization_tasks == 0
if self.num_uncompleted_materialization_tasks == 1
&& self.num_uncompleted_tasks_by_segment.is_empty()
{
// There is nothing to flush, proceed to register
Expand All @@ -776,6 +774,8 @@ impl Handler<TaskResult<MaterializeLogsResult, MaterializeLogOperatorError>>
)
.await;
}

self.num_uncompleted_materialization_tasks -= 1;
}
}

Expand Down

0 comments on commit 220a7ee

Please sign in to comment.