diff options
author | Harald Musum <musum@verizonmedia.com> | 2020-06-14 19:54:33 +0200 |
---|---|---|
committer | Harald Musum <musum@verizonmedia.com> | 2020-06-14 19:54:33 +0200 |
commit | bacf60aaa7829b319fe6b6d2c650429703b93260 (patch) | |
tree | 41e786013399ebe787e32bb04fe26656632200ec | |
parent | aacb857c63b9932ecac330d65bdd28d05d458b62 (diff) |
Do not throw exception if file reference is not found
-rw-r--r-- | configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java index c6e33ed39ef..7b8de20a5fd 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java @@ -526,10 +526,10 @@ public class SessionRepository { /** * Returns a new session instance for the given session id. */ - LocalSession createLocalSessionUsingDistributedApplicationPackage(long sessionId) { + Optional<LocalSession> createLocalSessionUsingDistributedApplicationPackage(long sessionId) { if (applicationRepo.hasLocalSession(sessionId)) { log.log(Level.FINE, "Local session for session id " + sessionId + " already exists"); - return createSessionFromId(sessionId); + return Optional.of(createSessionFromId(sessionId)); } log.log(Level.INFO, "Creating local session for session id " + sessionId); @@ -539,15 +539,18 @@ public class SessionRepository { if (fileReference != null) { File rootDir = new File(Defaults.getDefaults().underVespaHome(componentRegistry.getConfigserverConfig().fileReferencesDir())); File sessionDir = new FileDirectory(rootDir).getFile(fileReference); - if (!sessionDir.exists()) - throw new RuntimeException("File reference for session " + sessionId + " not found (" + sessionDir.getAbsolutePath() + ")"); + if (!sessionDir.exists()) { + // We cannot be guaranteed that the file reference exists (it could be that it has not been downloaded + // yet), and e.g when bootstrapping we cannot throw an exception if that is the case, so return instead + return Optional.empty(); + } ApplicationId applicationId = sessionZKClient.readApplicationId(); - return createLocalSession(sessionDir, - applicationId, - sessionId, - applicationRepo.activeSessionOf(applicationId).orElse(nonExistingActiveSession)); + return Optional.of(createLocalSession(sessionDir, + applicationId, + sessionId, + applicationRepo.activeSessionOf(applicationId).orElse(nonExistingActiveSession))); } - return null; + return Optional.empty(); } // Return Optional instead of faking it with nonExistingActiveSession |