Skip to content

Commit

Permalink
Introduce StoreDirectoryStructure.
Browse files Browse the repository at this point in the history
Replace creation of database directory with structure usage.
  • Loading branch information
MishaDemianenko committed Aug 21, 2018
1 parent 931e509 commit 7f5cb05
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 20 deletions.
Expand Up @@ -195,7 +195,7 @@ public ImpermanentPlatformModule( File storeDir, Config config, DatabaseInfo dat
@Override
protected StoreLocker createStoreLocker()
{
return new StoreLocker( fileSystem, storeDir );
return new StoreLocker( fileSystem, directoryStructure.rootDirectory() );
}

@Override
Expand Down
Expand Up @@ -347,7 +347,7 @@ protected FileSystemAbstraction createNewFileSystem()
@Override
protected StoreLocker createStoreLocker()
{
return new StoreLocker( fileSystem, storeDir );
return new StoreLocker( fileSystem, directoryStructure.rootDirectory() );
}
}
}
Expand Down
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2002-2018 "Neo4j,"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.kernel.impl.store.layout;

import java.io.File;

public class StoreDirectoryStructure
{
private final File rootDirectory;

public StoreDirectoryStructure( File rootDatabasesDirectory )
{
this.rootDirectory = rootDatabasesDirectory;
}

/**
* Databases root directory where all databases are located.
* @return all databases root directory
*/
public File rootDirectory()
{
return rootDirectory;
}

public File databaseDirectory( String databaseName )
{
return new File( rootDirectory, databaseName );
}
}
Expand Up @@ -205,7 +205,7 @@ public GraphDatabaseFacade initFacade( File storeDir, Config config, final Depen
catch ( final Throwable throwable )
{
error = new RuntimeException( "Error starting " + getClass().getName() + ", " +
platform.storeDir, throwable );
platform.directoryStructure.rootDirectory(), throwable );
}
finally
{
Expand Down
Expand Up @@ -85,7 +85,6 @@ public CommunityEditionModule( PlatformModule platformModule )
LogService logging = platformModule.logging;
FileSystemAbstraction fileSystem = platformModule.fileSystem;
PageCache pageCache = platformModule.pageCache;
File storeDir = platformModule.storeDir;
DataSourceManager dataSourceManager = platformModule.dataSourceManager;
LifeSupport life = platformModule.life;
life.add( platformModule.dataSourceManager );
Expand Down Expand Up @@ -113,7 +112,8 @@ public CommunityEditionModule( PlatformModule platformModule )
new DelegatingTokenHolder( createLabelIdCreator( config, dataSourceManager ), TokenHolder.TYPE_LABEL ),
new DelegatingTokenHolder( createRelationshipTypeCreator( config, dataSourceManager ), TokenHolder.TYPE_RELATIONSHIP_TYPE ) );

dependencies.satisfyDependency( createKernelData( fileSystem, pageCache, storeDir, config, life, dataSourceManager ) );
File kernelContextDirectory = platformModule.directoryStructure.rootDirectory();
dependencies.satisfyDependency( createKernelData( fileSystem, pageCache, kernelContextDirectory, config, life, dataSourceManager ) );

commitProcessFactory = new CommunityCommitProcessFactory();

Expand Down
Expand Up @@ -45,7 +45,7 @@ public DataSourceModule( String databaseName, final PlatformModule platformModul
{

tokenHolders = editionModule.tokenHoldersSupplier.get();
File databaseDirectory = new File( platformModule.storeDir, databaseName );
File databaseDirectory = platformModule.directoryStructure.databaseDirectory( databaseName );

platformModule.diagnosticsManager.prependProvider( platformModule.config );

Expand Down
Expand Up @@ -53,8 +53,10 @@
import org.neo4j.kernel.impl.scheduler.CentralJobScheduler;
import org.neo4j.kernel.impl.security.URLAccessRules;
import org.neo4j.kernel.impl.spi.SimpleKernelContext;
import org.neo4j.kernel.impl.store.layout.StoreDirectoryStructure;
import org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointerMonitor;
import org.neo4j.kernel.impl.transaction.state.DataSourceManager;
import org.neo4j.kernel.impl.util.Dependencies;
import org.neo4j.kernel.impl.util.collection.CachingOffHeapBlockAllocator;
import org.neo4j.kernel.impl.util.collection.CollectionsFactorySupplier;
import org.neo4j.kernel.impl.util.collection.OffHeapBlockAllocator;
Expand Down Expand Up @@ -98,7 +100,7 @@ public class PlatformModule

public final LifeSupport life;

public final File storeDir;
public final StoreDirectoryStructure directoryStructure;

public final DatabaseInfo databaseInfo;

Expand Down Expand Up @@ -144,7 +146,7 @@ public PlatformModule( File providedStoreDir, Config config, DatabaseInfo databa
{
this.databaseInfo = databaseInfo;
this.dataSourceManager = new DataSourceManager();
dependencies = new org.neo4j.kernel.impl.util.Dependencies();
dependencies = new Dependencies();
dependencies.satisfyDependency( databaseInfo );

clock = dependencies.satisfyDependency( createClock() );
Expand All @@ -155,7 +157,7 @@ public PlatformModule( File providedStoreDir, Config config, DatabaseInfo databa
config.augmentDefaults( GraphDatabaseSettings.neo4j_home, providedStoreDir.getAbsolutePath() );
this.config = dependencies.satisfyDependency( config );

this.storeDir = providedStoreDir.getAbsoluteFile();
this.directoryStructure = new StoreDirectoryStructure( providedStoreDir.getAbsoluteFile() );

fileSystem = dependencies.satisfyDependency( createFileSystemAbstraction() );
life.add( new FileSystemLifecycleAdapter( fileSystem ) );
Expand Down Expand Up @@ -216,7 +218,7 @@ public PlatformModule( File providedStoreDir, Config config, DatabaseInfo databa
kernelExtensionFactories = externalDependencies.kernelExtensions();
engineProviders = externalDependencies.executionEngines();
globalKernelExtensions = dependencies.satisfyDependency(
new GlobalKernelExtensions( new SimpleKernelContext( storeDir, databaseInfo, dependencies ), kernelExtensionFactories, dependencies,
new GlobalKernelExtensions( new SimpleKernelContext( directoryStructure.rootDirectory(), databaseInfo, dependencies ), kernelExtensionFactories, dependencies,
UnsatisfiedDependencyStrategies.fail() ) );

urlAccessRule = dependencies.satisfyDependency( URLAccessRules.combined( externalDependencies.urlAccessRules() ) );
Expand All @@ -243,7 +245,7 @@ protected AvailabilityGuard createAvailabilityGuard()

protected StoreLocker createStoreLocker()
{
return new GlobalStoreLocker( fileSystem, storeDir );
return new GlobalStoreLocker( fileSystem, directoryStructure.rootDirectory() );
}

protected SystemNanoClock createClock()
Expand Down
Expand Up @@ -205,8 +205,7 @@ public EnterpriseCoreEditionModule( final PlatformModule platformModule,
config = platformModule.config;
final LogService logging = platformModule.logging;
final FileSystemAbstraction fileSystem = platformModule.fileSystem;
final File storeDir = platformModule.storeDir;
final File databaseDirectory = new File( storeDir, config.get( GraphDatabaseSettings.active_database ) );
final File databaseDirectory = platformModule.directoryStructure.databaseDirectory( config.get( GraphDatabaseSettings.active_database ) );
final LifeSupport life = platformModule.life;

CoreMonitor.register( logging.getInternalLogProvider(), logging.getUserLogProvider(), platformModule.monitors );
Expand Down Expand Up @@ -420,7 +419,7 @@ private void editionInvariants( PlatformModule platformModule, Dependencies depe
statementLocksFactory = new StatementLocksFactorySelector( lockManager, config, logging ).select();

dependencies.satisfyDependency(
createKernelData( platformModule.fileSystem, platformModule.pageCache, platformModule.storeDir,
createKernelData( platformModule.fileSystem, platformModule.pageCache, platformModule.directoryStructure.rootDirectory(),
config, platformModule.dataSourceManager, life ) );

ioLimiter = new ConfigurableIOLimiter( platformModule.config );
Expand Down
Expand Up @@ -163,8 +163,7 @@ public EnterpriseReadReplicaEditionModule( final PlatformModule platformModule,
Config config = platformModule.config;
FileSystemAbstraction fileSystem = platformModule.fileSystem;
PageCache pageCache = platformModule.pageCache;
File storeDir = platformModule.storeDir;
final File databaseDirectory = new File( storeDir, config.get( GraphDatabaseSettings.active_database ) );
final File databaseDirectory = platformModule.directoryStructure.databaseDirectory( config.get( GraphDatabaseSettings.active_database ) );

LifeSupport life = platformModule.life;

Expand Down Expand Up @@ -192,7 +191,8 @@ public EnterpriseReadReplicaEditionModule( final PlatformModule platformModule,
new DelegatingTokenHolder( new ReadOnlyTokenCreator(), TokenHolder.TYPE_LABEL ),
new DelegatingTokenHolder( new ReadOnlyTokenCreator(), TokenHolder.TYPE_RELATIONSHIP_TYPE ) );

life.add( dependencies.satisfyDependency( new KernelData( fileSystem, pageCache, storeDir, config, platformModule.dataSourceManager ) ) );
File contextDirectory = platformModule.directoryStructure.rootDirectory();
life.add( dependencies.satisfyDependency( new KernelData( fileSystem, pageCache, contextDirectory, config, platformModule.dataSourceManager ) ) );

headerInformationFactory = TransactionHeaderInformationFactory.DEFAULT;

Expand Down
Expand Up @@ -213,7 +213,6 @@ public HighlyAvailableEditionModule( final PlatformModule platformModule )
final LifeSupport clusteringLife = new LifeSupport();

final FileSystemAbstraction fs = platformModule.fileSystem;
final File storeDir = platformModule.storeDir;
final Config config = platformModule.config;
final Dependencies dependencies = platformModule.dependencies;
final LogService logging = platformModule.logging;
Expand All @@ -229,7 +228,7 @@ public HighlyAvailableEditionModule( final PlatformModule platformModule )
// Set Netty logger
InternalLoggerFactory.setDefaultFactory( new NettyLoggerFactory( logging.getInternalLogProvider() ) );

File databaseDirectory = new File( platformModule.storeDir, DatabaseManager.DEFAULT_DATABASE_NAME );
File databaseDirectory = platformModule.directoryStructure.databaseDirectory( DatabaseManager.DEFAULT_DATABASE_NAME );
life.add( new BranchedDataMigrator( databaseDirectory ) );
DelegateInvocationHandler<Master> masterDelegateInvocationHandler =
new DelegateInvocationHandler<>( Master.class );
Expand Down Expand Up @@ -518,7 +517,7 @@ public void elected( String role, InstanceId instanceId, URI electedMember )

dependencies.satisfyDependency(
createKernelData( config, platformModule.dataSourceManager, members, fs, platformModule.pageCache,
storeDir, lastUpdateTime, lastTxIdGetter, life ) );
platformModule.directoryStructure.rootDirectory(), lastUpdateTime, lastTxIdGetter, life ) );

commitProcessFactory = createCommitProcessFactory( dependencies, logging, monitors, config, paxosLife,
clusterClient, members, platformModule.jobScheduler, master, requestContextFactory,
Expand Down

0 comments on commit 7f5cb05

Please sign in to comment.