Skip to content

Commit

Permalink
Optimize publish log retry logic
Browse files Browse the repository at this point in the history
  • Loading branch information
vogti committed Dec 17, 2023
1 parent 0be6360 commit e5111c5
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -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() );
Expand All @@ -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 );
} ) );
Expand Down

0 comments on commit e5111c5

Please sign in to comment.