Avoid adding local session to session cache twice
createLocalSessionUsingDistributedApplicationPackage already adds the
session to session cache
@@ -323,13 +323,15 @@ public class SessionRepository {
loadSessionIfActive(remoteSession);
addRemoteSession(remoteSession);
Optional<LocalSession> 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<LocalSession> 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> localSession) {
+ public void addWatcher(long sessionId, Curator.FileCache fileCache, RemoteSession remoteSession, Optional<LocalSession> 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));
