Skip to content

Commit

Permalink
Get rid of Initial operation state
Browse files Browse the repository at this point in the history
  • Loading branch information
codetheweb committed Dec 2, 2024
1 parent bc6b10d commit fb1dcf7
Show file tree
Hide file tree
Showing 7 changed files with 282 additions and 261 deletions.
3 changes: 0 additions & 3 deletions rust/types/src/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ pub enum Operation {

#[derive(Clone, Debug, PartialEq)]
pub enum MaterializedLogOperation {
// Set when the record is initially read from the segment
// before it is processed based on state of the log.
Initial,
// Set for records that don't exist in the segment and
// have been encountered for the first time in the log.
AddNew,
Expand Down
5 changes: 1 addition & 4 deletions rust/worker/src/execution/operators/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,7 @@ impl<'me> MetadataLogReader<'me> {
let mut updated_offset_ids = RoaringBitmap::new();
let mut user_id_to_offset_id = HashMap::new();
for (log, _) in logs.iter() {
if !matches!(
log.final_operation,
MaterializedLogOperation::Initial | MaterializedLogOperation::AddNew
) {
if !matches!(log.final_operation, MaterializedLogOperation::AddNew) {
updated_offset_ids.insert(log.offset_id);
}
if !matches!(
Expand Down
3 changes: 0 additions & 3 deletions rust/worker/src/segment/distributed_hnsw_segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,6 @@ impl<'a> SegmentWriter<'a> for DistributedHNSWSegmentWriter {
}
}
}
MaterializedLogOperation::Initial => panic!(
"Invariant violation. Mat records should not contain logs in initial state"
),
}
}
Ok(())
Expand Down
1 change: 0 additions & 1 deletion rust/worker/src/segment/metadata_segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,6 @@ impl<'log_records> SegmentWriter<'log_records> for MetadataSegmentWriter<'_> {
}

},
MaterializedLogOperation::Initial => panic!("Not expected mat records in the initial state")
}
}
tracing::info!("Applied {} records to metadata segment", count,);
Expand Down
10 changes: 7 additions & 3 deletions rust/worker/src/segment/record_segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,11 @@ impl<'a> SegmentWriter<'a> for RecordSegmentWriter {
.id_to_user_id
.as_ref()
.unwrap()
.set::<u32, String>("", log_record.offset_id, log_record.user_id.unwrap().to_string())
.set::<u32, String>(
"",
log_record.offset_id,
log_record.user_id.unwrap().to_string(),
)
.await
{
Ok(()) => (),
Expand All @@ -395,7 +399,8 @@ impl<'a> SegmentWriter<'a> for RecordSegmentWriter {
// Set max offset id.
max_new_offset_id = max_new_offset_id.max(log_record.offset_id);
}
MaterializedLogOperation::UpdateExisting | MaterializedLogOperation::OverwriteExisting => {
MaterializedLogOperation::UpdateExisting
| MaterializedLogOperation::OverwriteExisting => {
// Offset id and user id do not need to change. Only data
// needs to change. Blockfile does not have Read then write
// semantics so we'll delete and insert.
Expand Down Expand Up @@ -470,7 +475,6 @@ impl<'a> SegmentWriter<'a> for RecordSegmentWriter {
}
}
}
MaterializedLogOperation::Initial => panic!("Invariant violation. Materialized logs should not have any logs in the initial state")
}
}
self.max_new_offset_id
Expand Down
517 changes: 271 additions & 246 deletions rust/worker/src/segment/types.rs

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion rust/worker/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,9 @@ mod tests {
assert_eq!(response.unwrap_err().code(), tonic::Code::InvalidArgument);
}

fn gen_knn_request(mut scan_operator: Option<chroma_proto::ScanOperator>) -> chroma_proto::KnnPlan {
fn gen_knn_request(
mut scan_operator: Option<chroma_proto::ScanOperator>,
) -> chroma_proto::KnnPlan {
if scan_operator.is_none() {
scan_operator = Some(scan());
}
Expand Down

0 comments on commit fb1dcf7

Please sign in to comment.