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

refactor(puffin): adjust generic parameters #4279

Merged
merged 3 commits into from
Jul 4, 2024

Conversation

zhongzc
Copy link
Contributor

@zhongzc zhongzc commented Jul 4, 2024

I hereby agree to the terms of the GreptimeDB CLA.

Refer to a related PR or issue link (optional)

#4266 (comment)

What's changed and what's your intention?

reduce generic parameters for FsPuffinManager

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

  • Refactor

    • Enhanced the SstPuffinManager and related components for better type handling and efficiency.
    • Updated PuffinReader, BlobGuard, DirGuard, and Stager traits with auto_impl to support automatic implementation for Arc types.
    • Improved trait bounds for PuffinFileAccessor to enhance compatibility and performance.
  • Dependencies

    • Added auto_impl version 1.2.0 to the project dependencies.

Signed-off-by: Zhenchi <zhongzc_arch@outlook.com>
@zhongzc zhongzc requested review from evenyag, v0y4g3r, waynexia and a team as code owners July 4, 2024 07:00
Copy link
Contributor

coderabbitai bot commented Jul 4, 2024

Walkthrough

The recent code changes primarily involve refactoring the puffin_manager.rs file and related modules to use the auto_impl::auto_impl(Arc) attribute for automatic Arc implementations. This includes updating the PuffinReader, BlobGuard, DirGuard, and Stager traits, as well as modifying type declarations and constructors in SstPuffinManager. These adjustments streamline the codebase and improve maintainability.

Changes

Files Change Summary
src/mito2/src/sst/index/puffin_manager.rs, src/puffin/src/puffin_manager.rs, src/puffin/src/puffin_manager/file_accessor.rs, src/puffin/src/puffin_manager/stager.rs Annotated traits PuffinReader, BlobGuard, DirGuard, PuffinFileAccessor, and Stager with #[auto_impl::auto_impl(Arc)]. Updated trait bounds and type declarations to use Arc. Adjusted constructors and type implementations accordingly.
src/puffin/Cargo.toml Added auto_impl dependency version "1.2.0".

Poem

Tedious lines now melt away,
Arc advances, here to stay.
auto_impl guards our keep,
Less to code, more to reap.
Puffin safe in stager's arms,
Grace and speed in all its charms.
🌟🚀


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 4, 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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 03c933c and 81ea1b6.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (9)
  • src/mito2/src/sst/index/puffin_manager.rs (6 hunks)
  • src/puffin/Cargo.toml (1 hunks)
  • src/puffin/src/puffin_manager.rs (2 hunks)
  • src/puffin/src/puffin_manager/file_accessor.rs (1 hunks)
  • src/puffin/src/puffin_manager/fs_puffin_manager.rs (2 hunks)
  • src/puffin/src/puffin_manager/fs_puffin_manager/reader.rs (5 hunks)
  • src/puffin/src/puffin_manager/fs_puffin_manager/writer.rs (4 hunks)
  • src/puffin/src/puffin_manager/stager.rs (3 hunks)
  • src/puffin/src/puffin_manager/stager/bounded_stager.rs (2 hunks)
Files skipped from review due to trivial changes (2)
  • src/puffin/Cargo.toml
  • src/puffin/src/puffin_manager/file_accessor.rs
Additional comments not posted (24)
src/puffin/src/puffin_manager/fs_puffin_manager.rs (5)

23-23: Approved: Necessary import statement for PuffinFileAccessor.

This import is required for the new generic parameter F in the FsPuffinManager struct and its implementation.


25-25: Approved: Necessary import statement for Stager.

This import is required for the new generic parameter S in the FsPuffinManager struct and its implementation.


29-33: Approved: Generic parameters improve flexibility and reusability.

The update to use generic parameters S and F in the FsPuffinManager struct enhances its flexibility and reusability.


36-41: Approved: Updated constructor for FsPuffinManager.

The new constructor using the generic parameters S and F ensures proper initialization of the FsPuffinManager.


47-55: Approved: Updated PuffinManager implementation for FsPuffinManager.

The updated PuffinManager implementation using the new generic parameters S and F ensures proper functionality.

src/puffin/src/puffin_manager/stager.rs (1)

55-56: Approved: Enhanced flexibility and thread safety for Stager trait.

The #[auto_impl::auto_impl(Box, Rc, Arc)] annotation allows the Stager trait to be automatically implemented for Box, Rc, and Arc. The addition of Send and Sync bounds ensures thread safety.

src/puffin/src/puffin_manager.rs (3)

75-75: Approved: Enhanced flexibility for PuffinReader trait.

The #[auto_impl::auto_impl(Box, Rc, Arc)] annotation allows the PuffinReader trait to be automatically implemented for Box, Rc, and Arc.


95-95: Approved: Enhanced flexibility for BlobGuard trait.

The #[auto_impl::auto_impl(Box, Rc, Arc)] annotation allows the BlobGuard trait to be automatically implemented for Box, Rc, and Arc.


103-103: Approved: Enhanced flexibility for DirGuard trait.

The #[auto_impl::auto_impl(Box, Rc, Arc)] annotation allows the DirGuard trait to be automatically implemented for Box, Rc, and Arc.

src/puffin/src/puffin_manager/fs_puffin_manager/writer.rs (5)

33-33: Approved: Necessary import statement for Stager.

This import is required for the new generic parameter S in the FsPuffinWriter struct and its implementation.


Line range hint 37-50:
Approved: Generic parameters improve flexibility and reusability.

The update to use generic parameters S and W in the FsPuffinWriter struct enhances its flexibility and reusability.


Line range hint 51-61:
Approved: Updated constructor for FsPuffinWriter.

The new constructor using the generic parameters S and W ensures proper initialization of the FsPuffinWriter.


Line range hint 63-157:
Approved: Updated PuffinWriter implementation for FsPuffinWriter.

The updated PuffinWriter implementation using the new generic parameters S and W ensures proper functionality.


Line range hint 166-181:
Approved: Updated handle_compress method for FsPuffinWriter.

The new handle_compress method using the generic parameters S and W ensures proper functionality.

src/puffin/src/puffin_manager/fs_puffin_manager/reader.rs (5)

19-19: Imports look good.

The added imports are necessary for the changes in the struct and its implementation.

Also applies to: 28-31


34-42: Struct changes look good.

The changes in the FsPuffinReader struct to use generic parameters S and F are in line with the PR objective.


Line range hint 45-62:
Implementation changes look good.

The changes in the FsPuffinReader implementation to support the new generic parameters are necessary and correct.


95-104: Method changes look good.

The changes in the init_blob_to_cache method to support the new generic parameters are necessary and correct.


129-129: Method changes look good.

The changes in the init_dir_to_cache method to support the new generic parameters are necessary and correct.

src/mito2/src/sst/index/puffin_manager.rs (3)

24-24: Imports look good.

The added imports are necessary for the changes in the file.


39-40: Type declaration changes look good.

The changes in the type declaration to use the new generic parameters are in line with the PR objective.


101-101: New struct addition looks good.

The addition of the ObjectStorePuffinFileAccessor struct is necessary to support the changes in the file.

src/puffin/src/puffin_manager/stager/bounded_stager.rs (2)

428-428: BlobGuard implementation changes look good.

The changes in the implementation of the BlobGuard trait to remove the Arc wrapper are in line with the PR objective.


463-463: DirGuard implementation changes look good.

The changes in the implementation of the DirGuard trait to remove the Arc wrapper are in line with the PR objective.

Copy link

codecov bot commented Jul 4, 2024

Codecov Report

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

Project coverage is 84.69%. Comparing base (03c933c) to head (37e39c6).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4279      +/-   ##
==========================================
- Coverage   84.96%   84.69%   -0.27%     
==========================================
  Files        1058     1061       +3     
  Lines      188055   188107      +52     
==========================================
- Hits       159780   159317     -463     
- Misses      28275    28790     +515     

@v0y4g3r
Copy link
Contributor

v0y4g3r commented Jul 4, 2024

I wonder if we can change stager: S to stager: Arc<S> so that we don't have to derive Stager impl for Arc<T>/Rc<T>/Box<T>

diff --git a/src/mito2/src/sst/index/puffin_manager.rs b/src/mito2/src/sst/index/puffin_manager.rs
index f953ca5dd4..18cfd7f07a 100644
--- a/src/mito2/src/sst/index/puffin_manager.rs
+++ b/src/mito2/src/sst/index/puffin_manager.rs
@@ -36,8 +36,7 @@ type InstrumentedAsyncRead = store::InstrumentedAsyncRead<'static, FuturesAsyncR
 type InstrumentedAsyncWrite = store::InstrumentedAsyncWrite<'static, FuturesAsyncWriter>;
 
 pub(crate) type BlobReader = <Arc<FsBlobGuard> as BlobGuard>::Reader;
-pub(crate) type SstPuffinManager =
-    FsPuffinManager<Arc<BoundedStager>, ObjectStorePuffinFileAccessor>;
+pub(crate) type SstPuffinManager = FsPuffinManager<BoundedStager, ObjectStorePuffinFileAccessor>;
 
 const STAGING_DIR: &str = "staging";
 
@@ -71,7 +70,8 @@ impl PuffinManagerFactory {
     pub(crate) fn build(&self, store: ObjectStore) -> SstPuffinManager {
         let store = InstrumentedStore::new(store).with_write_buffer_size(self.write_buffer_size);
         let puffin_file_accessor = ObjectStorePuffinFileAccessor::new(store);
-        SstPuffinManager::new(self.stager.clone(), puffin_file_accessor)
+        let stager = self.stager.clone();
+        SstPuffinManager::new(stager, puffin_file_accessor)
     }
 }
 
diff --git a/src/puffin/src/puffin_manager/fs_puffin_manager.rs b/src/puffin/src/puffin_manager/fs_puffin_manager.rs
index 7c95532dc6..e9c3854e98 100644
--- a/src/puffin/src/puffin_manager/fs_puffin_manager.rs
+++ b/src/puffin/src/puffin_manager/fs_puffin_manager.rs
@@ -16,6 +16,8 @@ mod dir_meta;
 mod reader;
 mod writer;
 
+use std::sync::Arc;
+
 use async_trait::async_trait;
 pub use reader::FsPuffinReader;
 pub use writer::FsPuffinWriter;
@@ -28,14 +30,18 @@ use crate::puffin_manager::PuffinManager;
 /// `FsPuffinManager` is a `PuffinManager` that provides readers and writers for puffin data in filesystem.
 pub struct FsPuffinManager<S, F> {
     /// The stager.
-    stager: S,
+    stager: Arc<S>,
     /// The puffin file accessor.
     puffin_file_accessor: F,
 }
 
-impl<S, F> FsPuffinManager<S, F> {
+impl<S, F> FsPuffinManager<S, F>
+where
+    S: Stager,
+    F: PuffinFileAccessor + Clone,
+{
     /// Creates a new `FsPuffinManager` with the specified `stager` and `puffin_file_accessor`.
-    pub fn new(stager: S, puffin_file_accessor: F) -> Self {
+    pub fn new(stager: Arc<S>, puffin_file_accessor: F) -> Self {
         Self {
             stager,
             puffin_file_accessor,
@@ -46,7 +52,7 @@ impl<S, F> FsPuffinManager<S, F> {
 #[async_trait]
 impl<S, F> PuffinManager for FsPuffinManager<S, F>
 where
-    S: Stager + Clone,
+    S: Stager,
     F: PuffinFileAccessor + Clone,
 {
     type Reader = FsPuffinReader<S, F>;
diff --git a/src/puffin/src/puffin_manager/fs_puffin_manager/reader.rs b/src/puffin/src/puffin_manager/fs_puffin_manager/reader.rs
index a1b8d3a8ea..2430d5d2c3 100644
--- a/src/puffin/src/puffin_manager/fs_puffin_manager/reader.rs
+++ b/src/puffin/src/puffin_manager/fs_puffin_manager/reader.rs
@@ -12,6 +12,8 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+use std::sync::Arc;
+
 use async_compression::futures::bufread::ZstdDecoder;
 use async_trait::async_trait;
 use futures::future::BoxFuture;
@@ -36,14 +38,14 @@ pub struct FsPuffinReader<S, F> {
     puffin_file_name: String,
 
     /// The stager.
-    stager: S,
+    stager: Arc<S>,
 
     /// The puffin file accessor.
     puffin_file_accessor: F,
 }
 
 impl<S, F> FsPuffinReader<S, F> {
-    pub(crate) fn new(puffin_file_name: String, stager: S, puffin_file_accessor: F) -> Self {
+    pub(crate) fn new(puffin_file_name: String, stager: Arc<S>, puffin_file_accessor: F) -> Self {
         Self {
             puffin_file_name,
             stager,
diff --git a/src/puffin/src/puffin_manager/fs_puffin_manager/writer.rs b/src/puffin/src/puffin_manager/fs_puffin_manager/writer.rs
index ab7227606d..945cbbc236 100644
--- a/src/puffin/src/puffin_manager/fs_puffin_manager/writer.rs
+++ b/src/puffin/src/puffin_manager/fs_puffin_manager/writer.rs
@@ -14,6 +14,7 @@
 
 use std::collections::HashSet;
 use std::path::PathBuf;
+use std::sync::Arc;
 
 use async_compression::futures::bufread::ZstdEncoder;
 use async_trait::async_trait;
@@ -39,7 +40,7 @@ pub struct FsPuffinWriter<S, W> {
     puffin_file_name: String,
 
     /// The stager.
-    stager: S,
+    stager: Arc<S>,
 
     /// The underlying `PuffinFileWriter`.
     puffin_file_writer: PuffinFileWriter<W>,
@@ -49,7 +50,7 @@ pub struct FsPuffinWriter<S, W> {
 }
 
 impl<S, W> FsPuffinWriter<S, W> {
-    pub(crate) fn new(puffin_file_name: String, stager: S, writer: W) -> Self {
+    pub(crate) fn new(puffin_file_name: String, stager: Arc<S>, writer: W) -> Self {
         Self {
             puffin_file_name,
             stager,
diff --git a/src/puffin/src/puffin_manager/stager.rs b/src/puffin/src/puffin_manager/stager.rs
index fd2c09254c..0ec565c1c1 100644
--- a/src/puffin/src/puffin_manager/stager.rs
+++ b/src/puffin/src/puffin_manager/stager.rs
@@ -52,7 +52,6 @@ pub trait InitDirFn = Fn(DirWriterProviderRef) -> WriteResult;
 
 /// `Stager` manages the staging area for the puffin files.
 #[async_trait]
-#[auto_impl::auto_impl(Box, Rc, Arc)]
 pub trait Stager: Send + Sync {
     type Blob: BlobGuard;
     type Dir: DirGuard;

Signed-off-by: Zhenchi <zhongzc_arch@outlook.com>
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 81ea1b6 and ce0050d.

Files selected for processing (3)
  • src/puffin/src/puffin_manager.rs (2 hunks)
  • src/puffin/src/puffin_manager/file_accessor.rs (1 hunks)
  • src/puffin/src/puffin_manager/stager.rs (3 hunks)
Files skipped from review as they are similar to previous changes (3)
  • src/puffin/src/puffin_manager.rs
  • src/puffin/src/puffin_manager/file_accessor.rs
  • src/puffin/src/puffin_manager/stager.rs

@zhongzc
Copy link
Contributor Author

zhongzc commented Jul 4, 2024

I wonder if we can change stager: S to stager: Arc<S> so that we don't have to derive Stager impl for Arc<T>/Rc<T>/Box<T>

What benefits can be gained from this?

@zhongzc
Copy link
Contributor Author

zhongzc commented Jul 4, 2024

@v0y4g3r
Copy link
Contributor

v0y4g3r commented Jul 4, 2024

I wonder if we can change stager: S to stager: Arc<S> so that we don't have to derive Stager impl for Arc<T>/Rc<T>/Box<T>

What benefits can be gained from this?

Just make the code simpler 😄 overall 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, just don't forget remove the derived impl of Rc and Box for Stager since they're not used anywhere:

#[auto_impl::auto_impl(Box, Rc, Arc)]

Signed-off-by: Zhenchi <zhongzc_arch@outlook.com>
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ce0050d and 37e39c6.

Files selected for processing (3)
  • src/puffin/src/puffin_manager.rs (2 hunks)
  • src/puffin/src/puffin_manager/file_accessor.rs (1 hunks)
  • src/puffin/src/puffin_manager/stager.rs (3 hunks)
Files skipped from review as they are similar to previous changes (3)
  • src/puffin/src/puffin_manager.rs
  • src/puffin/src/puffin_manager/file_accessor.rs
  • src/puffin/src/puffin_manager/stager.rs

@zhongzc zhongzc enabled auto-merge July 4, 2024 12:13
@WenyXu
Copy link
Member

WenyXu commented Jul 4, 2024

@zhongzc zhongzc added this pull request to the merge queue Jul 4, 2024
Merged via the queue into GreptimeTeam:main with commit 6e2c21d Jul 4, 2024
52 of 53 checks passed
@zhongzc zhongzc deleted the zhongzc/fulltext-build-2 branch July 4, 2024 12:41
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.

4 participants