From e8ce57c2efd44a3e50590e6646a2aceec06fe25d Mon Sep 17 00:00:00 2001 From: Harald Musum Date: Fri, 26 Jun 2020 07:45:33 +0200 Subject: Avoid adding local session to session cache twice createLocalSessionUsingDistributedApplicationPackage already adds the session to session cache --- .../vespa/config/server/session/SessionRepository.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'configserver') 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 2110e6476b6..43b1b84c1e6 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 @@ -323,13 +323,15 @@ public class SessionRepository { loadSessionIfActive(remoteSession); addRemoteSession(remoteSession); Optional localSession = Optional.empty(); - if (distributeApplicationPackage.value()) { + if (distributeApplicationPackage()) localSession = createLocalSessionUsingDistributedApplicationPackage(sessionId); - localSession.ifPresent(this::addSession); - } addWatcher(sessionId, fileCache, remoteSession, localSession); } + private boolean distributeApplicationPackage() { + return distributeApplicationPackage.value(); + } + private void sessionRemoved(long sessionId) { SessionStateWatcher watcher = sessionStateWatchers.remove(sessionId); if (watcher != null) watcher.close(); @@ -462,7 +464,7 @@ public class SessionRepository { LocalSession session = create(existingApp, existingApplicationId, activeSessionId, internalRedeploy, timeoutBudget); // Note: Needs to be kept in sync with calls in SessionPreparer.writeStateToZooKeeper() session.setApplicationId(existingApplicationId); - if (distributeApplicationPackage.value() && existingSession.getApplicationPackageReference() != null) { + if (distributeApplicationPackage() && existingSession.getApplicationPackageReference() != null) { session.setApplicationPackageReference(existingSession.getApplicationPackageReference()); } session.setVespaVersion(existingSession.getVespaVersion()); @@ -526,7 +528,8 @@ public class SessionRepository { } /** - * Returns a new session instance for the given session id. + * Returns a new local session for the given session id if it does not already exist. + * Will also add the session to the local session cache if necessary */ public Optional createLocalSessionUsingDistributedApplicationPackage(long sessionId) { if (applicationRepo.hasLocalSession(sessionId)) { @@ -596,7 +599,7 @@ public class SessionRepository { return new TenantFileSystemDirs(componentRegistry.getConfigServerDB(), tenantName).getUserApplicationDir(sessionId); } - private void addWatcher(long sessionId, Curator.FileCache fileCache, RemoteSession remoteSession, Optional localSession) { + public void addWatcher(long sessionId, Curator.FileCache fileCache, RemoteSession remoteSession, Optional localSession) { // Remote session will always be present in an existing state watcher, but local session might not if (sessionStateWatchers.containsKey(sessionId)) { localSession.ifPresent(session -> sessionStateWatchers.get(sessionId).addLocalSession(session)); -- cgit v1.2.3 From 1c5d906292a3b4ec101fbcc591208aa09b6dd007 Mon Sep 17 00:00:00 2001 From: Harald Musum Date: Fri, 26 Jun 2020 11:50:47 +0200 Subject: Method should be private --- .../java/com/yahoo/vespa/config/server/session/SessionRepository.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'configserver') 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 43b1b84c1e6..53821a92894 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 @@ -599,7 +599,7 @@ public class SessionRepository { return new TenantFileSystemDirs(componentRegistry.getConfigServerDB(), tenantName).getUserApplicationDir(sessionId); } - public void addWatcher(long sessionId, Curator.FileCache fileCache, RemoteSession remoteSession, Optional localSession) { + private void addWatcher(long sessionId, Curator.FileCache fileCache, RemoteSession remoteSession, Optional localSession) { // Remote session will always be present in an existing state watcher, but local session might not if (sessionStateWatchers.containsKey(sessionId)) { localSession.ifPresent(session -> sessionStateWatchers.get(sessionId).addLocalSession(session)); -- cgit v1.2.3