Skip to content

[server] Offload NotifyLeaderAndIsr to dedicated single-thread executor#3647

Merged
fresh-borzoni merged 2 commits into
apache:mainfrom
zuston:seperateKvInit
Jul 16, 2026
Merged

[server] Offload NotifyLeaderAndIsr to dedicated single-thread executor#3647
fresh-borzoni merged 2 commits into
apache:mainfrom
zuston:seperateKvInit

Conversation

@zuston

@zuston zuston commented Jul 14, 2026

Copy link
Copy Markdown
Member

Purpose

Linked issue: close #3646

NotifyLeaderAndIsr is currently processed on the RPC worker thread. The underlying becomeLeaderOrFollower operation may perform relatively expensive replica state transitions, such as initializing local replicas and updating replica fetchers. A slow transition can therefore occupy an RPC worker thread and delay unrelated RPC requests.

Brief change log

Introduce a dedicated single-thread executor for NotifyLeaderAndIsr operations.
The executor is created and managed by TabletServer , injected into TabletService , and gracefully shut down before replica-related resources are closed. TabletService parses the request on the RPC worker thread and submits the replica state transition to the dedicated executor.

A single thread is sufficient because replica state changes are already serialized by the replica state change lock. It also preserves the execution order of NotifyLeaderAndIsr requests while preventing slow transitions from blocking other RPCs.
The RPC semantics remain unchanged: the response future is completed only after becomeLeaderOrFollower finishes.

Tests

API and Format

Documentation

@zuston

zuston commented Jul 15, 2026

Copy link
Copy Markdown
Member Author

Could you help review this? @fresh-borzoni

@fresh-borzoni fresh-borzoni left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@zuston Thank you, makes sense overall, left a suggestion, PTAL

notifyLeaderAndIsrRequestData,
result -> response.complete(makeNotifyLeaderAndIsrResponse(result)));
try {
replicaStateChangeExecutor.execute(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should stopReplicas go through this executor too?
It takes the same replicaStateChangeLock but still runs on the RPC worker, so a stop can now overtake queued notifies, which the per-connection ordering used to prevent.

Same-executor for both would fix the ordering, and also keep stops from blocking an RPC worker on the lock while a slow transition runs.
WDYT?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

nice suggestion. let me add the remaining rpcs into this dedicated executor.

@zuston

zuston commented Jul 16, 2026

Copy link
Copy Markdown
Member Author

updated. @fresh-borzoni

@zuston
zuston requested a review from fresh-borzoni July 16, 2026 04:06

@fresh-borzoni fresh-borzoni left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@zuston Thank you, LGTM 👍

@fresh-borzoni
fresh-borzoni merged commit 3da87ca into apache:main Jul 16, 2026
17 checks passed
@zuston
zuston deleted the seperateKvInit branch July 16, 2026 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Offload NotifyLeaderAndIsr from RPC worker threads

2 participants