diff options
author | gjoranv <gv@verizonmedia.com> | 2020-04-17 20:16:16 +0200 |
---|---|---|
committer | gjoranv <gv@verizonmedia.com> | 2020-04-17 20:47:18 +0200 |
commit | 4341860afe9a86af5046eba47b42b0343a6369b6 (patch) | |
tree | 537a6de97450f77031c8a5a764d57eb5501d1b07 /container-core | |
parent | a3cb09f37cef3595776eff9884042ab534b08eed (diff) |
Retry once if the acquired file bundle is not readable.
Diffstat (limited to 'container-core')
-rw-r--r-- | container-core/src/main/java/com/yahoo/container/core/config/FileAcquirerBundleInstaller.java | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/container-core/src/main/java/com/yahoo/container/core/config/FileAcquirerBundleInstaller.java b/container-core/src/main/java/com/yahoo/container/core/config/FileAcquirerBundleInstaller.java index 6f6f86a6366..599546c497b 100644 --- a/container-core/src/main/java/com/yahoo/container/core/config/FileAcquirerBundleInstaller.java +++ b/container-core/src/main/java/com/yahoo/container/core/config/FileAcquirerBundleInstaller.java @@ -7,13 +7,16 @@ import com.yahoo.osgi.Osgi; import org.osgi.framework.Bundle; import java.io.File; +import java.nio.file.Files; import java.util.List; import java.util.concurrent.TimeUnit; +import java.util.logging.Logger; /** * @author gjoranv */ public class FileAcquirerBundleInstaller implements BundleInstaller { + private static Logger log = Logger.getLogger(FileAcquirerBundleInstaller.class.getName()); private final FileAcquirer fileAcquirer; @@ -23,8 +26,30 @@ public class FileAcquirerBundleInstaller implements BundleInstaller { @Override public List<Bundle> installBundles(FileReference reference, Osgi osgi) throws InterruptedException { - File file = fileAcquirer.waitFor(reference, 7, TimeUnit.DAYS); + File file = acquireFile(reference); + + // Retrying is added in case FileAcquirer returns right before the file is actually ready. + // This happened on rare occasions due to a (fixed) bug in file distribution. + int retries = 0; + while (notReadable(file) && retries < 1) { + log.warning("Unable to open bundle file with reference '" + reference + "'. Retrying."); + file = acquireFile(reference); + retries++; + } + + if (notReadable(file)) { + com.yahoo.protect.Process.logAndDie("Shutting down - unable to read bundle file with reference '" + reference + + "' and path " + file.getAbsolutePath()); + } return osgi.install(file.getAbsolutePath()); } + private File acquireFile(FileReference reference) throws InterruptedException { + return fileAcquirer.waitFor(reference, 7, TimeUnit.DAYS); + } + + private static boolean notReadable(File file) { + return ! Files.isReadable(file.toPath()); + } + } |