bitflicker64 commented on code in PR #3417:
URL: https://github.com/apache/hugegraph/pull/3417#discussion_r4395011534
##########
hugegraph-store/hg-store-core/src/main/java/org/apache/hugegraph/store/meta/PartitionManager.java:
##########
@@ -269,53 +273,50 @@ private void loadPartitions() {
}
var metaParts = wrapper.scan(partId, Metapb.Partition.parser(),
key);
- int countOfPartition = 0;
-
- var shards = pdProvider.getShardGroup(partId).getShardsList();
+ if (metaParts.isEmpty()) {
+ wrapper.close(partId);
+ continue;
+ }
+ // A migrated replica can have an older derived SHARDGROUP in its
data DB than
+ // its durable Raft configuration. Validate recovery against PD
before Raft replay.
+ var pdGroup = recoveryShardGroup(partId);
+ var shards = pdGroup.getShardsList();
+ if (shards.stream().noneMatch(s -> s.getStoreId() == storeId)) {
+ log.error("partition {} is illegal. store id {} not in valid
shard group:{}",
+ partId, storeId, shards2Peers(shards));
+ throw new InvalidShardException();
+ }
for (var metaPart : metaParts) {
var graph = metaPart.getGraphName();
- var pdPartition = pdProvider.getPartitionByID(graph,
metaPart.getId());
- boolean isLegeal = false;
-
- if (pdPartition != null) {
- // Check if it contains this store id
- if (shards.stream().anyMatch(s -> s.getStoreId() ==
storeId)) {
- isLegeal = true;
- }
- } else {
- continue;
+ Partition pdPartition;
+ try {
+ pdPartition = pdProvider.getPartitionByID(graph,
metaPart.getId());
+ } catch (RuntimeException e) {
+ throw new InvalidShardException("Cannot read persisted
partition " + graph +
+ "-" + partId + " from PD",
e);
}
-
- if (isLegeal) {
- if (!partitions.containsKey(graph)) {
- partitions.put(graph, new ConcurrentHashMap<>());
- }
-
- countOfPartition += 1;
-
- Partition partition = new Partition(metaPart);
- partition.setWorkState(
- Metapb.PartitionState.PState_Normal); // Start
recovery work state
- partitions.get(graph).put(partition.getId(), partition);
- log.info("load partition : {} -{}",
partition.getGraphName(),
- partition.getId());
- } else {
- // Invalid
- // removePartitionFromLocalDb(graph, partId);
- // var businessHandler =
HgStoreEngine.getInstance().getBusinessHandler();
- // businessHandler.truncate(graph, partId);
- // businessHandler.dbCompaction(graph, partId);
- log.error("partition {}-{} is illegal. store id {} not in
valid shard group:{}",
- graph, partId, getStore().getId(),
shards2Peers(shards));
- throw new InvalidShardException();
+ if (metaPart.getId() != partId || graph.isEmpty() ||
pdPartition == null ||
Review Comment:
Important: `pdPartition == null` also means PD answered `NOT_FOUND`, for
example a graph dropped while this Store was down, so the Store that the base
started (it skipped that partition) now hits `requestExit(0)` on every start.
Keep skipping a partition PD reports as not found and block only when the PD
lookup fails.
--
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]