Skip to content

PHOENIX-7786 Improved handling for empty files in Replication Log Processor#2392

Merged
tkhurana merged 7 commits intoapache:PHOENIX-7562-feature-newfrom
Himanshu-g81:PHOENIX-7786
Mar 25, 2026
Merged

PHOENIX-7786 Improved handling for empty files in Replication Log Processor#2392
tkhurana merged 7 commits intoapache:PHOENIX-7562-feature-newfrom
Himanshu-g81:PHOENIX-7786

Conversation

@Himanshu-g81
Copy link
Contributor

No description provided.

// If trailer is missing or corrupt, create reader without trailer validation
LOG.warn("Invalid Trailer for file {}", filePath, invalidLogTrailerException);
logFileReaderContext.setValidateTrailer(false);
logFileReader.init(logFileReaderContext);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 2 init calls here so we need to handle failures from any of the two and close the reader

@Himanshu-g81 Himanshu-g81 requested a review from tkhurana March 21, 2026 04:01
// If trailer is missing or corrupt, create reader without trailer validation
LOG.warn("Invalid Trailer for file {}", filePath, invalidLogTrailerException);
// close the reader first to avoid leaking socket connection
logFileReader.close();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this still doesn't completely fix the issue. While it fixes the leak, you simply cannot use the same LogFileReader object because it internally maintains a closed state and then when you try to iterate it will not return any result. https://github.com/apache/phoenix/blob/PHOENIX-7562-feature-new/phoenix-core-server/src/main/java/org/apache/phoenix/replication/log/LogFileReader.java#L73-L74
You have to construct a new LogFileReader object. This also means you need to enhance your test to correctly capture the issue.

closeReader(logFileReader);
logFileReaderContext.setValidateTrailer(false);
LogFileReader newLogFileReader = new LogFileReader();
newLogFileReader.init(logFileReaderContext);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we are leaking the reference newLogFileReader. Maybe don't introduce a new reference and reassign the existing reference logFileReader to the new object.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is variable inside the method, once the method call is done, the object would still be purged by GC right?
But it's good to keep the old reference, I have updated in next commit in which I was increasing the test coverage also.
Thank you!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GC will not call close on the object. So you will have to explicitly close it to avoid leaking the socket.

@tkhurana tkhurana merged commit 5a9e2d5 into apache:PHOENIX-7562-feature-new Mar 25, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants