Skip to content

Commit

Permalink
Dropping a populating index actually calls IndexPopulator#drop()
Browse files Browse the repository at this point in the history
  • Loading branch information
tinwelint authored and burqen committed Mar 5, 2019
1 parent 2af2adc commit c938cfe
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
Expand Up @@ -156,6 +156,11 @@ void cancelPopulation( MultipleIndexPopulator.IndexPopulation population )
multiPopulator.cancelIndexPopulation( population );
}

void dropPopulation( MultipleIndexPopulator.IndexPopulation population )
{
multiPopulator.dropIndexPopulation( population );
}

/**
* A transaction happened that produced the given updates. Let this job incorporate its data,
* feeding it to the {@link IndexPopulator}.
Expand Down
Expand Up @@ -350,6 +350,11 @@ void cancelIndexPopulation( IndexPopulation indexPopulation )
indexPopulation.cancel();
}

void dropIndexPopulation( IndexPopulation indexPopulation )
{
indexPopulation.cancelAndDrop();
}

private boolean removeFromOngoingPopulations( IndexPopulation indexPopulation )
{
return populations.remove( indexPopulation );
Expand Down Expand Up @@ -541,6 +546,20 @@ void create()
}

void cancel()
{
cancel( () -> populator.close( false ) );
}

void cancelAndDrop()
{
cancel( populator::drop );
}

/**
* Cancels population also executing a specific operation on the populator
* @param specificPopulatorOperation specific operation in addition to closing the populator.
*/
private void cancel( Runnable specificPopulatorOperation )
{
populatorLock.lock();
try
Expand All @@ -550,8 +569,7 @@ void cancel()
// First of all remove this population from the list of ongoing populations so that it won't receive more updates.
// This is good because closing the populator may wait for an opportunity to perform the close, among the incoming writes to it.
removeFromOngoingPopulations( this );

populator.close( false );
specificPopulatorOperation.run();
resetIndexCountsForPopulation( this );
populationOngoing = false;
}
Expand Down
Expand Up @@ -82,7 +82,7 @@ public void process( IndexEntryUpdate<?> update )
@Override
public void drop()
{
job.cancelPopulation( indexPopulation );
job.dropPopulation( indexPopulation );
}

@Override
Expand Down
Expand Up @@ -122,6 +122,7 @@ public abstract class BlockBasedIndexPopulator<KEY extends NativeIndexKey<KEY>,V
private synchronized BlockStorage<KEY,VALUE> newThreadLocalBlockStorage()
{
Preconditions.checkState( !merged, "Already merged" );
Preconditions.checkState( !cancellation.cancelled(), "Already closed" );
try
{
int id = allScanUpdates.size();
Expand Down
Expand Up @@ -39,12 +39,12 @@
import org.neo4j.kernel.api.index.IndexEntryUpdate;
import org.neo4j.kernel.api.index.IndexPopulator;
import org.neo4j.kernel.api.index.IndexUpdater;
import org.neo4j.storageengine.api.NodePropertyAccessor;
import org.neo4j.kernel.api.schema.SchemaDescriptorFactory;
import org.neo4j.kernel.api.schema.index.TestIndexDescriptorFactory;
import org.neo4j.kernel.impl.api.SchemaState;
import org.neo4j.kernel.impl.api.index.MultipleIndexPopulator.IndexPopulation;
import org.neo4j.logging.LogProvider;
import org.neo4j.storageengine.api.NodePropertyAccessor;
import org.neo4j.storageengine.api.schema.IndexSample;
import org.neo4j.storageengine.api.schema.StoreIndexDescriptor;

Expand Down Expand Up @@ -119,6 +119,18 @@ public void flippedPopulationAreNotCanceable() throws FlipFailedKernelException
verify( indexPopulation.populator, never() ).close( false );
}

@Test
public void cancelAndDropShouldCallDropOnPopulator() throws FlipFailedKernelException
{
IndexPopulator populator = createIndexPopulator();
IndexPopulation indexPopulation = addPopulator( populator, 1 );

indexPopulation.cancelAndDrop();

verify( populator, never() ).close( false );
verify( populator ).drop();
}

@Test
public void testMultiplePopulatorsCreation() throws FlipFailedKernelException
{
Expand Down

0 comments on commit c938cfe

Please sign in to comment.