Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] pd /v1/partitions method returns data partition ID are all 0 #2595

Closed
1 task done
haohao0103 opened this issue Jul 19, 2024 · 1 comment · Fixed by #2596
Closed
1 task done

[Bug] pd /v1/partitions method returns data partition ID are all 0 #2595

haohao0103 opened this issue Jul 19, 2024 · 1 comment · Fixed by #2596
Labels
bug Something isn't working pd PD module

Comments

@haohao0103
Copy link
Contributor

Bug Type (问题类型)

rest-api (结果不合预期)

Before submit

  • 我已经确认现有的 IssuesFAQ 中没有相同 / 重复问题 (I have confirmed and searched that there are no similar problems in the historical issue and documents)

Environment (环境信息)

  • Server Version: 1.5.0 (Apache Release Version)

Expected & Actual behavior (期望与实际表现)

curl http://xxx:8620/v1/partitions

results:

{
      "id": 1,
      "version": 0,
      "graphName": "hugegraph/g",
      "startKey": 4096,
      "endKey": 8192,
      "workState": "PState_Normal",
      "shards": [{
        "address": "xx.xx.xx.xx:8501",
        "storeId": "6314496415565905494",
        "role": "Leader",
        "state": "SState_Normal",
        "progress": 0,
        "committedIndex": "12431845",
        "partitionId": 0
      }, {
        "address": "xx.xx.xx.xx:8501",
        "storeId": "8302673618813851034",
        "role": "Follower",
        "state": "SState_Normal",
        "progress": 0,
        "committedIndex": "12431846",
        "partitionId": 0
      }, {
        "address": "xx.xx.xx.xx:8501",
        "storeId": "5373255851016283814",
        "role": "Follower",
        "state": "SState_Normal",
        "progress": 0,
        "committedIndex": "12431853",
        "partitionId": 0
      }],
      "timestamp": "2024-07-18 15:59:41"
    }, {
      "id": 2,
      "version": 0,
      "graphName": "hugegraph/g",
      "startKey": 8192,
      "endKey": 12288,
      "workState": "PState_Normal",
      "shards": [{
        "address": "xx.xx.xx.xx:8501",
        "storeId": "8302673618813851034",
        "role": "Follower",
        "state": "SState_Normal",
        "progress": 0,
        "committedIndex": "12258651",
        "partitionId": 0
      }, {
        "address": "xx.xx.xx.xx:8501",
        "storeId": "5373255851016283814",
        "role": "Follower",
        "state": "SState_Normal",
        "progress": 0,
        "committedIndex": "12258651",
        "partitionId": 0
      }, {
        "address": "xx.xx.xx.xx:8501",
        "storeId": "487476059461220547",
        "role": "Leader",
        "state": "SState_Normal",
        "progress": 0,
        "committedIndex": "12258651",
        "partitionId": 0
      }],
      "timestamp": "2024-07-18 15:59:42"
    }

the partition IDs in the shards list of the returned data are all 0

Vertex/Edge example (问题点 / 边数据举例)

No response

Schema [VertexLabel, EdgeLabel, IndexLabel] (元数据结构)

No response

@haohao0103 haohao0103 added the bug Something isn't working label Jul 19, 2024
@dosubot dosubot bot added the pd PD module label Jul 19, 2024
haohao0103 added a commit to haohao0103/incubator-hugegraph that referenced this issue Jul 19, 2024
Copy link

dosubot bot commented Jul 19, 2024

The partition IDs in the shards list of the /v1/partitions REST API method are all returning as 0 because the partitionId field in the Shard class is not being set correctly. The code snippet provided shows that the partitionId field is not assigned any value within the Shard class initialization block.

Here is the relevant part of the code:

for (Metapb.Shard shard : pdRestService.getShardList(pt.getId())) {
    Map<Long, Metapb.ShardStats> finalShardStats = shardStats;
    partition.getShards().add(new Shard() {{
        storeId = Long.toString(shard.getStoreId());
        role = shard.getRole();
        address = pdRestService.getStore(shard.getStoreId()).getAddress();
        if (finalShardStats.containsKey(shard.getStoreId())) {
            state = finalShardStats.get(shard.getStoreId()).getState().toString();
            progress = finalShardStats.get(shard.getStoreId()).getProgress();
            role = finalShardStats.get(shard.getStoreId()).getRole();
        }

        HashMap<Integer, Metapb.RaftStats> storeRaftStats = raftMap.get(shard.getStoreId());
        if (storeRaftStats != null) {
            Metapb.RaftStats raftStats = storeRaftStats.get(partition.getId());
            if (raftStats != null) {
                committedIndex = Long.toString(raftStats.getCommittedIndex());
            }
        }
    }});
}

To fix this issue, you need to set the partitionId field within the Shard class initialization block. Here is the corrected code:

for (Metapb.Shard shard : pdRestService.getShardList(pt.getId())) {
    Map<Long, Metapb.ShardStats> finalShardStats = shardStats;
    partition.getShards().add(new Shard() {{
        storeId = Long.toString(shard.getStoreId());
        role = shard.getRole();
        address = pdRestService.getStore(shard.getStoreId()).getAddress();
        partitionId = pt.getId();  // Set the partitionId here
        if (finalShardStats.containsKey(shard.getStoreId())) {
            state = finalShardStats.get(shard.getStoreId()).getState().toString();
            progress = finalShardStats.get(shard.getStoreId()).getProgress();
            role = finalShardStats.get(shard.getStoreId()).getRole();
        }

        HashMap<Integer, Metapb.RaftStats> storeRaftStats = raftMap.get(shard.getStoreId());
        if (storeRaftStats != null) {
            Metapb.RaftStats raftStats = storeRaftStats.get(partition.getId());
            if (raftStats != null) {
                committedIndex = Long.toString(raftStats.getCommittedIndex());
            }
        }
    }});
}

By adding partitionId = pt.getId(); within the initialization block, the partitionId field will be correctly set for each shard [1][2].

To continue talking to Dosu, mention @dosu.

@github-project-automation github-project-automation bot moved this from In progress to Done in HugeGraph PD-Store Tasks Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pd PD module
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant