yuqi1129 commented on a change in pull request #1727: URL: https://github.com/apache/incubator-iotdb/pull/1727#discussion_r488599312
########## File path: server/src/main/java/org/apache/iotdb/db/writelog/io/SingleFileLogReader.java ########## @@ -53,54 +54,69 @@ private boolean fileCorrupted = false; + private boolean hasNext = false; + public SingleFileLogReader(File logFile) throws FileNotFoundException { open(logFile); } @Override public boolean hasNext() { - try { - if (batchLogReader != null && batchLogReader.hasNext()) { - return true; - } - - if (logStream.available() < LEAST_LOG_SIZE) { - return false; - } - int logSize = logStream.readInt(); - if (logSize <= 0) { - return false; - } - buffer = new byte[logSize]; + if (Objects.nonNull(batchLogReader)) { Review comment: Yes, if `hasNext()` should be called, there is not need to make any changes here ########## File path: server/src/main/java/org/apache/iotdb/db/writelog/io/SingleFileLogReader.java ########## @@ -53,54 +54,69 @@ private boolean fileCorrupted = false; + private boolean hasNext = false; + public SingleFileLogReader(File logFile) throws FileNotFoundException { open(logFile); } @Override public boolean hasNext() { - try { - if (batchLogReader != null && batchLogReader.hasNext()) { - return true; - } - - if (logStream.available() < LEAST_LOG_SIZE) { - return false; - } - int logSize = logStream.readInt(); - if (logSize <= 0) { - return false; - } - buffer = new byte[logSize]; + if (Objects.nonNull(batchLogReader)) { + hasNext = batchLogReader.hasNext(); - int readLen = logStream.read(buffer, 0, logSize); - if (readLen < logSize) { - throw new IOException("Reach eof"); + if (hasNext) { + return hasNext; } + } - final long checkSum = logStream.readLong(); - checkSummer.reset(); - checkSummer.update(buffer, 0, logSize); - if (checkSummer.getValue() != checkSum) { - throw new IOException(String.format("The check sum of the No.%d log batch is incorrect! In " - + "file: " - + "%d Calculated: %d.", idx, checkSum, checkSummer.getValue())); + try { + while (logStream.available() > LEAST_LOG_SIZE) { Review comment: if `batchLogReader ` is null, then we should find a position in logStream where we create BatchLogReader and make `hasNext()` is true repeatedly, it's in fact a loop ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org