Skip to content

[BUG] Coalesce when multiple collections return the same info to compact #4946

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

Merged
merged 2 commits into from
Jun 26, 2025

Conversation

rescrv
Copy link
Contributor

@rescrv rescrv commented Jun 25, 2025

Description of changes

If the same collection was returned twice, the results would be non-deterministic.

Test plan

CI + a new passing unit test.

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

Documentation Changes

N/A

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)

Copy link
Contributor

propel-code-bot bot commented Jun 25, 2025

Deduplicate Collection Info During Compaction Logic in grpc_log.rs

This PR addresses a bug in the compaction process where duplicate collection information could result in non-deterministic behavior. The core logic in grpc_log.rs has been modified to consistently coalesce and deduplicate collection info entries, ensuring that each collection appears only once, and the entry with the smallest (oldest) log offset is selected if duplicates exist. Additional comments have been added to clarify the deduplication approach, and unit testing has been improved to cover these changes.

Key Changes:
• Moved collection info aggregation logic into a new post_process_get_all() function
• Implemented deduplication: sort all collections by (collection_id, first_log_offset) and deduplicate by collection_id, keeping the entry with the smallest offset
• Added descriptive in-code comments explaining the deduplication rationale
• Introduced a new unit test (post_process_get_all_returns_smaller_first_log_offset) to verify correct deduplication behavior when the same collection appears multiple times

Affected Areas:
• rust/log/src/grpc_log.rs
• Collection info compaction logic
• Unit tests for collection compaction

This summary was automatically generated by @propel-code-bot

Comment on lines +654 to +655
all_collections.sort_by_key(|x| (x.collection_id, x.first_log_offset));
all_collections.dedup_by_key(|x| x.collection_id);
Copy link
Contributor

Choose a reason for hiding this comment

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

Mind leave a note on what is happening here?

@rescrv rescrv enabled auto-merge (squash) June 25, 2025 23:58
@rescrv rescrv disabled auto-merge June 26, 2025 00:23
@rescrv rescrv merged commit 28b551b into main Jun 26, 2025
111 of 113 checks passed
rescrv added a commit that referenced this pull request Jun 26, 2025
…act (#4946)

## Description of changes

If the same collection was returned twice, the results would be
non-deterministic.

## Test plan

CI + a new passing unit test.

- [X] Tests pass locally with `pytest` for python, `yarn test` for js,
`cargo test` for rust

## Documentation Changes

N/A
rescrv added a commit that referenced this pull request Jun 27, 2025
## Description of changes

Included changes

- **[ENH] Purge dirty log in background at the end of scheduled
compaction (#4915)**
- **[ENH] Move Log GC to operator (#4919)**
- **[BUG]  Do not leak tokio tasks in the log service. (#4936)**
- **[BUG] Log GC offset should be one above minimum compaction offset
(#4938)**
- **[ENH] Make roll dirty log always converge to coalesce everything.
(#4927)**
- **[BUG] Coalesce when multiple collections return the same info to
compact (#4946)**
- **[BUG]  Enrich from the manifest if a cursor doesn't exist. (#4947)**
- **[ENH] If the dirty log fails with LogContentionDurable, do not fail
the operation. (#4953)**
- **[ENH]  Warn, not error, if dirty log has no cursor. (#4952)**
- **[ENH]  Cancellation safety for append_batch. (#4959)**

## Test plan

CI

## Documentation Changes

N/A

---------

Co-authored-by: Macronova <60079945+Sicheng-Pan@users.noreply.github.com>
@rescrv rescrv deleted the rescrv/getall branch August 1, 2025 18:18
Inventrohyder pushed a commit to Inventrohyder/chroma that referenced this pull request Aug 5, 2025
…act (chroma-core#4946)

## Description of changes

If the same collection was returned twice, the results would be
non-deterministic.

## Test plan

CI + a new passing unit test.

- [X] Tests pass locally with `pytest` for python, `yarn test` for js,
`cargo test` for rust

## Documentation Changes

N/A
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.

2 participants