Skip to content

Commit 0b7a174

Browse files
committed
Addressing comments
1 parent c8e55d2 commit 0b7a174

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

hudi-common/src/main/java/org/apache/hudi/common/table/log/HoodieLogFileReader.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,15 @@ private HoodieLogBlock readBlock() throws IOException {
157157
} catch (EOFException | CorruptedLogFileException e) {
158158
// An exception reading any of the above indicates a corrupt block
159159
// Create a corrupt block by finding the next MAGIC marker or EOF
160-
return createCorruptBlock();
160+
return createCorruptBlock(blockStartPos);
161161
}
162162

163163
// We may have had a crash which could have written this block partially
164164
// Skip blockSize in the stream and we should either find a sync marker (start of the next
165165
// block) or EOF. If we did not find either of it, then this block is a corrupted block.
166-
boolean isCorrupted = isBlockCorrupt(blockStartPos, blocksize);
166+
boolean isCorrupted = isBlockCorrupt(blockSize);
167167
if (isCorrupted) {
168-
inputStream.seek(blockStartPos);
169-
return createCorruptBlock();
168+
return createCorruptBlock(blockStartPos);
170169
}
171170

172171
// 2. Read the version for this log format
@@ -255,14 +254,14 @@ private HoodieLogBlockType tryReadBlockType(HoodieLogFormat.LogFormatVersion blo
255254
return HoodieLogBlockType.values()[type];
256255
}
257256

258-
private HoodieLogBlock createCorruptBlock() throws IOException {
259-
LOG.info("Log " + logFile + " has a corrupted block at " + inputStream.getPos());
260-
long currentPos = inputStream.getPos();
257+
private HoodieLogBlock createCorruptBlock(long blockStartPos) throws IOException {
258+
LOG.info("Log " + logFile + " has a corrupted block at " + blockStartPos);
259+
inputStream.seek(blockStartPos);
261260
long nextBlockOffset = scanForNextAvailableBlockOffset();
262261
// Rewind to the initial start and read corrupted bytes till the nextBlockOffset
263-
inputStream.seek(currentPos);
262+
inputStream.seek(blockStartPos);
264263
LOG.info("Next available block in " + logFile + " starts at " + nextBlockOffset);
265-
int corruptedBlockSize = (int) (nextBlockOffset - currentPos);
264+
int corruptedBlockSize = (int) (nextBlockOffset - blockStartPos);
266265
long contentPosition = inputStream.getPos();
267266
Option<byte[]> corruptedBytes = HoodieLogBlock.tryReadContent(inputStream, corruptedBlockSize, readBlockLazily);
268267
HoodieLogBlock.HoodieLogBlockContentLocation logBlockContentLoc =

0 commit comments

Comments
 (0)