From e8691fda0ecb9b13d0bcdacb860615a922c10471 Mon Sep 17 00:00:00 2001 From: Chris Vest Date: Tue, 6 Dec 2016 10:35:44 +0100 Subject: [PATCH] Guard the check pointer for a 0 ms time threshold And also fix the tests to take the randomised start offset into account. --- .../log/checkpoint/TimeCheckPointThreshold.java | 8 ++++---- .../log/checkpoint/TimeCheckPointThresholdTest.java | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/log/checkpoint/TimeCheckPointThreshold.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/log/checkpoint/TimeCheckPointThreshold.java index 63cf30c6eb0e7..0fbace1d24c6c 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/log/checkpoint/TimeCheckPointThreshold.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/log/checkpoint/TimeCheckPointThreshold.java @@ -30,13 +30,13 @@ public class TimeCheckPointThreshold extends AbstractCheckPointThreshold private final long timeMillisThreshold; private final Clock clock; - public TimeCheckPointThreshold( long timeMillisThreshold, Clock clock ) + public TimeCheckPointThreshold( long thresholdMillis, Clock clock ) { - this.timeMillisThreshold = timeMillisThreshold; + this.timeMillisThreshold = thresholdMillis; this.clock = clock; // The random start offset means database in a cluster will not all check-point at the same time. - long randomStartOffset = ThreadLocalRandom.current().nextLong( timeMillisThreshold ); - this.nextCheckPointTime = clock.millis() + timeMillisThreshold + randomStartOffset; + long randomStartOffset = thresholdMillis > 0? ThreadLocalRandom.current().nextLong( thresholdMillis ) : 0; + this.nextCheckPointTime = clock.millis() + thresholdMillis + randomStartOffset; } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/log/checkpoint/TimeCheckPointThresholdTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/log/checkpoint/TimeCheckPointThresholdTest.java index 60fefdab6a804..884b916f1379d 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/log/checkpoint/TimeCheckPointThresholdTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/log/checkpoint/TimeCheckPointThresholdTest.java @@ -61,7 +61,7 @@ public void shouldBeTrueIfTimeThresholdIsReachedAndThereAreCommittedTransactions TimeCheckPointThreshold threshold = new TimeCheckPointThreshold( 100, clock ); threshold.initialize( 2 ); - clock.forward( 100, MILLISECONDS ); + clock.forward( 199, MILLISECONDS ); // when boolean checkPointingNeeded = threshold.isCheckPointingNeeded( 42, triggerInfo ); @@ -78,7 +78,7 @@ public void shouldBeFalseIfTimeThresholdIsReachedButThereAreNoCommittedTransacti TimeCheckPointThreshold threshold = new TimeCheckPointThreshold( 100, clock ); threshold.initialize( 42 ); - clock.forward( 100, MILLISECONDS ); + clock.forward( 199, MILLISECONDS ); // when boolean checkPointingNeeded = threshold.isCheckPointingNeeded( 42, triggerInfo ); @@ -96,7 +96,7 @@ public void shouldBeFalseIfTimeThresholdIsReachedAfterCheckPointHappenedButThere TimeCheckPointThreshold threshold = new TimeCheckPointThreshold( 100, clock ); threshold.initialize( 2 ); - clock.forward( 100, MILLISECONDS ); + clock.forward( 199, MILLISECONDS ); threshold.checkPointHappened( 42 ); @@ -118,7 +118,7 @@ public void shouldBeTrueIfTimeThresholdIsReachedAfterCheckPointHappenedAndThereA TimeCheckPointThreshold threshold = new TimeCheckPointThreshold( 100, clock ); threshold.initialize( 2 ); - clock.forward( 100, MILLISECONDS ); + clock.forward( 199, MILLISECONDS ); threshold.checkPointHappened( 42 );