Skip to content

Commit

Permalink
Make the continuous checkpoint policy less aggressive.
Browse files Browse the repository at this point in the history
* It now no longer calls for checkpoints if there hasn't actually been any new transactions committed.
* It no longer spins in a busy loop, but instead inserts a 100 millisecond delay between checkpoints.
* This is important because every checkpoint also includes a counts store rotation, which is inconvenient to do all the time.
  • Loading branch information
chrisvest committed Nov 1, 2018
1 parent 418e0b5 commit 8bb7fb7
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 9 deletions.
Expand Up @@ -26,6 +26,8 @@

class ContinuousCheckPointThreshold extends AbstractCheckPointThreshold
{
private volatile long nextTransactionIdTarget;

ContinuousCheckPointThreshold()
{
super( "continuous threshold" );
Expand All @@ -34,22 +36,24 @@ class ContinuousCheckPointThreshold extends AbstractCheckPointThreshold
@Override
protected boolean thresholdReached( long lastCommittedTransactionId )
{
return true;
return lastCommittedTransactionId >= nextTransactionIdTarget;
}

@Override
public void initialize( long transactionId )
{
checkPointHappened( transactionId );
}

@Override
public void checkPointHappened( long transactionId )
{
nextTransactionIdTarget = transactionId + 1;
}

@Override
public long checkFrequencyMillis()
{
return 0;
return 100;
}
}
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2002-2018 "Neo4j,"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j Enterprise Edition. The included source
* code can be redistributed and/or modified under the terms of the
* GNU AFFERO GENERAL PUBLIC LICENSE Version 3
* (http://www.fsf.org/licensing/licenses/agpl-3.0.html) with the
* Commons Clause, as found in the associated LICENSE.txt file.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* Neo4j object code can be licensed independently from the source
* under separate terms from the AGPL. Inquiries can be directed to:
* licensing@neo4j.com
*
* More information is also available at:
* https://neo4j.com/licensing/
*/
package org.neo4j.kernel.impl.enterprise.transaction.log.checkpoint;

import org.junit.Test;

import static org.hamcrest.Matchers.greaterThan;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

public class ContinuousCheckPointThresholdTest
{
@Test
public void continuousCheckPointMustReachThresholdOnEveryCommit()
{
ContinuousCheckPointThreshold threshold = new ContinuousCheckPointThreshold();
threshold.initialize( 10 );
assertFalse( threshold.thresholdReached( 10 ) );
assertTrue( threshold.thresholdReached( 11 ) );
assertTrue( threshold.thresholdReached( 11 ) );
threshold.checkPointHappened( 12 );
assertFalse( threshold.thresholdReached( 12 ) );
}

@Test
public void continuousThresholdMustNotBusySpin()
{
ContinuousCheckPointThreshold threshold = new ContinuousCheckPointThreshold();
assertThat( threshold.checkFrequencyMillis(), greaterThan( 0L ) );
}
}
Expand Up @@ -30,6 +30,7 @@
import org.neo4j.kernel.impl.transaction.log.pruning.LogPruning;

import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.lessThan;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -85,20 +86,18 @@ public void checkPointIsInitiallyNotNeededIfWeHaveNoLogsToPrune()

@SuppressWarnings( "ConstantConditions" )
@Test
public void continuousPolicyMustAlwaysTriggerCheckPoints()
public void continuousPolicyMustTriggerCheckPointsAfterAnyWriteTransaction()
{
withPolicy( "continuous" );
CheckPointThreshold threshold = createThreshold();
threshold.initialize( 2 );

assertThat( threshold.checkFrequencyMillis(), is( 0L ) );
assertThat( threshold.checkFrequencyMillis(), lessThan( CheckPointThreshold.DEFAULT_CHECKING_FREQUENCY_MILLIS ) );

assertTrue( threshold.isCheckPointingNeeded( 2, triggered ) );
assertFalse( threshold.isCheckPointingNeeded( 2, triggered ) );
threshold.checkPointHappened( 3 );
assertTrue( threshold.isCheckPointingNeeded( 3, triggered ) );
assertTrue( threshold.isCheckPointingNeeded( 3, triggered ) );
verifyTriggered( "continuous" );
verifyTriggered( "continuous" );
assertFalse( threshold.isCheckPointingNeeded( 3, triggered ) );
assertTrue( threshold.isCheckPointingNeeded( 4, triggered ) );
verifyTriggered( "continuous" );
verifyNoMoreTriggers();
}
Expand Down

0 comments on commit 8bb7fb7

Please sign in to comment.