diff options
author | Harald Musum <musum@yahooinc.com> | 2022-01-05 14:56:23 +0100 |
---|---|---|
committer | Harald Musum <musum@yahooinc.com> | 2022-01-05 14:56:23 +0100 |
commit | b67d3b13a9dc96cde15a3c780431d4e6cc19c2a0 (patch) | |
tree | 9f5a786ea9551a44b2c56967ce3b47dc0b5abf88 /configserver | |
parent | 1a4e1a9ecac8e9947c12c5fc65303d255ed5f499 (diff) |
Don't delete new sessions in file system
If delete runs while a deployment is ongoing and session does not exist
in ZooKeeper yet we should not delete it
Diffstat (limited to 'configserver')
-rw-r--r-- | configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java | 25 | ||||
-rw-r--r-- | configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java | 10 |
2 files changed, 33 insertions, 2 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 07cdc910253..c6a37e57e8a 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 @@ -572,8 +572,16 @@ public class SessionRepository { public void deleteExpiredSessions(Map<ApplicationId, Long> activeSessions) { log.log(Level.FINE, () -> "Purging old sessions for tenant '" + tenantName + "'"); Set<LocalSession> toDelete = new HashSet<>(); + Set<Long> newSessions = findNewSessionsInFileSystem(); try { for (LocalSession candidate : getLocalSessionsFromFileSystem()) { + // Skip sessions newly added (we might have a session in the file system, but not in ZooKeeper, + // we don't want to touch any of them) + if (newSessions.contains(candidate.getSessionId())) { + log.log(Level.INFO, () -> "Skipping session " + candidate.getSessionId() + ", newly created: "); + continue; + } + Instant createTime = candidate.getCreateTime(); log.log(Level.FINE, () -> "Candidate session for deletion: " + candidate.getSessionId() + ", created: " + createTime); @@ -618,6 +626,23 @@ public class SessionRepository { && created(sessionDir).plus(Duration.ofDays(30)).isBefore(clock.instant()); } + private Set<Long> findNewSessionsInFileSystem() { + File[] sessions = tenantFileSystemDirs.sessionsPath().listFiles(sessionApplicationsFilter); + Set<Long> newSessions = new HashSet<>(); + if (sessions != null) { + for (File session : sessions) { + try { + if (Files.getLastModifiedTime(session.toPath()).toInstant() + .isAfter(clock.instant().minus(Duration.ofSeconds(30)))) + newSessions.add(Long.parseLong(session.getName())); + } catch (IOException e) { + log.log(Level.INFO, "Unable to find last modified time for " + session.toPath()); + }; + } + } + return newSessions; + } + private Instant created(File file) { BasicFileAttributes fileAttributes; try { 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 e6d349ef481..7baad75ebc5 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 @@ -482,12 +482,18 @@ public class ApplicationRepositoryTest { sessionRepository.createSetStatusTransaction(session, Session.Status.UNKNOWN); assertEquals(2, sessionRepository.getLocalSessions().size()); // Still 2, no new local session - // Check that trying to expire local session when there exists a local session without any data in zookeeper should not delete session + // Check that trying to expire local session when there exists a local session without any data in zookeeper + // should not delete session if this is a new file ... deleteExpiredLocalSessionsAndAssertNumberOfSessions(2, tester, sessionRepository); + // ... but it should be deleted if some time has passed + clock.advance(Duration.ofSeconds(60)); + tester.applicationRepository().deleteExpiredLocalSessions(); + assertEquals(1, sessionRepository.getLocalSessions().size()); + // Set older created timestamp for session dir for local session without any data in zookeeper, should be deleted setCreatedTime(dir, Instant.now().minus(Duration.ofDays(31))); - deleteExpiredLocalSessionsAndAssertNumberOfSessions(1, tester, sessionRepository); + deleteExpiredLocalSessionsAndAssertNumberOfSessions(0, tester, sessionRepository); } @Test |