Guangcun Li created RATIS-2814:
----------------------------------
Summary: RaftServerImpl.replyPendingRequest() ignores the
replacement entry returned by refreshEntry()
Key: RATIS-2814
URL: https://issues.apache.org/jira/browse/RATIS-2814
Project: Ratis
Issue Type: Bug
Components: server
Reporter: Guangcun Li
Attachments:
org.apache.ratis.grpc.TestLeaderElectionWithGrpc-output.txt
h3. 1. RaftServerImpl.replyPendingRequest() ignores the replacement entry
returned by refreshEntry()
The old leader registers a write in the RetryCache, then steps down before
appending it to the log. The first attempt receives a {{NotLeaderException}}
reply. The client retries the write on the new leader with the same client ID
and call ID.
When the old leader applies the committed write,
{{RaftServerImpl.replyPendingRequest()}} replaces the failed cache entry, but
the reply callback still tries to complete the original entry's reply future.
With Java assertions enabled, {{CacheEntry.updateResult()}} throws
{{AssertionError}} because that future is already complete. The replacement
entry's future remains pending.
Use the entry returned by {{refreshEntry()}} when completing the reply.
h3. 2. Redundant log data parsing in FileStoreStateMachine
{{FileStoreStateMachine.startTransaction(LogEntryProto, RaftPeerRole)}} parses
the log data and sets {{stateMachineContext}} on the builder. The log-entry
branch of {{TransactionContext.Builder.build()}} drops this field, so
{{write()}}, {{read()}}, and {{applyTransaction()}} fall back to parsing the
log data when they receive a context with no cached request.
Create the transaction context with {{super.startTransaction(entry, role)}} and
set the parsed request on the returned context.
h3. Verification
* {{TestLeaderElectionWithGrpc#testRetryCacheCompletesAfterLeaderTransfer}}
reproduces the issue. The old leader logs an {{AssertionError}} in
{{CacheEntry.updateResult()}}, and the test fails because the replacement entry
has no reply. See lines 483–496 of
[^org.apache.ratis.grpc.TestLeaderElectionWithGrpc-output.txt] for the old
leader's {{CacheEntry.updateResult()}} stack trace.
* With the RetryCache fix, the reproducing test passes on gRPC, Netty, and
Simulated RPC.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)