diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/store/kvstore/RotationState.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/store/kvstore/RotationState.java index 7bd4ef15c4ac5..1a483ae51e7e7 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/store/kvstore/RotationState.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/store/kvstore/RotationState.java @@ -47,6 +47,7 @@ static final class Rotation extends RotationState private final ActiveState preState; private final PrototypeState postState; private final long threshold; + private boolean failed = false; Rotation( ActiveState preState, PrototypeState postState, long version ) { @@ -66,6 +67,7 @@ ActiveState rotate( boolean force, RotationStrategy strategy, RotationTimer { if ( rotationTimer.isTimedOut() ) { + failed = true; throw new RotationTimeoutException( threshold, preState.store.version(), rotationTimer.getElapsedTimeMillis()); } @@ -90,6 +92,17 @@ public void close() throws IOException preState.close(); } + @Override + ProgressiveState stop() throws IOException + { + if ( failed ) + { + // failed to rotate allow for stopping no matter what + return preState; + } + return super.stop(); + } + @Override long rotationVersion() { diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/store/counts/CountsRotationTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/store/counts/CountsRotationTest.java index 47d1bbdf08d88..133d33ac3c31d 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/store/counts/CountsRotationTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/store/counts/CountsRotationTest.java @@ -151,32 +151,33 @@ public void shouldCreateEmptyCountsTrackerStoreWhenCreatingDatabase() throws IOE } @Test - public void shouldUnMapThePrestateFileWhenTimingOutOnRotation() throws IOException + public void shouldUnMapThePrestateFileWhenTimingOutOnRotationAndAllowForShutdownInTheFailedRotationState() + throws Throwable { // Given dbBuilder.newGraphDatabase().shutdown(); CountsTracker store = createCountsTracker( pageCache, Config.defaults().augment( Collections .singletonMap( GraphDatabaseSettings.counts_store_rotation_timeout.name(), "100ms" ) ) ); - store.init(); - store.start(); - - try ( CountsAccessor.Updater updater = store.apply( 2 ).get() ) + try ( Lifespan lifespan = new Lifespan( store ) ) { - updater.incrementNodeCount( 0, 1 ); - } + try ( CountsAccessor.Updater updater = store.apply( 2 ).get() ) + { + updater.incrementNodeCount( 0, 1 ); + } - try - { - // when - store.rotate( 3 ); - fail( "should have thrown" ); - } - catch ( RotationTimeoutException ex ) - { - // good + try + { + // when + store.rotate( 3 ); + fail( "should have thrown" ); + } + catch ( RotationTimeoutException ex ) + { + // good + } } - // then no exceptions closing the page cache + // and also no exceptions closing the page cache pageCache.close(); }