-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[PERF]: parallelize applying log to segment types #3134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
codetheweb
wants to merge
10
commits into
feat-materialize-operator
from
perf-parallelize-applying-log
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e52824c
[CLN]: make materialization function rather than struct
codetheweb 3bc5002
Fix test
codetheweb 453a9ff
[ENH]: move materialization into operator
codetheweb 72989c0
Clean
codetheweb afc7c5a
Fix writers init
codetheweb cb43e94
Cleanup
codetheweb decba18
[PERF]: parallelize applying log to segment types
codetheweb 9ed5a63
fix changes after rebase
codetheweb 7245657
Span name actually can be dynamic :)
codetheweb f8ab4ac
Use LazyCell for segments, fix write counter
codetheweb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
rust/worker/src/execution/operators/apply_log_to_segment_writer.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
use super::materialize_logs::MaterializeLogOutput; | ||
use crate::execution::operator::Operator; | ||
use crate::segment::metadata_segment::MetadataSegmentError; | ||
use crate::segment::record_segment::ApplyMaterializedLogError; | ||
use crate::segment::record_segment::RecordSegmentReaderCreationError; | ||
use crate::segment::LogMaterializerError; | ||
use crate::segment::SegmentWriter; | ||
use async_trait::async_trait; | ||
use chroma_error::ChromaError; | ||
use chroma_error::ErrorCodes; | ||
use std::sync::Arc; | ||
use thiserror::Error; | ||
use tracing::Instrument; | ||
|
||
#[derive(Error, Debug)] | ||
pub enum ApplyLogToSegmentWriterOperatorError { | ||
#[error("Preparation for log materialization failed {0}")] | ||
LogMaterializationPreparationError(#[from] RecordSegmentReaderCreationError), | ||
#[error("Log materialization failed {0}")] | ||
LogMaterializationError(#[from] LogMaterializerError), | ||
#[error("Materialized logs failed to apply {0}")] | ||
ApplyMaterializedLogsError(#[from] ApplyMaterializedLogError), | ||
#[error("Materialized logs failed to apply {0}")] | ||
ApplyMaterializedLogsErrorMetadataSegment(#[from] MetadataSegmentError), | ||
} | ||
|
||
impl ChromaError for ApplyLogToSegmentWriterOperatorError { | ||
fn code(&self) -> ErrorCodes { | ||
match self { | ||
ApplyLogToSegmentWriterOperatorError::LogMaterializationPreparationError(e) => e.code(), | ||
ApplyLogToSegmentWriterOperatorError::LogMaterializationError(e) => e.code(), | ||
ApplyLogToSegmentWriterOperatorError::ApplyMaterializedLogsError(e) => e.code(), | ||
ApplyLogToSegmentWriterOperatorError::ApplyMaterializedLogsErrorMetadataSegment(e) => { | ||
e.code() | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct ApplyLogToSegmentWriterOperator {} | ||
|
||
impl ApplyLogToSegmentWriterOperator { | ||
pub fn new() -> Box<Self> { | ||
Box::new(ApplyLogToSegmentWriterOperator {}) | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct ApplyLogToSegmentWriterInput<Writer: SegmentWriter> { | ||
segment_writer: Writer, | ||
materialize_log_output: Arc<MaterializeLogOutput>, | ||
} | ||
|
||
impl<Writer: SegmentWriter> ApplyLogToSegmentWriterInput<Writer> { | ||
pub fn new(segment_writer: Writer, materialize_log_output: Arc<MaterializeLogOutput>) -> Self { | ||
ApplyLogToSegmentWriterInput { | ||
segment_writer, | ||
materialize_log_output, | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct ApplyLogToSegmentWriterOutput {} | ||
|
||
#[async_trait] | ||
impl<Writer: SegmentWriter + Send + Sync + Clone> | ||
Operator<ApplyLogToSegmentWriterInput<Writer>, ApplyLogToSegmentWriterOutput> | ||
for ApplyLogToSegmentWriterOperator | ||
{ | ||
type Error = ApplyLogToSegmentWriterOperatorError; | ||
|
||
fn get_name(&self) -> &'static str { | ||
"ApplyLogToSegmentWriterOperator" | ||
} | ||
|
||
async fn run( | ||
&self, | ||
input: &ApplyLogToSegmentWriterInput<Writer>, | ||
) -> Result<ApplyLogToSegmentWriterOutput, Self::Error> { | ||
let materialized_chunk = input.materialize_log_output.get_materialized_records(); | ||
|
||
// Apply materialized records. | ||
match input | ||
.segment_writer | ||
.apply_materialized_log_chunk(materialized_chunk.clone()) | ||
.instrument(tracing::trace_span!( | ||
"Apply materialized logs", | ||
otel.name = format!( | ||
"Apply materialized logs to segment writer {}", | ||
input.segment_writer.get_name() | ||
), | ||
segment = input.segment_writer.get_name() | ||
)) | ||
.await | ||
{ | ||
Ok(()) => (), | ||
Err(e) => { | ||
return Err(ApplyLogToSegmentWriterOperatorError::ApplyMaterializedLogsError(e)); | ||
} | ||
} | ||
|
||
Ok(ApplyLogToSegmentWriterOutput {}) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.