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

qiaojialin 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 bcadf4d99b prune inappropriate warn log in WALReader (#6969)
bcadf4d99b is described below

commit bcadf4d99bd232d59f2bd977779460fde41aeec0
Author: Alan Choo <[email protected]>
AuthorDate: Fri Aug 12 11:43:37 2022 +0800

    prune inappropriate warn log in WALReader (#6969)
---
 .../src/main/java/org/apache/iotdb/db/wal/io/WALReader.java   | 11 ++++++++++-
 .../org/apache/iotdb/db/wal/recover/WALNodeRecoverTask.java   |  8 +++++---
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/wal/io/WALReader.java 
b/server/src/main/java/org/apache/iotdb/db/wal/io/WALReader.java
index 24fefc4c0c..18e1b89b1f 100644
--- a/server/src/main/java/org/apache/iotdb/db/wal/io/WALReader.java
+++ b/server/src/main/java/org/apache/iotdb/db/wal/io/WALReader.java
@@ -45,12 +45,18 @@ public class WALReader implements Closeable {
       (int) 
IoTDBDescriptor.getInstance().getConfig().getWalFileSizeThresholdInByte() / 10;
 
   private final File logFile;
+  private final boolean fileMayCorrupt;
   private final DataInputStream logStream;
   private WALEntry nextEntry;
   private boolean fileCorrupted = false;
 
   public WALReader(File logFile) throws IOException {
+    this(logFile, false);
+  }
+
+  public WALReader(File logFile, boolean fileMayCorrupt) throws IOException {
     this.logFile = logFile;
+    this.fileMayCorrupt = fileMayCorrupt;
     this.logStream =
         new DataInputStream(
             new BufferedInputStream(Files.newInputStream(logFile.toPath()), 
STREAM_BUFFER_SIZE));
@@ -77,7 +83,10 @@ public class WALReader implements Closeable {
           "WALEntry of wal file {} contains illegal path, skip illegal 
WALEntries.", logFile, e);
     } catch (Exception e) {
       fileCorrupted = true;
-      logger.warn("Fail to read WALEntry from wal file {}, skip broken 
WALEntries.", logFile, e);
+      // log only when file should be complete
+      if (!fileMayCorrupt) {
+        logger.warn("Fail to read WALEntry from wal file {}, skip broken 
WALEntries.", logFile, e);
+      }
     }
 
     return nextEntry != null;
diff --git 
a/server/src/main/java/org/apache/iotdb/db/wal/recover/WALNodeRecoverTask.java 
b/server/src/main/java/org/apache/iotdb/db/wal/recover/WALNodeRecoverTask.java
index 1d61897742..cdc9d92cca 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/wal/recover/WALNodeRecoverTask.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/wal/recover/WALNodeRecoverTask.java
@@ -141,7 +141,7 @@ public class WALNodeRecoverTask implements Runnable {
     long lastSearchIndex = 
WALFileUtils.parseStartSearchIndex(lastWALFile.getName());
     WALMetaData metaData = new WALMetaData(lastSearchIndex, new ArrayList<>());
     WALFileStatus fileStatus = WALFileStatus.CONTAINS_NONE_SEARCH_INDEX;
-    try (WALReader walReader = new WALReader(lastWALFile)) {
+    try (WALReader walReader = new WALReader(lastWALFile, true)) {
       while (walReader.hasNext()) {
         WALEntry walEntry = walReader.next();
         long searchIndex = DEFAULT_SEARCH_INDEX;
@@ -232,8 +232,10 @@ public class WALNodeRecoverTask implements Runnable {
     // asc sort by version id
     WALFileUtils.ascSortByVersionId(walFiles);
     // read .wal files and redo logs
-    for (File walFile : walFiles) {
-      try (WALReader walReader = new WALReader(walFile)) {
+    for (int i = 0; i < walFiles.length; ++i) {
+      File walFile = walFiles[i];
+      // last wal file may corrupt
+      try (WALReader walReader = new WALReader(walFile, i == walFiles.length - 
1)) {
         while (walReader.hasNext()) {
           WALEntry walEntry = walReader.next();
           if (!memTableId2Info.containsKey(walEntry.getMemTableId())) {

Reply via email to