tkhurana commented on code in PR #2392:
URL: https://github.com/apache/phoenix/pull/2392#discussion_r2956744383


##########
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);
+          return Optional.of(logFileReader);
+        }
+      } else {
+        // Ignore the file and returning empty LogReader.

Review Comment:
   Don't we need to delete the file ? Don't we need the directory to be empty ?



-- 
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]

Reply via email to