You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ca...@apache.org on 2022/12/06 01:35:34 UTC
[iotdb] branch master updated: [IOTDB-5122] forward exception when Ratis request failed (#8338)
This is an automated email from the ASF dual-hosted git repository.
caogaofei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 9a72a2aa20 [IOTDB-5122] forward exception when Ratis request failed (#8338)
9a72a2aa20 is described below
commit 9a72a2aa205885cfe8584e557f482426f9dbb2d7
Author: William Song <48...@users.noreply.github.com>
AuthorDate: Tue Dec 6 09:35:28 2022 +0800
[IOTDB-5122] forward exception when Ratis request failed (#8338)
---
.../java/org/apache/iotdb/consensus/ratis/RatisConsensus.java | 11 ++++++-----
.../org/apache/iotdb/consensus/ratis/RatisConsensusTest.java | 5 +++++
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisConsensus.java b/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisConsensus.java
index 29c7ce9dd0..59e4449624 100644
--- a/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisConsensus.java
+++ b/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisConsensus.java
@@ -341,9 +341,7 @@ class RatisConsensus implements IConsensus {
public ConsensusGenericResponse createPeer(ConsensusGroupId groupId, List<Peer> peers) {
RaftGroup group = buildRaftGroup(groupId, peers);
// add RaftPeer myself to this RaftGroup
- ConsensusGenericResponse reply = addNewGroupToServer(group, myself);
-
- return ConsensusGenericResponse.newBuilder().setSuccess(reply.isSuccess()).build();
+ return addNewGroupToServer(group, myself);
}
private ConsensusGenericResponse addNewGroupToServer(RaftGroup group, RaftPeer server) {
@@ -476,7 +474,7 @@ class RatisConsensus implements IConsensus {
@Override
public ConsensusGenericResponse updatePeer(ConsensusGroupId groupId, Peer oldPeer, Peer newPeer) {
- return ConsensusGenericResponse.newBuilder().setSuccess(true).build();
+ return ConsensusGenericResponse.newBuilder().setSuccess(false).build();
}
@Override
@@ -493,7 +491,7 @@ class RatisConsensus implements IConsensus {
try {
reply = sendReconfiguration(raftGroup);
} catch (RatisRequestFailedException e) {
- return failed(new RatisRequestFailedException(e));
+ return failed(e);
}
return ConsensusGenericResponse.newBuilder().setSuccess(reply.isSuccess()).build();
}
@@ -676,6 +674,9 @@ class RatisConsensus implements IConsensus {
RaftClientReply reply;
try {
reply = server.snapshotManagement(request);
+ if (!reply.isSuccess()) {
+ return failed(new RatisRequestFailedException(reply.getException()));
+ }
} catch (IOException ioException) {
return failed(new RatisRequestFailedException(ioException));
}
diff --git a/consensus/src/test/java/org/apache/iotdb/consensus/ratis/RatisConsensusTest.java b/consensus/src/test/java/org/apache/iotdb/consensus/ratis/RatisConsensusTest.java
index 8e790020cd..6bd98a27d3 100644
--- a/consensus/src/test/java/org/apache/iotdb/consensus/ratis/RatisConsensusTest.java
+++ b/consensus/src/test/java/org/apache/iotdb/consensus/ratis/RatisConsensusTest.java
@@ -31,6 +31,7 @@ import org.apache.iotdb.consensus.common.response.ConsensusReadResponse;
import org.apache.iotdb.consensus.common.response.ConsensusWriteResponse;
import org.apache.iotdb.consensus.config.ConsensusConfig;
import org.apache.iotdb.consensus.config.RatisConfig;
+import org.apache.iotdb.consensus.exception.RatisRequestFailedException;
import org.apache.ratis.util.FileUtils;
import org.junit.After;
@@ -148,6 +149,10 @@ public class RatisConsensusTest {
servers.get(0).createPeer(group.getGroupId(), original);
doConsensus(servers.get(0), group.getGroupId(), 10, 10);
+ ConsensusGenericResponse resp = servers.get(0).createPeer(group.getGroupId(), original);
+ Assert.assertFalse(resp.isSuccess());
+ Assert.assertTrue(resp.getException() instanceof RatisRequestFailedException);
+
// add 2 members
servers.get(1).createPeer(group.getGroupId(), Collections.emptyList());
servers.get(0).addPeer(group.getGroupId(), peers.get(1));