Skip to content

Update reactor-bom to 2020.0.8 #947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;
import reactor.util.context.Context;
import reactor.util.function.Tuples;
import reactor.util.retry.Retry;

import java.time.Duration;
import java.util.ArrayList;
Expand All @@ -34,7 +34,6 @@
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.function.Supplier;

import org.neo4j.driver.Logger;
Expand Down Expand Up @@ -145,7 +144,7 @@ public <T> CompletionStage<T> retryAsync( Supplier<CompletionStage<T>> work )
@Override
public <T> Publisher<T> retryRx( Publisher<T> work )
{
return Flux.from( work ).retryWhen( retryRxCondition() );
return Flux.from( work ).retryWhen( exponentialBackoffRetryRx() );
}

protected boolean canRetryOn( Throwable error )
Expand Down Expand Up @@ -177,48 +176,46 @@ private static Throwable extractPossibleTerminationCause( Throwable error )
return error;
}

private Function<Flux<Throwable>,Publisher<Context>> retryRxCondition()
private Retry exponentialBackoffRetryRx()
{
return errorCurrentAttempt -> errorCurrentAttempt.flatMap( e -> Mono.subscriberContext().map( ctx -> Tuples.of( e, ctx ) ) ).flatMap( t2 ->
{

Throwable throwable = t2.getT1();
Throwable error = extractPossibleTerminationCause( throwable );

Context ctx = t2.getT2();

List<Throwable> errors = ctx.getOrDefault( "errors", null );

long startTime = ctx.getOrDefault( "startTime", -1L );
long nextDelayMs = ctx.getOrDefault( "nextDelayMs", initialRetryDelayMs );

if ( canRetryOn( error ) )
{
long currentTime = clock.millis();
if ( startTime == -1 )
return Retry.from( retrySignals -> retrySignals.flatMap( retrySignal -> Mono.deferContextual(
contextView ->
{
startTime = currentTime;
}
Throwable throwable = retrySignal.failure();
Throwable error = extractPossibleTerminationCause( throwable );

long elapsedTime = currentTime - startTime;
if ( elapsedTime < maxRetryTimeMs )
{
long delayWithJitterMs = computeDelayWithJitter( nextDelayMs );
log.warn( "Reactive transaction failed and is scheduled to retry in " + delayWithJitterMs + "ms", error );

nextDelayMs = (long) (nextDelayMs * multiplier);
errors = recordError( error, errors );
List<Throwable> errors = contextView.getOrDefault( "errors", null );

// retry on netty event loop thread
EventExecutor eventExecutor = eventExecutorGroup.next();
return Mono.just( ctx.put( "errors", errors ).put( "startTime", startTime ).put( "nextDelayMs", nextDelayMs ) ).delayElement(
Duration.ofMillis( delayWithJitterMs ), Schedulers.fromExecutorService( eventExecutor ) );
}
}
addSuppressed( throwable, errors );
if ( canRetryOn( error ) )
{
long currentTime = clock.millis();

long startTime = contextView.getOrDefault( "startTime", currentTime );
long nextDelayMs = contextView.getOrDefault( "nextDelayMs", initialRetryDelayMs );

long elapsedTime = currentTime - startTime;
if ( elapsedTime < maxRetryTimeMs )
{
long delayWithJitterMs = computeDelayWithJitter( nextDelayMs );
log.warn( "Reactive transaction failed and is scheduled to retry in " + delayWithJitterMs + "ms", error );

nextDelayMs = (long) (nextDelayMs * multiplier);
errors = recordError( error, errors );

// retry on netty event loop thread
EventExecutor eventExecutor = eventExecutorGroup.next();
Context context = Context.of(
"errors", errors,
"startTime", startTime,
"nextDelayMs", nextDelayMs
);
return Mono.just( context ).delayElement( Duration.ofMillis( delayWithJitterMs ), Schedulers.fromExecutorService( eventExecutor ) );
}
}
addSuppressed( throwable, errors );

return Mono.error( throwable );
} );
return Mono.error( throwable );
} ) ) );
}

private <T> void executeWorkInEventLoop( CompletableFuture<T> resultFuture, Supplier<CompletionStage<T>> work )
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<!-- Please note that when updating this dependency -->
<!-- (i.e. due to a security vulnerability or bug) that the -->
<!-- corresponding server dependency also needs updating.-->
<reactor-bom.version>Dysprosium-SR21</reactor-bom.version>
<reactor-bom.version>2020.0.8</reactor-bom.version>
<rxjava.version>2.2.21</rxjava.version>
<slf4j-api.version>1.7.31</slf4j-api.version>
<hamcrest-junit.version>2.0.0.0</hamcrest-junit.version>
Expand Down