You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hugegraph.apache.org by "haohao0103 (via GitHub)" <gi...@apache.org> on 2024/07/19 09:56:01 UTC
[I] [Bug] pd /v1/partitions method returns data partition ID are all 0 [incubator-hugegraph]
haohao0103 opened a new issue, #2595:
URL: https://github.com/apache/incubator-hugegraph/issues/2595
### Bug Type (问题类型)
rest-api (结果不合预期)
### Before submit
- [X] 我已经确认现有的 [Issues](https://github.com/apache/hugegraph/issues) 与 [FAQ](https://hugegraph.apache.org/docs/guides/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_
--
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: dev-unsubscribe@hugegraph.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Bug] pd /v1/partitions method returns data partition ID are all 0 [incubator-hugegraph]
Posted by "VGalaxies (via GitHub)" <gi...@apache.org>.
VGalaxies closed issue #2595: [Bug] pd /v1/partitions method returns data partition ID are all 0
URL: https://github.com/apache/incubator-hugegraph/issues/2595
--
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: dev-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Bug] pd /v1/partitions method returns data partition ID are all 0 [incubator-hugegraph]
Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
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: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org