GreptimeTeam / greptimedb

An Open-Source, Cloud-Native, Unified Time Series Database for Metrics, Events, and Logs with SQL/PromQL supported. Available on GreptimeCloud.
https://greptime.com/
Apache License 2.0
4k stars 289 forks source link

feat(inverted_index): inverted index cache #4309

Closed v0y4g3r closed 1 week ago

v0y4g3r commented 1 week ago

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 im-memory cache for inverted index that boost most queries by reducing the pruning cost, which reduces total cost by 2~3ms:

image

Future work

Checklist

Summary by CodeRabbit

coderabbitai[bot] commented 1 week ago

[!IMPORTANT]

Review skipped

Review was skipped due to path filters

Files ignored due to path filters (1) * `Cargo.lock` is excluded by `!**/*.lock`

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

Walkthrough

The updates include the addition and enhancement of methods to the InvertedIndexReader trait, restructuring the CacheManager to manage index caching, introducing new modules for index caching, and modifying test cases accordingly. Additionally, it includes changing various signature methods and utilizing Arc to manage shared metadata efficiently.

Changes

File/Path Change Summary
src/index/Cargo.toml Added uuid as a workspace dependency.
src/index/src/inverted_index/.../reader.rs Added read_all and seek_read methods and modified return types for metadata, fst, and bitmap.
src/index/src/inverted_index/.../blob.rs Adjusted method signatures to use Arc for metadata and renamed methods for reading data.
src/index/src/inverted_index/.../predicates_apply.rs Modified mock_metas function to use Arc for shared metadata ownership.
src/mito2/src/cache.rs Added index module with caching declarations and methods in CacheManager and CacheManagerBuilder.
src/mito2/src/cache/index.rs Introduced CachedInvertedIndexBlobReader struct and related caching implementations.
src/mito2/src/config.rs Added cache size fields for inverted index metadata and content to MitoConfig.
src/mito2/src/read/scan_region.rs Introduced index_cache variable and passed it to SstIndexApplierBuilder.
src/mito2/src/sst/file.rs Added conversion implementation from FileId to Uuid.
src/mito2/src/sst/.../applier.rs Added inverted_index_cache field, modified apply method, and updated blob reader creation conditions.
src/mito2/src/sst/.../builder.rs Added index_cache field and parameter to SstIndexApplierBuilder.
src/mito2/src/sst/.../between.rs Updated test cases to include None for the index_cache parameter.
src/mito2/src/sst/.../comparison.rs Updated test cases to include None for the index_cache parameter.
src/mito2/src/sst/.../eq_list.rs Updated test cases to include None for the index_cache parameter.
src/mito2/src/sst/.../in_list.rs Updated test cases to include None for the index_cache parameter.
src/mito2/src/sst/.../regex_match.rs Updated test cases to include None for the index_cache parameter.
src/mito2/src/sst/.../creator.rs Added usage of InvertedIndexCache and passed it to the builder.
src/mito2/src/worker.rs Added index metadata and content size configurations.
tests-integration/tests/http.rs Added configuration settings for cache sizes for inverted index metadata and content.

Poem

In the lines of Rust we weave, With bytes and cache we achieve, Indexes cached, with data vast, Efficiency and speed to outlast.

Oh, code of magic, so refined, Full of treasures left behind, We celebrate this feat so grand, In the realm of data we now stand. 🌟


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 .` - `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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
killme2008 commented 1 week ago

Do we have any benchmark program and results for this PR? @v0y4g3r

v0y4g3r commented 1 week ago

Do we have any benchmark program and results for this PR? @v0y4g3r

I updated the PR description. This PR improves those queries which are already fast, but not fast enough, namely those 5~6ms queries. An improvement of 2 to 3ms means cutting the total cost time by half.

codecov[bot] commented 1 week ago

Codecov Report

Attention: Patch coverage is 91.07981% with 19 lines in your changes missing coverage. Please review.

Project coverage is 84.85%. Comparing base (e5730a3) to head (b42a932). Report is 1 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #4309 +/- ## ========================================== - Coverage 85.11% 84.85% -0.27% ========================================== Files 1060 1061 +1 Lines 187648 187832 +184 ========================================== - Hits 159720 159387 -333 - Misses 27928 28445 +517 ```