Skip to content
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

[ENH] Add log materializer v2 taking care of updates/deletes/upserts + wire compactor to use it + clean up old abstraction #2239

Merged
merged 8 commits into from
May 30, 2024

Conversation

sanketkedia
Copy link
Contributor

@sanketkedia sanketkedia commented May 22, 2024

Description of changes

Summarize the changes made by this PR.

  • New functionality
    Adds log materializer v2 taking care of updates/deletes/upserts.
    Wires the compactor (i.e. record segment writer and hnsw index writer) to use the new materialization
    Cleans up the old needless abstraction

Test plan

Rust test

  • Tests pass locally with pytest for python, yarn test for js, cargo test for rust

Documentation Changes

None

Copy link

vercel bot commented May 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
chroma ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 30, 2024 4:58pm

Copy link

Reviewer Checklist

Please leverage this checklist to ensure your code review is thorough before approving

Testing, Bugs, Errors, Logs, Documentation

  • Can you think of any use case in which the code does not behave as intended? Have they been tested?
  • Can you think of any inputs or external events that could break the code? Is user input validated and safe? Have they been tested?
  • If appropriate, are there adequate property based tests?
  • If appropriate, are there adequate unit tests?
  • Should any logging, debugging, tracing information be added or removed?
  • Are error messages user-friendly?
  • Have all documentation changes needed been made?
  • Have all non-obvious changes been commented?

System Compatibility

  • Are there any potential impacts on other parts of the system or backward compatibility?
  • Does this change intersect with any items on our roadmap, and if so, is there a plan for fitting them together?

Quality

  • Is this code of a unexpectedly high quality (Readability, Modularity, Intuitiveness)

pub(crate) trait SegmentWriter {
fn apply_materialized_log_chunk(&self, records: Chunk<MaterializedLogRecord>);
fn apply_log_chunk(&self, records: Chunk<LogRecord>);
pub(crate) trait SegmentWriter<'a> {
Copy link
Collaborator

@HammadB HammadB May 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we let the compiler infer this lifetime ( i think thats how it was working before?) - otherwise prefer explicit named lifetimes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no this was complaining. For the distributed hnsw segment writer it was complaining with error[E0726]: implicit elided lifetime not allowed here. Don't understand it fully yet though

.max_offset_id
.as_ref()
.unwrap()
.set("", MAX_OFFSET_ID, log_record.offset_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember where we landed on the offset_id reuse conversation. @Ishiihara @HammadB if a record is deleted and then a new record is added, will the new record always get a brand new (and therefore highest) offset ID or do we reuse old offset IDs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently we don't track "released" ids and always increment the counter when assigning a new one

impl ChromaError for WriteSegmentsOperatorError {
fn code(&self) -> crate::errors::ErrorCodes {
match self {
WriteSegmentsOperatorError::LogMaterializationPreparationError(e) => e.code(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't seen this before -- usually we use these impls to map crate-specific errors to one of the standard grpc error codes. Does .code() know how to do so correctly?

Copy link
Collaborator

@HammadB HammadB May 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its already a Box dyn ChromaError .code() comes from that trait and just forwards the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#[error("Preparation for log materialization failed {0}")]
    LogMaterializationPreparationError(#[from] RecordSegmentReaderCreationError),

The LogMaterializationPreparationError composes on top of RecordSegmentReaderCreationError which has an error code that is mapped to one of the standard grpc error codes. So e.code() will resolve to that

// If log has [Insert, Update, Update] then final operation is Insert.
// If log has [Update, Update] then final operation is Update.
// All Upserts are converted to Update or Insert as the final operation.
// For e.g. if log has [Insert, Upsert] then final operation is update.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case isn't the final operation Insert?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes my bad. The code is still correct though

// E.g. if has log has [Insert(a: h), Update(a: b, c: d), Update(a: e, f: g)] then this
// will contain (a: e, c: d, f: g). This is None if the final operation
// above is Delete.
pub(super) metadata_to_be_merged: Option<Metadata>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we represent metadata deletions? For example, if I insert a record with {'a': 1, 'b': 2} and then I set {'a': None}' to represent clearing that metadata key on the record

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I am following up on that in the next PR

Copy link
Collaborator

@HammadB HammadB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer if we named the lifetimes, otherwise I believe this looks good.

@sanketkedia sanketkedia merged commit cc69b65 into main May 30, 2024
45 of 47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants