tkhurana commented on code in PR #2392:
URL: https://github.com/apache/phoenix/pull/2392#discussion_r2976950693
##########
phoenix-core-server/src/main/java/org/apache/phoenix/replication/reader/ReplicationLogProcessor.java:
##########
@@ -303,32 +303,33 @@ protected Optional<LogFileReader>
createLogFileReader(FileSystem fs, Path filePa
LogFileReader logFileReader = new LogFileReader();
LogFileReaderContext logFileReaderContext =
new LogFileReaderContext(conf).setFileSystem(fs).setFilePath(filePath);
- boolean isClosed = isFileClosed(fs, filePath);
- if (isClosed) {
- // As file is closed, ensure that the file has a valid header and trailer
- logFileReader.init(logFileReaderContext);
- return Optional.of(logFileReader);
- } else {
- LOG.warn("Found un-closed file {}. Starting lease recovery.", filePath);
+ try {
+ // Ensure to recover lease first, in case file was un-closed. If it was
already closed,
+ // recoverLease would return true immediately.
recoverLease(fs, filePath);
- if (fs.getFileStatus(filePath).getLen() <= 0) {
- // Found empty file, returning null LogReader
+ if (fs.getFileStatus(filePath).getLen() > 0) {
+ try {
+ // Acquired the lease, try to create reader with validation both
header and trailer
+ logFileReader.init(logFileReaderContext);
+ return Optional.of(logFileReader);
+ } catch (InvalidLogTrailerException invalidLogTrailerException) {
+ // 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();
Review Comment:
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.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]