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: add a cache for last value result in row group #4369

Merged
merged 2 commits into from
Jul 15, 2024

Conversation

evenyag
Copy link
Contributor

@evenyag evenyag commented Jul 15, 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 new cache selector_result_cache for TimeSeriesRowSelector results. Now it caches the last_value() result for parquet row groups.

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 caching for time series selectors to improve performance.
    • Introduced configuration for selector_result_cache_size to control cache behavior.
    • Added memory size calculation for batches to optimize resource management.
  • Improvements

    • Enhanced CacheManager with methods to manage selector result caching.
    • Updated MitoConfig to initialize and assign selector result cache size settings.
  • Tests

    • Added tests for the new selector result caching feature.

Copy link
Contributor

coderabbitai bot commented Jul 15, 2024

Walkthrough

The changes implement a caching mechanism for time series selector results within the mito2 module. This involves updates across various files to introduce new cache-related structures and methods, integrate cache configurations, and provide unit tests. Specifically, a new TimeSeriesRowSelector is added, along with a CacheManager to handle caching, and corresponding configuration adjustments are made.

Changes

Files/Groups Change Summary
src/mito2/src/cache.rs Added TimeSeriesRowSelector, CacheManager updates, cache methods, new structs, and unit tests.
src/mito2/src/config.rs Added selector_result_cache_size to MitoConfig and related initialization and assignment methods.
src/mito2/src/read.rs Added memory_size() method to the Batch struct.
src/mito2/src/worker.rs Updated WorkerGroup to include selector_result_cache_size configuration.
tests-integration/tests/http.rs Added selector_result_cache_size configuration and adjusted formatting in processors section.

Poem

In the land of code and bytes,
A cache was born, a new delight.
Selector results now rest with ease,
Speeding up our queries with utmost breeze.
Configs tweaked, methods new,
Mito's future, bright and true.


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 the docs-not-required This change does not impact docs. label Jul 15, 2024
@evenyag evenyag marked this pull request as ready for review July 15, 2024 09:20
@evenyag evenyag requested review from v0y4g3r, waynexia and a team as code owners July 15, 2024 09:20
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: 0

Outside diff range, codebase verification and nitpick comments (5)
src/store-api/src/storage/requests.rs (2)

20-20: Add documentation for LastRow variant.

The LastRow variant in the TimeSeriesRowSelector enum lacks documentation. Adding a brief comment explaining its purpose would improve code readability.

/// Only keep the last row of each time-series.
LastRow,

Line range hint 33-33: Add documentation for series_row_selector field.

The series_row_selector field in the ScanRequest struct lacks documentation. Adding a brief comment explaining its purpose would improve code readability.

/// Optional hint to select rows from time-series.
pub series_row_selector: Option<TimeSeriesRowSelector>,
src/mito2/src/config.rs (3)

87-88: Add documentation for selector_result_cache_size field.

The selector_result_cache_size field in the MitoConfig struct lacks documentation. Adding a brief comment explaining its purpose would improve code readability.

/// Cache size for time series selector (e.g. `last_value()`). Setting it to 0 to disable the cache.
pub selector_result_cache_size: ReadableSize,

138-138: Add initialization for selector_result_cache_size in Default implementation.

The selector_result_cache_size field should be initialized in the Default implementation of MitoConfig.

selector_result_cache_size: ReadableSize::mb(512),

243-243: Add adjustment for selector_result_cache_size in adjust_buffer_and_cache_size method.

The selector_result_cache_size field should be adjusted according to system memory in the adjust_buffer_and_cache_size method.

self.selector_result_cache_size = mem_cache_size;
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 04ac0c8 and 6322455.

Files selected for processing (6)
  • src/mito2/src/cache.rs (10 hunks)
  • src/mito2/src/config.rs (3 hunks)
  • src/mito2/src/read.rs (1 hunks)
  • src/mito2/src/worker.rs (2 hunks)
  • src/store-api/src/storage/requests.rs (1 hunks)
  • tests-integration/tests/http.rs (2 hunks)
Files skipped from review due to trivial changes (2)
  • src/mito2/src/read.rs
  • tests-integration/tests/http.rs
Additional comments not posted (16)
src/mito2/src/cache.rs (14)

33-33: Add import for TimeSeriesRowSelector.

The TimeSeriesRowSelector is imported to be used in the cache mechanism.


52-52: Add constant for selector result cache type.

The SELECTOR_RESULT_TYPE constant is added for metrics labeling.


69-70: Add field for selector result cache in CacheManager.

The selector_result_cache field is added to the CacheManager struct.


175-186: Add method to get selector result from cache.

The get_selector_result method is added to retrieve cached selector results.


188-200: Add method to put selector result into cache.

The put_selector_result method is added to store selector results in the cache.


221-221: Add field for selector result cache size in CacheManagerBuilder.

The selector_result_cache_size field is added to the CacheManagerBuilder struct.


261-266: Add method to set selector result cache size in CacheManagerBuilder.

The selector_result_cache_size method is added to configure the selector result cache size.


305-316: Add initialization for selector result cache in CacheManagerBuilder.

The selector_result_cache is initialized in the CacheManagerBuilder's build method.


323-323: Add field for selector result cache in CacheManager.

The selector_result_cache is added to the CacheManager struct.


342-344: Add weigher function for selector result cache.

The selector_result_cache_weight function is added to compute the weight of cache entries.


406-415: Add SelectorResultKey struct.

The SelectorResultKey struct is added to represent the cache key for selector results.


417-434: Add SelectorResultValue struct.

The SelectorResultValue struct is added to represent the cached selector results.


444-445: Add type alias for SelectorResultCache.

The SelectorResultCache type alias is added for the cache of selector results.


546-561: Add test for selector result cache.

A test is added to verify the functionality of the selector result cache.

src/mito2/src/worker.rs (2)

161-161: Add selector result cache size configuration in WorkerGroup.

The selector_result_cache_size configuration is used to initialize the cache manager in the WorkerGroup.


296-296: Add selector result cache size configuration in test WorkerGroup.

The selector_result_cache_size configuration is used to initialize the cache manager in the test WorkerGroup.

Copy link

codecov bot commented Jul 15, 2024

Codecov Report

Attention: Patch coverage is 80.24691% with 16 lines in your changes missing coverage. Please review.

Project coverage is 84.96%. Comparing base (04ac0c8) to head (6322455).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4369      +/-   ##
==========================================
- Coverage   85.24%   84.96%   -0.28%     
==========================================
  Files        1068     1068              
  Lines      191277   191356      +79     
==========================================
- Hits       163046   162580     -466     
- Misses      28231    28776     +545     

Copy link
Collaborator

@fengjiachun fengjiachun left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@v0y4g3r v0y4g3r left a comment

Choose a reason for hiding this comment

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

LGTM

@v0y4g3r v0y4g3r added this pull request to the merge queue Jul 15, 2024
Merged via the queue into GreptimeTeam:main with commit 2e7b12c Jul 15, 2024
63 of 72 checks passed
@v0y4g3r v0y4g3r deleted the feat/last-value-cache branch July 15, 2024 12:49
@@ -133,6 +135,7 @@ impl Default for MitoConfig {
sst_meta_cache_size: ReadableSize::mb(128),
vector_cache_size: ReadableSize::mb(512),
page_cache_size: ReadableSize::mb(512),
selector_result_cache_size: ReadableSize::mb(512),
Copy link
Contributor

Choose a reason for hiding this comment

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

Forget to update the config.toml?

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.

None yet

4 participants