tkhurana commented on code in PR #2392:
URL: https://github.com/apache/phoenix/pull/2392#discussion_r2956898078
##########
phoenix-core-server/src/main/java/org/apache/phoenix/replication/reader/ReplicationLogProcessor.java:
##########
@@ -303,32 +303,31 @@ 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);
+ logFileReaderContext.setValidateTrailer(false);
+ logFileReader.init(logFileReaderContext);
Review Comment:
There are 2 init calls here so we need to handle failures from any of the
two and close the reader
--
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]