Skip to content

Query counter bug fix - query counter in example server#1476

Open
haroon3rd wants to merge 2 commits into
apache:masterfrom
haroon3rd:master
Open

Query counter bug fix - query counter in example server#1476
haroon3rd wants to merge 2 commits into
apache:masterfrom
haroon3rd:master

Conversation

@haroon3rd
Copy link
Copy Markdown

What changes were proposed in this pull request?

This patch fixes an issue in the membership example where the query command displayed an empty counter value even after successful counter updates.

The root cause was an encoding mismatch between the server and client implementations. The CounterStateMachine returns 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 in RaftCluster to correctly deserialize the binary response using ByteBuffer.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:

  1. Build and run the membership example.
  2. Start a cluster with multiple peers.
  3. Execute the incr command multiple times.
  4. Execute the query command.

Before the fix:

>>> incr
>>> incr
>>> query
Current counter value:

After the fix:

>>> incr
>>> incr
>>> query
Current counter value: 2

The returned counter value now correctly reflects the state maintained by CounterStateMachine.

haroon3rd added 2 commits June 3, 2026 00:22
Query counter returned empty counter... fixed the code
Refactor queryCounter to use ByteBuffer for count
Copilot AI review requested due to automatic review settings June 3, 2026 05:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 from toStringUtf8() to ByteBuffer.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 {
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.

2 participants