You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2018/04/27 23:22:33 UTC

[GitHub] sijie closed pull request #1674: Clean the local cache of downloaded packages if it already exists

sijie closed pull request #1674: Clean the local cache of downloaded packages if it already exists
URL: https://github.com/apache/incubator-pulsar/pull/1674
 
 
   

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/worker/src/main/java/org/apache/pulsar/functions/worker/FunctionActioner.java b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/FunctionActioner.java
index 702f314a7f..d7bbc96618 100644
--- a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/FunctionActioner.java
+++ b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/FunctionActioner.java
@@ -117,41 +117,44 @@ private void startFunction(FunctionRuntimeInfo functionRuntimeInfo) throws Excep
             pkgDir,
             new File(FunctionDetailsUtils.getDownloadFileName(functionMetaData.getFunctionDetails())).getName());
 
-        if (!pkgFile.exists()) {
-            // download only when the package file doesn't exist
-            File tempPkgFile;
-            while (true) {
-                tempPkgFile = new File(
+        if (pkgFile.exists()) {
+            log.warn("Function package exists already {} deleting it",
+                    pkgFile);
+            pkgFile.delete();
+        }
+
+        File tempPkgFile;
+        while (true) {
+            tempPkgFile = new File(
                     pkgDir,
                     pkgFile.getName() + "." + instanceId + "." + UUID.randomUUID().toString());
-                if (!tempPkgFile.exists() && tempPkgFile.createNewFile()) {
-                    break;
-                }
+            if (!tempPkgFile.exists() && tempPkgFile.createNewFile()) {
+                break;
             }
-            try {
-                log.info("Function package file {} will be downloaded from {}",
+        }
+        try {
+            log.info("Function package file {} will be downloaded from {}",
                     tempPkgFile, functionMetaData.getPackageLocation());
-                Utils.downloadFromBookkeeper(
+            Utils.downloadFromBookkeeper(
                     dlogNamespace,
                     new FileOutputStream(tempPkgFile),
                     functionMetaData.getPackageLocation().getPackagePath());
 
-                // create a hardlink, if there are two concurrent createLink operations, one will fail.
-                // this ensures one instance will successfully download the package.
-                try {
-                    Files.createLink(
+            // create a hardlink, if there are two concurrent createLink operations, one will fail.
+            // this ensures one instance will successfully download the package.
+            try {
+                Files.createLink(
                         Paths.get(pkgFile.toURI()),
                         Paths.get(tempPkgFile.toURI()));
-                    log.info("Function package file is linked from {} to {}",
+                log.info("Function package file is linked from {} to {}",
                         tempPkgFile, pkgFile);
-                } catch (FileAlreadyExistsException faee) {
-                    // file already exists
-                    log.warn("Function package has been downloaded from {} and saved at {}",
+            } catch (FileAlreadyExistsException faee) {
+                // file already exists
+                log.warn("Function package has been downloaded from {} and saved at {}",
                         functionMetaData.getPackageLocation(), pkgFile);
-                }
-            } finally {
-                tempPkgFile.delete();
             }
+        } finally {
+            tempPkgFile.delete();
         }
 
         InstanceConfig instanceConfig = new InstanceConfig();


 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services