Skip to content

Commit

Permalink
Introduce system database.
Browse files Browse the repository at this point in the history
Introduce system database in commercial editions.
Partial update of database - old data source manager relationships.
Make dataSource dependent extensions database scoped.
Start of DataSource module dependencies cleanup.
  • Loading branch information
MishaDemianenko committed Aug 1, 2018
1 parent 69e1f4f commit 6c03fae
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 36 deletions.
Expand Up @@ -351,6 +351,7 @@ public void start() throws IOException
dataSourceDependencies.satisfyDependency( facade );

life = new LifeSupport();
dataSourceDependencies.satisfyDependency( explicitIndexProvider );
life.add( initializeExtensions( dataSourceDependencies ) );
life.add( recoveryCleanupWorkCollector );
dataSourceDependencies.satisfyDependency( lockService );
Expand Down Expand Up @@ -442,7 +443,6 @@ public void start() throws IOException
dataSourceDependencies.satisfyDependency( databaseSchemaState );
dataSourceDependencies.satisfyDependency( logEntryReader );
dataSourceDependencies.satisfyDependency( storageEngine );
dataSourceDependencies.satisfyDependency( explicitIndexProvider );

executionEngine = QueryEngineProvider.initialize( dataSourceDependencies, facade, engineProviders );
}
Expand Down
Expand Up @@ -19,6 +19,8 @@
*/
package org.neo4j.kernel.impl.transaction.state;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;

import org.neo4j.helpers.Listeners;
Expand All @@ -45,18 +47,15 @@ public interface Listener

private LifeSupport life = new LifeSupport();
private final Listeners<Listener> dsRegistrationListeners = new Listeners<>();
private NeoStoreDataSource dataSource;
private List<NeoStoreDataSource> dataSources = new ArrayList<>();

public void addListener( Listener listener )
{
if ( life.getStatus().equals( LifecycleStatus.STARTED ) )
{
try
{
if ( dataSource != null )
{
listener.registered( dataSource );
}
dataSources.forEach( listener::registered );
}
catch ( Throwable t )
{ // OK
Expand All @@ -67,34 +66,31 @@ public void addListener( Listener listener )

public void register( NeoStoreDataSource dataSource )
{
//TODO: temp workaround for multiple listeners
if ( this.dataSource == null )
dataSources.add( dataSource );
if ( life.getStatus().equals( LifecycleStatus.STARTED ) )
{
this.dataSource = dataSource;
if ( life.getStatus().equals( LifecycleStatus.STARTED ) )
{
dsRegistrationListeners.notify( listener -> listener.registered( dataSource ) );
}
life.add( dataSource );
dsRegistrationListeners.notify( listener -> listener.registered( dataSource ) );
}
}

public void unregister( NeoStoreDataSource dataSource )
{
this.dataSource = null;
dataSources.remove( dataSource );
dsRegistrationListeners.notify( listener -> listener.unregistered( dataSource ) );
life.remove( dataSource );
}

public NeoStoreDataSource getDataSource()
{
return dataSource;
return dataSources.get( 0 );
}

@Override
public void init()
{
life = new LifeSupport();
life.add( dataSource );
dataSources.forEach( life::add );
}

@Override
Expand All @@ -106,10 +102,7 @@ public void start()
{
try
{
if ( dataSource != null )
{
listener.registered( dataSource );
}
dataSources.forEach( listener::registered );
}
catch ( Throwable t )
{ // OK
Expand All @@ -127,12 +120,12 @@ public void stop()
public void shutdown()
{
life.shutdown();
dataSource = null;
dataSources.clear();
}

@Override
public Kernel get()
{
return dataSource.getKernel();
return dataSources.get( 0 ).getKernel();
}
}
Expand Up @@ -32,17 +32,17 @@

public class LuceneKernelExtension extends LifecycleAdapter
{
private final File storeDir;
private final File databaseDirectory;
private final Config config;
private final Supplier<IndexConfigStore> indexStore;
private final FileSystemAbstraction fileSystemAbstraction;
private final IndexProviders indexProviders;
private final OperationalMode operationalMode;

public LuceneKernelExtension( File storeDir, Config config, Supplier<IndexConfigStore> indexStore,
public LuceneKernelExtension( File databaseDirecytory, Config config, Supplier<IndexConfigStore> indexStore,
FileSystemAbstraction fileSystemAbstraction, IndexProviders indexProviders, OperationalMode operationalMode )
{
this.storeDir = storeDir;
this.databaseDirectory = databaseDirecytory;
this.config = config;
this.indexStore = indexStore;
this.fileSystemAbstraction = fileSystemAbstraction;
Expand All @@ -54,7 +54,7 @@ public LuceneKernelExtension( File storeDir, Config config, Supplier<IndexConfig
public void init()
{
LuceneIndexImplementation indexImplementation =
new LuceneIndexImplementation( storeDir, config, indexStore, fileSystemAbstraction, operationalMode );
new LuceneIndexImplementation( databaseDirectory, config, indexStore, fileSystemAbstraction, operationalMode );
indexProviders.registerIndexProvider( LuceneIndexImplementation.SERVICE_NAME, indexImplementation );
}

Expand Down
Expand Up @@ -64,6 +64,7 @@ public GraphDatabaseFacade createDatabase( String name )
DataSourceModule dataSource = new DataSourceModule( name, platform, edition, procedures, graphDatabaseFacade );
ClassicCoreSPI spi = new ClassicCoreSPI( platform, dataSource, msgLog, edition.coreAPIAvailabilityGuard );
graphDatabaseFacade.init( spi, dataSource.threadToTransactionBridge, platform.config, dataSource.tokenHolders );
platform.dataSourceManager.register( dataSource.neoStoreDataSource );
database = graphDatabaseFacade;
return database;
}
Expand Down
Expand Up @@ -184,7 +184,9 @@ public GraphDatabaseFacade initFacade( File storeDir, Config config, final Depen
platform.life.add( new StartupWaiter( platform.availabilityGuard, edition.transactionStartTimeout ) );
platform.life.setLast( platform.eventHandlers );

GraphDatabaseFacade databaseFacade = databaseManager.createDatabase( config.get( GraphDatabaseSettings.active_database ) );
edition.createDatabases( databaseManager, config );

GraphDatabaseFacade databaseFacade = databaseManager.getDatabaseFacade( config.get( GraphDatabaseSettings.active_database ) ).get();

RuntimeException error = null;
try
Expand Down
Expand Up @@ -113,7 +113,6 @@ public DataSourceModule( String databaseName, final PlatformModule platformModul
IndexConfigStore indexConfigStore = new IndexConfigStore( databaseDirectory, fileSystem );
deps.satisfyDependencies( indexConfigStore );
DefaultExplicitIndexProvider explicitIndexProvider = new DefaultExplicitIndexProvider();
deps.satisfyDependencies( explicitIndexProvider );

NonTransactionalTokenNameLookup tokenNameLookup = new NonTransactionalTokenNameLookup( tokenHolders );

Expand Down Expand Up @@ -162,8 +161,6 @@ public DataSourceModule( String databaseName, final PlatformModule platformModul
graphDatabaseFacade,
platformModule.engineProviders ) );

dataSourceManager.register( neoStoreDataSource );

this.storeId = neoStoreDataSource::getStoreId;
this.kernelAPI = neoStoreDataSource::getKernel;

Expand Down
Expand Up @@ -265,4 +265,9 @@ protected DefaultIdController createDefaultIdController()
{
return new DefaultIdController();
}

public void createDatabases( DatabaseManager databaseManager, Config config )
{
databaseManager.createDatabase( config.get( GraphDatabaseSettings.active_database ) );
}
}
Expand Up @@ -26,7 +26,9 @@

import java.io.File;
import java.util.Collections;
import java.util.Optional;

import org.neo4j.dbms.database.DatabaseManager;
import org.neo4j.graphdb.factory.module.EditionModule;
import org.neo4j.graphdb.factory.module.PlatformModule;
import org.neo4j.helpers.Exceptions;
Expand Down Expand Up @@ -70,7 +72,7 @@ void setup()
void shouldThrowAppropriateExceptionIfStartFails()
{
RuntimeException startupError = new RuntimeException();
GraphDatabaseFacadeFactory db = newFaultyGraphDatabaseFacadeFactory( startupError );
GraphDatabaseFacadeFactory db = newFaultyGraphDatabaseFacadeFactory( startupError, mockFacade );
RuntimeException startException =
assertThrows( RuntimeException.class, () -> db.initFacade( testDirectory.storeDir(), Collections.emptyMap(), deps, mockFacade ) );
assertEquals( startupError, Exceptions.rootCause( startException ) );
Expand All @@ -82,7 +84,7 @@ void shouldThrowAppropriateExceptionIfBothStartAndShutdownFail()
RuntimeException startupError = new RuntimeException();
RuntimeException shutdownError = new RuntimeException();

GraphDatabaseFacadeFactory db = newFaultyGraphDatabaseFacadeFactory( startupError );
GraphDatabaseFacadeFactory db = newFaultyGraphDatabaseFacadeFactory( startupError, mockFacade );
doThrow( shutdownError ).when( mockFacade ).shutdown();
RuntimeException initException =
assertThrows( RuntimeException.class, () -> db.initFacade( testDirectory.storeDir(), Collections.emptyMap(), deps, mockFacade ) );
Expand All @@ -92,10 +94,16 @@ void shouldThrowAppropriateExceptionIfBothStartAndShutdownFail()
assertEquals( shutdownError, initException.getSuppressed()[0] );
}

private static GraphDatabaseFacadeFactory newFaultyGraphDatabaseFacadeFactory( final RuntimeException startupError )
private static GraphDatabaseFacadeFactory newFaultyGraphDatabaseFacadeFactory( final RuntimeException startupError, GraphDatabaseFacade facade )
{
return new GraphDatabaseFacadeFactory( DatabaseInfo.UNKNOWN,
p -> mock( EditionModule.class, Mockito.RETURNS_DEEP_STUBS ) )
return new GraphDatabaseFacadeFactory( DatabaseInfo.UNKNOWN, p ->
{
EditionModule editionModule = mock( EditionModule.class, Mockito.RETURNS_DEEP_STUBS );
DatabaseManager databaseManager = mock( DatabaseManager.class );
when( databaseManager.getDatabaseFacade( DatabaseManager.DEFAULT_DATABASE_NAME ) ).thenReturn( Optional.of( facade ) );
when( editionModule.createDatabaseManager( any(), any(), any(), any(), any() ) ).thenReturn( databaseManager );
return editionModule;
} )
{
@Override
protected PlatformModule createPlatform( File storeDir, Config config, Dependencies dependencies )
Expand Down
Expand Up @@ -27,6 +27,7 @@
import org.neo4j.io.pagecache.PageCache;
import org.neo4j.kernel.AvailabilityGuard;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.extension.ExtensionType;
import org.neo4j.kernel.extension.KernelExtensionFactory;
import org.neo4j.kernel.impl.logging.LogService;
import org.neo4j.kernel.impl.spi.KernelContext;
Expand Down Expand Up @@ -61,7 +62,7 @@ public interface Dependencies

public PageCacheWarmerKernelExtensionFactory()
{
super( "pagecachewarmer" );
super( ExtensionType.DATABASE, "pagecachewarmer" );
}

@Override
Expand Down

0 comments on commit 6c03fae

Please sign in to comment.