Skip to content

Commit

Permalink
Introduce tags for native and lucene label indexes, introduce additio…
Browse files Browse the repository at this point in the history
…nal test for lucene label case.
  • Loading branch information
MishaDemianenko committed May 15, 2017
1 parent 5119cb2 commit 04ce8b3
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 33 deletions.
Expand Up @@ -22,7 +22,6 @@
import java.util.function.Supplier;

import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.graphdb.factory.GraphDatabaseSettings.LabelIndex;
import org.neo4j.io.pagecache.PageCache;
import org.neo4j.kernel.api.labelscan.LoggingMonitor;
import org.neo4j.kernel.configuration.Config;
Expand All @@ -38,8 +37,6 @@
public class NativeLabelScanStoreExtension extends
KernelExtensionFactory<NativeLabelScanStoreExtension.Dependencies>
{
private static final String NAME = LabelIndex.NATIVE.name();

public interface Dependencies
{
Config getConfig();
Expand All @@ -55,22 +52,22 @@ public interface Dependencies

public NativeLabelScanStoreExtension()
{
super( NAME );
super( NativeLabelScanStore.NATIVE_LABEL_INDEX_TAG );
}

@Override
public Lifecycle newInstance( KernelContext context, Dependencies dependencies ) throws Throwable
{
Log log = dependencies.getLogService().getInternalLog( NativeLabelScanStore.class );
Monitors monitors = dependencies.monitors();
monitors.addMonitorListener( new LoggingMonitor( log ), NativeLabelScanStore.NATIVE_INDEX_TAG );
monitors.addMonitorListener( new LoggingMonitor( log ), NativeLabelScanStore.NATIVE_LABEL_INDEX_TAG );
NativeLabelScanStore labelScanStore = new NativeLabelScanStore(
dependencies.pageCache(),
context.storeDir(),
new FullLabelStream( dependencies.indexStoreView() ),
dependencies.getConfig().get( GraphDatabaseSettings.read_only ),
monitors );

return new LabelScanStoreProvider( NAME, labelScanStore );
return new LabelScanStoreProvider( NativeLabelScanStore.NATIVE_LABEL_INDEX_TAG, labelScanStore );
}
}
Expand Up @@ -96,10 +96,9 @@ public class NativeLabelScanStore implements LabelScanStore
private static final byte REBUILDING = (byte) 0x01;

/**
* Native index monitor tag, to distinguish monitors for native index store
* from others.
* Native label index tag, to distinguish native label index from other label indexes
*/
public static final String NATIVE_INDEX_TAG = GraphDatabaseSettings.LabelIndex.NATIVE.name();
public static final String NATIVE_LABEL_INDEX_TAG = GraphDatabaseSettings.LabelIndex.NATIVE.name();

/**
* Whether or not this label scan store is read-only.
Expand Down Expand Up @@ -184,7 +183,7 @@ public NativeLabelScanStore( PageCache pageCache, File storeDir, FullStoreChange
this.singleWriter = new NativeLabelScanWriter( 1_000 );
this.readOnly = readOnly;
this.monitors = monitors;
this.monitor = monitors.newMonitor( Monitor.class, NATIVE_INDEX_TAG );
this.monitor = monitors.newMonitor( Monitor.class, NATIVE_LABEL_INDEX_TAG );
}

/**
Expand Down Expand Up @@ -351,8 +350,8 @@ private FileHandle storeFileHandle() throws IOException
*/
private boolean instantiateTree() throws IOException
{
monitors.addMonitorListener( treeMonitor(), NATIVE_INDEX_TAG );
GBPTree.Monitor monitor = monitors.newMonitor( GBPTree.Monitor.class, NATIVE_INDEX_TAG );
monitors.addMonitorListener( treeMonitor(), NATIVE_LABEL_INDEX_TAG );
GBPTree.Monitor monitor = monitors.newMonitor( GBPTree.Monitor.class, NATIVE_LABEL_INDEX_TAG );
MutableBoolean isRebuilding = new MutableBoolean();
Header.Reader readRebuilding =
(pageCursor, length) -> isRebuilding.setValue( pageCursor.getByte() == REBUILDING );
Expand Down
Expand Up @@ -23,7 +23,9 @@

import java.io.File;
import java.io.IOException;

import org.neo4j.graphdb.ResourceIterator;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.io.pagecache.IOLimiter;
import org.neo4j.kernel.api.labelscan.AllEntriesLabelScanReader;
import org.neo4j.kernel.api.labelscan.LabelScanStore;
Expand All @@ -35,6 +37,11 @@

public class LuceneLabelScanStore implements LabelScanStore
{
/**
* Lucene label index tag, to distinguish lucene label index from other label indexes
*/
public static final String LUCENE_LABEL_INDEX_TAG = GraphDatabaseSettings.LabelIndex.LUCENE.name();

private final LuceneLabelScanIndexBuilder indexBuilder;
private volatile LabelScanIndex luceneIndex;
// We get in a full store stream here in case we need to fully rebuild the store if it's missing or corrupted.
Expand Down
Expand Up @@ -21,7 +21,6 @@

import java.util.function.Supplier;

import org.neo4j.graphdb.factory.GraphDatabaseSettings.LabelIndex;
import org.neo4j.helpers.Service;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.NeoStoreDataSource;
Expand All @@ -45,7 +44,6 @@
@Service.Implementation(KernelExtensionFactory.class)
public class LuceneLabelScanStoreExtension extends KernelExtensionFactory<LuceneLabelScanStoreExtension.Dependencies>
{
private static final String NAME = LabelIndex.LUCENE.name();

public interface Dependencies
{
Expand Down Expand Up @@ -82,12 +80,13 @@ public LabelScanStoreProvider newInstance( KernelContext context, Dependencies d
LuceneLabelScanIndexBuilder indexBuilder = getIndexBuilder( context, directoryFactory, fileSystem, config );
LogProvider logger = dependencies.getLogService().getInternalLogProvider();
Monitors monitors = dependencies.monitors();
monitors.addMonitorListener( new LoggingMonitor( logger.getLog( LuceneLabelScanStore.class ) ), NAME );
monitors.addMonitorListener( new LoggingMonitor( logger.getLog( LuceneLabelScanStore.class ) ),
LuceneLabelScanStore.LUCENE_LABEL_INDEX_TAG );
LuceneLabelScanStore scanStore = new LuceneLabelScanStore( indexBuilder,
new FullLabelStream( dependencies.indexStoreView() ),
monitors.newMonitor( LabelScanStore.Monitor.class, NAME ) );
monitors.newMonitor( LabelScanStore.Monitor.class, LuceneLabelScanStore.LUCENE_LABEL_INDEX_TAG ) );

return new LabelScanStoreProvider( NAME, scanStore );
return new LabelScanStoreProvider( LuceneLabelScanStore.LUCENE_LABEL_INDEX_TAG, scanStore );
}

private LuceneLabelScanIndexBuilder getIndexBuilder( KernelContext context, DirectoryFactory directoryFactory,
Expand Down
Expand Up @@ -22,11 +22,13 @@
import org.junit.Rule;
import org.junit.Test;

import java.io.File;
import java.io.IOException;

import org.neo4j.graphdb.DependencyResolver;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.kernel.api.impl.labelscan.LuceneLabelScanStore;
import org.neo4j.kernel.api.labelscan.LabelScanStore;
import org.neo4j.kernel.api.labelscan.LabelScanWriter;
import org.neo4j.kernel.api.labelscan.NodeLabelUpdate;
import org.neo4j.kernel.impl.index.labelscan.NativeLabelScanStore;
Expand All @@ -45,26 +47,14 @@ public class LabelScanStoreLoggingTest
public void noLuceneLabelScanStoreMonitorMessages() throws Throwable
{
AssertableLogProvider logProvider = new AssertableLogProvider( true );
File storeDir = testDirectory.directory();
GraphDatabaseService database = new TestGraphDatabaseFactory()
.setInternalLogProvider( logProvider )
.newEmbeddedDatabase( storeDir );
.newEmbeddedDatabase( testDirectory.directory() );
try
{

DependencyResolver resolver = ((GraphDatabaseAPI) database).getDependencyResolver();

NativeLabelScanStore labelScanStore = resolver.resolveDependency( NativeLabelScanStore.class );
try ( LabelScanWriter labelScanWriter = labelScanStore.newWriter() )
{
labelScanWriter.write( NodeLabelUpdate.labelChanges( 1, new long[]{}, new long[]{1} ) );
}
labelScanStore.stop();
labelScanStore.shutdown();

labelScanStore.init();
labelScanStore.start();

NativeLabelScanStore labelScanStore = resolveDependency( (GraphDatabaseAPI) database, NativeLabelScanStore.class);
performWriteAndRestartStore( labelScanStore );
logProvider.assertNoLogCallContaining( LuceneLabelScanStore.class.getName() );
logProvider.assertContainsLogCallContaining( NativeLabelScanStore.class.getName() );
logProvider.assertContainsMessageContaining(
Expand All @@ -75,4 +65,45 @@ public void noLuceneLabelScanStoreMonitorMessages() throws Throwable
database.shutdown();
}
}

@Test
public void noNativeLabelScanStoreMonitorMessages() throws Throwable
{
AssertableLogProvider logProvider = new AssertableLogProvider( true );
GraphDatabaseService database = new TestGraphDatabaseFactory()
.setInternalLogProvider( logProvider )
.newEmbeddedDatabaseBuilder( testDirectory.directory() )
.setConfig( GraphDatabaseSettings.label_index.name(), GraphDatabaseSettings.LabelIndex.LUCENE.name() )
.newGraphDatabase();
try
{
LuceneLabelScanStore labelScanStore = resolveDependency( (GraphDatabaseAPI) database, LuceneLabelScanStore.class);
performWriteAndRestartStore( labelScanStore );
logProvider.assertNoLogCallContaining( NativeLabelScanStore.class.getName() );
logProvider.assertContainsLogCallContaining( LuceneLabelScanStore.class.getName() );
}
finally
{
database.shutdown();
}
}

private void performWriteAndRestartStore( LabelScanStore labelScanStore ) throws IOException
{
try ( LabelScanWriter labelScanWriter = labelScanStore.newWriter() )
{
labelScanWriter.write( NodeLabelUpdate.labelChanges( 1, new long[]{}, new long[]{1} ) );
}
labelScanStore.stop();
labelScanStore.shutdown();

labelScanStore.init();
labelScanStore.start();
}

private static <T> T resolveDependency( GraphDatabaseAPI database, Class<T> clazz )
{
DependencyResolver resolver = database.getDependencyResolver();
return resolver.resolveDependency( clazz );
}
}

0 comments on commit 04ce8b3

Please sign in to comment.