diff options
author | Harald Musum <musum@verizonmedia.com> | 2020-07-01 10:22:39 +0200 |
---|---|---|
committer | Harald Musum <musum@verizonmedia.com> | 2020-07-01 10:22:39 +0200 |
commit | 1f6cbbce449ca379c80cf0561de157938ec6d881 (patch) | |
tree | fc5a523f0d345b10be9c08dcdcf122f92536265e | |
parent | aac7958354aab414dc036a82dcf493a749d6f1d5 (diff) |
Try to create local session when session state changes
* If local session does not exist, try to create it when session state changes
2 files changed, 25 insertions, 17 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 2da93b7f243..abb592228a2 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 @@ -330,7 +330,7 @@ public class SessionRepository { addWatcher(sessionId, fileCache, remoteSession, localSession); } - private boolean distributeApplicationPackage() { + boolean distributeApplicationPackage() { return distributeApplicationPackage.value(); } @@ -553,7 +553,6 @@ public class SessionRepository { return Optional.of(createSessionFromId(sessionId)); } - log.log(Level.INFO, "Creating local session for session id " + sessionId); SessionZooKeeperClient sessionZKClient = createSessionZooKeeperClient(sessionId); FileReference fileReference = sessionZKClient.readApplicationPackageReference(); log.log(Level.FINE, "File reference for session id " + sessionId + ": " + fileReference); @@ -570,6 +569,7 @@ public class SessionRepository { return Optional.empty(); } ApplicationId applicationId = sessionZKClient.readApplicationId(); + log.log(Level.INFO, "Creating local session for session id " + sessionId); LocalSession localSession = createLocalSession(sessionDir, applicationId, sessionId); addSession(localSession); return Optional.of(localSession); diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionStateWatcher.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionStateWatcher.java index e3f4854105a..1cbab9be1a8 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionStateWatcher.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionStateWatcher.java @@ -1,17 +1,19 @@ // Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.config.server.session; -import java.util.Optional; -import java.util.logging.Level; import com.yahoo.text.Utf8; import com.yahoo.vespa.config.server.ReloadHandler; import com.yahoo.vespa.config.server.monitoring.MetricUpdater; import com.yahoo.vespa.curator.Curator; import org.apache.curator.framework.recipes.cache.ChildData; +import java.util.Optional; import java.util.concurrent.Executor; +import java.util.logging.Level; import java.util.logging.Logger; +import static com.yahoo.vespa.config.server.session.Session.Status; + /** * Watches one particular session (/config/v2/tenants/<tenantName>/sessions/<n>/sessionState in ZooKeeper) * The session must be in the session repo. @@ -49,18 +51,19 @@ public class SessionStateWatcher { this.sessionRepository = sessionRepository; } - private void sessionStatusChanged(Session.Status newStatus) { + private void sessionStatusChanged(Status newStatus) { long sessionId = remoteSession.getSessionId(); - log.log(Level.FINE, remoteSession.logPre() + "Session change: Session " + remoteSession.getSessionId() + " changed status to " + newStatus); - if (newStatus.equals(Session.Status.PREPARE)) { + if (newStatus.equals(Status.PREPARE)) { + createLocalSession(sessionId); log.log(Level.FINE, remoteSession.logPre() + "Loading prepared session: " + sessionId); remoteSession.loadPrepared(); - } else if (newStatus.equals(Session.Status.ACTIVATE)) { + } else if (newStatus.equals(Status.ACTIVATE)) { + createLocalSession(sessionId); remoteSession.makeActive(reloadHandler); - } else if (newStatus.equals(Session.Status.DEACTIVATE)) { + } else if (newStatus.equals(Status.DEACTIVATE)) { remoteSession.deactivate(); - } else if (newStatus.equals(Session.Status.DELETE)) { + } else if (newStatus.equals(Status.DELETE)) { remoteSession.deactivate(); localSession.ifPresent(session -> { log.log(Level.FINE, session.logPre() + "Deleting session " + sessionId); @@ -69,6 +72,12 @@ public class SessionStateWatcher { } } + private void createLocalSession(long sessionId) { + if (sessionRepository.distributeApplicationPackage() && localSession.isEmpty()) { + localSession = sessionRepository.createLocalSessionUsingDistributedApplicationPackage(sessionId); + } + } + public long getSessionId() { return remoteSession.getSessionId(); } @@ -83,19 +92,18 @@ public class SessionStateWatcher { private void nodeChanged() { zkWatcherExecutor.execute(() -> { - Session.Status currentStatus = remoteSession.getStatus(); - Session.Status newStatus = Session.Status.NONE; + Status newStatus = Status.NONE; try { ChildData node = fileCache.getCurrentData(); if (node != null) { - newStatus = Session.Status.parse(Utf8.toString(node.getData())); - log.log(Level.FINE, remoteSession.logPre() + "Session change: Remote session " + remoteSession.getSessionId() + - " changed status from " + currentStatus.name() + " to " + newStatus.name()); + newStatus = Status.parse(Utf8.toString(node.getData())); + log.log(Level.FINE, remoteSession.logPre() + "Session change: Session " + + remoteSession.getSessionId() + " changed status to " + newStatus.name()); sessionStatusChanged(newStatus); } } catch (Exception e) { - log.log(Level.WARNING, remoteSession.logPre() + "Error handling session change from " + currentStatus.name() + - " to " + newStatus.name() + " for session " + getSessionId(), e); + log.log(Level.WARNING, remoteSession.logPre() + "Error handling session change to " + + newStatus.name() + " for session " + getSessionId(), e); metrics.incSessionChangeErrors(); } }); |