Query counter bug fix - query counter in example server#1476
Open
haroon3rd wants to merge 2 commits into
Open
Conversation
Query counter returned empty counter... fixed the code
Refactor queryCounter to use ByteBuffer for count
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates the membership example’s counter query path to decode the read-only reply as a binary int instead of a UTF-8 string.
Changes:
- Switched
queryCounter()reply decoding fromtoStringUtf8()toByteBuffer.getInt() - Reformatted the
queryCounter()method body (line breaks / indentation)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+148
to
+156
| RaftClientReply reply = client.io().sendReadOnly( | ||
| CounterCommand.GET.getMessage()); | ||
|
|
||
| ByteBuffer buffer = | ||
| reply.getMessage() | ||
| .getContent() | ||
| .asReadOnlyByteBuffer(); | ||
|
|
||
| int count = buffer.getInt(); |
Comment on lines
+146
to
+149
| RaftClient client = createClient(); | ||
| try { | ||
| RaftClientReply reply = client.io().sendReadOnly( | ||
| CounterCommand.GET.getMessage()); |
Comment on lines
+146
to
+147
| RaftClient client = createClient(); | ||
| try { |
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?
This patch fixes an issue in the membership example where the
querycommand displayed an empty counter value even after successful counter updates.The root cause was an encoding mismatch between the server and client implementations. The
CounterStateMachinereturns the counter value as a 4-byte binary integer (ByteString), while the membership example client attempted to decode the response using UTF-8 string conversion. As a result, the query output appeared empty.This patch updates the
queryCounter()implementation inRaftClusterto correctly deserialize the binary response usingByteBuffer.getInt(), allowing the current counter value to be displayed correctly.What is the link to the Apache JIRA
Apache JIRA: RATIS-XXXX
(Replace with the actual JIRA issue link after creating the issue.)
How was this patch tested?
The fix was verified manually using the Ratis membership example.
Test procedure:
incrcommand multiple times.querycommand.Before the fix:
After the fix:
The returned counter value now correctly reflects the state maintained by
CounterStateMachine.