summaryrefslogtreecommitdiffstats
path: root/vespa-feed-client/src
diff options
context:
space:
mode:
authorJon Marius Venstad <venstad@gmail.com>2021-06-02 09:04:54 +0200
committerJon Marius Venstad <venstad@gmail.com>2021-06-02 09:04:54 +0200
commitea94163aa5af3efcd54f28d46552dde5d0bd36e5 (patch)
treef1f881416835590e44f1de2cdd051b8dbee8431a /vespa-feed-client/src
parent87be3ceb55a7e767a5eb7d24a8ff6f53add30033 (diff)
Delay retries 1s when hasFailed()
Diffstat (limited to 'vespa-feed-client/src')
-rw-r--r--vespa-feed-client/src/main/java/ai/vespa/feed/client/HttpRequestStrategy.java16
1 files changed, 14 insertions, 2 deletions
diff --git a/vespa-feed-client/src/main/java/ai/vespa/feed/client/HttpRequestStrategy.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/HttpRequestStrategy.java
index baed9019be7..1dd8736cd2b 100644
--- a/vespa-feed-client/src/main/java/ai/vespa/feed/client/HttpRequestStrategy.java
+++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/HttpRequestStrategy.java
@@ -11,6 +11,9 @@ import java.time.Instant;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;
import java.util.logging.Logger;
@@ -29,7 +32,7 @@ import static java.util.logging.Level.INFO;
*
* @author jonmv
*/
-class HttpRequestStrategy implements RequestStrategy {
+class HttpRequestStrategy implements RequestStrategy, AutoCloseable {
private static final Logger log = Logger.getLogger(HttpRequestStrategy.class.getName());
@@ -37,6 +40,7 @@ class HttpRequestStrategy implements RequestStrategy {
private final Object monitor = new Object();
private final Clock clock;
private final RetryStrategy wrapped;
+ private final ScheduledExecutorService delayer = Executors.newScheduledThreadPool(1);
private final long maxInflight;
private final long minInflight;
private double targetInflight;
@@ -183,7 +187,10 @@ class HttpRequestStrategy implements RequestStrategy {
if ( ! failed && (thrown != null ? retry(request, thrown, attempt)
: retry(request, response, attempt))) {
CompletableFuture<SimpleHttpResponse> retry = new CompletableFuture<>();
- dispatch.accept(request, retry);
+ if (hasFailed())
+ delayer.schedule(() -> dispatch.accept(request, retry), 1, TimeUnit.SECONDS);
+ else
+ dispatch.accept(request, retry);
handleAttempt(retry, dispatch, blocker, request, result, documentId, attempt + 1);
return;
}
@@ -205,4 +212,9 @@ class HttpRequestStrategy implements RequestStrategy {
});
}
+ @Override
+ public void close() {
+ delayer.shutdown();
+ }
+
}