Skip to content

Commit

Permalink
Safe close/drop of all parts in ParallelNativeIndexPopulator
Browse files Browse the repository at this point in the history
  • Loading branch information
tinwelint committed Oct 10, 2018
1 parent 28491d1 commit fe63228
Showing 1 changed file with 24 additions and 4 deletions.
Expand Up @@ -40,6 +40,7 @@
import org.neo4j.kernel.api.index.NodePropertyAccessor;
import org.neo4j.storageengine.api.schema.IndexSample;

import static org.neo4j.helpers.collection.Iterables.safeForAll;
import static org.neo4j.io.IOUtils.closeAll;

/**
Expand Down Expand Up @@ -79,6 +80,10 @@ protected synchronized ThreadLocalPopulator initialValue()
{
throw new IllegalStateException( "Already closed" );
}
if ( merged )
{
throw new IllegalStateException( "Already merged" );
}

File file = new File( baseIndexFile + "-part-" + partPopulators.size() );
NativeIndexPopulator<KEY,VALUE> populator = populatorSupplier.apply( file );
Expand All @@ -101,8 +106,19 @@ public void create()
@Override
public void drop()
{
partPopulators.forEach( p -> p.populator.drop() );
completePopulator.drop();
try
{
closeAndDropAllParts();
}
finally
{
completePopulator.drop();
}
}

private void closeAndDropAllParts()
{
safeForAll( p -> p.populator.drop(), partPopulators );
}

@Override
Expand Down Expand Up @@ -154,7 +170,6 @@ public void close( boolean populationCompletedSuccessfully )
{
if ( populationCompletedSuccessfully )
{
// We're already merged at this point, so it's only to close the complete tree
ensureMerged();
completePopulator.close( true );
}
Expand All @@ -171,7 +186,7 @@ public void close( boolean populationCompletedSuccessfully )
}
finally
{
partPopulators.forEach( p -> p.populator.drop() );
closeAndDropAllParts();
}
}

Expand Down Expand Up @@ -202,6 +217,11 @@ public void consistencyCheck()
completePopulator.consistencyCheck();
}

/**
* Will ensure that the merge have been done. This is a method which is called in several places because depending on population
* parameters and scenarios different methods of this populator will be considered the first method after population to operate
* on the complete index.
*/
private void ensureMerged()
{
if ( !merged )
Expand Down

0 comments on commit fe63228

Please sign in to comment.