Skip to content

Commit

Permalink
Allow for stopping counts store in failed rotation state
Browse files Browse the repository at this point in the history
  • Loading branch information
davidegrohmann committed Nov 17, 2016
1 parent 56d2520 commit ecf6772
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
Expand Up @@ -47,6 +47,7 @@ static final class Rotation<Key> extends RotationState<Key>
private final ActiveState<Key> preState; private final ActiveState<Key> preState;
private final PrototypeState<Key> postState; private final PrototypeState<Key> postState;
private final long threshold; private final long threshold;
private boolean failed = false;


Rotation( ActiveState<Key> preState, PrototypeState<Key> postState, long version ) Rotation( ActiveState<Key> preState, PrototypeState<Key> postState, long version )
{ {
Expand All @@ -66,6 +67,7 @@ ActiveState<Key> rotate( boolean force, RotationStrategy strategy, RotationTimer
{ {
if ( rotationTimer.isTimedOut() ) if ( rotationTimer.isTimedOut() )
{ {
failed = true;
throw new RotationTimeoutException( threshold, preState.store.version(), throw new RotationTimeoutException( threshold, preState.store.version(),
rotationTimer.getElapsedTimeMillis()); rotationTimer.getElapsedTimeMillis());
} }
Expand All @@ -90,6 +92,17 @@ public void close() throws IOException
preState.close(); preState.close();
} }


@Override
ProgressiveState<Key> stop() throws IOException
{
if ( failed )
{
// failed to rotate allow for stopping no matter what
return preState;
}
return super.stop();
}

@Override @Override
long rotationVersion() long rotationVersion()
{ {
Expand Down
Expand Up @@ -151,32 +151,33 @@ public void shouldCreateEmptyCountsTrackerStoreWhenCreatingDatabase() throws IOE
} }


@Test @Test
public void shouldUnMapThePrestateFileWhenTimingOutOnRotation() throws IOException public void shouldUnMapThePrestateFileWhenTimingOutOnRotationAndAllowForShutdownInTheFailedRotationState()
throws Throwable
{ {
// Given // Given
dbBuilder.newGraphDatabase().shutdown(); dbBuilder.newGraphDatabase().shutdown();
CountsTracker store = createCountsTracker( pageCache, Config.defaults().augment( Collections CountsTracker store = createCountsTracker( pageCache, Config.defaults().augment( Collections
.singletonMap( GraphDatabaseSettings.counts_store_rotation_timeout.name(), "100ms" ) ) ); .singletonMap( GraphDatabaseSettings.counts_store_rotation_timeout.name(), "100ms" ) ) );
store.init(); try ( Lifespan lifespan = new Lifespan( store ) )
store.start();

try ( CountsAccessor.Updater updater = store.apply( 2 ).get() )
{ {
updater.incrementNodeCount( 0, 1 ); try ( CountsAccessor.Updater updater = store.apply( 2 ).get() )
} {
updater.incrementNodeCount( 0, 1 );
}


try try
{ {
// when // when
store.rotate( 3 ); store.rotate( 3 );
fail( "should have thrown" ); fail( "should have thrown" );
} }
catch ( RotationTimeoutException ex ) catch ( RotationTimeoutException ex )
{ {
// good // good
}
} }


// then no exceptions closing the page cache // and also no exceptions closing the page cache
pageCache.close(); pageCache.close();
} }


Expand Down

0 comments on commit ecf6772

Please sign in to comment.