You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] pd /v1/partitions method returns data partition ID are all 0 #2595
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.Shardshard : pdRestService.getShardList(pt.getId())) {
Map<Long, Metapb.ShardStats> finalShardStats = shardStats;
partition.getShards().add(newShard() {{
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.RaftStatsraftStats = 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.Shardshard : pdRestService.getShardList(pt.getId())) {
Map<Long, Metapb.ShardStats> finalShardStats = shardStats;
partition.getShards().add(newShard() {{
storeId = Long.toString(shard.getStoreId());
role = shard.getRole();
address = pdRestService.getStore(shard.getStoreId()).getAddress();
partitionId = pt.getId(); // Set the partitionId hereif (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.RaftStatsraftStats = 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].
Activity
close apache#2595
dosubot commentedon Jul 19, 2024
The partition IDs in the shards list of the
/v1/partitionsREST API method are all returning as 0 because thepartitionIdfield in theShardclass is not being set correctly. The code snippet provided shows that thepartitionIdfield is not assigned any value within theShardclass initialization block.Here is the relevant part of the code:
To fix this issue, you need to set the
partitionIdfield within theShardclass initialization block. Here is the corrected code:By adding
partitionId = pt.getId();within the initialization block, thepartitionIdfield will be correctly set for each shard [1][2].To continue talking to Dosu, mention @dosu.