GreptimeTeam / greptimedb

An open-source, cloud-native, unified time series database for metrics, logs and events with SQL/PromQL supported. Available on GreptimeCloud.
https://greptime.com/
Apache License 2.0
4.35k stars 315 forks source link

fix: prune memtable/files range independently in each partition #4998

Closed evenyag closed 3 days ago

evenyag commented 1 week ago

I hereby agree to the terms of the GreptimeDB CLA.

Refer to a related PR or issue link (optional)

https://github.com/GreptimeTeam/greptimedb/issues/4828

What's changed and what's your intention?

This PR removes the scanner level global lock for range builders. Each partition will create a range builder for a file to prune. In UnorderedScan, each partition may prune the same file multiple times. But this usually doesn't increase the total query time.

The global lock may have potential issues while the query engine is doing something like streaming merge. Since partitions may wait for each other. If the top partition currently polling is waiting for a lock owned by another partition in the merge heap, then the top partition may never have a chance to get the lock.

Checklist

Summary by CodeRabbit

Release Notes

coderabbitai[bot] commented 1 week ago

Walkthrough

The pull request introduces several modifications across multiple files in the mito2 module. Key changes include enhancements to logging levels in twcs.rs, the addition of new metrics in metrics.rs, and the introduction of new structures and methods for range management in range.rs. Other files, such as scan_region.rs, scan_util.rs, seq_scan.rs, and unordered_scan.rs, have been updated to incorporate the new RangeBuilderList, improving the handling of range building during scanning operations. Overall, the changes focus on refining logging, enhancing metrics tracking, and improving range management.

Changes

File Path Change Summary
src/mito2/src/compaction/twcs.rs Changed logging level from debug to trace in build_output method; adjusted logging statements for compaction.
src/mito2/src/metrics.rs Added constant PARTITION_LABEL and static reference IN_PROGRESS_SCAN for tracking in-progress scans.
src/mito2/src/read/range.rs Introduced FileRangeBuilder, MemRangeBuilder, and RangeBuilderList for managing file and memory ranges.
src/mito2/src/read/scan_region.rs Removed unused imports and RangeBuilderList; updated prune_memtable and prune_file methods for clarity.
src/mito2/src/read/scan_util.rs Added in_progress_scan metric to PartitionMetricsInner; updated scan_mem_ranges and scan_file_ranges methods.
src/mito2/src/read/seq_scan.rs Updated methods to include range_builder_list for managing range building in scans.
src/mito2/src/read/unordered_scan.rs Enhanced scan_partition_range and scan_partition_impl methods with range_builder_list for improved scanning.

Possibly related PRs

Suggested labels

breaking-change

Suggested reviewers

Poem

πŸ‡ In the forest where data flows,
A rabbit hops where the compaction grows.
With metrics bright, and ranges neat,
Scanning paths, oh what a treat!
Logs now trace the journey clear,
In the code, we hold so dear! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❀️ Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
πŸͺ§ Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit , please review it.` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` - `@coderabbitai help me debug CodeRabbit configuration file.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (Invoked using PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to do a full review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. ### Other keywords and placeholders - Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. - Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description. - Add `@coderabbitai` anywhere in the PR title to generate the title automatically. ### Documentation and Community - Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit. - Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
evenyag commented 1 week ago

@coderabbitai summary

coderabbitai[bot] commented 1 week ago
:white_check_mark: Actions performed Summary regeneration triggered.
codecov[bot] commented 1 week ago

Codecov Report

Attention: Patch coverage is 91.66667% with 13 lines in your changes missing coverage. Please review.

Project coverage is 83.79%. Comparing base (42bf7e9) to head (7a4f8f2). Report is 17 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #4998 +/- ## ========================================== - Coverage 84.03% 83.79% -0.24% ========================================== Files 1146 1146 Lines 213828 213873 +45 ========================================== - Hits 179690 179221 -469 - Misses 34138 34652 +514 ```

🚨 Try these New Features: