Skip to content

Commit

Permalink
The fulltext index now deletes any existing index files from any prio…
Browse files Browse the repository at this point in the history
…r starts of the database, in order to avoid configuration changes from creating persistent stale index entries
  • Loading branch information
chrisvest committed Sep 19, 2017
1 parent 77757c0 commit 4f237e4
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 1 deletion.
Expand Up @@ -70,8 +70,13 @@ public FulltextFactory( FileSystemAbstraction fileSystem, File storeDir, Analyze
public void createFulltextIndex( String identifier, FulltextProvider.FulltextIndexType type, List<String> properties, FulltextProvider provider )
throws IOException
{
// First delete any existing index, since we don't know if whatever it might contain actually matches our
// current configuration:
File indexRootFolder = new File( indexDir, identifier );
fileSystem.deleteRecursively( indexRootFolder );

LuceneIndexStorageBuilder storageBuilder = LuceneIndexStorageBuilder.create();
storageBuilder.withFileSystem( fileSystem ).withIndexFolder( new File( indexDir, identifier ) );
storageBuilder.withFileSystem( fileSystem ).withIndexFolder( indexRootFolder );
provider.register( new LuceneFulltext( storageBuilder.build(), partitionFactory, properties, analyzer, identifier, type ) );
}
}
Expand Up @@ -164,6 +164,116 @@ public void shouldPopulateIndexWithExistingDataOnIndexCreate() throws Exception
assertFalse( result.hasNext() );
}

@Test
public void startupPopulationShouldNotCauseDuplicates() throws Exception
{
GraphDatabaseBuilder builder = factory.newEmbeddedDatabaseBuilder( testDirectory.graphDbDir() );
builder.setConfig( LoadableBloomFulltextConfig.bloom_indexed_properties, "prop" );

db = builder.newGraphDatabase();
long nodeId;
try ( Transaction tx = db.beginTx() )
{
Node node = db.createNode();
nodeId = node.getId();
node.setProperty( "prop", "Jyllingevej" );
tx.success();
}

// Verify it's indexed exactly once
db.execute( "CALL db.fulltext.bloomAwaitPopulation" ).close();
Result result = db.execute( String.format( NODES, "Jyllingevej" ) );
assertTrue( result.hasNext() );
assertEquals( nodeId, result.next().get( ENTITYID ) );
assertFalse( result.hasNext() );

db.shutdown();
db = builder.newGraphDatabase();

// Verify it's STILL indexed exactly once
db.execute( "CALL db.fulltext.bloomAwaitPopulation" ).close();
result = db.execute( String.format( NODES, "Jyllingevej" ) );
assertTrue( result.hasNext() );
assertEquals( nodeId, result.next().get( ENTITYID ) );
assertFalse( result.hasNext() );
}

@Test
public void staleDataFromEntityDeleteShouldNotBeAccessibleAfterConfigurationChange() throws Exception
{
GraphDatabaseBuilder builder = factory.newEmbeddedDatabaseBuilder( testDirectory.graphDbDir() );
builder.setConfig( LoadableBloomFulltextConfig.bloom_indexed_properties, "prop" );

db = builder.newGraphDatabase();
long nodeId;
try ( Transaction tx = db.beginTx() )
{
Node node = db.createNode();
nodeId = node.getId();
node.setProperty( "prop", "Esplanaden" );
tx.success();
}

db.shutdown();
builder.setConfig( LoadableBloomFulltextConfig.bloom_indexed_properties, "not-prop" );
db = builder.newGraphDatabase();

try ( Transaction tx = db.beginTx() )
{
// This should no longer be indexed
db.getNodeById( nodeId ).delete();
tx.success();
}

db.shutdown();
builder.setConfig( LoadableBloomFulltextConfig.bloom_indexed_properties, "prop" );
db = builder.newGraphDatabase();

// Verify that the node is no longer indexed
db.execute( "CALL db.fulltext.bloomAwaitPopulation" ).close();
Result result = db.execute( String.format( NODES, "Esplanaden" ) );
assertFalse( result.hasNext() );
result.close();
}

@Test
public void staleDataFromPropertyRemovalShouldNotBeAccessibleAfterConfigurationChange() throws Exception
{
GraphDatabaseBuilder builder = factory.newEmbeddedDatabaseBuilder( testDirectory.graphDbDir() );
builder.setConfig( LoadableBloomFulltextConfig.bloom_indexed_properties, "prop" );

db = builder.newGraphDatabase();
long nodeId;
try ( Transaction tx = db.beginTx() )
{
Node node = db.createNode();
nodeId = node.getId();
node.setProperty( "prop", "Esplanaden" );
tx.success();
}

db.shutdown();
builder.setConfig( LoadableBloomFulltextConfig.bloom_indexed_properties, "not-prop" );
db = builder.newGraphDatabase();

try ( Transaction tx = db.beginTx() )
{
// This should no longer be indexed
db.getNodeById( nodeId ).removeProperty( "prop" );
tx.success();
}

db.shutdown();
builder.setConfig( LoadableBloomFulltextConfig.bloom_indexed_properties, "prop" );
db = builder.newGraphDatabase();

// Verify that the node is no longer indexed
db.execute( "CALL db.fulltext.bloomAwaitPopulation" ).close();
Result result = db.execute( String.format( NODES, "Esplanaden" ) );
assertFalse( result.hasNext() );
result.close();
}

@Test
public void shouldNotBeAbleToStartWithoutConfiguringProperties() throws Exception
{
Expand Down

0 comments on commit 4f237e4

Please sign in to comment.