Skip to content

Conversation

@bufferflies
Copy link
Contributor

@bufferflies bufferflies commented Jan 12, 2026

ref code:

reqs := b.entries.Take(int(n))
if len(reqs) == 0 {
	break
}
build(reqs)

Summary by CodeRabbit

  • Refactor
    • Optimized internal batch processing logic with improved early exit conditions to enhance performance.

✏️ Tip: You can customize this high-level summary in your review settings.

@ti-chi-bot ti-chi-bot bot added dco-signoff: yes Indicates the PR's author has signed the dco. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jan 12, 2026
Signed-off-by: bufferflies <1045931706@qq.com>
@ti-chi-bot
Copy link

ti-chi-bot bot commented Jan 13, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: rleungx
Once this PR has been reviewed and has the lgtm label, please assign crazycs520 for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jan 13, 2026
@ti-chi-bot
Copy link

ti-chi-bot bot commented Jan 13, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-01-13 07:50:17.820056139 +0000 UTC m=+343861.881921049: ☑️ agreed by rleungx.

@rleungx
Copy link
Member

rleungx commented Jan 15, 2026

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Jan 15, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link

coderabbitai bot commented Jan 15, 2026

📝 Walkthrough

Walkthrough

Adds an exhaust flag to the internal batching logic that signals when no additional requests remain available. When the flag is set, the batching loop exits early, modifying the control flow of batch extraction without affecting public interfaces.

Changes

Cohort / File(s) Summary
Batch extraction control flow
internal/client/client_batch.go
Introduces an exhaust flag initialized to false in buildWithLimit; sets exhaust based on remaining requests during iteration; adds early-exit break statement after batch extraction when exhaust condition is true

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A batching hop with cleaner breaks,
No more requests, the loop it takes—
An exit swift when wells run dry,
Efficiency made way up high!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: adding an early-exit condition that breaks the loop when entries are exhausted (no more entries to process).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing touches
  • 📝 Generate docstrings


📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 01cdf70 and 5d240ae.

📒 Files selected for processing (1)
  • internal/client/client_batch.go

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


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

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.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/client/client_batch.go (1)

155-193: Bug: exhaust flag can never be set to true.

The assignment exhaust = len(reqs) == 0 on line 182 is placed inside the for _, e := range reqs loop. This means:

  1. If reqs is empty, the loop body never executes, so exhaust stays false.
  2. If reqs is non-empty, len(reqs) > 0 inside the loop, so exhaust is set to false.

The check should occur at the start of the build function, before entering the loop.

🐛 Proposed fix
 build := func(reqs []Item) {
+	if len(reqs) == 0 {
+		exhaust = true
+		return
+	}
 	for _, e := range reqs {
 		e := e.(*batchCommandsEntry)
 		if e.isCanceled() {
 			continue
 		}
 		if e.priority() < highTaskPriority {
 			count++
 		}

 		if collect != nil {
 			collect(b.idAlloc, e)
 		}
 		if e.forwardedHost == "" {
 			b.requestIDs = append(b.requestIDs, b.idAlloc)
 			b.requests = append(b.requests, e.req)
 		} else {
 			batchReq, ok := b.forwardingReqs[e.forwardedHost]
 			if !ok {
 				batchReq = &tikvpb.BatchCommandsRequest{}
 				b.forwardingReqs[e.forwardedHost] = batchReq
 			}
 			batchReq.RequestIds = append(batchReq.RequestIds, b.idAlloc)
 			batchReq.Requests = append(batchReq.Requests, e.req)
 		}
 		b.idAlloc++
-		exhaust = len(reqs) == 0
 	}
 }
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 01cdf70 and 5d240ae.

📒 Files selected for processing (1)
  • internal/client/client_batch.go

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

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

Labels

dco-signoff: yes Indicates the PR's author has signed the dco. needs-1-more-lgtm Indicates a PR needs 1 more LGTM. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants