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(mito): limit compaction output file size #4754

Merged
merged 5 commits into from
Sep 27, 2024

Conversation

v0y4g3r
Copy link
Contributor

@v0y4g3r v0y4g3r commented Sep 21, 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 adds a limit to the compaction output file size so that compaction will not generate a huge file which may slow down queries.

Now we can create tables with explicit output file limit:

CREATE TABLE monitor (
    host STRING,
    ts TimestampSecond DEFAULT CURRENT_TIMESTAMP() TIME INDEX,
    cpu FLOAT64 DEFAULT 0,
    memory FLOAT64,
    PRIMARY KEY(host)
) WITH (
    'append_mode'='true', 
    'compaction.type'='twcs', 
    'compaction.twcs.max_output_file_size'='1GB'
);

SST files distribution under TSBS workload (with max_output_file_size=128MB):

 # Before
-rw-rw-r-- 1 lei lei 135M Sep 20 16:38 32f86803-e73e-4ca2-a61e-68dc45b653e0.parquet
-rw-rw-r-- 1 lei lei  46M Sep 20 16:36 69539117-4acc-4f8f-9af2-e685c505c5b2.parquet
-rw-rw-r-- 1 lei lei  91M Sep 20 16:37 838dfa1c-1330-499d-8a15-5a0179ce801e.parquet
-rw-rw-r-- 1 lei lei  46M Sep 20 16:38 9cd89ebb-044a-450b-98e2-ab3ffa40e806.parquet
-rw-rw-r-- 1 lei lei 279M Sep 20 16:37 9d8e7106-62b5-4a72-ab4e-684a246fd326.parquet
-rw-rw-r-- 1 lei lei 273M Sep 20 16:35 af108633-fbc1-44f7-a352-7be08431cd97.parquet

# After
-rw-rw-r-- 1 lei lei  90M Sep 20 22:19 0e172b52-ebf8-4ac0-b1f3-34f17154295e.parquet
-rw-rw-r-- 1 lei lei  91M Sep 20 22:18 1f2ac123-f381-4cf6-b0f7-760f6ceda18a.parquet
-rw-rw-r-- 1 lei lei  90M Sep 20 22:19 3c47a5dd-c648-4b61-aa48-ae0f55bb8686.parquet
-rw-rw-r-- 1 lei lei  90M Sep 20 22:16 3e7b24dd-cfe3-4155-a268-5f2dba6d2bd3.parquet
-rw-rw-r-- 1 lei lei  90M Sep 20 22:19 4bbbcd26-fd9a-444b-b14d-db11e20b1350.parquet
-rw-rw-r-- 1 lei lei  90M Sep 20 22:17 8432536a-93e3-45fa-ab8f-f63ad1d90fa1.parquet
-rw-rw-r-- 1 lei lei  46M Sep 20 22:19 c66a2604-b076-4eec-b085-2a013f5ff6c0.parquet
-rw-rw-r-- 1 lei lei  91M Sep 20 22:16 cb2dbe3f-691b-4dc9-a877-7213282905b4.parquet
-rw-rw-r-- 1 lei lei  91M Sep 20 22:18 d5b72303-7fbe-4aef-904e-6e681b68f0bb.parquet
-rw-rw-r-- 1 lei lei  91M Sep 20 22:16 fa146609-2875-44f9-9a7c-094e968d5aa4.parquet

Caveats

Currently this policy only applies when either append mode is enabled or compacted inputs does not overlap with other inputs (so that we can reasobably estimate the ouput file size). For those overlapping files, we may need to examine row groups' statistic data to further calculate the output file size. But this is not oncluded in this patch.

Checklist

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

 Clarify documentation for CompactionOutput struct

 Updated the documentation for the `CompactionOutput` struct to specify that the output time range is only relevant for windowed compaction.
 - Introduced `max_output_file_size` to `TwcsPicker` struct and its logic to enforce output file size limits during compaction.
 - Updated `TwcsOptions` to include `max_output_file_size` and adjusted related tests.
 - Modified `new_picker` function to initialize `TwcsPicker` with the new `max_output_file_size` field.
 Refactor compaction picker and TWCS to support append mode and improve options handling

 - Update compaction picker to accept a reference to options and append mode flag
 - Modify TWCS picker logic to consider append mode when filtering deleted rows
 - Remove VersionControl usage in compactor and simplify return type
 - Adjust enforce_max_output_size logic in TWCS picker to handle max output file size
 - Add append mode flag to TwcsPicker struct
 - Fix incorrect condition in TWCS picker for enforcing max output size
 - Update region options tests to reflect new max output file size format (1GB and 7MB)
 - Simplify InvalidTableOptionSnafu error handling in create_parser
 - Add `compaction.twcs.max_output_file_size` to mito engine option keys
@v0y4g3r v0y4g3r requested review from evenyag, waynexia and a team as code owners September 21, 2024 05:44
Copy link
Contributor

coderabbitai bot commented Sep 21, 2024

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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>, 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 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 the docs-required This change requires docs update. label Sep 21, 2024
@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 Sep 21, 2024
Copy link

codecov bot commented Sep 21, 2024

Codecov Report

Attention: Patch coverage is 86.66667% with 18 lines in your changes missing coverage. Please review.

Project coverage is 84.28%. Comparing base (163cea8) to head (2aa6d42).
Report is 12 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4754      +/-   ##
==========================================
- Coverage   84.67%   84.28%   -0.39%     
==========================================
  Files        1118     1117       -1     
  Lines      202454   202759     +305     
==========================================
- Hits       171429   170900     -529     
- Misses      31025    31859     +834     

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.

what happens if those params are in conflict and cannot all be met?

src/mito2/src/compaction/twcs.rs Outdated Show resolved Hide resolved
src/mito2/src/compaction/twcs.rs Outdated Show resolved Hide resolved
src/mito2/src/compaction/twcs.rs Outdated Show resolved Hide resolved
@evenyag
Copy link
Contributor

evenyag commented Sep 23, 2024

We should allow a compaction task to generate multiple files to avoid outputting a huge file. So the task can finish writing the current output file and start a new output file. But this requires the compaction task itself to generate file ids.

@v0y4g3r
Copy link
Contributor Author

v0y4g3r commented Sep 23, 2024

what happens if those params are in conflict and cannot all be met?

max_output_file_size has higher priority than max_[in]active_window_files. For example, if max_[in]active_window_files allows at most 1 file per window, while the output file size exceedsmax_output_file_size, the output will be split.

@v0y4g3r
Copy link
Contributor Author

v0y4g3r commented Sep 23, 2024

We should allow a compaction task to generate multiple files to avoid outputting a huge file. So the task can finish writing the current output file and start a new output file. But this requires the compaction task itself to generate file ids.

This will not be included in this PR since it involves refactoring both WriteCache and ParquetWriter.

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.

It might also be beneficial to group small size inputs into a larger one while still keeping the total size under the threshold. But this PR looks fine to merge and we can do this in follow-up changes.

@evenyag evenyag added this pull request to the merge queue Sep 27, 2024
Merged via the queue into GreptimeTeam:main with commit 934bc13 Sep 27, 2024
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs-not-required This change does not impact docs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants