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

feat!: reduce sorted runs during compaction #3702

Merged
merged 14 commits into from
Jun 28, 2024

Conversation

v0y4g3r
Copy link
Contributor

@v0y4g3r v0y4g3r commented Apr 14, 2024

I hereby agree to the terms of the GreptimeDB CLA.

Refer to a related PR or issue link (optional)

What's changed and what's your intention?

This PR changes the behavior during compaction from reduce file nums to sorted runs.

A sorted run in GreptimeDB is defined as a sequence of non-overlapping SST files. If multiple sorted runs exist in some time window, even a simple query with explicit time ranges may invole multiple files. Before this PR, GreptimeDB merges all files in active window into one single file if the total num of files exceeds max_active_window_files, of which the write amplification is rather severe. In this PR, we only enforce a max_active_window_runs in active window to reduce read amplication. If num of sorted runs exceeds that threshold, it only merges the overlapping files on demand.

Checklist

  • I have written the necessary rustdoc comments.
  • I have added the necessary unit tests and integration tests.
  • This PR requires documentation updates.

Summary by CodeRabbit

  • New Features

    • Added the ability to merge ranged items efficiently and manage sorted runs in the new run module.
  • Improvements

    • Renamed compaction parameters from max_active_window_files and max_inactive_window_files to max_active_window_runs and max_inactive_window_runs for clarity.
    • Updated logic in compaction-related modules to handle runs instead of files.
  • Bug Fixes

    • Corrected configurations and assertions in tests to align with the updated compaction parameters.

Copy link

codecov bot commented Apr 26, 2024

Codecov Report

Attention: Patch coverage is 99.83871% with 1 line in your changes missing coverage. Please review.

Project coverage is 84.67%. Comparing base (b6585e3) to head (f126da3).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3702      +/-   ##
==========================================
- Coverage   84.89%   84.67%   -0.23%     
==========================================
  Files        1040     1041       +1     
  Lines      183506   184060     +554     
==========================================
+ Hits       155789   155844      +55     
- Misses      27717    28216     +499     

src/mito2/src/region/options.rs Show resolved Hide resolved
src/mito2/src/engine/compaction_test.rs Show resolved Hide resolved
src/mito2/src/engine/compaction_test.rs Outdated Show resolved Hide resolved
src/mito2/src/engine/compaction_test.rs Outdated Show resolved Hide resolved
src/mito2/src/region/options.rs Outdated Show resolved Hide resolved
src/mito2/src/compaction/run.rs Show resolved Hide resolved
src/mito2/src/compaction/run.rs Outdated Show resolved Hide resolved
src/mito2/src/compaction/run.rs Outdated Show resolved Hide resolved
src/mito2/src/compaction/run.rs Outdated Show resolved Hide resolved
src/mito2/src/compaction/run.rs Outdated Show resolved Hide resolved
@v0y4g3r v0y4g3r requested a review from evenyag May 6, 2024 08:52
src/mito2/src/region/options.rs Show resolved Hide resolved
src/mito2/src/engine/compaction_test.rs Outdated Show resolved Hide resolved
src/mito2/src/compaction/run.rs Outdated Show resolved Hide resolved
src/mito2/src/compaction/run.rs Outdated Show resolved Hide resolved
src/mito2/src/compaction/run.rs Show resolved Hide resolved
Copy link
Member

@waynexia waynexia left a comment

Choose a reason for hiding this comment

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

Rest LGTM

@killme2008
Copy link
Contributor

What's the progress of this PR? @v0y4g3r

@killme2008
Copy link
Contributor

@v0y4g3r What's the status of this PR? It's deprecated or just wait for resolving conflicts.

 Refactor compaction logic and update test configurations

 - Refactored `merge_all_runs` function to use `sort_ranged_items` for sorting.
 - Improved item merging logic by iterating with `into_iter` and handling overlaps.
 - Updated test configurations to use `max_active_window_runs` instead of `max_active_window_files` for consistency.
Copy link
Contributor

coderabbitai bot commented Jun 27, 2024

Warning

Rate limit exceeded

@tisonkun has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 49 minutes and 18 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 379cd71 and f126da3.

Walkthrough

The changes primarily revolve around transitioning from file-based to run-based terminology and logic within the compaction mechanism, focusing on improving clarity in file handling and compaction processes. Key modifications include renaming file-related parameters for better representation of run handling, introducing a new module for run management, and updating test cases to align with the new terminology.

Changes

File(s) Change Summary
src/.../compaction.rs Added new run module.
src/.../picker.rs, src/.../twcs.rs Renamed parameters from files to runs and updated compaction logic accordingly.
src/.../run.rs Introduced functionalities for handling sorted runs and merging items, defining related traits and structures.
src/.../append_mode_test.rs, src/.../compaction_test.rs, src/.../filter_deleted_test.rs Updated test cases to use runs terminology and adjusted assertions to reflect the new logic.
src/.../options.rs Renamed struct fields from max_active_window_files to max_active_window_runs and the respective inactive counterparts.
src/.../file.rs Added size method in FileHandle.
src/.../mito_engine_options.rs Updated keys for compaction options from files to runs.
tests/.../create_with_options.result, tests/.../create_with_options.sql Adjusted configuration options and parameters in test scripts to use runs instead of files.

Poem

In the land where code runs free,
New 'runs' are born, no longer 'files' to see,
Merging smart, and sorted neat,
Efficiency in compaction we now greet.
Tests revised, all aligned,
For a smoother, future-compacted time.
🐰✨


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
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added docs-not-required This change does not impact docs. and removed docs-required This change requires docs update. labels Jun 27, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 9

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8702066 and 379cd71.

Files selected for processing (12)
  • src/mito2/src/compaction.rs (1 hunks)
  • src/mito2/src/compaction/picker.rs (1 hunks)
  • src/mito2/src/compaction/run.rs (1 hunks)
  • src/mito2/src/compaction/twcs.rs (3 hunks)
  • src/mito2/src/engine/append_mode_test.rs (2 hunks)
  • src/mito2/src/engine/compaction_test.rs (7 hunks)
  • src/mito2/src/engine/filter_deleted_test.rs (1 hunks)
  • src/mito2/src/region/options.rs (6 hunks)
  • src/mito2/src/sst/file.rs (1 hunks)
  • src/store-api/src/mito_engine_options.rs (2 hunks)
  • tests/cases/standalone/common/create/create_with_options.result (2 hunks)
  • tests/cases/standalone/common/create/create_with_options.sql (2 hunks)
Files skipped from review due to trivial changes (1)
  • src/mito2/src/compaction.rs
Additional comments not posted (15)
tests/cases/standalone/common/create/create_with_options.sql (1)

60-61: Correct option values for window runs.

The options max_active_window_runs and max_inactive_window_runs are correctly set to '2' which aligns with the new run-based compaction logic.

tests/cases/standalone/common/create/create_with_options.result (1)

70-71: Correct option values for window runs.

The options max_active_window_runs and max_inactive_window_runs are correctly set to '2' which aligns with the new run-based compaction logic.

src/store-api/src/mito_engine_options.rs (1)

25-26: Updated option keys for run-based compaction.

The addition of max_active_window_runs and max_inactive_window_runs to the list of valid option keys aligns with the new run-based compaction logic. The changes are correctly implemented in the function.

Also applies to: 50-53

src/mito2/src/engine/filter_deleted_test.rs (1)

37-37: Updated test to include new compaction option.

The inclusion of the max_active_window_runs option in the test setup aligns with the new run-based compaction logic. The test is correctly updated to reflect the expected behavior.

src/mito2/src/engine/append_mode_test.rs (1)

103-104: Updated test to include new compaction options.

The inclusion of the max_active_window_runs and max_inactive_window_runs options in the test setup aligns with the new run-based compaction logic. The test is correctly updated to reflect the expected behavior.

src/mito2/src/compaction/picker.rs (1)

135-136: Updated parameter names to reflect run-based terminology.

The function new_picker now correctly uses max_active_window_runs and max_inactive_window_runs as parameters. This change aligns with the PR's objective to shift from file-based to run-based compaction metrics. Ensure that all references to these parameters across the system are consistently updated.

src/mito2/src/sst/file.rs (1)

204-206: Added a method to retrieve file size.

The new size method in the FileHandle class provides a way to retrieve the file size, which is essential for making informed decisions during compaction processes. This is a straightforward addition and correctly implements the functionality.

src/mito2/src/engine/compaction_test.rs (2)

174-175: Updated compaction configuration keys in test cases.

The test cases have been updated to use the new run-based configuration keys: max_active_window_runs and max_inactive_window_runs. This ensures that the tests align with the new compaction strategy and are testing the system under the correct configuration.

Also applies to: 218-219, 280-280


294-294: Ensure overlapping handling in compaction tests.

The test case test_compaction_region_with_overlapping introduces overlapping time windows to verify the compaction logic. This is crucial for testing the robustness of the new compaction strategy under complex scenarios.

src/mito2/src/region/options.rs (2)

135-138: Updated TwcsOptions to use run-based terminology.

The TwcsOptions struct now uses max_active_window_runs and max_inactive_window_runs instead of the previous file-based terminology. This change is consistent with the overarching theme of the PR and correctly reflects the new compaction strategy.


163-164: Default values for TwcsOptions.

The default values for max_active_window_runs and max_inactive_window_runs have been set to 1. This change is reasonable, assuming a conservative default setting is desired until tuned by actual system usage or configuration.

src/mito2/src/compaction/twcs.rs (4)

32-32: Good introduction of a constant for compaction level.

Using a constant for the compaction level improves code maintainability and readability by avoiding magic numbers.


37-59: Struct and constructor updates are consistent with new terminology.

The changes to the TwcsPicker struct and its constructor method are consistent with the shift from file-based to run-based compaction logic.


65-101: Ensure comprehensive handling of runs in build_output.

The build_output method has been significantly refactored to handle runs instead of files. Ensure that this method correctly handles edge cases, such as when there are no active windows or when the number of runs is already within the allowed limit. The use of find_sorted_runs and reduce_runs should be closely monitored in integration tests to ensure they function as expected.

Consider adding more detailed logging within the build_output method to aid in debugging and monitoring the compaction process.


138-140: Review the handling of file assignments in pick.

The pick method has been updated to handle the assignment of files to windows. Ensure that the logic for assigning files and handling expired SSTs is correct and robust, especially in edge cases where timestamp calculations might be complex.

Consider improving the robustness of timestamp calculations and handling in the pick method to prevent potential issues in edge cases.

src/mito2/src/compaction/run.rs Show resolved Hide resolved
src/mito2/src/compaction/run.rs Show resolved Hide resolved
src/mito2/src/compaction/run.rs Show resolved Hide resolved
src/mito2/src/compaction/run.rs Show resolved Hide resolved
src/mito2/src/compaction/run.rs Show resolved Hide resolved
src/mito2/src/compaction/run.rs Show resolved Hide resolved
src/mito2/src/compaction/run.rs Show resolved Hide resolved
@evenyag evenyag enabled auto-merge June 28, 2024 08:03
@evenyag evenyag changed the title feat: reduce sorted runs during compaction feat!: reduce sorted runs during compaction Jun 28, 2024
@github-actions github-actions bot added the breaking-change This pull request contains breaking changes. label Jun 28, 2024
@evenyag evenyag added docs-required This change requires docs update. and removed docs-not-required This change does not impact docs. labels Jun 28, 2024
@evenyag evenyag added this pull request to the merge queue Jun 28, 2024
Merged via the queue into GreptimeTeam:main with commit ef935a1 Jun 28, 2024
53 checks passed
zyy17 pushed a commit to zyy17/greptimedb that referenced this pull request Jun 28, 2024
* feat: add functions to find and merge sorted runs

* chore: refactor code

* chore: remove some duplicates

* chore: remove one clone

* refactor: change max_active_window_files to max_active_window_runs

* feat: integrate with sorted runs

* fix: unit tests

* feat: limit num of sorted runs during compaction

* fix: some test

* fix: some cr comments

* feat: use smallvec

* chore: rebase main

* feat/reduce-sorted-runs:
 Refactor compaction logic and update test configurations

 - Refactored `merge_all_runs` function to use `sort_ranged_items` for sorting.
 - Improved item merging logic by iterating with `into_iter` and handling overlaps.
 - Updated test configurations to use `max_active_window_runs` instead of `max_active_window_files` for consistency.

---------

Co-authored-by: tison <wander4096@gmail.com>
zyy17 pushed a commit to zyy17/greptimedb that referenced this pull request Jun 28, 2024
* feat: add functions to find and merge sorted runs

* chore: refactor code

* chore: remove some duplicates

* chore: remove one clone

* refactor: change max_active_window_files to max_active_window_runs

* feat: integrate with sorted runs

* fix: unit tests

* feat: limit num of sorted runs during compaction

* fix: some test

* fix: some cr comments

* feat: use smallvec

* chore: rebase main

* feat/reduce-sorted-runs:
 Refactor compaction logic and update test configurations

 - Refactored `merge_all_runs` function to use `sort_ranged_items` for sorting.
 - Improved item merging logic by iterating with `into_iter` and handling overlaps.
 - Updated test configurations to use `max_active_window_runs` instead of `max_active_window_files` for consistency.

---------

Co-authored-by: tison <wander4096@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change This pull request contains breaking changes. docs-required This change requires docs update.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants