Skip to content

Commit

Permalink
Add a procedure for waiting for the fulltext index to finish populati…
Browse files Browse the repository at this point in the history
…ng e.g. after startup
  • Loading branch information
chrisvest committed Sep 19, 2017
1 parent 54c53e2 commit 77757c0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ public void init() throws IOException
db.registerTransactionEventHandler( fulltextTransactionEventUpdater );
}

public void awaitPopulation() throws IOException
{
applier.writeBarrier().await();
}

/**
* Closes the provider and all associated resources.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ <E extends Entity> BinaryLatch removePropertyData( Iterable<PropertyEntry<E>> pr
return completedLatch;
}

BinaryLatch writeBarrier() throws IOException
{
BinaryLatch barrierLatch = new BinaryLatch();
enqueueUpdate( () -> Pair.of( null, barrierLatch ) );
return barrierLatch;
}

BinaryLatch populateNodes( WritableFulltext index, GraphDatabaseService db ) throws IOException
{
return enqueuePopulateIndex( index, db, db::getAllNodes );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package org.neo4j.kernel.api.impl.fulltext.integrations.bloom;

import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Spliterator;
Expand Down Expand Up @@ -47,6 +48,13 @@ public class BloomProcedures
@Context
public FulltextProvider provider;

@Description( "Await the completion of any background index population or updates" )
@Procedure( name = "db.fulltext.bloomAwaitPopulation", mode = READ )
public void awaitPopulation() throws IOException
{
provider.awaitPopulation();
}

@Description( "Queries the bloom index for nodes" )
@Procedure( name = "db.fulltext.bloomFulltextNodes", mode = READ )
public Stream<Output> bloomFulltextNodes( @Name( "terms" ) List<String> terms ) throws Exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,7 @@ public void shouldPopulateIndexWithExistingDataOnIndexCreate() throws Exception
builder.setConfig( LoadableBloomFulltextConfig.bloom_analyzer, "org.apache.lucene.analysis.da.DanishAnalyzer" );
db = builder.newGraphDatabase();

try ( Transaction tx = db.beginTx() )
{
Node node = db.createNode();
node.setProperty( "prop", "Something else" ); // To wait for fulltext index population to finish
tx.success();
}
db.execute( "CALL db.fulltext.bloomAwaitPopulation" ).close();

Result result = db.execute( String.format( NODES, "Roskildevej" ) );
assertTrue( result.hasNext() );
Expand Down

0 comments on commit 77757c0

Please sign in to comment.