diff --git a/iotdb/src/main/java/org/apache/iotdb/db/tools/WalChecker.java b/iotdb/src/main/java/org/apache/iotdb/db/tools/WalChecker.java index 6bef7a57de497a56f82a56c8bc93c747e584da4a..a3fbf4e1f4af2a51d102234486ff4369f176b641 100644 --- a/iotdb/src/main/java/org/apache/iotdb/db/tools/WalChecker.java +++ b/iotdb/src/main/java/org/apache/iotdb/db/tools/WalChecker.java @@ -54,6 +54,7 @@ public class WalChecker { */ public List doCheck() throws SysCheckException { File walFolderFile = new File(walFolder); + LOGGER.info("Checking folder: {}", walFolderFile.getAbsolutePath()); if(!walFolderFile.exists() || !walFolderFile.isDirectory()) { throw new SysCheckException(String.format("%s is not a directory", walFolder)); } @@ -67,13 +68,21 @@ public class WalChecker { List failedFiles = new ArrayList<>(); for (int dirIndex = 0; dirIndex < storageWalFolders.length; dirIndex++) { File storageWalFolder = storageWalFolders[dirIndex]; - LOGGER.debug("Checking the No.{} directory {}", dirIndex, storageWalFolder.getName()); + LOGGER.info("Checking the No.{} directory {}", dirIndex, storageWalFolder.getName()); File walFile = new File(storageWalFolder, WAL_FILE_NAME); if (!walFile.exists()) { LOGGER.debug("No wal file in this dir, skipping"); continue; } + if (walFile.length() > 0 && walFile.length() < RAFLogReader.LEAST_LOG_SIZE) { + // contains only one damaged log + LOGGER.error("{} fails the check because it is non-empty but does not contain enough bytes " + + "even for one log.", walFile.getAbsoluteFile()); + failedFiles.add(walFile); + continue; + } + RAFLogReader logReader = null; try { logReader = new RAFLogReader(walFile); diff --git a/iotdb/src/main/java/org/apache/iotdb/db/writelog/io/RAFLogReader.java b/iotdb/src/main/java/org/apache/iotdb/db/writelog/io/RAFLogReader.java index 6700805f02dcf5b5a6284ae3537634eb57405450..1834569c4485eac1ec5c8e792dcf2b623ce8b3c8 100644 --- a/iotdb/src/main/java/org/apache/iotdb/db/writelog/io/RAFLogReader.java +++ b/iotdb/src/main/java/org/apache/iotdb/db/writelog/io/RAFLogReader.java @@ -32,6 +32,7 @@ import org.slf4j.LoggerFactory; public class RAFLogReader implements ILogReader { private static final Logger logger = LoggerFactory.getLogger(RAFLogReader.class); + public static final int LEAST_LOG_SIZE = 12; // size + checksum private RandomAccessFile logRaf; private String filepath; private int bufferSize = 4 * 1024 * 1024; @@ -53,7 +54,7 @@ public class RAFLogReader implements ILogReader { return true; } - if (logRaf.getFilePointer() + 12 > logRaf.length()) { + if (logRaf.getFilePointer() + LEAST_LOG_SIZE > logRaf.length()) { return false; } diff --git a/iotdb/src/test/java/org/apache/iotdb/db/tools/WalCheckerTest.java b/iotdb/src/test/java/org/apache/iotdb/db/tools/WalCheckerTest.java index 0c3ca290bc664bfef5cc4a0c7df2f56c4853cfd8..8619ebacd5b9a732e91d562aa6c5076e3fc817cb 100644 --- a/iotdb/src/test/java/org/apache/iotdb/db/tools/WalCheckerTest.java +++ b/iotdb/src/test/java/org/apache/iotdb/db/tools/WalCheckerTest.java @@ -24,6 +24,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.io.File; +import java.io.FileOutputStream; +import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -129,5 +131,29 @@ public class WalCheckerTest { } finally { FileUtils.deleteDirectory(tempRoot); } + + } + + @Test + public void testOneDamagedCheck() throws IOException, SysCheckException { + File tempRoot = new File("root"); + tempRoot.mkdir(); + + try { + for (int i = 0; i < 5; i++) { + File subDir = new File(tempRoot, "storage_group" + i); + subDir.mkdir(); + + FileOutputStream fileOutputStream = new FileOutputStream(new File(subDir, WAL_FILE_NAME)); + fileOutputStream.write(i); + fileOutputStream.close(); + } + + WalChecker checker = new WalChecker(tempRoot.getAbsolutePath()); + assertEquals(5, checker.doCheck().size()); + } finally { + FileUtils.deleteDirectory(tempRoot); + } + } }