Skip to content

[ISSUE #3491]🚀Add group_commit_request module to log_file for enhanced commit handling✨#3492

Merged
rocketmq-rust-bot merged 1 commit intomainfrom
feature-3491
Jun 21, 2025
Merged

[ISSUE #3491]🚀Add group_commit_request module to log_file for enhanced commit handling✨#3492
rocketmq-rust-bot merged 1 commit intomainfrom
feature-3491

Conversation

@mxsm
Copy link
Owner

@mxsm mxsm commented Jun 21, 2025

Which Issue(s) This PR Fixes(Closes)

Fixes #3491

Brief Description

How Did You Test This Change?

Summary by CodeRabbit

  • New Features
    • Introduced a mechanism to manage and track group commit requests with support for timeouts and acknowledgment requirements.
    • Added asynchronous notification for flush completion status, allowing tasks to wait for commit results or timeouts.
    • Enhanced logging for group commit requests and included comprehensive tests to verify behavior.

Copilot AI review requested due to automatic review settings June 21, 2025 14:41
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 21, 2025

Walkthrough

A new module, group_commit_request, has been introduced and publicly exported in the rocketmq-store crate. This module provides the GroupCommitRequest struct, which manages asynchronous group commit requests with timeout and acknowledgment tracking, along with associated methods and tests.

Changes

File(s) Change Summary
rocketmq-store/src/log_file.rs Added public export of the group_commit_request module.
rocketmq-store/src/log_file/group_commit_request.rs Introduced new module with the GroupCommitRequest struct, its methods, async tests, and Debug implementation.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant GroupCommitRequest
    participant StorageEngine

    Client->>GroupCommitRequest: Create new request (with offset, timeout, ack_nums)
    GroupCommitRequest->>StorageEngine: Submit commit request
    StorageEngine-->>GroupCommitRequest: Process commit, reach required acks
    GroupCommitRequest->>Client: Notify via channel (wakeup_customer)
    Client->>GroupCommitRequest: Await flush result (with/without timeout)
    GroupCommitRequest-->>Client: Return PutMessageStatus or timeout error
Loading

Assessment against linked issues

Objective Addressed Explanation
Add group_commit_request module to log_file for enhanced commit handling (#3491)

Poem

In the warren where code bunnies hop,
A group commit request now takes the top!
With timeouts and acks, it keeps things in sync,
Async and safe—faster than you think.
So thump your paws and wiggle your nose,
For rocket-fast commits—off the rabbit goes! 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@rocketmq-rust-robot rocketmq-rust-robot added the feature🚀 Suggest an idea for this project. label Jun 21, 2025
@rocketmq-rust-bot rocketmq-rust-bot added the AI review first Ai review pr first label Jun 21, 2025
@rocketmq-rust-bot
Copy link
Collaborator

🔊@mxsm 🚀Thanks for your contribution🎉!

💡CodeRabbit(AI) will review your code first🔥!

Note

🚨The code review suggestions from CodeRabbit are to be used as a reference only, and the PR submitter can decide whether to make changes based on their own judgment. Ultimately, the project management personnel will conduct the final code review💥.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds a new group_commit_request module to coordinate flush requests with configurable timeouts and acknowledgement counts.

  • Introduced GroupCommitRequest for handling batched commit flushes, with timeout and ack number support.
  • Exposed the new module in log_file.rs.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
rocketmq-store/src/log_file/group_commit_request.rs Added GroupCommitRequest implementation and tests
rocketmq-store/src/log_file.rs Exported the group_commit_request module
Comments suppressed due to low confidence (3)

rocketmq-store/src/log_file/group_commit_request.rs:179

  • The test starts a wait_for_result future but never awaits it or asserts its outcome. To cover the wake_up_customer path, await result_future and assert it returns PutMessageStatus::PutOk.
        let result_future = request.clone_with_new_channel().wait_for_result();

rocketmq-store/src/log_file/group_commit_request.rs:127

  • There's no test verifying that clone_with_new_channel preserves the request data and creates an independent channel. Consider adding a test asserting the clone's fields match the original and that waking up one request doesn't affect the other.
    pub fn clone_with_new_channel(&self) -> Self {

rocketmq-store/src/log_file/group_commit_request.rs:189

  • The test test_timeout uses Instant::now() without importing Instant, causing a compilation error. Consider adding use std::time::Instant; in the tests module.
        let start = Instant::now();

Comment on lines +37 to +48
let (sender, receiver) = oneshot::channel();
Self {
next_offset,
flush_ok_sender: Some(sender),
flush_ok_receiver: Some(receiver),
ack_nums: 1,
deadline: Instant::now() + Duration::from_millis(timeout_millis),
}
}

/// Create a new GroupCommitRequest with timeout and ack numbers
pub fn with_ack_nums(next_offset: i64, timeout_millis: u64, ack_nums: i32) -> Self {
Copy link

Copilot AI Jun 21, 2025

Choose a reason for hiding this comment

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

[nitpick] There's duplicated logic between new and with_ack_nums for creating channels and setting the deadline. Consider refactoring by extracting a private constructor that accepts ack_nums, reducing code duplication.

Suggested change
let (sender, receiver) = oneshot::channel();
Self {
next_offset,
flush_ok_sender: Some(sender),
flush_ok_receiver: Some(receiver),
ack_nums: 1,
deadline: Instant::now() + Duration::from_millis(timeout_millis),
}
}
/// Create a new GroupCommitRequest with timeout and ack numbers
pub fn with_ack_nums(next_offset: i64, timeout_millis: u64, ack_nums: i32) -> Self {
Self::create_request(next_offset, timeout_millis, 1)
}
/// Create a new GroupCommitRequest with timeout and ack numbers
pub fn with_ack_nums(next_offset: i64, timeout_millis: u64, ack_nums: i32) -> Self {
Self::create_request(next_offset, timeout_millis, ack_nums)
}
/// Private constructor to encapsulate common logic
fn create_request(next_offset: i64, timeout_millis: u64, ack_nums: i32) -> Self {

Copilot uses AI. Check for mistakes.
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: 2

🧹 Nitpick comments (1)
rocketmq-store/src/log_file/group_commit_request.rs (1)

34-57: Eliminate constructor code duplication.

The two constructors contain identical logic except for the ack_nums parameter. Consider refactoring to improve maintainability:

 /// Create a new GroupCommitRequest with timeout in milliseconds
 pub fn new(next_offset: i64, timeout_millis: u64) -> Self {
-    let (sender, receiver) = oneshot::channel();
-    Self {
-        next_offset,
-        flush_ok_sender: Some(sender),
-        flush_ok_receiver: Some(receiver),
-        ack_nums: 1,
-        deadline: Instant::now() + Duration::from_millis(timeout_millis),
-    }
+    Self::with_ack_nums(next_offset, timeout_millis, 1)
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3bb4a29 and 56bb359.

📒 Files selected for processing (2)
  • rocketmq-store/src/log_file.rs (1 hunks)
  • rocketmq-store/src/log_file/group_commit_request.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: auto-approve
  • GitHub Check: build (windows-latest, stable)
  • GitHub Check: build (ubuntu-latest, stable)
  • GitHub Check: build (windows-latest, nightly)
  • GitHub Check: build (ubuntu-latest, nightly)
  • GitHub Check: build (macos-latest, stable)
  • GitHub Check: build (macos-latest, nightly)
  • GitHub Check: test
  • GitHub Check: build
🔇 Additional comments (3)
rocketmq-store/src/log_file.rs (1)

21-21: LGTM! Clean module integration.

The module export follows standard Rust conventions and integrates the new group_commit_request module into the existing module hierarchy appropriately.

rocketmq-store/src/log_file/group_commit_request.rs (2)

139-149: Excellent Debug implementation.

The custom Debug implementation provides meaningful information while appropriately hiding internal channel implementation details. The boolean flags for channel presence are much more useful than attempting to debug the actual channels.


26-137: Solid architectural design for async group commit management.

The GroupCommitRequest struct demonstrates excellent async patterns:

  • Proper use of oneshot channels for async communication
  • Clean separation between request creation, waiting, and signaling
  • Flexible API supporting both timed and untimed operations
  • Clever clone_with_new_channel() method for multiple waiters

The implementation follows Rust async best practices and provides a robust foundation for group commit functionality.

Comment on lines +174 to +183
#[tokio::test]
async fn test_wakeup_customer() {
let mut request = GroupCommitRequest::new(12345, 5000);

// Start waiting for result in background
let result_future = request.clone_with_new_channel().wait_for_result();

// Wakeup with success status
request.wakeup_customer(PutMessageStatus::PutOk);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix incomplete test - result future is never awaited.

The test creates result_future but never awaits it, so it doesn't verify that wakeup_customer actually works.

 #[tokio::test]
 async fn test_wakeup_customer() {
     let mut request = GroupCommitRequest::new(12345, 5000);

     // Start waiting for result in background
-    let result_future = request.clone_with_new_channel().wait_for_result();
+    let cloned_request = request.clone_with_new_channel();
+    let result_future = tokio::spawn(async move {
+        cloned_request.wait_for_result().await
+    });

     // Wakeup with success status
     request.wakeup_customer(PutMessageStatus::PutOk);
+    
+    // Verify the result was received
+    let result = result_future.await.unwrap().unwrap();
+    assert!(matches!(result, PutMessageStatus::PutOk));
 }
🤖 Prompt for AI Agents
In rocketmq-store/src/log_file/group_commit_request.rs around lines 174 to 183,
the test_wakeup_customer function creates a future result_future but never
awaits it, so it does not verify the effect of wakeup_customer. Fix this by
awaiting result_future after calling wakeup_customer to ensure the test properly
waits for and checks the result.

Comment on lines +105 to +123
pub async fn wait_for_result_with_timeout(
mut self,
) -> Result<PutMessageStatus, Box<dyn std::error::Error + Send + Sync>> {
if let Some(receiver) = self.flush_ok_receiver.take() {
let timeout_duration = if self.deadline > Instant::now() {
self.deadline - Instant::now()
} else {
Duration::from_millis(0)
};

match tokio::time::timeout(timeout_duration, receiver).await {
Ok(Ok(status)) => Ok(status),
Ok(Err(_)) => Err("Sender was dropped before sending result".into()),
Err(_) => Ok(PutMessageStatus::FlushDiskTimeout),
}
} else {
Err("Receiver was already consumed".into())
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Handle past deadline edge case and improve documentation.

Two observations:

  1. Edge case: When deadline is in the past, timeout_duration becomes 0, causing immediate timeout. Consider if this is the intended behavior or if it should return an error/expired status immediately.

  2. Documentation: The one-time consumption nature of wait_for_result* methods should be documented since they consume self and take the receiver.

 /// Get a future that resolves when the flush operation completes with timeout
+/// Note: This method consumes self and can only be called once per request instance.
 pub async fn wait_for_result_with_timeout(
     mut self,
 ) -> Result<PutMessageStatus, Box<dyn std::error::Error + Send + Sync>> {
     if let Some(receiver) = self.flush_ok_receiver.take() {
         let timeout_duration = if self.deadline > Instant::now() {
             self.deadline - Instant::now()
         } else {
-            Duration::from_millis(0)
+            return Ok(PutMessageStatus::FlushDiskTimeout);
         };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
pub async fn wait_for_result_with_timeout(
mut self,
) -> Result<PutMessageStatus, Box<dyn std::error::Error + Send + Sync>> {
if let Some(receiver) = self.flush_ok_receiver.take() {
let timeout_duration = if self.deadline > Instant::now() {
self.deadline - Instant::now()
} else {
Duration::from_millis(0)
};
match tokio::time::timeout(timeout_duration, receiver).await {
Ok(Ok(status)) => Ok(status),
Ok(Err(_)) => Err("Sender was dropped before sending result".into()),
Err(_) => Ok(PutMessageStatus::FlushDiskTimeout),
}
} else {
Err("Receiver was already consumed".into())
}
}
/// Get a future that resolves when the flush operation completes with timeout
/// Note: This method consumes self and can only be called once per request instance.
pub async fn wait_for_result_with_timeout(
mut self,
) -> Result<PutMessageStatus, Box<dyn std::error::Error + Send + Sync>> {
if let Some(receiver) = self.flush_ok_receiver.take() {
let timeout_duration = if self.deadline > Instant::now() {
self.deadline - Instant::now()
} else {
return Ok(PutMessageStatus::FlushDiskTimeout);
};
match tokio::time::timeout(timeout_duration, receiver).await {
Ok(Ok(status)) => Ok(status),
Ok(Err(_)) => Err("Sender was dropped before sending result".into()),
Err(_) => Ok(PutMessageStatus::FlushDiskTimeout),
}
} else {
Err("Receiver was already consumed".into())
}
}
🤖 Prompt for AI Agents
In rocketmq-store/src/log_file/group_commit_request.rs around lines 105 to 123,
handle the edge case where the deadline is in the past by returning an immediate
error or expired status instead of setting a zero timeout that causes immediate
timeout. Also, add documentation comments to the wait_for_result_with_timeout
method explaining that it consumes self and the receiver can only be used once,
clarifying its one-time consumption behavior.

@codecov
Copy link

codecov bot commented Jun 21, 2025

Codecov Report

Attention: Patch coverage is 76.92308% with 24 lines in your changes missing coverage. Please review.

Project coverage is 26.41%. Comparing base (3bb4a29) to head (56bb359).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ocketmq-store/src/log_file/group_commit_request.rs 76.92% 24 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3492      +/-   ##
==========================================
+ Coverage   26.34%   26.41%   +0.06%     
==========================================
  Files         547      548       +1     
  Lines       77877    77981     +104     
==========================================
+ Hits        20516    20596      +80     
- Misses      57361    57385      +24     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Collaborator

@rocketmq-rust-bot rocketmq-rust-bot left a comment

Choose a reason for hiding this comment

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

LGTM

@rocketmq-rust-bot rocketmq-rust-bot merged commit e237869 into main Jun 21, 2025
24 checks passed
@rocketmq-rust-bot rocketmq-rust-bot added approved PR has approved and removed ready to review waiting-review waiting review this PR labels Jun 21, 2025
@mxsm mxsm deleted the feature-3491 branch June 26, 2025 03:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI review first Ai review pr first approved PR has approved auto merge feature🚀 Suggest an idea for this project.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature🚀] Add group_commit_request module to log_file for enhanced commit handling

4 participants