summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Marius Venstad <jonmv@users.noreply.github.com>2023-01-20 18:37:42 +0100
committerGitHub <noreply@github.com>2023-01-20 18:37:42 +0100
commit76d05bba8b1fef5fc87884bdc7feda98d7158719 (patch)
tree5dee7e253e3dc0924c27e4b121081639961cb652
parentf1d32c60a23ad9b8dc5223fefac0b14020ba49fa (diff)
parent366c3561d3bd5df18d4a8e05a80c52f6fc2d7007 (diff)
Merge pull request #25664 from vespa-engine/jonmv/fix-sublist-search
Also match lists which are the tail of the full
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/dns/NameServiceQueue.java2
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/NameServiceDispatcherTest.java17
2 files changed, 17 insertions, 2 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/dns/NameServiceQueue.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/dns/NameServiceQueue.java
index 9c1390788ca..dbcfa6705ec 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/dns/NameServiceQueue.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/dns/NameServiceQueue.java
@@ -159,7 +159,7 @@ public record NameServiceQueue(List<NameServiceRequest> requests) {
/** Lowest index {@code i} in {@code list} s.t. {@code list.sublist(i, i + sub.size()).equals(sub)}. Naïve implementation. */
static <T> int indexOf(List<T> list, List<T> sub) {
- for (int i = 0; i + sub.size() < list.size(); i++)
+ for (int i = 0; i + sub.size() <= list.size(); i++)
if (list.subList(i, i + sub.size()).equals(sub))
return i;
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/NameServiceDispatcherTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/NameServiceDispatcherTest.java
index 540511dbc7f..cf5567f5f2f 100644
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/NameServiceDispatcherTest.java
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/NameServiceDispatcherTest.java
@@ -66,10 +66,25 @@ class NameServiceDispatcherTest {
var req8 = new CreateRecord(owner0, rec3);
// Queue initially contains a subsequence of requests, 3–6.
- // The dispatch of requests owned by owner1 will fail, so the remaining list is subsequence or the original.
var base = new LinkedList<NameServiceRequest>(List.of(req3, req4, req5, req6));
+
+ // Whole queue is consumed by dispatcher the first time, and a few records prepended.
tester.curator().writeNameServiceQueue(new NameServiceQueue(base));
+ expectations.add(name -> assertEquals(rec1.name(), name));
+ expectations.add(name -> assertEquals(rec4.name(), name));
+ expectations.add(name -> assertEquals(rec3.name(), name));
+ expectations.add(name -> {
+ assertEquals(rec4.name(), name);
+ tester.curator().writeNameServiceQueue(tester.curator().readNameServiceQueue()
+ .with(req1, Priority.high)
+ .with(req2, Priority.high)
+ .with(req1, Priority.high));
+ });
+ assertEquals(1.0, dispatcher.maintain());
+ assertEquals(List.of(req1, req2, req1), tester.curator().readNameServiceQueue().requests());
+ // Now, the dispatch of requests owned by owner1 will fail, so the remaining list is subsequence or the original.
+ tester.curator().writeNameServiceQueue(new NameServiceQueue(base));
AtomicReference<Consumer<RecordName>> failOwner1 = new AtomicReference<>();
failOwner1.set(name -> {
assertEquals(rec4.name(), name);