You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ta...@apache.org on 2024/08/23 10:30:36 UTC
(iotdb) branch rc/1.3.3 updated: [to rc/1.3.3][region migration] Ratis delete local peer when resetPeerList is called and myself not in correct peer list #13285
This is an automated email from the ASF dual-hosted git repository.
tanxinyu pushed a commit to branch rc/1.3.3
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/rc/1.3.3 by this push:
new 55db67ab07a [to rc/1.3.3][region migration] Ratis delete local peer when resetPeerList is called and myself not in correct peer list #13285
55db67ab07a is described below
commit 55db67ab07a2f43ad003b80233e04d0f351ebfa1
Author: Li Yu Heng <li...@126.com>
AuthorDate: Fri Aug 23 18:30:29 2024 +0800
[to rc/1.3.3][region migration] Ratis delete local peer when resetPeerList is called and myself not in correct peer list #13285
---
.../org/apache/iotdb/consensus/IConsensus.java | 4 +--
.../apache/iotdb/consensus/iot/IoTConsensus.java | 3 +-
.../iotdb/consensus/ratis/RatisConsensus.java | 32 ++++++++++++++++++++--
.../iotdb/consensus/simple/SimpleConsensus.java | 3 +-
4 files changed, 35 insertions(+), 7 deletions(-)
diff --git a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/IConsensus.java b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/IConsensus.java
index 7dc3fb6e94d..0e3af42d802 100644
--- a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/IConsensus.java
+++ b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/IConsensus.java
@@ -151,11 +151,11 @@ public interface IConsensus {
* so it will only be less but not more.
*
* @param groupId the consensus group
- * @param peers the new peer list
+ * @param correctPeers the correct peer list
* @throws ConsensusException when resetPeerList doesn't success with other reasons
* @throws ConsensusGroupNotExistException when the specified consensus group doesn't exist
*/
- void resetPeerList(ConsensusGroupId groupId, List<Peer> peers) throws ConsensusException;
+ void resetPeerList(ConsensusGroupId groupId, List<Peer> correctPeers) throws ConsensusException;
// management API
diff --git a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensus.java b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensus.java
index 89894a4c01a..ed089ff63bf 100644
--- a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensus.java
+++ b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensus.java
@@ -477,12 +477,13 @@ public class IoTConsensus implements IConsensus {
@Override
public void resetPeerList(ConsensusGroupId groupId, List<Peer> correctPeers)
throws ConsensusException {
+ logger.info("[RESET PEER LIST] Start to reset peer list to {}", correctPeers);
IoTConsensusServerImpl impl =
Optional.ofNullable(stateMachineMap.get(groupId))
.orElseThrow(() -> new ConsensusGroupNotExistException(groupId));
Peer localPeer = new Peer(groupId, thisNodeId, thisNode);
if (!correctPeers.contains(localPeer)) {
- logger.warn(
+ logger.info(
"[RESET PEER LIST] Local peer is not in the correct configuration, delete local peer {}",
groupId);
deleteLocalPeer(groupId);
diff --git a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisConsensus.java b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisConsensus.java
index f346d90ac35..3bf52b11f99 100644
--- a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisConsensus.java
+++ b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisConsensus.java
@@ -563,7 +563,9 @@ class RatisConsensus implements IConsensus {
}
@Override
- public void resetPeerList(ConsensusGroupId groupId, List<Peer> peers) throws ConsensusException {
+ public void resetPeerList(ConsensusGroupId groupId, List<Peer> correctPeers)
+ throws ConsensusException {
+ logger.info("[RESET PEER LIST] Start to reset peer list to {}", correctPeers);
final RaftGroupId raftGroupId = Utils.fromConsensusGroupIdToRaftGroupId(groupId);
final RaftGroup group = getGroupInfo(raftGroupId);
@@ -571,11 +573,35 @@ class RatisConsensus implements IConsensus {
throw new ConsensusGroupNotExistException(groupId);
}
+ boolean myselfInCorrectPeers =
+ correctPeers.stream()
+ .map(
+ peer ->
+ Utils.fromNodeInfoAndPriorityToRaftPeer(
+ peer.getNodeId(), peer.getEndpoint(), DEFAULT_PRIORITY))
+ .anyMatch(
+ raftPeer ->
+ myself.getId() == raftPeer.getId()
+ && myself.getAddress().equals(raftPeer.getAddress()));
+ if (!myselfInCorrectPeers) {
+ logger.info(
+ "[RESET PEER LIST] Local peer is not in the correct peer list, delete local peer {}",
+ groupId);
+ deleteLocalPeer(groupId);
+ return;
+ }
+
final List<RaftPeer> newGroupPeers =
- Utils.fromPeersAndPriorityToRaftPeers(peers, DEFAULT_PRIORITY);
+ Utils.fromPeersAndPriorityToRaftPeers(correctPeers, DEFAULT_PRIORITY);
final RaftGroup newGroup = RaftGroup.valueOf(raftGroupId, newGroupPeers);
- sendReconfiguration(newGroup);
+ RaftClientReply reply = sendReconfiguration(newGroup);
+ if (reply.isSuccess()) {
+ logger.info("[RESET PEER LIST] Peer list has been reset to {}", newGroupPeers);
+ } else {
+ logger.warn(
+ "[RESET PEER LIST] Peer list failed to reset to {}, reply is {}", newGroup, reply);
+ }
}
/** NOTICE: transferLeader *does not guarantee* the leader be transferred to newLeader. */
diff --git a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/simple/SimpleConsensus.java b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/simple/SimpleConsensus.java
index 8547b52b7c4..19258309028 100644
--- a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/simple/SimpleConsensus.java
+++ b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/simple/SimpleConsensus.java
@@ -270,7 +270,8 @@ class SimpleConsensus implements IConsensus {
}
@Override
- public void resetPeerList(ConsensusGroupId groupId, List<Peer> peers) throws ConsensusException {
+ public void resetPeerList(ConsensusGroupId groupId, List<Peer> correctPeers)
+ throws ConsensusException {
throw new ConsensusException("SimpleConsensus does not support reset peer list");
}