aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Musum <musum@verizonmedia.com>2020-05-20 15:25:46 +0200
committerHarald Musum <musum@verizonmedia.com>2020-05-20 15:25:46 +0200
commite354869c4ad9063c97e8c37417fc7c92673b3331 (patch)
treeede153550ab44bbd97820f0ce0dffe5dfba9a508
parenta350ddbe7384815674965f22461a049cd0a29c86 (diff)
Use remote session repo to find active session
Active session is not necessarily a local session, it might have been created on another config server.
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java22
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/deploy/Deployment.java9
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionActiveHandler.java2
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/session/LocalSession.java9
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/session/RemoteSession.java46
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionFactory.java2
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionFactoryImpl.java2
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java5
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/http/SessionHandlerTest.java8
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionPrepareHandlerTest.java5
10 files changed, 63 insertions, 47 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 47a2ccde4f3..c47ba5fd4ce 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
@@ -308,7 +308,7 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye
Tenant tenant = tenantRepository.getTenant(application.tenant());
if (tenant == null) return Optional.empty();
- LocalSession activeSession = getActiveSession(tenant, application);
+ RemoteSession activeSession = getActiveSession(tenant, application);
if (activeSession == null) return Optional.empty();
TimeoutBudget timeoutBudget = new TimeoutBudget(clock, timeout);
LocalSession newSession = tenant.getSessionFactory().createSessionFromExisting(activeSession, logger, true, timeoutBudget);
@@ -322,7 +322,7 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye
public Optional<Instant> lastDeployTime(ApplicationId application) {
Tenant tenant = tenantRepository.getTenant(application.tenant());
if (tenant == null) return Optional.empty();
- LocalSession activeSession = getActiveSession(tenant, application);
+ RemoteSession activeSession = getActiveSession(tenant, application);
if (activeSession == null) return Optional.empty();
return Optional.of(Instant.ofEpochSecond(activeSession.getCreateTime()));
}
@@ -610,7 +610,7 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye
*
* @return the active session, or null if there is no active session for the given application id.
*/
- public LocalSession getActiveSession(ApplicationId applicationId) {
+ public RemoteSession getActiveSession(ApplicationId applicationId) {
return getActiveSession(tenantRepository.getTenant(applicationId.tenant()), applicationId);
}
@@ -648,7 +648,7 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye
Tenant tenant = tenantRepository.getTenant(applicationId.tenant());
LocalSessionRepo localSessionRepo = tenant.getLocalSessionRepo();
SessionFactory sessionFactory = tenant.getSessionFactory();
- LocalSession fromSession = getExistingSession(tenant, applicationId);
+ RemoteSession fromSession = getExistingSession(tenant, applicationId);
LocalSession session = sessionFactory.createSessionFromExisting(fromSession, logger, internalRedeploy, timeoutBudget);
localSessionRepo.addSession(session);
return session.getSessionId();
@@ -730,7 +730,7 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye
// ---------------- Misc operations ----------------------------------------------------------------
- public ApplicationMetaData getMetadataFromSession(Tenant tenant, long sessionId) {
+ public ApplicationMetaData getMetadataFromLocalSession(Tenant tenant, long sessionId) {
return getLocalSession(tenant, sessionId).getMetaData();
}
@@ -765,9 +765,7 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye
try {
long currentActiveSessionId = applicationRepo.requireActiveSessionOf(appId);
RemoteSession currentActiveSession = getRemoteSession(tenant, currentActiveSessionId);
- if (currentActiveSession != null) {
- currentActiveApplicationSet = Optional.ofNullable(currentActiveSession.ensureApplicationLoaded());
- }
+ currentActiveApplicationSet = Optional.ofNullable(currentActiveSession.ensureApplicationLoaded());
} catch (IllegalArgumentException e) {
// Do nothing if we have no currently active session
}
@@ -798,15 +796,15 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye
}
}
- private LocalSession getExistingSession(Tenant tenant, ApplicationId applicationId) {
+ private RemoteSession getExistingSession(Tenant tenant, ApplicationId applicationId) {
TenantApplications applicationRepo = tenant.getApplicationRepo();
- return getLocalSession(tenant, applicationRepo.requireActiveSessionOf(applicationId));
+ return getRemoteSession(tenant, applicationRepo.requireActiveSessionOf(applicationId));
}
- private LocalSession getActiveSession(Tenant tenant, ApplicationId applicationId) {
+ private RemoteSession getActiveSession(Tenant tenant, ApplicationId applicationId) {
TenantApplications applicationRepo = tenant.getApplicationRepo();
if (applicationRepo.activeApplications().contains(applicationId)) {
- return tenant.getLocalSessionRepo().getSession(applicationRepo.requireActiveSessionOf(applicationId));
+ return tenant.getRemoteSessionRepo().getSession(applicationRepo.requireActiveSessionOf(applicationId));
}
return null;
}
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/Deployment.java b/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/Deployment.java
index af4e85109e6..768ef1be93c 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/Deployment.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/Deployment.java
@@ -18,6 +18,7 @@ import com.yahoo.vespa.config.server.TimeoutBudget;
import com.yahoo.vespa.config.server.http.InternalServerException;
import com.yahoo.vespa.config.server.session.LocalSession;
import com.yahoo.vespa.config.server.session.PrepareParams;
+import com.yahoo.vespa.config.server.session.RemoteSession;
import com.yahoo.vespa.config.server.session.Session;
import com.yahoo.vespa.config.server.session.SilentDeployLogger;
import com.yahoo.vespa.config.server.tenant.Tenant;
@@ -132,7 +133,7 @@ public class Deployment implements com.yahoo.config.provision.Deployment {
TimeoutBudget timeoutBudget = new TimeoutBudget(clock, timeout);
ApplicationId applicationId = session.getApplicationId();
- LocalSession previousActiveSession;
+ RemoteSession previousActiveSession;
try (Lock lock = tenant.getApplicationRepo().lock(applicationId)) {
validateSessionStatus(session);
NestedTransaction transaction = new NestedTransaction();
@@ -181,7 +182,7 @@ public class Deployment implements com.yahoo.config.provision.Deployment {
}
}
- private Transaction deactivateCurrentActivateNew(LocalSession active, LocalSession prepared, boolean ignoreStaleSessionFailure) {
+ private Transaction deactivateCurrentActivateNew(RemoteSession active, LocalSession prepared, boolean ignoreStaleSessionFailure) {
Transaction transaction = prepared.createActivateTransaction();
if (isValidSession(active)) {
checkIfActiveHasChanged(prepared, active, ignoreStaleSessionFailure);
@@ -191,11 +192,11 @@ public class Deployment implements com.yahoo.config.provision.Deployment {
return transaction;
}
- private boolean isValidSession(LocalSession session) {
+ private boolean isValidSession(RemoteSession session) {
return session != null;
}
- private void checkIfActiveHasChanged(LocalSession session, LocalSession currentActiveSession, boolean ignoreStaleSessionFailure) {
+ private void checkIfActiveHasChanged(LocalSession session, RemoteSession currentActiveSession, boolean ignoreStaleSessionFailure) {
long activeSessionAtCreate = session.getActiveSessionAtCreate();
log.log(Level.FINE, currentActiveSession.logPre() + "active session id at create time=" + activeSessionAtCreate);
if (activeSessionAtCreate == 0) return; // No active session at create
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionActiveHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionActiveHandler.java
index 4cf59135026..124902c988a 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionActiveHandler.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionActiveHandler.java
@@ -48,7 +48,7 @@ public class SessionActiveHandler extends SessionHandler {
final Long sessionId = getSessionIdV2(request);
ApplicationId applicationId = applicationRepository.activate(tenant, sessionId, timeoutBudget,
shouldIgnoreSessionStaleFailure(request));
- ApplicationMetaData metaData = applicationRepository.getMetadataFromSession(tenant, sessionId);
+ ApplicationMetaData metaData = applicationRepository.getMetadataFromLocalSession(tenant, sessionId);
return new SessionActiveResponse(metaData.getSlime(), request, applicationId, sessionId, zone);
}
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/LocalSession.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/LocalSession.java
index 4946c24efbc..5a0174a7af7 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/LocalSession.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/LocalSession.java
@@ -98,10 +98,6 @@ public class LocalSession extends Session implements Comparable<LocalSession> {
return transaction;
}
- public Transaction createDeactivateTransaction() {
- return createSetStatusTransaction(Status.DEACTIVATE);
- }
-
private void markSessionEdited() {
setStatus(Session.Status.NEW);
}
@@ -110,11 +106,6 @@ public class LocalSession extends Session implements Comparable<LocalSession> {
return applicationPackage.getMetaData().getPreviousActiveGeneration();
}
- // Note: Assumes monotonically increasing session ids
- public boolean isNewerThan(long sessionId) {
- return getSessionId() > sessionId;
- }
-
/** Add transactions to delete this session to the given nested transaction */
public void delete(NestedTransaction transaction) {
transaction.add(zooKeeperClient.deleteTransaction(), FileTransaction.class);
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/RemoteSession.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/RemoteSession.java
index 9da3ad2fd7a..68c00cafd07 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/RemoteSession.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/RemoteSession.java
@@ -1,11 +1,15 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server.session;
+import com.yahoo.component.Version;
+import com.yahoo.config.application.api.ApplicationMetaData;
import com.yahoo.config.application.api.ApplicationPackage;
import com.yahoo.config.provision.AllocatedHosts;
+import com.yahoo.config.provision.ApplicationId;
+import com.yahoo.config.provision.AthenzDomain;
+import com.yahoo.config.provision.DockerImage;
import com.yahoo.config.provision.TenantName;
import com.yahoo.lang.SettableOptional;
-import java.util.logging.Level;
import com.yahoo.transaction.Transaction;
import com.yahoo.vespa.config.server.GlobalComponentRegistry;
import com.yahoo.vespa.config.server.ReloadHandler;
@@ -16,8 +20,8 @@ import com.yahoo.vespa.curator.Curator;
import org.apache.zookeeper.KeeperException;
import java.time.Clock;
-import java.time.Instant;
import java.util.Optional;
+import java.util.logging.Level;
import java.util.logging.Logger;
/**
@@ -99,11 +103,11 @@ public class RemoteSession extends Session {
@Override
public String logPre() {
- if (applicationSet != null) {
- return TenantRepository.logPre(applicationSet.getForVersionOrLatest(Optional.empty(), Instant.now()).getId());
+ if (getApplicationId().equals(ApplicationId.defaultId())) {
+ return TenantRepository.logPre(getTenant());
+ } else {
+ return TenantRepository.logPre(getApplicationId());
}
-
- return TenantRepository.logPre(getTenant());
}
void confirmUpload() {
@@ -135,4 +139,34 @@ public class RemoteSession extends Session {
transaction.close();
}
+ public ApplicationId getApplicationId() { return zooKeeperClient.readApplicationId(); }
+
+ public Optional<DockerImage> getDockerImageRepository() { return zooKeeperClient.readDockerImageRepository(); }
+
+ public Version getVespaVersion() { return zooKeeperClient.readVespaVersion(); }
+
+ public Optional<AthenzDomain> getAthenzDomain() { return zooKeeperClient.readAthenzDomain(); }
+
+ public AllocatedHosts getAllocatedHosts() {
+ return zooKeeperClient.getAllocatedHosts();
+ }
+
+ // Note: Assumes monotonically increasing session ids
+ public boolean isNewerThan(long sessionId) {
+ return getSessionId() > sessionId;
+ }
+
+ public Transaction createDeactivateTransaction() {
+ return createSetStatusTransaction(Status.DEACTIVATE);
+ }
+
+ private Transaction createSetStatusTransaction(Status status) {
+ return zooKeeperClient.createWriteStatusTransaction(status);
+ }
+
+ public ApplicationMetaData getMetaData() {
+ return zooKeeperClient.loadApplicationPackage().getMetaData();
+ }
+
+
}
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionFactory.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionFactory.java
index 5527d3060f7..3e2605b9c02 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionFactory.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionFactory.java
@@ -33,7 +33,7 @@ public interface SessionFactory {
* @param timeoutBudget timeout for creating session and waiting for other servers.
* @return a new session
*/
- LocalSession createSessionFromExisting(LocalSession existingSession, DeployLogger logger,
+ LocalSession createSessionFromExisting(RemoteSession existingSession, DeployLogger logger,
boolean internalRedeploy, TimeoutBudget timeoutBudget);
}
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionFactoryImpl.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionFactoryImpl.java
index 58b643ec82c..f85bb8caf4d 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionFactoryImpl.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionFactoryImpl.java
@@ -119,7 +119,7 @@ public class SessionFactoryImpl implements SessionFactory, LocalSessionLoader {
}
@Override
- public LocalSession createSessionFromExisting(LocalSession existingSession,
+ public LocalSession createSessionFromExisting(RemoteSession existingSession,
DeployLogger logger,
boolean internalRedeploy,
TimeoutBudget timeoutBudget) {
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 80b199cb2dd..8ee76843e94 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
@@ -28,6 +28,7 @@ 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.PrepareParams;
+import com.yahoo.vespa.config.server.session.RemoteSession;
import com.yahoo.vespa.config.server.session.SilentDeployLogger;
import com.yahoo.vespa.config.server.tenant.ApplicationRolesStore;
import com.yahoo.vespa.config.server.tenant.Tenant;
@@ -294,7 +295,7 @@ public class ApplicationRepositoryTest {
// No active session or remote session (deleted in step above), but an exception was thrown above
// A new delete should cleanup and be successful
- LocalSession activeSession = applicationRepository.getActiveSession(applicationId());
+ RemoteSession activeSession = applicationRepository.getActiveSession(applicationId());
assertNull(activeSession);
Tenant tenant = tenantRepository.getTenant(applicationId().tenant());
assertNull(tenant.getRemoteSessionRepo().getSession(prepareResult.sessionId()));
@@ -468,7 +469,7 @@ public class ApplicationRepositoryTest {
private ApplicationMetaData getApplicationMetaData(ApplicationId applicationId, long sessionId) {
Tenant tenant = tenantRepository.getTenant(applicationId.tenant());
- return applicationRepository.getMetadataFromSession(tenant, sessionId);
+ return applicationRepository.getMetadataFromLocalSession(tenant, sessionId);
}
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/SessionHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/SessionHandlerTest.java
index a1e252c8130..79912e8ea82 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/SessionHandlerTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/SessionHandlerTest.java
@@ -30,6 +30,7 @@ import com.yahoo.vespa.config.server.session.DummyTransaction;
import com.yahoo.vespa.config.server.session.LocalSession;
import com.yahoo.vespa.config.server.session.MockSessionZKClient;
import com.yahoo.vespa.config.server.session.PrepareParams;
+import com.yahoo.vespa.config.server.session.RemoteSession;
import com.yahoo.vespa.config.server.session.Session;
import com.yahoo.vespa.config.server.session.SessionContext;
import com.yahoo.vespa.config.server.session.SessionFactory;
@@ -147,11 +148,6 @@ public class SessionHandlerTest {
}
@Override
- public Transaction createDeactivateTransaction() {
- return new DummyTransaction().add((DummyTransaction.RunnableOperation) () -> status = Status.DEACTIVATE);
- }
-
- @Override
public Transaction createActivateTransaction() {
return new DummyTransaction().add((DummyTransaction.RunnableOperation) () -> status = Status.ACTIVATE);
}
@@ -219,7 +215,7 @@ public class SessionHandlerTest {
}
@Override
- public LocalSession createSessionFromExisting(LocalSession existingSession, DeployLogger logger,
+ public LocalSession createSessionFromExisting(RemoteSession existingSession, DeployLogger logger,
boolean internalRedeploy, TimeoutBudget timeoutBudget) {
if (doThrow) {
throw new RuntimeException("foo");
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionPrepareHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionPrepareHandlerTest.java
index 94276b30f42..7c3fbb25828 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionPrepareHandlerTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionPrepareHandlerTest.java
@@ -404,11 +404,6 @@ public class SessionPrepareHandlerTest extends SessionHandlerTest {
}
@Override
- public Transaction createDeactivateTransaction() {
- return null;
- }
-
- @Override
public Transaction createActivateTransaction() {
return null;
}