You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ji...@apache.org on 2019/04/23 01:58:46 UTC
[incubator-iotdb] branch master updated: [IOTDB-74]fix that the
damaged log will be skipped if it is the only log (#166)
This is an automated email from the ASF dual-hosted git repository.
jiangtian pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 6c7b851 [IOTDB-74]fix that the damaged log will be skipped if it is the only log (#166)
6c7b851 is described below
commit 6c7b85165ea7d7faced939a87bb3699cad791322
Author: Jiang Tian <jt...@163.com>
AuthorDate: Tue Apr 23 09:58:42 2019 +0800
[IOTDB-74]fix that the damaged log will be skipped if it is the only log (#166)
* fix that the damaged log will be skipped if it is the only log
* add error log
* fix test
---
.../java/org/apache/iotdb/db/tools/WalChecker.java | 11 ++++++++-
.../apache/iotdb/db/writelog/io/RAFLogReader.java | 3 ++-
.../org/apache/iotdb/db/tools/WalCheckerTest.java | 26 ++++++++++++++++++++++
3 files changed, 38 insertions(+), 2 deletions(-)
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 6bef7a5..a3fbf4e 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<File> 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<File> 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 6700805..1834569 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 0c3ca29..8619eba 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);
+ }
+
}
}