Himanshu-g81 commented on code in PR #2392:
URL: https://github.com/apache/phoenix/pull/2392#discussion_r2987980735
##########
phoenix-core-server/src/main/java/org/apache/phoenix/replication/reader/ReplicationLogProcessor.java:
##########
@@ -303,32 +303,35 @@ 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 a new reader without
trailer validation.
+ // We must create a new instance because close() sets the closed
flag, making
+ // the old instance unusable for reading.
+ LOG.warn("Invalid Trailer for file {}", filePath,
invalidLogTrailerException);
+ closeReader(logFileReader);
+ logFileReaderContext.setValidateTrailer(false);
+ LogFileReader newLogFileReader = new LogFileReader();
+ newLogFileReader.init(logFileReaderContext);
Review Comment:
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!
--
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]