summaryrefslogtreecommitdiffstats
path: root/configserver
diff options
context:
space:
mode:
authorHarald Musum <musum@verizonmedia.com>2020-05-07 21:37:26 +0200
committerHarald Musum <musum@verizonmedia.com>2020-05-07 21:37:26 +0200
commitd24340856f6cf84e79d3693dbdd8b8801ec8b145 (patch)
tree8ce171886a40e1fae6d16b0b60307bd3330acfc1 /configserver
parente9596683c4f7510b07f3979f0120244790798860 (diff)
Do not delete active sessions
Diffstat (limited to 'configserver')
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java7
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/session/RemoteSessionRepo.java11
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java2
3 files changed, 13 insertions, 7 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java b/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java
index f6846a7448e..40f223b47d3 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java
@@ -80,7 +80,6 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
-import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
@@ -675,9 +674,13 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye
}
public int deleteExpiredRemoteSessions(Duration expiryTime) {
+ return deleteExpiredRemoteSessions(clock, expiryTime);
+ }
+
+ public int deleteExpiredRemoteSessions(Clock clock, Duration expiryTime) {
return tenantRepository.getAllTenants()
.stream()
- .map(tenant -> tenant.getRemoteSessionRepo().deleteExpiredSessions(expiryTime))
+ .map(tenant -> tenant.getRemoteSessionRepo().deleteExpiredSessions(clock, expiryTime))
.mapToInt(i -> i)
.sum();
}
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 6189b97eaec..c27b7c6802b 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
@@ -6,6 +6,8 @@ import com.google.common.collect.Multiset;
import com.yahoo.concurrent.StripedExecutor;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.TenantName;
+
+import java.time.Clock;
import java.util.logging.Level;
import com.yahoo.path.Path;
import com.yahoo.vespa.config.server.GlobalComponentRegistry;
@@ -81,13 +83,14 @@ public class RemoteSessionRepo extends SessionRepo<RemoteSession> {
return getSessionList(curator.getChildren(sessionsPath));
}
- public int deleteExpiredSessions(Duration expiryTime) {
+ public int deleteExpiredSessions(Clock clock, Duration expiryTime) {
int deleted = 0;
for (long sessionId : getSessions()) {
RemoteSession session = getSession(sessionId);
if (session == null) continue; // Internal sessions not in synch with zk, continue
+ if (session.getStatus() == Session.Status.ACTIVATE) continue;
Instant created = Instant.ofEpochSecond(session.getCreateTime());
- if (sessionHasExpired(created, expiryTime)) {
+ if (sessionHasExpired(created, expiryTime, clock)) {
log.log(Level.INFO, "Remote session " + sessionId + " for " + tenantName + " has expired, deleting it");
session.delete();
deleted++;
@@ -96,8 +99,8 @@ public class RemoteSessionRepo extends SessionRepo<RemoteSession> {
return deleted;
}
- private boolean sessionHasExpired(Instant created, Duration expiryTime) {
- return (created.plus(expiryTime).isBefore(Instant.now()));
+ private boolean sessionHasExpired(Instant created, Duration expiryTime, Clock clock) {
+ return (created.plus(expiryTime).isBefore(clock.instant()));
}
private List<Long> getSessionListFromDirectoryCache(List<ChildData> children) {
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java
index 0e076d60d52..9ae079c87e0 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java
@@ -327,7 +327,7 @@ public class ApplicationRepositoryTest {
assertEquals(3, new ArrayList<>(sessions).get(0).getSessionId());
// There should be no expired remote sessions in the common case
- assertEquals(0, applicationRepository.deleteExpiredRemoteSessions(Duration.ofSeconds(0)));
+ assertEquals(0, tester.applicationRepository().deleteExpiredRemoteSessions(clock, Duration.ofSeconds(0)));
}
@Test