Skip to content

Commit

Permalink
Open legacy index in writable mode for non single instance read only …
Browse files Browse the repository at this point in the history
…environments

Open legacy indexes in writable mode for all read only environments
except single instance. We need to allow indexes to be writable since
they need to be updated during catch up updates.
  • Loading branch information
MishaDemianenko committed Jul 20, 2017
1 parent c2a95db commit faaa618
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 25 deletions.
Expand Up @@ -59,6 +59,7 @@
import org.neo4j.io.fs.FileUtils; import org.neo4j.io.fs.FileUtils;
import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory; import org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory;
import org.neo4j.kernel.impl.factory.OperationalMode;
import org.neo4j.kernel.impl.index.IndexConfigStore; import org.neo4j.kernel.impl.index.IndexConfigStore;
import org.neo4j.kernel.impl.index.IndexEntityType; import org.neo4j.kernel.impl.index.IndexEntityType;
import org.neo4j.kernel.lifecycle.LifecycleAdapter; import org.neo4j.kernel.lifecycle.LifecycleAdapter;
Expand Down Expand Up @@ -100,6 +101,7 @@ public String toString()
private final File storeDir; private final File storeDir;
private final Config config; private final Config config;
private final FileSystemAbstraction fileSystemAbstraction; private final FileSystemAbstraction fileSystemAbstraction;
private final OperationalMode operationalMode;
private IndexClockCache indexSearchers; private IndexClockCache indexSearchers;
private File baseStorePath; private File baseStorePath;
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
Expand All @@ -113,21 +115,23 @@ public String toString()
/** /**
* Constructs this data source. * Constructs this data source.
*/ */
public LuceneDataSource( File storeDir, Config config, IndexConfigStore indexStore, FileSystemAbstraction fileSystemAbstraction ) public LuceneDataSource( File storeDir, Config config, IndexConfigStore indexStore, FileSystemAbstraction
fileSystemAbstraction, OperationalMode operationalMode )
{ {
this.storeDir = storeDir; this.storeDir = storeDir;
this.config = config; this.config = config;
this.indexStore = indexStore; this.indexStore = indexStore;
this.typeCache = new IndexTypeCache( indexStore ); this.typeCache = new IndexTypeCache( indexStore );
this.fileSystemAbstraction = fileSystemAbstraction; this.fileSystemAbstraction = fileSystemAbstraction;
this.operationalMode = operationalMode;
} }


@Override @Override
public void init() public void init()
{ {
this.filesystemFacade = config.get( Configuration.ephemeral ) ? LuceneFilesystemFacade.MEMORY this.filesystemFacade = config.get( Configuration.ephemeral ) ? LuceneFilesystemFacade.MEMORY
: LuceneFilesystemFacade.FS; : LuceneFilesystemFacade.FS;
readOnly = config.get( GraphDatabaseSettings.read_only ); readOnly = isReadOnly( config, operationalMode );
indexSearchers = new IndexClockCache( config.get( Configuration.lucene_searcher_cache_size ) ); indexSearchers = new IndexClockCache( config.get( Configuration.lucene_searcher_cache_size ) );
this.baseStorePath = this.filesystemFacade.ensureDirectoryExists( fileSystemAbstraction, this.baseStorePath = this.filesystemFacade.ensureDirectoryExists( fileSystemAbstraction,
getLuceneIndexStoreDirectory( storeDir ) ); getLuceneIndexStoreDirectory( storeDir ) );
Expand Down Expand Up @@ -473,6 +477,11 @@ private void makeSureAllIndexesAreInstantiated()
} }
} }


private boolean isReadOnly( Config config, OperationalMode operationalMode )
{
return config.get( GraphDatabaseSettings.read_only ) && (OperationalMode.single == operationalMode);
}

enum LuceneFilesystemFacade enum LuceneFilesystemFacade
{ {
FS FS
Expand Down
Expand Up @@ -32,6 +32,7 @@
import org.neo4j.io.fs.FileSystemAbstraction; import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.api.TransactionApplier; import org.neo4j.kernel.impl.api.TransactionApplier;
import org.neo4j.kernel.impl.factory.OperationalMode;
import org.neo4j.kernel.impl.index.IndexConfigStore; import org.neo4j.kernel.impl.index.IndexConfigStore;
import org.neo4j.kernel.lifecycle.LifecycleAdapter; import org.neo4j.kernel.lifecycle.LifecycleAdapter;
import org.neo4j.kernel.spi.legacyindex.IndexCommandFactory; import org.neo4j.kernel.spi.legacyindex.IndexCommandFactory;
Expand Down Expand Up @@ -60,20 +61,22 @@ public class LuceneIndexImplementation extends LifecycleAdapter implements Index
private final Config config; private final Config config;
private final Supplier<IndexConfigStore> indexStore; private final Supplier<IndexConfigStore> indexStore;
private final FileSystemAbstraction fileSystemAbstraction; private final FileSystemAbstraction fileSystemAbstraction;
private final OperationalMode operationalMode;


public LuceneIndexImplementation( File storeDir, Config config, Supplier<IndexConfigStore> indexStore, public LuceneIndexImplementation( File storeDir, Config config, Supplier<IndexConfigStore> indexStore,
FileSystemAbstraction fileSystemAbstraction ) FileSystemAbstraction fileSystemAbstraction, OperationalMode operationalMode )
{ {
this.storeDir = storeDir; this.storeDir = storeDir;
this.config = config; this.config = config;
this.indexStore = indexStore; this.indexStore = indexStore;
this.fileSystemAbstraction = fileSystemAbstraction; this.fileSystemAbstraction = fileSystemAbstraction;
this.operationalMode = operationalMode;
} }


@Override @Override
public void init() throws Throwable public void init() throws Throwable
{ {
this.dataSource = new LuceneDataSource( storeDir, config, indexStore.get(), fileSystemAbstraction ); this.dataSource = new LuceneDataSource( storeDir, config, indexStore.get(), fileSystemAbstraction, operationalMode );
this.dataSource.init(); this.dataSource.init();
} }


Expand Down
Expand Up @@ -25,6 +25,7 @@
import org.neo4j.index.impl.lucene.legacy.LuceneIndexImplementation; import org.neo4j.index.impl.lucene.legacy.LuceneIndexImplementation;
import org.neo4j.io.fs.FileSystemAbstraction; import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.factory.OperationalMode;
import org.neo4j.kernel.impl.index.IndexConfigStore; import org.neo4j.kernel.impl.index.IndexConfigStore;
import org.neo4j.kernel.lifecycle.LifecycleAdapter; import org.neo4j.kernel.lifecycle.LifecycleAdapter;
import org.neo4j.kernel.spi.legacyindex.IndexProviders; import org.neo4j.kernel.spi.legacyindex.IndexProviders;
Expand All @@ -36,23 +37,25 @@ public class LuceneKernelExtension extends LifecycleAdapter
private final Supplier<IndexConfigStore> indexStore; private final Supplier<IndexConfigStore> indexStore;
private final FileSystemAbstraction fileSystemAbstraction; private final FileSystemAbstraction fileSystemAbstraction;
private final IndexProviders indexProviders; private final IndexProviders indexProviders;
private final OperationalMode operationalMode;


public LuceneKernelExtension( File storeDir, Config config, Supplier<IndexConfigStore> indexStore, public LuceneKernelExtension( File storeDir, Config config, Supplier<IndexConfigStore> indexStore,
FileSystemAbstraction fileSystemAbstraction, IndexProviders indexProviders ) FileSystemAbstraction fileSystemAbstraction, IndexProviders indexProviders, OperationalMode operationalMode )
{ {
this.storeDir = storeDir; this.storeDir = storeDir;
this.config = config; this.config = config;
this.indexStore = indexStore; this.indexStore = indexStore;
this.fileSystemAbstraction = fileSystemAbstraction; this.fileSystemAbstraction = fileSystemAbstraction;
this.indexProviders = indexProviders; this.indexProviders = indexProviders;
this.operationalMode = operationalMode;
} }


@Override @Override
public void init() public void init()
{ {


LuceneIndexImplementation indexImplementation = LuceneIndexImplementation indexImplementation =
new LuceneIndexImplementation( storeDir, config, indexStore, fileSystemAbstraction ); new LuceneIndexImplementation( storeDir, config, indexStore, fileSystemAbstraction, operationalMode );
indexProviders.registerIndexProvider( LuceneIndexImplementation.SERVICE_NAME, indexImplementation ); indexProviders.registerIndexProvider( LuceneIndexImplementation.SERVICE_NAME, indexImplementation );
} }


Expand Down
Expand Up @@ -51,6 +51,7 @@ public Lifecycle newInstance( KernelContext context, Dependencies dependencies )
dependencies.getConfig(), dependencies.getConfig(),
dependencies::getIndexStore, dependencies::getIndexStore,
context.fileSystem(), context.fileSystem(),
dependencies.getIndexProviders() ); dependencies.getIndexProviders(),
context.databaseInfo().operationalMode );
} }
} }
Expand Up @@ -26,9 +26,10 @@
import java.util.Map; import java.util.Map;


import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Node;
import org.neo4j.kernel.configuration.Settings;
import org.neo4j.helpers.collection.MapUtil; import org.neo4j.helpers.collection.MapUtil;
import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.configuration.Settings;
import org.neo4j.kernel.impl.factory.OperationalMode;
import org.neo4j.kernel.impl.index.IndexCommand.AddNodeCommand; import org.neo4j.kernel.impl.index.IndexCommand.AddNodeCommand;
import org.neo4j.kernel.impl.index.IndexConfigStore; import org.neo4j.kernel.impl.index.IndexConfigStore;
import org.neo4j.kernel.impl.index.IndexDefineCommand; import org.neo4j.kernel.impl.index.IndexDefineCommand;
Expand All @@ -39,7 +40,6 @@
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;

import static org.neo4j.helpers.collection.MapUtil.stringMap; import static org.neo4j.helpers.collection.MapUtil.stringMap;
import static org.neo4j.index.impl.lucene.legacy.LuceneIndexImplementation.EXACT_CONFIG; import static org.neo4j.index.impl.lucene.legacy.LuceneIndexImplementation.EXACT_CONFIG;


Expand All @@ -61,7 +61,7 @@ public void shouldHandleMultipleIdSpaces() throws Exception
configStore.set( Node.class, indexName, EXACT_CONFIG ); configStore.set( Node.class, indexName, EXACT_CONFIG );
LuceneDataSource dataSource = life.add( spy( new LuceneDataSource( dir, new Config( stringMap( LuceneDataSource dataSource = life.add( spy( new LuceneDataSource( dir, new Config( stringMap(
LuceneDataSource.Configuration.ephemeral.name(), Settings.TRUE ) ), LuceneDataSource.Configuration.ephemeral.name(), Settings.TRUE ) ),
configStore, fs.get() ) ) ); configStore, fs.get(), OperationalMode.single ) ) );


try ( LuceneCommandApplier applier = new LuceneCommandApplier( dataSource, false ) ) try ( LuceneCommandApplier applier = new LuceneCommandApplier( dataSource, false ) )
{ {
Expand Down
Expand Up @@ -35,6 +35,7 @@
import org.neo4j.helpers.collection.MapUtil; import org.neo4j.helpers.collection.MapUtil;
import org.neo4j.io.fs.DefaultFileSystemAbstraction; import org.neo4j.io.fs.DefaultFileSystemAbstraction;
import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.factory.OperationalMode;
import org.neo4j.kernel.impl.index.IndexConfigStore; import org.neo4j.kernel.impl.index.IndexConfigStore;
import org.neo4j.kernel.impl.index.IndexEntityType; import org.neo4j.kernel.impl.index.IndexEntityType;
import org.neo4j.kernel.lifecycle.LifeRule; import org.neo4j.kernel.lifecycle.LifeRule;
Expand Down Expand Up @@ -74,8 +75,7 @@ public void doNotTryToCommitWritersOnForceInReadOnlyMode() throws IOException
stopDataSource(); stopDataSource();


Config readOnlyConfig = new Config( readOnlyConfig(), GraphDatabaseSettings.class ); Config readOnlyConfig = new Config( readOnlyConfig(), GraphDatabaseSettings.class );
LuceneDataSource readOnlyDataSource = life.add( new LuceneDataSource( directory.graphDbDir(), readOnlyConfig, LuceneDataSource readOnlyDataSource = life.add( getLuceneDataSource( readOnlyConfig ) );
indexStore, new DefaultFileSystemAbstraction() ) );
assertNotNull( readOnlyDataSource.getIndexSearcher( indexIdentifier ) ); assertNotNull( readOnlyDataSource.getIndexSearcher( indexIdentifier ) );


readOnlyDataSource.force(); readOnlyDataSource.force();
Expand All @@ -89,27 +89,42 @@ public void notAllowIndexDeletionInReadOnlyMode() throws IOException
stopDataSource(); stopDataSource();


Config readOnlyConfig = new Config( readOnlyConfig(), GraphDatabaseSettings.class ); Config readOnlyConfig = new Config( readOnlyConfig(), GraphDatabaseSettings.class );
dataSource = life.add( new LuceneDataSource( directory.graphDbDir(), readOnlyConfig, indexStore, new DefaultFileSystemAbstraction() ) ); dataSource = life.add( getLuceneDataSource( readOnlyConfig, OperationalMode.single ) );
expectedException.expect( IllegalStateException.class ); expectedException.expect( IllegalStateException.class );
expectedException.expectMessage("Index deletion in read only mode is not supported."); expectedException.expectMessage("Index deletion in read only mode is not supported.");
dataSource.deleteIndex( indexIdentifier, false ); dataSource.deleteIndex( indexIdentifier, false );
} }


@Test @Test
public void useReadOnlyIndexSearcherInReadOnlyMode() throws IOException public void useReadOnlyIndexSearcherInReadOnlyModeForSingleInstance() throws IOException
{ {
IndexIdentifier indexIdentifier = identifier( "foo" ); IndexIdentifier indexIdentifier = identifier( "foo" );
prepareIndexesByIdentifiers( indexIdentifier ); prepareIndexesByIdentifiers( indexIdentifier );
stopDataSource(); stopDataSource();


Config readOnlyConfig = new Config( readOnlyConfig(), GraphDatabaseSettings.class ); Config readOnlyConfig = new Config( readOnlyConfig(), GraphDatabaseSettings.class );
dataSource = life.add( new LuceneDataSource( directory.graphDbDir(), readOnlyConfig, indexStore, new DefaultFileSystemAbstraction() ) ); dataSource = life.add( getLuceneDataSource( readOnlyConfig, OperationalMode.single ) );


IndexReference indexSearcher = dataSource.getIndexSearcher( indexIdentifier ); IndexReference indexSearcher = dataSource.getIndexSearcher( indexIdentifier );
assertTrue( "Read only index reference should be used in read only mode.", assertTrue( "Read only index reference should be used in read only mode.",
ReadOnlyIndexReference.class.isInstance( indexSearcher ) ); ReadOnlyIndexReference.class.isInstance( indexSearcher ) );
} }


@Test
public void useWritableIndexSearcherInReadOnlyModeForNonSingleInstance() throws IOException
{
IndexIdentifier indexIdentifier = identifier( "foo" );
prepareIndexesByIdentifiers( indexIdentifier );
stopDataSource();

Config readOnlyConfig = new Config( readOnlyConfig(), GraphDatabaseSettings.class );
dataSource = life.add( getLuceneDataSource( readOnlyConfig, OperationalMode.ha ) );

IndexReference indexSearcher = dataSource.getIndexSearcher( indexIdentifier );
assertTrue( "Writable index reference should be used in read only mode in ha mode.",
WritableIndexReference.class.isInstance( indexSearcher ) );
}

@Test @Test
public void refreshReadOnlyIndexSearcherInReadOnlyMode() throws IOException public void refreshReadOnlyIndexSearcherInReadOnlyMode() throws IOException
{ {
Expand All @@ -118,7 +133,7 @@ public void refreshReadOnlyIndexSearcherInReadOnlyMode() throws IOException
stopDataSource(); stopDataSource();


Config readOnlyConfig = new Config( readOnlyConfig(), GraphDatabaseSettings.class ); Config readOnlyConfig = new Config( readOnlyConfig(), GraphDatabaseSettings.class );
dataSource = life.add( new LuceneDataSource( directory.graphDbDir(), readOnlyConfig, indexStore, new DefaultFileSystemAbstraction() ) ); dataSource = life.add( getLuceneDataSource( readOnlyConfig ) );


IndexReference indexSearcher = dataSource.getIndexSearcher( indexIdentifier ); IndexReference indexSearcher = dataSource.getIndexSearcher( indexIdentifier );
IndexReference indexSearcher2 = dataSource.getIndexSearcher( indexIdentifier ); IndexReference indexSearcher2 = dataSource.getIndexSearcher( indexIdentifier );
Expand All @@ -133,7 +148,7 @@ public void refreshReadOnlyIndexSearcherInReadOnlyMode() throws IOException
public void testShouldReturnIndexWriterFromLRUCache() throws Throwable public void testShouldReturnIndexWriterFromLRUCache() throws Throwable
{ {
Config config = new Config( config(), GraphDatabaseSettings.class ); Config config = new Config( config(), GraphDatabaseSettings.class );
dataSource = life.add( new LuceneDataSource( directory.graphDbDir(), config, indexStore, new DefaultFileSystemAbstraction() ) ); dataSource = life.add( getLuceneDataSource( config ) );
IndexIdentifier identifier = identifier( "foo" ); IndexIdentifier identifier = identifier( "foo" );
IndexWriter writer = dataSource.getIndexSearcher( identifier ).getWriter(); IndexWriter writer = dataSource.getIndexSearcher( identifier ).getWriter();
assertSame( writer, dataSource.getIndexSearcher( identifier ).getWriter() ); assertSame( writer, dataSource.getIndexSearcher( identifier ).getWriter() );
Expand All @@ -143,7 +158,7 @@ public void testShouldReturnIndexWriterFromLRUCache() throws Throwable
public void testShouldReturnIndexSearcherFromLRUCache() throws Throwable public void testShouldReturnIndexSearcherFromLRUCache() throws Throwable
{ {
Config config = new Config( config(), GraphDatabaseSettings.class ); Config config = new Config( config(), GraphDatabaseSettings.class );
dataSource = life.add( new LuceneDataSource( directory.graphDbDir(), config, indexStore, new DefaultFileSystemAbstraction() ) ); dataSource = life.add( getLuceneDataSource( config ) );
IndexIdentifier identifier = identifier( "foo" ); IndexIdentifier identifier = identifier( "foo" );
IndexReference searcher = dataSource.getIndexSearcher( identifier ); IndexReference searcher = dataSource.getIndexSearcher( identifier );
assertSame( searcher, dataSource.getIndexSearcher( identifier ) ); assertSame( searcher, dataSource.getIndexSearcher( identifier ) );
Expand All @@ -158,7 +173,7 @@ public void testClosesOldestIndexWriterWhenCacheSizeIsExceeded() throws Throwabl
Map<String, String> configMap = config(); Map<String, String> configMap = config();
configMap.put( GraphDatabaseSettings.lucene_searcher_cache_size.name(), "2" ); configMap.put( GraphDatabaseSettings.lucene_searcher_cache_size.name(), "2" );
Config config = new Config( configMap, GraphDatabaseSettings.class ); Config config = new Config( configMap, GraphDatabaseSettings.class );
dataSource = life.add( new LuceneDataSource( directory.graphDbDir(), config, indexStore, new DefaultFileSystemAbstraction() ) ); dataSource = life.add( getLuceneDataSource( config ) );
IndexIdentifier fooIdentifier = identifier( "foo" ); IndexIdentifier fooIdentifier = identifier( "foo" );
IndexIdentifier barIdentifier = identifier( "bar" ); IndexIdentifier barIdentifier = identifier( "bar" );
IndexIdentifier bazIdentifier = identifier( "baz" ); IndexIdentifier bazIdentifier = identifier( "baz" );
Expand All @@ -177,7 +192,7 @@ public void testClosesOldestIndexSearcherWhenCacheSizeIsExceeded() throws Throwa
Map<String, String> configMap = config(); Map<String, String> configMap = config();
configMap.put( GraphDatabaseSettings.lucene_searcher_cache_size.name(), "2" ); configMap.put( GraphDatabaseSettings.lucene_searcher_cache_size.name(), "2" );
Config config = new Config( configMap, GraphDatabaseSettings.class ); Config config = new Config( configMap, GraphDatabaseSettings.class );
dataSource = life.add( new LuceneDataSource( directory.graphDbDir(), config, indexStore, new DefaultFileSystemAbstraction() ) ); dataSource = life.add( getLuceneDataSource( config ) );
IndexIdentifier fooIdentifier = identifier( "foo" ); IndexIdentifier fooIdentifier = identifier( "foo" );
IndexIdentifier barIdentifier = identifier( "bar" ); IndexIdentifier barIdentifier = identifier( "bar" );
IndexIdentifier bazIdentifier = identifier( "baz" ); IndexIdentifier bazIdentifier = identifier( "baz" );
Expand All @@ -198,7 +213,7 @@ public void testRecreatesSearcherWhenRequestedAgain() throws Throwable
Map<String, String> configMap = config(); Map<String, String> configMap = config();
configMap.put( GraphDatabaseSettings.lucene_searcher_cache_size.name(), "2" ); configMap.put( GraphDatabaseSettings.lucene_searcher_cache_size.name(), "2" );
Config config = new Config( configMap, GraphDatabaseSettings.class ); Config config = new Config( configMap, GraphDatabaseSettings.class );
dataSource = life.add( new LuceneDataSource( directory.graphDbDir(), config, indexStore, new DefaultFileSystemAbstraction() ) ); dataSource = life.add( getLuceneDataSource( config ) );
IndexIdentifier fooIdentifier = identifier( "foo" ); IndexIdentifier fooIdentifier = identifier( "foo" );
IndexIdentifier barIdentifier = identifier( "bar" ); IndexIdentifier barIdentifier = identifier( "bar" );
IndexIdentifier bazIdentifier = identifier( "baz" ); IndexIdentifier bazIdentifier = identifier( "baz" );
Expand All @@ -222,7 +237,7 @@ public void testRecreatesWriterWhenRequestedAgainAfterCacheEviction() throws Thr
Map<String, String> configMap = config(); Map<String, String> configMap = config();
configMap.put( GraphDatabaseSettings.lucene_searcher_cache_size.name(), "2" ); configMap.put( GraphDatabaseSettings.lucene_searcher_cache_size.name(), "2" );
Config config = new Config( configMap, GraphDatabaseSettings.class ); Config config = new Config( configMap, GraphDatabaseSettings.class );
dataSource = life.add( new LuceneDataSource( directory.graphDbDir(), config, indexStore, new DefaultFileSystemAbstraction() ) ); dataSource = life.add( getLuceneDataSource( config ) );
IndexIdentifier fooIdentifier = identifier( "foo" ); IndexIdentifier fooIdentifier = identifier( "foo" );
IndexIdentifier barIdentifier = identifier( "bar" ); IndexIdentifier barIdentifier = identifier( "bar" );
IndexIdentifier bazIdentifier = identifier( "baz" ); IndexIdentifier bazIdentifier = identifier( "baz" );
Expand All @@ -247,7 +262,7 @@ private Map<String, String> config()
private void prepareIndexesByIdentifiers( IndexIdentifier indexIdentifier ) private void prepareIndexesByIdentifiers( IndexIdentifier indexIdentifier )
{ {
Config config = new Config( config(), GraphDatabaseSettings.class ); Config config = new Config( config(), GraphDatabaseSettings.class );
dataSource = life.add( new LuceneDataSource( directory.graphDbDir(), config, indexStore, new DefaultFileSystemAbstraction() ) ); dataSource = life.add( getLuceneDataSource( config ) );
dataSource.getIndexSearcher( indexIdentifier ); dataSource.getIndexSearcher( indexIdentifier );
dataSource.force(); dataSource.force();
} }
Expand All @@ -269,4 +284,14 @@ private IndexIdentifier identifier( String name )
return new IndexIdentifier( IndexEntityType.Node, name ); return new IndexIdentifier( IndexEntityType.Node, name );
} }


private LuceneDataSource getLuceneDataSource( Config config )
{
return getLuceneDataSource( config, OperationalMode.unknown );
}

private LuceneDataSource getLuceneDataSource( Config config, OperationalMode operationalMode )
{
return new LuceneDataSource( directory.graphDbDir(), config, indexStore,
new DefaultFileSystemAbstraction(), operationalMode );
}
} }
Expand Up @@ -33,6 +33,7 @@
import org.neo4j.helpers.collection.MapUtil; import org.neo4j.helpers.collection.MapUtil;
import org.neo4j.io.fs.DefaultFileSystemAbstraction; import org.neo4j.io.fs.DefaultFileSystemAbstraction;
import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.factory.OperationalMode;
import org.neo4j.kernel.impl.index.IndexConfigStore; import org.neo4j.kernel.impl.index.IndexConfigStore;
import org.neo4j.kernel.impl.index.IndexEntityType; import org.neo4j.kernel.impl.index.IndexEntityType;
import org.neo4j.test.CleanupRule; import org.neo4j.test.CleanupRule;
Expand Down Expand Up @@ -89,7 +90,7 @@ private void setupIndexInfrastructure() throws IOException
indexStore = new IndexConfigStore( storeDir, fileSystemAbstraction ); indexStore = new IndexConfigStore( storeDir, fileSystemAbstraction );
indexStore.set( Node.class, INDEX_NAME, MapUtil.stringMap( IndexManager.PROVIDER, "lucene", "type", "fulltext" ) ); indexStore.set( Node.class, INDEX_NAME, MapUtil.stringMap( IndexManager.PROVIDER, "lucene", "type", "fulltext" ) );
LuceneDataSource luceneDataSource = new LuceneDataSource( storeDir, new Config( MapUtil.stringMap() ), LuceneDataSource luceneDataSource = new LuceneDataSource( storeDir, new Config( MapUtil.stringMap() ),
indexStore, fileSystemAbstraction ); indexStore, fileSystemAbstraction, OperationalMode.single );
try try
{ {
luceneDataSource.init(); luceneDataSource.init();
Expand Down
Expand Up @@ -38,6 +38,7 @@
import org.neo4j.io.fs.DefaultFileSystemAbstraction; import org.neo4j.io.fs.DefaultFileSystemAbstraction;
import org.neo4j.io.fs.FileSystemAbstraction; import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.factory.OperationalMode;
import org.neo4j.kernel.impl.index.IndexConfigStore; import org.neo4j.kernel.impl.index.IndexConfigStore;
import org.neo4j.test.DatabaseRule; import org.neo4j.test.DatabaseRule;
import org.neo4j.test.EmbeddedDatabaseRule; import org.neo4j.test.EmbeddedDatabaseRule;
Expand Down Expand Up @@ -166,7 +167,7 @@ public void recoveryForRelationshipCommandsOnly() throws Throwable
FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction(); FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
Config config = new Config( MapUtil.stringMap(), GraphDatabaseSettings.class ); Config config = new Config( MapUtil.stringMap(), GraphDatabaseSettings.class );
LuceneDataSource ds = new LuceneDataSource( storeDir, config, new IndexConfigStore( storeDir, fileSystem ), LuceneDataSource ds = new LuceneDataSource( storeDir, config, new IndexConfigStore( storeDir, fileSystem ),
fileSystem ); fileSystem, OperationalMode.single );
ds.start(); ds.start();
ds.stop(); ds.stop();
} }
Expand Down

0 comments on commit faaa618

Please sign in to comment.