summaryrefslogtreecommitdiffstats
path: root/controller-server
diff options
context:
space:
mode:
authorJon Marius Venstad <venstad@gmail.com>2020-01-26 16:33:29 +0100
committerJon Marius Venstad <venstad@gmail.com>2020-01-27 08:33:48 +0100
commite80f389317d4d10b1970e48c61f1aedcdd41ce25 (patch)
treecdb34d55739f9708e8a1a7a707a90f57f07ef3ac /controller-server
parente0ce7ed6df4877721284f338f03a85750df112d1 (diff)
Avoid concurrent modification of cached runs
Diffstat (limited to 'controller-server')
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/JobController.java12
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/CuratorDb.java1
2 files changed, 9 insertions, 4 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/JobController.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/JobController.java
index c8cfc8ac286..0c2b6ee1744 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/JobController.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/JobController.java
@@ -1,6 +1,7 @@
// Copyright 2020 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.deployment;
+import com.google.common.collect.ImmutableSortedMap;
import com.yahoo.component.Version;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.zone.ZoneId;
@@ -226,9 +227,14 @@ public class JobController {
/** Returns an immutable map of all known runs for the given application and job type. */
public NavigableMap<RunId, Run> runs(ApplicationId id, JobType type) {
- NavigableMap<RunId, Run> runs = curator.readHistoricRuns(id, type);
- last(id, type).ifPresent(run -> runs.put(run.id(), run));
- return Collections.unmodifiableNavigableMap(runs);
+ ImmutableSortedMap.Builder<RunId, Run> runs = ImmutableSortedMap.orderedBy(Comparator.comparing(RunId::number));
+ Optional<Run> last = last(id, type);
+ curator.readHistoricRuns(id, type).forEach((runId, run) -> {
+ if (last.isEmpty() || ! runId.equals(last.get().id()))
+ runs.put(runId, run);
+ });
+ last.ifPresent(run -> runs.put(run.id(), run));
+ return runs.build();
}
/** Returns the run with the given id, if it exists. */
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/CuratorDb.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/CuratorDb.java
index 01ef6db1dc8..a8d040e321d 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/CuratorDb.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/CuratorDb.java
@@ -387,7 +387,6 @@ public class CuratorDb {
public void writeHistoricRuns(ApplicationId id, JobType type, Iterable<Run> runs) {
Path path = runsPath(id, type);
- cachedHistoricRuns.remove(path);
curator.set(path, asJson(runSerializer.toSlime(runs)));
}