This is an automated email from the ASF dual-hosted git repository.

tanxinyu pushed a commit to branch jira3505
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/jira3505 by this push:
     new 75e9865f7f fix
75e9865f7f is described below

commit 75e9865f7f3514bda085263c75375b8627bc4275
Author: LebronAl <[email protected]>
AuthorDate: Wed Jun 15 18:12:35 2022 +0800

    fix
---
 .../iotdb/consensus/multileader/MultiLeaderConsensus.java  | 10 ++--------
 .../iotdb/consensus/standalone/StandAloneConsensus.java    | 10 ++--------
 .../consensus/{standalone => }/EmptyStateMachine.java      |  3 +--
 .../{standalone => multileader}/RecoveryTest.java          | 14 ++++++++------
 .../apache/iotdb/consensus/standalone/RecoveryTest.java    |  1 +
 .../consensus/standalone/StandAloneConsensusTest.java      |  1 +
 .../java/org/apache/iotdb/commons/utils/FileUtils.java     |  2 +-
 7 files changed, 16 insertions(+), 25 deletions(-)

diff --git 
a/consensus/src/main/java/org/apache/iotdb/consensus/multileader/MultiLeaderConsensus.java
 
b/consensus/src/main/java/org/apache/iotdb/consensus/multileader/MultiLeaderConsensus.java
index 30484bfa09..fbd9b280f3 100644
--- 
a/consensus/src/main/java/org/apache/iotdb/consensus/multileader/MultiLeaderConsensus.java
+++ 
b/consensus/src/main/java/org/apache/iotdb/consensus/multileader/MultiLeaderConsensus.java
@@ -23,6 +23,7 @@ import org.apache.iotdb.common.rpc.thrift.TEndPoint;
 import org.apache.iotdb.commons.consensus.ConsensusGroupId;
 import org.apache.iotdb.commons.exception.StartupException;
 import org.apache.iotdb.commons.service.RegisterManager;
+import org.apache.iotdb.commons.utils.FileUtils;
 import org.apache.iotdb.consensus.IConsensus;
 import org.apache.iotdb.consensus.IStateMachine;
 import org.apache.iotdb.consensus.IStateMachine.Registry;
@@ -48,7 +49,6 @@ import java.io.IOException;
 import java.nio.file.DirectoryStream;
 import java.nio.file.Files;
 import java.nio.file.Path;
-import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -186,13 +186,7 @@ public class MultiLeaderConsensus implements IConsensus {
         (k, v) -> {
           exist.set(true);
           v.stop();
-          String path = buildPeerDir(groupId);
-          try {
-            Files.delete(Paths.get(path));
-          } catch (IOException e) {
-            logger.warn(
-                "Unable to delete consensus dir for group {} at {} because 
{}", groupId, path, e);
-          }
+          FileUtils.deleteDirectory(new File(buildPeerDir(groupId)));
           return null;
         });
 
diff --git 
a/consensus/src/main/java/org/apache/iotdb/consensus/standalone/StandAloneConsensus.java
 
b/consensus/src/main/java/org/apache/iotdb/consensus/standalone/StandAloneConsensus.java
index 69b23d3691..1aa568416b 100644
--- 
a/consensus/src/main/java/org/apache/iotdb/consensus/standalone/StandAloneConsensus.java
+++ 
b/consensus/src/main/java/org/apache/iotdb/consensus/standalone/StandAloneConsensus.java
@@ -21,6 +21,7 @@ package org.apache.iotdb.consensus.standalone;
 
 import org.apache.iotdb.common.rpc.thrift.TEndPoint;
 import org.apache.iotdb.commons.consensus.ConsensusGroupId;
+import org.apache.iotdb.commons.utils.FileUtils;
 import org.apache.iotdb.consensus.IConsensus;
 import org.apache.iotdb.consensus.IStateMachine;
 import org.apache.iotdb.consensus.IStateMachine.Registry;
@@ -43,7 +44,6 @@ import java.io.IOException;
 import java.nio.file.DirectoryStream;
 import java.nio.file.Files;
 import java.nio.file.Path;
-import java.nio.file.Paths;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -168,13 +168,7 @@ class StandAloneConsensus implements IConsensus {
         (k, v) -> {
           exist.set(true);
           v.stop();
-          String path = buildPeerDir(groupId);
-          try {
-            Files.delete(Paths.get(path));
-          } catch (IOException e) {
-            logger.warn(
-                "Unable to delete consensus dir for group {} at {} because 
{}", groupId, path, e);
-          }
+          FileUtils.deleteDirectory(new File(buildPeerDir(groupId)));
           return null;
         });
 
diff --git 
a/consensus/src/test/java/org/apache/iotdb/consensus/standalone/EmptyStateMachine.java
 b/consensus/src/test/java/org/apache/iotdb/consensus/EmptyStateMachine.java
similarity index 94%
rename from 
consensus/src/test/java/org/apache/iotdb/consensus/standalone/EmptyStateMachine.java
rename to 
consensus/src/test/java/org/apache/iotdb/consensus/EmptyStateMachine.java
index 3428f5abff..01992f472f 100644
--- 
a/consensus/src/test/java/org/apache/iotdb/consensus/standalone/EmptyStateMachine.java
+++ b/consensus/src/test/java/org/apache/iotdb/consensus/EmptyStateMachine.java
@@ -17,10 +17,9 @@
  * under the License.
  */
 
-package org.apache.iotdb.consensus.standalone;
+package org.apache.iotdb.consensus;
 
 import org.apache.iotdb.common.rpc.thrift.TSStatus;
-import org.apache.iotdb.consensus.IStateMachine;
 import org.apache.iotdb.consensus.common.DataSet;
 import org.apache.iotdb.consensus.common.request.IConsensusRequest;
 
diff --git 
a/consensus/src/test/java/org/apache/iotdb/consensus/standalone/RecoveryTest.java
 
b/consensus/src/test/java/org/apache/iotdb/consensus/multileader/RecoveryTest.java
similarity index 90%
copy from 
consensus/src/test/java/org/apache/iotdb/consensus/standalone/RecoveryTest.java
copy to 
consensus/src/test/java/org/apache/iotdb/consensus/multileader/RecoveryTest.java
index 2dd7cd9fbc..bb40a19b4e 100644
--- 
a/consensus/src/test/java/org/apache/iotdb/consensus/standalone/RecoveryTest.java
+++ 
b/consensus/src/test/java/org/apache/iotdb/consensus/multileader/RecoveryTest.java
@@ -16,17 +16,18 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.iotdb.consensus.standalone;
+
+package org.apache.iotdb.consensus.multileader;
 
 import org.apache.iotdb.common.rpc.thrift.TEndPoint;
 import org.apache.iotdb.commons.consensus.ConsensusGroupId;
 import org.apache.iotdb.commons.consensus.SchemaRegionId;
 import org.apache.iotdb.consensus.ConsensusFactory;
+import org.apache.iotdb.consensus.EmptyStateMachine;
 import org.apache.iotdb.consensus.IConsensus;
 import org.apache.iotdb.consensus.common.Peer;
 import org.apache.iotdb.consensus.common.response.ConsensusGenericResponse;
 import org.apache.iotdb.consensus.config.ConsensusConfig;
-import 
org.apache.iotdb.consensus.exception.ConsensusGroupAlreadyExistException;
 
 import org.apache.ratis.util.FileUtils;
 import org.junit.After;
@@ -39,13 +40,14 @@ import java.io.IOException;
 import java.util.Collections;
 
 public class RecoveryTest {
+
   private final ConsensusGroupId schemaRegionId = new SchemaRegionId(1);
   private IConsensus consensusImpl;
 
   public void constructConsensus() throws IOException {
     consensusImpl =
         ConsensusFactory.getConsensusImpl(
-                ConsensusFactory.StandAloneConsensus,
+                ConsensusFactory.MultiLeaderConsensus,
                 ConsensusConfig.newBuilder()
                     .setThisNode(new TEndPoint("0.0.0.0", 9000))
                     .setStorageDir("target" + java.io.File.separator + 
"recovery")
@@ -77,6 +79,8 @@ public class RecoveryTest {
         schemaRegionId,
         Collections.singletonList(new Peer(schemaRegionId, new 
TEndPoint("0.0.0.0", 9000))));
 
+    consensusImpl.removeConsensusGroup(schemaRegionId);
+
     consensusImpl.stop();
     consensusImpl = null;
 
@@ -87,8 +91,6 @@ public class RecoveryTest {
             schemaRegionId,
             Collections.singletonList(new Peer(schemaRegionId, new 
TEndPoint("0.0.0.0", 9000))));
 
-    Assert.assertEquals(
-        response.getException().getMessage(),
-        new ConsensusGroupAlreadyExistException(schemaRegionId).getMessage());
+    Assert.assertTrue(response.isSuccess());
   }
 }
diff --git 
a/consensus/src/test/java/org/apache/iotdb/consensus/standalone/RecoveryTest.java
 
b/consensus/src/test/java/org/apache/iotdb/consensus/standalone/RecoveryTest.java
index 2dd7cd9fbc..23244da47a 100644
--- 
a/consensus/src/test/java/org/apache/iotdb/consensus/standalone/RecoveryTest.java
+++ 
b/consensus/src/test/java/org/apache/iotdb/consensus/standalone/RecoveryTest.java
@@ -22,6 +22,7 @@ import org.apache.iotdb.common.rpc.thrift.TEndPoint;
 import org.apache.iotdb.commons.consensus.ConsensusGroupId;
 import org.apache.iotdb.commons.consensus.SchemaRegionId;
 import org.apache.iotdb.consensus.ConsensusFactory;
+import org.apache.iotdb.consensus.EmptyStateMachine;
 import org.apache.iotdb.consensus.IConsensus;
 import org.apache.iotdb.consensus.common.Peer;
 import org.apache.iotdb.consensus.common.response.ConsensusGenericResponse;
diff --git 
a/consensus/src/test/java/org/apache/iotdb/consensus/standalone/StandAloneConsensusTest.java
 
b/consensus/src/test/java/org/apache/iotdb/consensus/standalone/StandAloneConsensusTest.java
index 44a43f9e5b..9e0e13be6d 100644
--- 
a/consensus/src/test/java/org/apache/iotdb/consensus/standalone/StandAloneConsensusTest.java
+++ 
b/consensus/src/test/java/org/apache/iotdb/consensus/standalone/StandAloneConsensusTest.java
@@ -26,6 +26,7 @@ import org.apache.iotdb.commons.consensus.DataRegionId;
 import org.apache.iotdb.commons.consensus.PartitionRegionId;
 import org.apache.iotdb.commons.consensus.SchemaRegionId;
 import org.apache.iotdb.consensus.ConsensusFactory;
+import org.apache.iotdb.consensus.EmptyStateMachine;
 import org.apache.iotdb.consensus.IConsensus;
 import org.apache.iotdb.consensus.IStateMachine;
 import org.apache.iotdb.consensus.common.DataSet;
diff --git 
a/node-commons/src/main/java/org/apache/iotdb/commons/utils/FileUtils.java 
b/node-commons/src/main/java/org/apache/iotdb/commons/utils/FileUtils.java
index 7c4d3a6bad..a641e11381 100644
--- a/node-commons/src/main/java/org/apache/iotdb/commons/utils/FileUtils.java
+++ b/node-commons/src/main/java/org/apache/iotdb/commons/utils/FileUtils.java
@@ -36,7 +36,7 @@ import java.util.Arrays;
 import java.util.Objects;
 
 public class FileUtils {
-  private static Logger logger = LoggerFactory.getLogger(FileUtils.class);
+  private static final Logger logger = 
LoggerFactory.getLogger(FileUtils.class);
 
   private static final int bufferSize = 1024;
 

Reply via email to