BUAAserein commented on code in PR #12293:
URL: https://github.com/apache/iotdb/pull/12293#discussion_r1555167862
##########
iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensus.java:
##########
@@ -414,28 +417,41 @@ public List<ConsensusGroupId> getAllConsensusGroupIds() {
return new ArrayList<>(stateMachineMap.keySet());
}
+ @Override
+ public List<ConsensusGroupId> getAllConsensusGroupIdsFromDisk() {
+ List<ConsensusGroupId> consensusGroupIds = new ArrayList<>();
+ try (DirectoryStream<Path> stream =
Files.newDirectoryStream(storageDir.toPath())) {
+ for (Path path : stream) {
+ String[] items = path.getFileName().toString().split("_");
+ ConsensusGroupId consensusGroupId =
+ ConsensusGroupId.Factory.create(Integer.parseInt(items[0]),
Integer.parseInt(items[1]));
+ consensusGroupIds.add(consensusGroupId);
+ }
+ } catch (IOException e) {
+ logger.error("Failed to get all consensus group ids from disk", e);
+ }
+ return consensusGroupIds;
+ }
+
public void resetPeerList(ConsensusGroupId groupId, List<Peer> peers) throws
ConsensusException {
IoTConsensusServerImpl impl =
Optional.ofNullable(stateMachineMap.get(groupId))
.orElseThrow(() -> new ConsensusGroupNotExistException(groupId));
- if (impl.isReadOnly()) {
- throw new ConsensusException("system is in read-only status now");
- } else if (!impl.isActive()) {
- throw new ConsensusException(
- "peer is inactive and not ready to receive reset configuration
request.");
- }
-
- for (Peer peer : impl.getConfiguration()) {
- if (!peers.contains(peer)) {
- try {
- removeRemotePeer(groupId, peer);
- } catch (ConsensusException e) {
- logger.error("Failed to remove peer {} from group {}", peer,
groupId, e);
- throw e;
+ Peer localPeer = new Peer(groupId, thisNodeId, thisNode);
+ if (!peers.contains(localPeer)) {
+ logger.info("local peer is not in the new configuration, delete local
peer {}", groupId);
+ deleteLocalPeer(groupId);
+ } else {
+ for (Peer peer : impl.getConfiguration()) {
+ if (!peers.contains(peer)) {
+ try {
+ impl.removeSyncLogChannel(peer);
+ } catch (ConsensusGroupModifyPeerException e) {
+ logger.error("Failed to remove peer {} from group {}", peer,
groupId, e);
+ }
Review Comment:
Yes! It looks good.
--
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]