Skip to content

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

Closed

Description

@haohao0103

Bug Type (问题类型)

rest-api (结果不合预期)

Before submit

  • 我已经确认现有的 Issues 与 FAQ 中没有相同 / 重复问题 (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

Activity

  1. added a commit that references this issue on Jul 19, 2024
    4d5ba12
  2. dosubot commented on Jul 19, 2024

    @dosubot

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpdPD module

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions