summaryrefslogtreecommitdiffstats
path: root/configserver
diff options
context:
space:
mode:
authorHarald Musum <musum@oath.com>2018-06-27 08:23:25 +0200
committerHarald Musum <musum@oath.com>2018-06-27 08:23:25 +0200
commit9cfa304ab65add68229dd906bfebd9be9ca51b32 (patch)
treec43e9f55dd27d81721ed42e972d1239e5083e729 /configserver
parentc32227420c19dda126a8cf8c0f63da82b7fbe3e6 (diff)
Simplify and clean up
Diffstat (limited to 'configserver')
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/session/LocalSessionRepo.java7
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/session/RemoteSessionRepo.java24
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepo.java33
3 files changed, 11 insertions, 53 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/LocalSessionRepo.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/LocalSessionRepo.java
index 550b08f3d5c..184ba686f63 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/LocalSessionRepo.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/LocalSessionRepo.java
@@ -3,7 +3,6 @@ package com.yahoo.vespa.config.server.session;
import com.yahoo.concurrent.ThreadFactoryFactory;
import com.yahoo.log.LogLevel;
-import com.yahoo.vespa.config.server.application.ZKTenantApplications;
import com.yahoo.vespa.config.server.deploy.TenantFileSystemDirs;
import java.io.File;
@@ -12,8 +11,6 @@ import java.time.Clock;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@@ -22,7 +19,7 @@ import java.util.logging.Logger;
/**
* File-based session repository for LocalSessions. Contains state for the local instance of the configserver.
*
- * @author lulf
+ * @author Ulf Lilleengen
*/
public class LocalSessionRepo extends SessionRepo<LocalSession> {
@@ -95,7 +92,7 @@ public class LocalSessionRepo extends SessionRepo<LocalSession> {
}
private void deleteSession(LocalSession candidate) {
- removeSessionOrThrow(candidate.getSessionId());
+ removeSession(candidate.getSessionId());
candidate.delete();
}
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/RemoteSessionRepo.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/RemoteSessionRepo.java
index 12fa828f692..076b6c07bd3 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/RemoteSessionRepo.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/RemoteSessionRepo.java
@@ -91,32 +91,12 @@ public class RemoteSessionRepo extends SessionRepo<RemoteSession> implements Nod
//---------- START overrides to keep sessions changed in sync
- @Override
public synchronized void addSession(RemoteSession session) {
super.addSession(session);
sessionAdded(session.getSessionId());
}
@Override
- public synchronized void removeSessionOrThrow(long id) {
- super.removeSessionOrThrow(id);
- sessionRemoved(id);
- }
-
- /**
- * Removes a session
- *
- * @param id the id of the session to remove
- * @return the removed session, or null if none was found
- */
- @Override
- public synchronized RemoteSession removeSession(long id) {
- RemoteSession session = super.removeSession(id);
- sessionRemoved(id);
- return session;
- }
-
- @Override
public void removeSession(long id, NestedTransaction transaction) {
super.removeSession(id, transaction);
transaction.onCommitted(() -> sessionRemoved(id));
@@ -184,7 +164,7 @@ public class RemoteSessionRepo extends SessionRepo<RemoteSession> implements Nod
fileCache.addListener(this);
loadSessionIfActive(session);
sessionStateWatchers.put(sessionId, new SessionStateWatcher(fileCache, reloadHandler, session, metrics));
- internalAddSession(session);
+ addSession(session);
metrics.incAddedSessions();
} catch (Exception e) {
log.log(Level.WARNING, "Failed loading session " + sessionId + ": No config for this session can be served", e);
@@ -194,7 +174,7 @@ public class RemoteSessionRepo extends SessionRepo<RemoteSession> implements Nod
private void sessionRemoved(long sessionId) {
SessionStateWatcher watcher = sessionStateWatchers.remove(sessionId);
watcher.close();
- internalRemoveSessionOrThrow(sessionId);
+ removeSession(sessionId);
metrics.incRemovedSessions();
}
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepo.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepo.java
index 645a2f19d89..415ff268309 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepo.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepo.java
@@ -16,8 +16,7 @@ import java.util.HashMap;
/**
* A generic session repository that can store any type of session that extends the abstract interface.
*
- * @author lulf
- * @since 5.1
+ * @author Ulf Lilleengen
*/
// TODO: This is a ZK cache. We should probably remove it, or make that explicit
public class SessionRepo<SESSIONTYPE extends Session> {
@@ -25,35 +24,17 @@ public class SessionRepo<SESSIONTYPE extends Session> {
private final HashMap<Long, SESSIONTYPE> sessions = new HashMap<>();
public synchronized void addSession(SESSIONTYPE session) {
- internalAddSession(session);
- }
-
- /** Why is this needed? Because of implementation inheritance - see RemoteSessionRepo */
- protected synchronized final void internalAddSession(SESSIONTYPE session) {
if (sessions.containsKey(session.getSessionId()))
throw new IllegalArgumentException("There already exists a session with id '" + session.getSessionId() + "'");
sessions.put(session.getSessionId(), session);
}
- public synchronized void removeSessionOrThrow(long id) {
- internalRemoveSessionOrThrow(id);
- }
-
- /** Why is this needed? Because of implementation inheritance - see RemoteSessionRepo */
- protected synchronized final void internalRemoveSessionOrThrow(long id) {
+ public synchronized SESSIONTYPE removeSession(long id) {
if ( ! sessions.containsKey(id))
- throw new IllegalArgumentException("No such session exists '" + id + "'");
- sessions.remove(id);
+ throw new IllegalArgumentException("No session with id '" + id + "' exists");
+ return sessions.remove(id);
}
- /**
- * Removes a session in a transaction
- *
- * @param id the id of the session to remove
- * @return the removed session, or null if none was found
- */
- public synchronized SESSIONTYPE removeSession(long id) { return sessions.remove(id); }
-
public void removeSession(long id, NestedTransaction nestedTransaction) {
SessionRepoTransaction transaction = new SessionRepoTransaction();
transaction.addRemoveOperation(id);
@@ -103,7 +84,7 @@ public class SessionRepo<SESSIONTYPE extends Session> {
public class SessionRepoTransaction extends AbstractTransaction {
- public void addRemoveOperation(long sessionIdToRemove) {
+ void addRemoveOperation(long sessionIdToRemove) {
add(new RemoveOperation(sessionIdToRemove));
}
@@ -124,7 +105,7 @@ public class SessionRepo<SESSIONTYPE extends Session> {
((SessionOperation)operation).rollback();
}
- public abstract class SessionOperation implements Transaction.Operation {
+ abstract class SessionOperation implements Transaction.Operation {
abstract void commit();
@@ -137,7 +118,7 @@ public class SessionRepo<SESSIONTYPE extends Session> {
private final long sessionIdToRemove;
private SESSIONTYPE removed = null;
- public RemoveOperation(long sessionIdToRemove) {
+ RemoveOperation(long sessionIdToRemove) {
this.sessionIdToRemove = sessionIdToRemove;
}