Repository navigation
RATIS-2816. Preserve stateMachineContext in FileStoreStateMachine.startTransaction() - #1696
Merged
Merged
Conversation
amaliujia
reviewed
Nov 17, 2026
amaliujia
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the change.
We could also have a unit test in TestStateMachine.java as:
@Test
public void testTransactionContextFromLogEntry() {
final LogEntryProto entry = LogEntryProto.newBuilder()
.setTerm(1)
.setIndex(1)
.setStateMachineLogEntry(StateMachineLogEntryProto.newBuilder()
.setLogData(ByteString.copyFromUtf8("log-data")))
.build();
final StateMachine sm = new SimpleStateMachine4Testing();
final Object context = new Object();
final TransactionContext withContext = TransactionContext.newBuilder()
.setStateMachine(sm)
.setLogEntry(entry)
.setServerRole(RaftPeerRole.FOLLOWER)
.setStateMachineContext(context)
.build();
Assertions.assertSame(context, withContext.getStateMachineContext());
Assertions.assertSame(entry, withContext.getLogEntry());
assertEquals(RaftPeerRole.FOLLOWER, withContext.getServerRole());
final TransactionContext withoutContext = sm.startTransaction(entry, RaftPeerRole.FOLLOWER);
assertNull(withoutContext.getStateMachineContext());
}| .setStateMachineContext(getProto(entry)) | ||
| .build(); | ||
| final TransactionContext trx = super.startTransaction(entry, role); | ||
| return trx.setStateMachineContext(getProto(entry)); |
Contributor
There was a problem hiding this comment.
Thanks for reporting this. The real issue then is inside the builder actually. So we should fix there directly at
} else {
Objects.requireNonNull(logEntry, "logEntry must not be null since clientRequest == null");
Preconditions.assertTrue(logEntry.hasStateMachineLogEntry(),
() -> "Unexpected logEntry: stateMachineLogEntry not found, logEntry=" + logEntry);
return newTransactionContext(serverRole, stateMachine, logEntry)
.setStateMachineContext(stateMachineContext);
}
amaliujia
approved these changes
Nov 18, 2026
Contributor
Author
|
Thanks @amaliujia for reviewing and merging! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
FileStoreStateMachine#startTransaction(LogEntryProto, RaftPeerRole)parses the log data and sets the parsed request on the transaction context builder. The log-entry branch ofTransactionContext.Builder#build()drops that value, sowrite(),read(), andapplyTransaction()fall back to parsing the log data again.super.startTransaction(entry, role)and set the parsed request on the returned context so it can be reused.What is the link to the Apache JIRA
RATIS-2816
How was this patch tested?
Tested locally.
TestFileStoreWithGrpcTestFileStoreAsyncWithGrpcTestFileStoreStreamingWithGrpcCluster