-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing memory leak due to HoodieLogFileReader holding on to a logblock #346
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,7 +56,6 @@ class HoodieLogFileReader implements HoodieLogFormat.Reader { | |
private static final byte[] oldMagicBuffer = new byte[4]; | ||
private static final byte[] magicBuffer = new byte[6]; | ||
private final Schema readerSchema; | ||
private HoodieLogBlock nextBlock = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this cause additional memory overhead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this issue. The following is my analysis. Essentially, we pass an inputstream from HoodieLogFileReader to the LogBlocks. An inputstream can be shared in more than 1 logblock. A list of logBlocks are kept until they are merged. So until all logblocks holding the inputstream generated in HoodieLogFileReader are GC'd, they will continue to hold memory. So the last block read is kept in this variable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per the screenshot in the ticket, most retained memory comes from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But I think we will hold onto the last block in each file and that's what you are seeing.. |
||
private LogFormatVersion nextBlockVersion; | ||
private boolean readBlockLazily; | ||
private long reverseLogFilePosition; | ||
|
@@ -271,8 +270,8 @@ public boolean hasNext() { | |
if (isEOF) { | ||
return false; | ||
} | ||
this.nextBlock = readBlock(); | ||
return nextBlock != null; | ||
// If not hasNext(), we either we reach EOF or throw an exception on invalid magic header | ||
return true; | ||
} catch (IOException e) { | ||
throw new HoodieIOException("IOException when reading logfile " + logFile, e); | ||
} | ||
|
@@ -322,11 +321,12 @@ private boolean readMagic() throws IOException { | |
|
||
@Override | ||
public HoodieLogBlock next() { | ||
if (nextBlock == null) { | ||
// may be hasNext is not called | ||
hasNext(); | ||
try { | ||
// hasNext() must be called before next() | ||
return readBlock(); | ||
} catch(IOException io) { | ||
throw new HoodieIOException("IOException when reading logblock from log file " + logFile, io); | ||
} | ||
return nextBlock; | ||
} | ||
|
||
/** | ||
|
@@ -378,7 +378,7 @@ public HoodieLogBlock prev() throws IOException { | |
boolean hasNext = hasNext(); | ||
reverseLogFilePosition -= blockSize; | ||
lastReverseLogFilePosition = reverseLogFilePosition; | ||
return this.nextBlock; | ||
return next(); | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This intermediate map was causing the issue? I guess we don't need this anymore given we are lazy reading the metadata and the content is only read when we are sure we want to merge?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 issues. This one is just extra overhead which we don't need and cannot afford. So yes, we merge only when we are sure so this is not needed.