diff --git a/enterprise/core-edge/src/main/java/org/neo4j/coreedge/raft/replication/tx/ExpontentialBackoffStrategy.java b/enterprise/core-edge/src/main/java/org/neo4j/coreedge/raft/replication/tx/ExpontentialBackoffStrategy.java index 29432b18ff7c7..95559375c8b19 100644 --- a/enterprise/core-edge/src/main/java/org/neo4j/coreedge/raft/replication/tx/ExpontentialBackoffStrategy.java +++ b/enterprise/core-edge/src/main/java/org/neo4j/coreedge/raft/replication/tx/ExpontentialBackoffStrategy.java @@ -24,7 +24,6 @@ public class ExpontentialBackoffStrategy implements RetryStrategy { private long timeout; - private long previous; public ExpontentialBackoffStrategy( long initialTimeout, TimeUnit timeUnit ) { @@ -32,16 +31,14 @@ public ExpontentialBackoffStrategy( long initialTimeout, TimeUnit timeUnit ) } @Override - public long nextTimeout() + public long get() { - previous = timeout; - timeout = 2 * timeout; return timeout; } @Override - public long previousTimeout() + public void increaseTimeout() { - return previous; + timeout = 2 * timeout; } } diff --git a/enterprise/core-edge/src/main/java/org/neo4j/coreedge/raft/replication/tx/ReplicatedTransactionCommitProcess.java b/enterprise/core-edge/src/main/java/org/neo4j/coreedge/raft/replication/tx/ReplicatedTransactionCommitProcess.java index 1777b2f6da177..bb7d3f2aa9502 100644 --- a/enterprise/core-edge/src/main/java/org/neo4j/coreedge/raft/replication/tx/ReplicatedTransactionCommitProcess.java +++ b/enterprise/core-edge/src/main/java/org/neo4j/coreedge/raft/replication/tx/ReplicatedTransactionCommitProcess.java @@ -104,7 +104,8 @@ public long commit( final TransactionToApply tx, try { - Long txId = futureTxId.waitUntilCommitted( retryStrategy.nextTimeout(), TimeUnit.MILLISECONDS ); + Long txId = futureTxId.waitUntilCommitted( retryStrategy.get(), TimeUnit.MILLISECONDS ); + retryStrategy.increaseTimeout(); sessionPool.releaseSession( operationContext ); return txId; @@ -118,7 +119,7 @@ public long commit( final TransactionToApply tx, catch ( TimeoutException e ) { log.info( "Replication of %s timed out after %d %s; retrying.", - operationContext, retryStrategy.previousTimeout(), TimeUnit.MILLISECONDS ); + operationContext, retryStrategy.get(), TimeUnit.MILLISECONDS ); txRetryMonitor.retry(); } } diff --git a/enterprise/core-edge/src/main/java/org/neo4j/coreedge/raft/replication/tx/RetryStrategy.java b/enterprise/core-edge/src/main/java/org/neo4j/coreedge/raft/replication/tx/RetryStrategy.java index 27fa6928a145a..835ab03c7a720 100644 --- a/enterprise/core-edge/src/main/java/org/neo4j/coreedge/raft/replication/tx/RetryStrategy.java +++ b/enterprise/core-edge/src/main/java/org/neo4j/coreedge/raft/replication/tx/RetryStrategy.java @@ -21,6 +21,6 @@ public interface RetryStrategy { - long nextTimeout(); - long previousTimeout(); + long get(); + void increaseTimeout(); } diff --git a/enterprise/core-edge/src/test/java/org/neo4j/coreedge/raft/replication/tx/ConstantTimeRetryStrategy.java b/enterprise/core-edge/src/test/java/org/neo4j/coreedge/raft/replication/tx/ConstantTimeRetryStrategy.java index 4fc7d7d9aaf9c..f717b63cf9457 100644 --- a/enterprise/core-edge/src/test/java/org/neo4j/coreedge/raft/replication/tx/ConstantTimeRetryStrategy.java +++ b/enterprise/core-edge/src/test/java/org/neo4j/coreedge/raft/replication/tx/ConstantTimeRetryStrategy.java @@ -23,7 +23,7 @@ public class ConstantTimeRetryStrategy implements RetryStrategy { - private final long timeout; + private long timeout; public ConstantTimeRetryStrategy( long backoffTime, TimeUnit timeUnit ) { @@ -31,14 +31,13 @@ public ConstantTimeRetryStrategy( long backoffTime, TimeUnit timeUnit ) } @Override - public long nextTimeout() + public long get() { return timeout; } @Override - public long previousTimeout() + public void increaseTimeout() { - return timeout; } } diff --git a/enterprise/core-edge/src/test/java/org/neo4j/coreedge/raft/replication/tx/ExpontentialBackoffStrategyTest.java b/enterprise/core-edge/src/test/java/org/neo4j/coreedge/raft/replication/tx/ExpontentialBackoffStrategyTest.java index 106dd8ce12418..add27584ffde1 100644 --- a/enterprise/core-edge/src/test/java/org/neo4j/coreedge/raft/replication/tx/ExpontentialBackoffStrategyTest.java +++ b/enterprise/core-edge/src/test/java/org/neo4j/coreedge/raft/replication/tx/ExpontentialBackoffStrategyTest.java @@ -38,11 +38,11 @@ public void shouldDoubleEachTime() throws Exception // when for ( int i = 0; i < NUMBER_OF_ACCESSES; i++ ) { - strategy.nextTimeout(); + strategy.increaseTimeout(); } // then - assertEquals( 2 << NUMBER_OF_ACCESSES, strategy.nextTimeout() ); + assertEquals( 2 << NUMBER_OF_ACCESSES - 1, strategy.get() ); } @Test @@ -54,10 +54,10 @@ public void shouldProvidePreviousTimeout() throws Exception // when for ( int i = 0; i <= NUMBER_OF_ACCESSES; i++ ) { - strategy.nextTimeout(); + strategy.increaseTimeout(); } // then - assertEquals( 2 << NUMBER_OF_ACCESSES - 1, strategy.previousTimeout() ); + assertEquals( 2 << NUMBER_OF_ACCESSES, strategy.get() ); } } \ No newline at end of file