diff options
author | Martin Polden <mpolden@mpolden.no> | 2020-06-18 14:22:12 +0200 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2020-06-18 14:22:53 +0200 |
commit | a4ecf00d18a2ddd57a48c6932bd36ad2567ced56 (patch) | |
tree | ebfb071c5eb51d7eec215272c210c62ee31f61e1 | |
parent | 544ba2e3d8cc1e4f1766ead5651712401d98a86f (diff) |
Log correct dispatched requests
3 files changed, 27 insertions, 8 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 ee5d50414c1..786547d4a67 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 @@ -1,7 +1,6 @@ // Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.controller.dns; -import java.util.logging.Level; import com.yahoo.vespa.hosted.controller.api.integration.dns.NameService; import java.util.ArrayList; @@ -10,6 +9,8 @@ import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.concurrent.LinkedBlockingDeque; +import java.util.function.UnaryOperator; +import java.util.logging.Level; import java.util.logging.Logger; /** @@ -39,12 +40,14 @@ public class NameServiceQueue { return Collections.unmodifiableCollection(requests); } - /** Returns a copy of this containing only the n most recent requests */ + /** Returns a copy of this containing the last n requests */ public NameServiceQueue last(int n) { - requireNonNegative(n); - if (requests.size() <= n) return this; - List<NameServiceRequest> requests = new ArrayList<>(this.requests); - return new NameServiceQueue(requests.subList(requests.size() - n, requests.size())); + return resize(n, (requests) -> requests.subList(requests.size() - n, requests.size())); + } + + /** Returns a copy of this containing the first n requests */ + public NameServiceQueue first(int n) { + return resize(n, (requests) -> requests.subList(0, n)); } /** Returns a copy of this with given request queued according to priority */ @@ -58,6 +61,7 @@ public class NameServiceQueue { return queue; } + /** Returns a copy of this with given request added */ public NameServiceQueue with(NameServiceRequest request) { return with(request, Priority.normal); } @@ -91,6 +95,13 @@ public class NameServiceQueue { return requests.toString(); } + private NameServiceQueue resize(int n, UnaryOperator<List<NameServiceRequest>> resizer) { + requireNonNegative(n); + if (requests.size() <= n) return this; + List<NameServiceRequest> requests = new ArrayList<>(this.requests); + return new NameServiceQueue(resizer.apply(requests)); + } + private static void requireNonNegative(int n) { if (n < 0) throw new IllegalArgumentException("n must be >= 0, got " + n); } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/NameServiceDispatcher.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/NameServiceDispatcher.java index 73daef7c2b0..e7eaf083a57 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/NameServiceDispatcher.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/NameServiceDispatcher.java @@ -45,7 +45,7 @@ public class NameServiceDispatcher extends ControllerMaintainer { var remaining = queue.dispatchTo(nameService, requestCount); if (queue == remaining) return; // Queue unchanged - var dispatched = queue.last(requestCount); + var dispatched = queue.first(requestCount); if (!dispatched.requests().isEmpty()) { log.log(Level.INFO, "Dispatched name service request(s) in " + Duration.between(instant, clock.instant()) + diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/dns/NameServiceQueueTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/dns/NameServiceQueueTest.java index d0362ae98b8..30ed9b5432c 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/dns/NameServiceQueueTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/dns/NameServiceQueueTest.java @@ -74,13 +74,21 @@ public class NameServiceQueueTest { assertTrue(queue.requests().isEmpty()); assertTrue("Removed " + r1, nameService.findRecords(Record.Type.CNAME, r1.name()).isEmpty()); - // Keep n most recent requests + // Keep n last requests queue = queue.with(req1).with(req2).with(req3).with(req4).with(req6) .last(2); assertEquals(List.of(req4, req6), List.copyOf(queue.requests())); assertSame(queue, queue.last(2)); assertSame(queue, queue.last(10)); assertTrue(queue.last(0).requests().isEmpty()); + + // Keep n first requests + queue = NameServiceQueue.EMPTY.with(req1).with(req2).with(req3).with(req4).with(req6) + .first(3); + assertEquals(List.of(req1, req2, req3), List.copyOf(queue.requests())); + assertSame(queue, queue.first(3)); + assertSame(queue, queue.first(10)); + assertTrue(queue.first(0).requests().isEmpty()); } } |