Skip to content

Commit 8bf9e97

Browse files
XNX02SteveYurongSu
andauthored
Pipe: fix the problems that unable to start when cannot parse reboot times (#14594) (#14601)
Co-authored-by: Steve Yurong Su <rong@apache.org>
1 parent 35b8a00 commit 8bf9e97

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/agent/runtime/SimpleProgressIndexAssigner.java

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
package org.apache.iotdb.db.pipe.agent.runtime;
2121

2222
import org.apache.iotdb.commons.consensus.index.impl.SimpleProgressIndex;
23-
import org.apache.iotdb.commons.exception.StartupException;
2423
import org.apache.iotdb.commons.file.SystemFileFactory;
2524
import org.apache.iotdb.db.conf.IoTDBConfig;
2625
import org.apache.iotdb.db.conf.IoTDBDescriptor;
@@ -31,6 +30,7 @@
3130
import org.slf4j.LoggerFactory;
3231

3332
import java.io.File;
33+
import java.io.FileOutputStream;
3434
import java.io.IOException;
3535
import java.nio.charset.StandardCharsets;
3636
import java.util.concurrent.atomic.AtomicLong;
@@ -55,17 +55,21 @@ public class SimpleProgressIndexAssigner {
5555
private int rebootTimes = 0;
5656
private final AtomicLong insertionRequestId = new AtomicLong(1);
5757

58-
public void start() throws StartupException {
58+
public void start() {
5959
isSimpleConsensusEnable =
6060
IOTDB_CONFIG.getDataRegionConsensusProtocolClass().equals(SIMPLE_CONSENSUS);
61-
LOGGER.info("Start SimpleProgressIndexAssigner ...");
61+
LOGGER.info("Starting SimpleProgressIndexAssigner ...");
6262

6363
try {
6464
makeDirIfNecessary();
6565
parseRebootTimes();
6666
recordRebootTimes();
67+
LOGGER.info(
68+
"SimpleProgressIndexAssigner started successfully. isSimpleConsensusEnable: {}, rebootTimes: {}",
69+
isSimpleConsensusEnable,
70+
rebootTimes);
6771
} catch (Exception e) {
68-
throw new StartupException(e);
72+
LOGGER.error("Cannot start SimpleProgressIndexAssigner because of {}", e.getMessage(), e);
6973
}
7074
}
7175

@@ -86,15 +90,27 @@ private void parseRebootTimes() {
8690
try {
8791
String content = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
8892
rebootTimes = Integer.parseInt(content);
89-
} catch (IOException e) {
90-
LOGGER.error("Cannot parse reboot times from file {}", file.getAbsolutePath(), e);
91-
rebootTimes = 0;
93+
} catch (final Exception e) {
94+
rebootTimes = (int) (System.currentTimeMillis() / 1000);
95+
LOGGER.error(
96+
"Cannot parse reboot times from file {}, set the current time in seconds ({}) as the reboot times",
97+
file.getAbsolutePath(),
98+
rebootTimes);
9299
}
93100
}
94101

95-
private void recordRebootTimes() throws IOException {
96-
File file = SystemFileFactory.INSTANCE.getFile(PIPE_SYSTEM_DIR + REBOOT_TIMES_FILE_NAME);
97-
FileUtils.writeStringToFile(file, String.valueOf(rebootTimes + 1), StandardCharsets.UTF_8);
102+
private void recordRebootTimes() {
103+
final File file = SystemFileFactory.INSTANCE.getFile(PIPE_SYSTEM_DIR + REBOOT_TIMES_FILE_NAME);
104+
try (final FileOutputStream fos = new FileOutputStream(file, false)) {
105+
fos.write(String.valueOf(rebootTimes + 1).getBytes(StandardCharsets.UTF_8));
106+
fos.flush();
107+
fos.getFD().sync();
108+
} catch (final Exception e) {
109+
LOGGER.error(
110+
"Cannot record reboot times {} to file {}, the reboot times will not be updated",
111+
rebootTimes,
112+
file.getAbsolutePath());
113+
}
98114
}
99115

100116
public void assignIfNeeded(InsertNode insertNode) {

0 commit comments

Comments
 (0)