summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Musum <musum@verizonmedia.com>2020-09-11 19:05:37 +0200
committerHarald Musum <musum@verizonmedia.com>2020-09-11 19:05:37 +0200
commitf4800606610983debcab3cf8cab288ce3d49886c (patch)
treeea2b345777d3e332701273b895124a36b68edf4b
parent305c24a5aa8771855ca0b3d51a50186df317f48c (diff)
Look up local session when needed
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java32
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionStateWatcher.java14
2 files changed, 17 insertions, 29 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 3b2c03072c2..a9bab3ffdf8 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
@@ -124,7 +124,7 @@ public class SessionRepository {
localSessionCache.putSession(session);
long sessionId = session.getSessionId();
RemoteSession remoteSession = createRemoteSession(sessionId);
- addSessionStateWatcher(sessionId, remoteSession, Optional.of(session));
+ addSessionStateWatcher(sessionId, remoteSession);
}
public LocalSession getLocalSession(long sessionId) {
@@ -348,10 +348,9 @@ public class SessionRepository {
RemoteSession remoteSession = createRemoteSession(sessionId);
loadSessionIfActive(remoteSession);
addRemoteSession(remoteSession);
- Optional<LocalSession> localSession = Optional.empty();
if (distributeApplicationPackage())
- localSession = createLocalSessionUsingDistributedApplicationPackage(sessionId);
- addSessionStateWatcher(sessionId, remoteSession, localSession);
+ createLocalSessionUsingDistributedApplicationPackage(sessionId);
+ addSessionStateWatcher(sessionId, remoteSession);
}
void activate(RemoteSession session) {
@@ -370,8 +369,10 @@ public class SessionRepository {
remoteSession.deactivate();
}
- public void delete(RemoteSession remoteSession, Optional<LocalSession> localSession) {
- localSession.ifPresent(this::deleteLocalSession);
+ public void delete(RemoteSession remoteSession) {
+ LocalSession localSession = getLocalSession(remoteSession.getSessionId());
+ if (localSession != null)
+ deleteLocalSession(localSession);
remoteSession.deactivate();
}
@@ -603,10 +604,11 @@ public class SessionRepository {
* 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) {
+ public void createLocalSessionUsingDistributedApplicationPackage(long sessionId) {
if (applicationRepo.hasLocalSession(sessionId)) {
log.log(Level.FINE, () -> "Local session for session id " + sessionId + " already exists");
- return Optional.of(createSessionFromId(sessionId));
+ createSessionFromId(sessionId);
+ return;
}
SessionZooKeeperClient sessionZKClient = createSessionZooKeeperClient(sessionId);
@@ -622,16 +624,14 @@ public class SessionRepository {
// 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 in that case
log.log(Level.INFO, "File reference for session id " + sessionId + ": " + fileReference + " not found in " + fileDirectory);
- return Optional.empty();
+ return;
}
ApplicationId applicationId = sessionZKClient.readApplicationId()
.orElseThrow(() -> new RuntimeException("Could not find application id for session " + sessionId));
log.log(Level.FINE, () -> "Creating local session for tenant '" + tenantName + "' with session id " + sessionId);
LocalSession localSession = createLocalSession(sessionDir, applicationId, sessionId);
addLocalSession(localSession);
- return Optional.of(localSession);
}
- return Optional.empty();
}
private Optional<Long> getActiveSessionId(ApplicationId applicationId) {
@@ -670,15 +670,11 @@ public class SessionRepository {
return new TenantFileSystemDirs(componentRegistry.getConfigServerDB(), tenantName).getUserApplicationDir(sessionId);
}
- private void addSessionStateWatcher(long sessionId, 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));
- } else {
+ private void addSessionStateWatcher(long sessionId, RemoteSession remoteSession) {
+ if ( ! sessionStateWatchers.containsKey(sessionId)) {
Curator.FileCache fileCache = curator.createFileCache(getSessionStatePath(sessionId).getAbsolute(), false);
fileCache.addListener(this::nodeChanged);
- sessionStateWatchers.put(sessionId, new SessionStateWatcher(fileCache, remoteSession, localSession,
- metrics, zkWatcherExecutor, this));
+ sessionStateWatchers.put(sessionId, new SessionStateWatcher(fileCache, remoteSession, metrics, zkWatcherExecutor, this));
}
}
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 57d9f027447..c6c08beea17 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
@@ -6,7 +6,6 @@ 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;
@@ -29,17 +28,14 @@ public class SessionStateWatcher {
private final MetricUpdater metrics;
private final Executor zkWatcherExecutor;
private final SessionRepository sessionRepository;
- private Optional<LocalSession> localSession;
SessionStateWatcher(Curator.FileCache fileCache,
RemoteSession remoteSession,
- Optional<LocalSession> localSession,
MetricUpdater metrics,
Executor zkWatcherExecutor,
SessionRepository sessionRepository) {
this.fileCache = fileCache;
this.remoteSession = remoteSession;
- this.localSession = localSession;
this.metrics = metrics;
this.fileCache.addListener(this::nodeChanged);
this.fileCache.start();
@@ -65,7 +61,7 @@ public class SessionStateWatcher {
sessionRepository.deactivate(remoteSession);
break;
case DELETE:
- sessionRepository.delete(remoteSession, localSession);
+ sessionRepository.delete(remoteSession);
break;
default:
throw new IllegalStateException("Unknown status " + newStatus);
@@ -73,8 +69,8 @@ public class SessionStateWatcher {
}
private void createLocalSession(long sessionId) {
- if (sessionRepository.distributeApplicationPackage() && localSession.isEmpty()) {
- localSession = sessionRepository.createLocalSessionUsingDistributedApplicationPackage(sessionId);
+ if (sessionRepository.distributeApplicationPackage()) {
+ sessionRepository.createLocalSessionUsingDistributedApplicationPackage(sessionId);
}
}
@@ -109,8 +105,4 @@ public class SessionStateWatcher {
});
}
- void addLocalSession(LocalSession session) {
- localSession = Optional.of(session);
- }
-
}