dosubot[bot] commented on issue #2595:
URL:
https://github.com/apache/incubator-hugegraph/issues/2595#issuecomment-2238854466
<!-- Answer -->
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:
```java
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:
```java
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
<sup>[[1]](https://github.com/apache/incubator-hugegraph/blob/master/hugegraph-pd/hg-pd-service/src/main/java/org/apache/hugegraph/pd/rest/PartitionAPI.java)</sup><sup>[[2]](https://github.com/apache/incubator-hugegraph/blob/master/hugegraph-pd/hg-pd-service/src/main/java/org/apache/hugegraph/pd/rest/ShardAPI.java)</sup>.
<!-- Dosu Comment Footer -->
*To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]