From e5111c5dede12293a1b1d748f9aee4856561d138 Mon Sep 17 00:00:00 2001 From: Marco Vogt Date: Sun, 17 Dec 2023 12:09:25 +0100 Subject: [PATCH] Optimize publish log retry logic --- .../dbis/chronos/agent/ChronosHttpClient.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/ch/unibas/dmi/dbis/chronos/agent/ChronosHttpClient.java b/src/main/java/ch/unibas/dmi/dbis/chronos/agent/ChronosHttpClient.java index e9c596e..ff6b08a 100644 --- a/src/main/java/ch/unibas/dmi/dbis/chronos/agent/ChronosHttpClient.java +++ b/src/main/java/ch/unibas/dmi/dbis/chronos/agent/ChronosHttpClient.java @@ -839,7 +839,7 @@ public final class ChronosLogHandler { final AtomicInteger sequenceNumber = new AtomicInteger(); - final static int MAX_RETRIES = 1; + final static int MAX_RETRIES = 2; public ChronosLogHandler( final ChronosJob job ) { @@ -859,6 +859,14 @@ public void publish( String message ) { pendingMessages.add( executor.submit( () -> { int attempt = 0; while ( attempt < MAX_RETRIES ) { + if ( attempt > 0 ) { + try { + TimeUnit.MILLISECONDS.sleep( 500 ); + } catch ( InterruptedException e ) { + Thread.currentThread().interrupt(); + return; + } + } try { parameters.clear(); parameters.put( "recordSequenceNumber", sequenceNumber.incrementAndGet() ); @@ -879,12 +887,6 @@ public void publish( String message ) { log.debug( "Exception while publishing log records. Attempt {}: {}", attempt + 1, MAX_RETRIES + 1, ex ); } attempt++; - try { - TimeUnit.MILLISECONDS.sleep( 500 ); - } catch ( InterruptedException e ) { - Thread.currentThread().interrupt(); - return; - } } log.warn( "Failed to publish log after {} attempts", MAX_RETRIES + 1 ); } ) );