diff options
author | Harald Musum <musum@verizonmedia.com> | 2020-05-25 23:30:38 +0200 |
---|---|---|
committer | Harald Musum <musum@verizonmedia.com> | 2020-05-25 23:30:38 +0200 |
commit | 11eefc09080fa1df9bfd056b705dda25373dccc7 (patch) | |
tree | 44942a77ef3cb2462f0c219c73ccafbb5929e1b4 /configserver | |
parent | 2ed4b72f28a69192934f9de256035c52196d0688 (diff) |
Check for null when getting active session
Diffstat (limited to 'configserver')
3 files changed, 26 insertions, 6 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 bcdb2618bda..490ab988048 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 @@ -684,8 +684,11 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye sessionsPerTenant.values().forEach(sessionList -> sessionList.forEach(s -> applicationIds.add(s.getApplicationId()))); Map<ApplicationId, Long> activeSessions = new HashMap<>(); - applicationIds.forEach(applicationId -> activeSessions.put(applicationId, getActiveSession(applicationId).getSessionId())); - + applicationIds.forEach(applicationId -> { + RemoteSession activeSession = getActiveSession(applicationId); + if (activeSession != null) + activeSessions.put(applicationId, activeSession.getSessionId()); + }); sessionsPerTenant.keySet().forEach(tenant -> tenant.getLocalSessionRepo().deleteExpiredSessions(activeSessions)); } 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 f9b851fe197..d276a59327d 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 @@ -120,7 +120,7 @@ public class LocalSessionRepo extends SessionRepo<LocalSession> { return candidate.getStatus() == Session.Status.ACTIVATE; } - void deleteSession(LocalSession session) { + public void deleteSession(LocalSession session) { long sessionId = session.getSessionId(); log.log(Level.FINE, "Deleting local session " + sessionId); LocalSessionStateWatcher watcher = sessionStateWatchers.remove(sessionId); 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 4d0253cd3f8..e977284e06c 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 @@ -21,12 +21,14 @@ import com.yahoo.io.IOUtils; import com.yahoo.jdisc.Metric; import com.yahoo.test.ManualClock; import com.yahoo.text.Utf8; +import com.yahoo.transaction.NestedTransaction; import com.yahoo.vespa.config.server.application.OrchestratorMock; import com.yahoo.vespa.config.server.deploy.DeployTester; import com.yahoo.vespa.config.server.http.InternalServerException; import com.yahoo.vespa.config.server.http.SessionHandlerTest; import com.yahoo.vespa.config.server.http.v2.PrepareResult; import com.yahoo.vespa.config.server.session.LocalSession; +import com.yahoo.vespa.config.server.session.LocalSessionRepo; import com.yahoo.vespa.config.server.session.PrepareParams; import com.yahoo.vespa.config.server.session.RemoteSession; import com.yahoo.vespa.config.server.session.SilentDeployLogger; @@ -331,18 +333,33 @@ public class ApplicationRepositoryTest { assertNotEquals(activeSessionId, deployment3session); // No change to active session id assertEquals(activeSessionId, tester.tenant().getApplicationRepo().requireActiveSessionOf(tester.applicationId())); - assertEquals(3, tester.tenant().getLocalSessionRepo().listSessions().size()); + LocalSessionRepo localSessionRepo = tester.tenant().getLocalSessionRepo(); + assertEquals(3, localSessionRepo.listSessions().size()); clock.advance(Duration.ofHours(1)); // longer than session lifetime // All sessions except 3 should be removed after the call to deleteExpiredLocalSessions tester.applicationRepository().deleteExpiredLocalSessions(); - Collection<LocalSession> sessions = tester.tenant().getLocalSessionRepo().listSessions(); + Collection<LocalSession> sessions = localSessionRepo.listSessions(); assertEquals(1, sessions.size()); - assertEquals(3, new ArrayList<>(sessions).get(0).getSessionId()); + ArrayList<LocalSession> localSessions = new ArrayList<>(sessions); + LocalSession localSession = localSessions.get(0); + assertEquals(3, localSession.getSessionId()); // There should be no expired remote sessions in the common case assertEquals(0, tester.applicationRepository().deleteExpiredRemoteSessions(clock, Duration.ofSeconds(0))); + + // Deploy, but do not activate + Optional<com.yahoo.config.provision.Deployment> deployment4 = tester.redeployFromLocalActive(); + assertTrue(deployment4.isPresent()); + deployment4.get().prepare(); // session 5 (not activated) + + assertEquals(2, localSessionRepo.listSessions().size()); + localSessionRepo.deleteSession(localSession); + assertEquals(1, localSessionRepo.listSessions().size()); + + // Check that trying to expire when there are no active sessions works + tester.applicationRepository().deleteExpiredLocalSessions(); } @Test |