aboutsummaryrefslogtreecommitdiffstats
path: root/configserver
diff options
context:
space:
mode:
authorHarald Musum <musum@verizonmedia.com>2021-07-14 12:34:33 +0200
committerHarald Musum <musum@verizonmedia.com>2021-07-14 12:34:33 +0200
commite7bff5537329fd28a598af0ba101a5bedb57ffb9 (patch)
treed618dcb318c736fbdb18fbd092291060220f14c2 /configserver
parent3534840687517be5d8f90af0a7bde4ebb43bc06a (diff)
Use local sessions fromm file system when deleting expired sessions
Earlier we loaded all local sessions at startup time and added to a cache, that was used when deleting expired sessions. We don't load local sessions at startup that anymore, but sessions are still added to cache as they are created. Local sessions that were leftover for some other reason (crash, failure in logic, whatnot) should still be deleted, which is fixed with this.
Diffstat (limited to 'configserver')
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java1
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java18
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java5
3 files changed, 20 insertions, 4 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 56fd6a64305..1eb27a3224a 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
@@ -107,7 +107,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
-import static com.yahoo.config.model.api.container.ContainerServiceType.CLUSTERCONTROLLER_CONTAINER;
import static com.yahoo.config.model.api.container.ContainerServiceType.CONTAINER;
import static com.yahoo.config.model.api.container.ContainerServiceType.LOGSERVER_CONTAINER;
import static com.yahoo.vespa.config.server.filedistribution.FileDistributionUtil.fileReferenceExistsOnDisk;
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 27ee040fe4f..1e025bd8e35 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
@@ -208,6 +208,22 @@ public class SessionRepository {
return List.copyOf(localSessionCache.values());
}
+ public Set<LocalSession> getLocalSessionsFromFileSystem() {
+ File[] sessions = tenantFileSystemDirs.sessionsPath().listFiles(sessionApplicationsFilter);
+ if (sessions == null) return Set.of();
+
+ Set<LocalSession> sessionIds = new HashSet<>();
+ for (File session : sessions) {
+ long sessionId = Long.parseLong(session.getName());
+ SessionZooKeeperClient sessionZKClient = createSessionZooKeeperClient(sessionId);
+ File sessionDir = getAndValidateExistingSessionAppDir(sessionId);
+ ApplicationPackage applicationPackage = FilesApplicationPackage.fromFile(sessionDir);
+ LocalSession localSession = new LocalSession(tenantName, sessionId, applicationPackage, sessionZKClient);
+ sessionIds.add(localSession);
+ }
+ return sessionIds;
+ }
+
private void loadLocalSessions(ExecutorService executor) {
File[] sessions = tenantFileSystemDirs.sessionsPath().listFiles(sessionApplicationsFilter);
if (sessions == null) return;
@@ -553,7 +569,7 @@ public class SessionRepository {
log.log(Level.FINE, () -> "Purging old sessions for tenant '" + tenantName + "'");
Set<LocalSession> toDelete = new HashSet<>();
try {
- for (LocalSession candidate : getLocalSessions()) {
+ for (LocalSession candidate : getLocalSessionsFromFileSystem()) {
Instant createTime = candidate.getCreateTime();
log.log(Level.FINE, () -> "Candidate session for deletion: " + candidate.getSessionId() + ", created: " + createTime);
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 1b31d02d222..8f8005894e5 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
@@ -465,12 +465,13 @@ public class ApplicationRepositoryTest {
// Create a local session without any data in zookeeper (corner case seen in production occasionally)
// and check that expiring local sessions still work
int sessionId = 6;
- Files.createDirectory(new TenantFileSystemDirs(serverdb, tenant1).getUserApplicationDir(sessionId).toPath());
+ TenantName tenantName = tester.tenant().getName();
+ Files.createDirectory(new TenantFileSystemDirs(serverdb, tenantName).getUserApplicationDir(sessionId).toPath());
LocalSession localSession2 = new LocalSession(tenant1,
sessionId,
FilesApplicationPackage.fromFile(testApp),
new SessionZooKeeperClient(curator,
- tenant1,
+ tenantName,
sessionId,
ConfigUtils.getCanonicalHostName()));
sessionRepository.addLocalSession(localSession2);