Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,35 @@ public BriefStatistics index() throws PDException, ExecutionException, Interrupt
BriefStatistics statistics = new BriefStatistics();
statistics.leader = RaftEngine.getInstance().getLeaderGrpcAddress();
statistics.state = pdService.getStoreNodeService().getClusterStats().getState().toString();

// Use pdService (consistent with cluster()) rather than RaftEngine directly
CallStreamObserverWrap<Pdpb.GetMembersResponse> membersResp =
new CallStreamObserverWrap<>();
pdService.getMembers(Pdpb.GetMembersRequest.newBuilder().build(), membersResp);
statistics.memberSize = membersResp.get().get(0).getMembersList().size();

statistics.storeSize = pdService.getStoreNodeService().getActiveStores().size();
statistics.graphSize = pdService.getPartitionService().getGraphs().size();
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.

The previous fix adds:
statistics.memberSize = RaftEngine.getInstance().getMembers().size();

But the cluster() method (the "correct" counterpart) uses the service layer:

pdService.getMembers(Pdpb.GetMembersRequest.newBuilder().build(), response);
statistics.memberSize = pdList.size();  // from pdService, not RaftEngine

The issue discussion (comments 3–4 from bitflicker64 and dosubot) explicitly recommends using pdService.getMembers().size() for consistency with cluster() and to stay in the service layer. The merged fix goes against this recommendation.

// Filter to user-facing graphs only (consistent with cluster())
List<Metapb.Graph> graphs = pdRestService.getGraphs();
statistics.graphSize = (int) graphs.stream()
.filter(g -> g.getGraphName() != null &&
g.getGraphName().endsWith("/g"))
.count();
statistics.partitionSize = pdService.getStoreNodeService().getShardGroups().size();

// Derive worst partition health state across all graphs
Metapb.PartitionState dataState = Metapb.PartitionState.PState_Normal;
for (Metapb.Graph graph : graphs) {
if (graph.getState() == Metapb.PartitionState.UNRECOGNIZED) {
continue;
}
if (graph.getState() != null &&
graph.getState().getNumber() > dataState.getNumber()) {
dataState = graph.getState();
}
}
statistics.dataState = dataState.name();

return statistics;

}
Expand Down Expand Up @@ -157,9 +183,13 @@ public RestApiResponse cluster() throws InterruptedException, ExecutionException
class BriefStatistics {

String state;
/** Worst partition health state across all graphs (mirrors cluster().dataState) */
String dataState;
String leader;
int memberSize;
/** Active (online) store count only */
int storeSize;
/** User-facing graphs count (graphName ending with /g) */
int graphSize;
int partitionSize;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,25 @@

public class RestApiTest extends BaseServerTest {

@Test
public void testQueryIndexInfo() throws URISyntaxException, IOException, InterruptedException,
JSONException {
String url = pdRestAddr + "/";
HttpRequest request = HttpRequest.newBuilder()
.uri(new URI(url))
.header("Authorization", "Basic c3RvcmU6MTIz")
.GET()
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
assert response.statusCode() == 200;
JSONObject obj = new JSONObject(response.body());
assert obj.getString("state") != null;
assert obj.getString("leader") != null;
assert obj.getInt("memberSize") > 0 : "memberSize should be > 0 for a running cluster";
// storeSize can be 0 in PD-only test environments with no store nodes registered
assert obj.getInt("storeSize") >= 0;
}

@Test
public void testQueryClusterInfo() throws URISyntaxException, IOException, InterruptedException,
JSONException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@

public class RestApiTest extends BaseServerTest {

@Test
public void testQueryIndexInfo() throws URISyntaxException, IOException, InterruptedException,
JSONException {
String url = pdRestAddr + "/";
HttpRequest request = HttpRequest.newBuilder()
.uri(new URI(url)).header(key, value)
.GET()
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
assert response.statusCode() == 200;
JSONObject obj = new JSONObject(response.body());
assert obj.getString("state") != null;
assert obj.getString("leader") != null;
assert obj.getInt("memberSize") > 0 : "memberSize should be > 0 for a running cluster";
// storeSize can be 0 in PD-only test environments with no store nodes registered
assert obj.getInt("storeSize") >= 0;
}

@Test
public void testQueryClusterInfo() throws URISyntaxException, IOException, InterruptedException,
JSONException {
Expand Down
Loading