This is an automated email from the ASF dual-hosted git repository.
marklau99 pushed a commit to branch IOTDB-4027
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/IOTDB-4027 by this push:
new c70123f046 check and create log file in the init function of
SnapshotLogger
c70123f046 is described below
commit c70123f0468058cadd71008f41011d7f85b07c3b
Author: Liu Xuxin <[email protected]>
AuthorDate: Mon Aug 29 09:49:16 2022 +0800
check and create log file in the init function of SnapshotLogger
---
.../java/org/apache/iotdb/db/engine/snapshot/SnapshotLogger.java | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git
a/server/src/main/java/org/apache/iotdb/db/engine/snapshot/SnapshotLogger.java
b/server/src/main/java/org/apache/iotdb/db/engine/snapshot/SnapshotLogger.java
index fe1937fbcf..b2b8c06ba5 100644
---
a/server/src/main/java/org/apache/iotdb/db/engine/snapshot/SnapshotLogger.java
+++
b/server/src/main/java/org/apache/iotdb/db/engine/snapshot/SnapshotLogger.java
@@ -20,7 +20,6 @@ package org.apache.iotdb.db.engine.snapshot;
import java.io.BufferedOutputStream;
import java.io.File;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@@ -33,8 +32,14 @@ public class SnapshotLogger implements AutoCloseable {
private File logFile;
private BufferedOutputStream os;
- public SnapshotLogger(File logFile) throws FileNotFoundException {
+ public SnapshotLogger(File logFile) throws IOException {
this.logFile = logFile;
+ if (!logFile.getParentFile().exists() &&
!logFile.getParentFile().mkdirs()) {
+ throw new IOException("Cannot create parent folder for " +
logFile.getAbsolutePath());
+ }
+ if (!this.logFile.createNewFile()) {
+ throw new IOException("Cannot create file " + logFile.getAbsolutePath());
+ }
os = new BufferedOutputStream(new FileOutputStream(logFile));
}