This is an automated email from the ASF dual-hosted git repository.
tanxinyu 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 634d0e07dd4 Fixed issue where ConfigNode might recover incorrectly
under SimpleConsensus (#12002)
634d0e07dd4 is described below
commit 634d0e07dd4c723dbf4d9205b2156d614bdb13b4
Author: Xiangpeng Hu <[email protected]>
AuthorDate: Tue Jan 30 16:23:47 2024 +0800
Fixed issue where ConfigNode might recover incorrectly under
SimpleConsensus (#12002)
---
.../statemachine/ConfigRegionStateMachine.java | 31 ++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/statemachine/ConfigRegionStateMachine.java
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/statemachine/ConfigRegionStateMachine.java
index 8b8e1507d37..b68370f9668 100644
---
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/statemachine/ConfigRegionStateMachine.java
+++
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/statemachine/ConfigRegionStateMachine.java
@@ -53,10 +53,14 @@ import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
+import java.util.Arrays;
+import java.util.Comparator;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
/** StateMachine for ConfigRegion. */
public class ConfigRegionStateMachine implements IStateMachine,
IStateMachine.EventApi {
@@ -84,6 +88,8 @@ public class ConfigRegionStateMachine implements
IStateMachine, IStateMachine.Ev
private static final long LOG_FILE_MAX_SIZE =
CONF.getConfigNodeSimpleConsensusLogSegmentSizeMax();
private final TEndPoint currentNodeTEndPoint;
+ private static Pattern LOG_INPROGRESS_PATTERN = Pattern.compile("\\d+");
+ private static Pattern LOG_PATTERN = Pattern.compile("(?<=_)(\\d+)$");
public ConfigRegionStateMachine(ConfigManager configManager,
ConfigPlanExecutor executor) {
this.executor = executor;
@@ -323,6 +329,7 @@ public class ConfigRegionStateMachine implements
IStateMachine, IStateMachine.Ev
dir.mkdirs();
String[] list = new File(CURRENT_FILE_DIR).list();
if (list != null && list.length != 0) {
+ Arrays.sort(list, new FileComparator());
for (String logFileName : list) {
File logFile =
SystemFileFactory.INSTANCE.getFile(CURRENT_FILE_DIR +
File.separator + logFileName);
@@ -395,4 +402,28 @@ public class ConfigRegionStateMachine implements
IStateMachine, IStateMachine.Ev
e);
}
}
+
+ static class FileComparator implements Comparator<String> {
+ @Override
+ public int compare(String filename1, String filename2) {
+ long id1 = parseEndIndex(filename1);
+ long id2 = parseEndIndex(filename2);
+ return Long.compare(id1, id2);
+ }
+ }
+
+ static long parseEndIndex(String filename) {
+ if (filename.startsWith("log_inprogress_")) {
+ Matcher matcher = LOG_INPROGRESS_PATTERN.matcher(filename);
+ if (matcher.find()) {
+ return Long.parseLong(matcher.group());
+ }
+ } else {
+ Matcher matcher = LOG_PATTERN.matcher(filename);
+ if (matcher.find()) {
+ return Long.parseLong(matcher.group());
+ }
+ }
+ return 0;
+ }
}