未验证 提交 6c7b8516 编写于 作者: J Jiang Tian 提交者: GitHub

[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
上级 519e3980
......@@ -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);
......
......@@ -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;
}
......
......@@ -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);
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册