srkukarni closed pull request #3165: Check if log folder exists
URL: https://github.com/apache/pulsar/pull/3165
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/ProcessRuntime.java
 
b/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/ProcessRuntime.java
index 6a5f79a025..d3046ba99b 100644
--- 
a/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/ProcessRuntime.java
+++ 
b/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/ProcessRuntime.java
@@ -42,6 +42,8 @@
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.util.List;
 import java.util.TimerTask;
 import java.util.concurrent.CompletableFuture;
@@ -139,15 +141,17 @@ public void start() {
 
         // Note: we create the expected log folder before the function process 
logger attempts to create it
         // This is because if multiple instances are launched they can 
encounter a race condition creation of the dir.
+
         log.info("Creating function log directory {}", funcLogDir);
-        boolean success = createFolder(funcLogDir);
 
-        if (!success) {
-            log.error("Log folder could not be created : {}", funcLogDir);
+        try {
+            Files.createDirectories(Paths.get(funcLogDir));
+        } catch (IOException e) {
+            log.info("Exception when creating log folder : {}",funcLogDir, e);
             throw new RuntimeException("Log folder creation error");
         }
 
-        log.info("Created function log directory {}", funcLogDir);
+        log.info("Created or found function log directory {}", funcLogDir);
 
         startProcess();
         if (channel == null && stub == null) {
@@ -348,11 +352,6 @@ public boolean isAlive() {
         return true;
     }
 
-    private boolean createFolder(final String path) {
-        final boolean success = new File(path).mkdirs();
-        return success;
-    }
-
     private void tryExtractingDeathException() {
         InputStream errorStream = process.getErrorStream();
         try {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to