Browse Source

[Fix-4271][server] Fix IOException or NoSuchFileException in logger server (#4272)

Shiwen Cheng 4 years ago
parent
commit
c4d75443e1

+ 9 - 4
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/log/LoggerRequestProcessor.java

@@ -169,10 +169,15 @@ public class LoggerRequestProcessor implements NettyRequestProcessor {
     private List<String> readPartFileContent(String filePath,
                                             int skipLine,
                                             int limit) {
-        try (Stream<String> stream = Files.lines(Paths.get(filePath))) {
-            return stream.skip(skipLine).limit(limit).collect(Collectors.toList());
-        } catch (IOException e) {
-            logger.error("read file error",e);
+        File file = new File(filePath);
+        if (file.exists() && file.isFile()) {
+            try (Stream<String> stream = Files.lines(Paths.get(filePath))) {
+                return stream.skip(skipLine).limit(limit).collect(Collectors.toList());
+            } catch (IOException e) {
+                logger.error("read file error",e);
+            }
+        } else {
+            logger.info("file path: {} not exists", filePath);
         }
         return Collections.emptyList();
     }