aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Musum <musum@yahooinc.com>2022-06-20 23:23:12 +0200
committerHarald Musum <musum@yahooinc.com>2022-06-20 23:23:12 +0200
commit030c8c464801d0706bb7004312ed3f54f6a144a1 (patch)
tree544e88a320091eea9609a2488035e212edbe395a
parentf8fa54808bdd8bb58aad59dadc6f3d362178e3fe (diff)
Synchronize access to sessionStateWatchers map
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java26
1 files changed, 17 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 059d192e7d2..9b8abbf4cf6 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
@@ -315,7 +315,7 @@ public class SessionRepository {
public void deleteLocalSession(LocalSession session) {
long sessionId = session.getSessionId();
log.log(Level.FINE, () -> "Deleting local session " + sessionId);
- SessionStateWatcher watcher = sessionStateWatchers.remove(sessionId);
+ SessionStateWatcher watcher = removeSessionStateWatcher(sessionId);
if (watcher != null) watcher.close();
localSessionCache.remove(sessionId);
NestedTransaction transaction = new NestedTransaction();
@@ -323,6 +323,12 @@ public class SessionRepository {
transaction.commit();
}
+ private SessionStateWatcher removeSessionStateWatcher(long sessionId) {
+ synchronized (sessionStateWatchers) {
+ return sessionStateWatchers.remove(sessionId);
+ }
+ }
+
private void deleteAllSessions() {
for (LocalSession session : getLocalSessions()) {
deleteLocalSession(session);
@@ -886,13 +892,15 @@ public class SessionRepository {
}
private void updateSessionStateWatcher(long sessionId, RemoteSession remoteSession) {
- SessionStateWatcher sessionStateWatcher = sessionStateWatchers.get(sessionId);
- if (sessionStateWatcher == null) {
- Curator.FileCache fileCache = curator.createFileCache(getSessionStatePath(sessionId).getAbsolute(), false);
- fileCache.addListener(this::nodeChanged);
- sessionStateWatchers.put(sessionId, new SessionStateWatcher(fileCache, remoteSession, metricUpdater, zkWatcherExecutor, this));
- } else {
- sessionStateWatcher.updateRemoteSession(remoteSession);
+ synchronized (sessionStateWatchers) {
+ SessionStateWatcher sessionStateWatcher = sessionStateWatchers.get(sessionId);
+ if (sessionStateWatcher == null) {
+ Curator.FileCache fileCache = curator.createFileCache(getSessionStatePath(sessionId).getAbsolute(), false);
+ fileCache.addListener(this::nodeChanged);
+ sessionStateWatchers.put(sessionId, new SessionStateWatcher(fileCache, remoteSession, metricUpdater, zkWatcherExecutor, this));
+ } else {
+ sessionStateWatcher.updateRemoteSession(remoteSession);
+ }
}
}
@@ -928,7 +936,7 @@ public class SessionRepository {
long sessionId = it.next().sessionId;
if (existingSessions.contains(sessionId)) continue;
- SessionStateWatcher watcher = sessionStateWatchers.remove(sessionId);
+ SessionStateWatcher watcher = removeSessionStateWatcher(sessionId);
if (watcher != null) watcher.close();
it.remove();
metricUpdater.incRemovedSessions();