Skip to content

support updating raft-max-inflight-msgs setting#582

Open
glorv wants to merge 1 commit intotikv:masterfrom
glorv:update-max-inflight
Open

support updating raft-max-inflight-msgs setting#582
glorv wants to merge 1 commit intotikv:masterfrom
glorv:update-max-inflight

Conversation

@glorv
Copy link
Contributor

@glorv glorv commented Mar 18, 2026

The current impl only provide function Raft::adjust_max_inflight_msgs that changes the inflight cap of a specific peer. So even when we set all the peers' cap with this function, any incoming peer's cap will still be set with the initial inflight cap. This is not what we want when we want to update the global setting which should update the max_inflight_msgs for all existing and incoming peers.

So this PR add a new function set_raft_max_inflight_msgs to support updating the max_inflight setting.

Signed-off-by: glorv <glorvs@163.com>
@coderabbitai
Copy link

coderabbitai bot commented Mar 18, 2026

📝 Walkthrough

Walkthrough

Added functionality to dynamically adjust the maximum inflight replication messages in a Raft cluster. Three new methods enable updating the cap across the raft instance, progress tracker, and individual inflight entries, with a unit test validating the behavior including preservation of per-peer overrides.

Changes

Cohort / File(s) Summary
Raft Max Inflight Adjustment
src/raft.rs, src/tracker.rs, src/tracker/inflights.rs
Added adjust_raft_max_inflight_msgs() to Raft, set_max_inflight() to ProgressTracker, and get_cap() helper to Inflights to enable dynamic adjustment of maximum inflight messages across all peers while preserving per-peer overrides. Includes unit test verifying the adjustment behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Inflight messages dance and play,
Adjustments tune them every day,
Caps and limits, all in sync,
No more bottlenecks, in a blink!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'support updating raft-max-inflight-msgs setting' directly and clearly summarizes the main change: adding support for updating the global raft max-inflight-msgs setting for all peers.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

You can disable poems in the walkthrough.

Disable the reviews.poem setting to disable the poems in the walkthrough.

@glorv
Copy link
Contributor Author

glorv commented Mar 18, 2026

Copy link

@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.

🧹 Nitpick comments (2)
src/raft.rs (2)

2967-2971: Clean up public API doc wording/typos.

There are a few doc typos and grammar issues around the new API description (e.g., max_inflight_megs, update, overrided, must greater).

✏️ Suggested doc cleanup
- /// Adjust the `max_inflight_megs` setting for this raft group. - /// This function update the `max_inflight` for the whole raft group for any - /// existing peers (if their existing settings are not explicitly overrided) + /// Adjust the `max_inflight_msgs` setting for this raft group. + /// This function updates `max_inflight` for the whole raft group for any + /// existing peers (if their existing settings are not explicitly overridden) /// as well as any incoming peers (via ProgressTracker::apply_conf). - /// The config value must greater than 0. + /// The config value must be greater than 0.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/raft.rs` around lines 2967 - 2971, Fix the public API doc for the max-inflight setting: update the comment for the function that adjusts `max_inflight_megs` so it reads clearly and fixes typos — e.g. "Adjust the `max_inflight_megs` setting for this raft group." then "This function updates the `max_inflight` for the whole raft group for any existing peers (if their existing settings are not explicitly overridden) as well as for any incoming peers (via ProgressTracker::apply_conf)." and finish with "The config value must be greater than 0." Ensure references to `max_inflight_megs`, `max_inflight`, and `ProgressTracker::apply_conf` remain intact. 

2994-3011: Add one test assertion for newly added peers after global update.

This test validates existing-peer propagation and override preservation well, but it does not yet verify the “incoming peers use updated cap” path from the PR objective. Please add a follow-up case that adds a new peer after Line 3004 and checks its inflight cap is 512.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/raft.rs` around lines 2994 - 3011, In the test test_adjust_raft_max_inflight_msgs_preserves_peer_overrides, after you call raft.adjust_raft_max_inflight_msgs(512) add a new peer and assert it receives the updated global cap: create a new Peer via raft.mut_prs().get_mut(<new_peer_id>) (e.g., 4), call its ins.add(...) if needed, then assert its ins.get_cap() == 512 to verify newly added peers inherit the global max_inflight; keep existing assertions unchanged. 
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed. Nitpick comments: In `@src/raft.rs`: - Around line 2967-2971: Fix the public API doc for the max-inflight setting: update the comment for the function that adjusts `max_inflight_megs` so it reads clearly and fixes typos — e.g. "Adjust the `max_inflight_megs` setting for this raft group." then "This function updates the `max_inflight` for the whole raft group for any existing peers (if their existing settings are not explicitly overridden) as well as for any incoming peers (via ProgressTracker::apply_conf)." and finish with "The config value must be greater than 0." Ensure references to `max_inflight_megs`, `max_inflight`, and `ProgressTracker::apply_conf` remain intact. - Around line 2994-3011: In the test test_adjust_raft_max_inflight_msgs_preserves_peer_overrides, after you call raft.adjust_raft_max_inflight_msgs(512) add a new peer and assert it receives the updated global cap: create a new Peer via raft.mut_prs().get_mut(<new_peer_id>) (e.g., 4), call its ins.add(...) if needed, then assert its ins.get_cap() == 512 to verify newly added peers inherit the global max_inflight; keep existing assertions unchanged. 

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 22ac2f20-0535-42d7-9980-d4d2df5fef18

📥 Commits

Reviewing files that changed from the base of the PR and between aafb07c and f56a2e8.

📒 Files selected for processing (3)
  • src/raft.rs
  • src/tracker.rs
  • src/tracker/inflights.rs
@glorv
Copy link
Contributor Author

glorv commented Mar 18, 2026

/retest

@glorv
Copy link
Contributor Author

glorv commented Mar 18, 2026

/test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

1 participant