Skip to content

Commit

Permalink
Switch to using factory methods
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaDemianenko committed Aug 21, 2018
1 parent 48abee2 commit 8e1c273
Show file tree
Hide file tree
Showing 50 changed files with 92 additions and 83 deletions.
Expand Up @@ -183,7 +183,7 @@ public void execute( String[] args ) throws IncorrectUsage, CommandFailed
try ( FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction() )
{
File databaseDirectory = backupPath.map( Path::toFile ).orElse( config.get( database_path ) );
DatabaseLayout databaseLayout = new DatabaseLayout( databaseDirectory );
DatabaseLayout databaseLayout = DatabaseLayout.of( databaseDirectory );
checkDbState( databaseLayout, config );
ZoneId logTimeZone = config.get( GraphDatabaseSettings.db_timezone ).getZoneId();
// Only output progress indicator if a console receives the output
Expand Down
Expand Up @@ -113,7 +113,7 @@ ConsistencyCheckService.Result run( String... args ) throws ToolFailureException
Config tuningConfiguration = readConfiguration( arguments );
boolean verbose = isVerbose( arguments );

DatabaseLayout databaseLayout = new DatabaseLayout( storeDir );
DatabaseLayout databaseLayout = DatabaseLayout.of( storeDir );
checkDbState( databaseLayout, tuningConfiguration );

ZoneId logTimeZone = tuningConfiguration.get( GraphDatabaseSettings.db_timezone ).getZoneId();
Expand Down
Expand Up @@ -76,7 +76,7 @@ void runsConsistencyChecker() throws Exception
new CheckConsistencyCommand( homeDir, testDir.directory( "conf" ).toPath(), outsideWorld,
consistencyCheckService );

DatabaseLayout databaseLayout = new DatabaseLayout( databasesFolder, "mydb" );
DatabaseLayout databaseLayout = DatabaseLayout.of( databasesFolder, "mydb" );

when( consistencyCheckService
.runFullConsistencyCheck( eq( databaseLayout ), any( Config.class ), any( ProgressMonitorFactory.class ),
Expand Down Expand Up @@ -104,7 +104,7 @@ void enablesVerbosity() throws Exception
new CheckConsistencyCommand( homeDir, testDir.directory( "conf" ).toPath(), outsideWorld,
consistencyCheckService );

DatabaseLayout databaseLayout = new DatabaseLayout( databasesFolder, "mydb" );
DatabaseLayout databaseLayout = DatabaseLayout.of( databasesFolder, "mydb" );

when( consistencyCheckService
.runFullConsistencyCheck( eq( databaseLayout ), any( Config.class ), any( ProgressMonitorFactory.class ),
Expand All @@ -131,7 +131,7 @@ void failsWhenInconsistenciesAreFound() throws Exception
CheckConsistencyCommand checkConsistencyCommand =
new CheckConsistencyCommand( homeDir, testDir.directory( "conf" ).toPath(), outsideWorld,
consistencyCheckService );
DatabaseLayout databaseLayout = new DatabaseLayout( databasesFolder, "mydb" );
DatabaseLayout databaseLayout = DatabaseLayout.of( databasesFolder, "mydb" );

when( consistencyCheckService
.runFullConsistencyCheck( eq( databaseLayout ), any( Config.class ), any( ProgressMonitorFactory.class ),
Expand Down
Expand Up @@ -125,7 +125,7 @@ public void doImport() throws IOException
new WrappedCsvInputConfigurationForNeo4jAdmin( csvConfiguration( args, false ) ),
badCollector );

ImportTool.doImport( outsideWorld.errorStream(), outsideWorld.errorStream(), outsideWorld.inStream(), new DatabaseLayout( storeDir ), logsDir,
ImportTool.doImport( outsideWorld.errorStream(), outsideWorld.errorStream(), outsideWorld.inStream(), DatabaseLayout.of( storeDir ), logsDir,
reportFile, fs, nodesFiles, relationshipsFiles, false, input, this.databaseConfig, badOutput, configuration, false );
}

Expand Down
Expand Up @@ -481,7 +481,7 @@ public static void main( String[] incomingArguments, boolean defaultSettingsSuit
in = defaultSettingsSuitableForTests ? new ByteArrayInputStream( EMPTY_BYTE_ARRAY ) : System.in;
boolean detailedPrinting = args.getBoolean( Options.DETAILED_PROGRESS.key(), (Boolean) Options.DETAILED_PROGRESS.defaultValue() );

doImport( out, err, in, new DatabaseLayout( storeDir ), logsDir, badFile, fs, nodesFiles, relationshipsFiles,
doImport( out, err, in, DatabaseLayout.of( storeDir ), logsDir, badFile, fs, nodesFiles, relationshipsFiles,
enableStacktrace, input, dbConfig, badOutput, configuration, detailedPrinting );

success = true;
Expand Down
Expand Up @@ -168,7 +168,7 @@ public long maxMemoryUsage()
{
System.out.println( "Seed " + randomSeed );
final JobScheduler jobScheduler = life.add( new CentralJobScheduler() );
consumer = BatchImporterFactory.withHighestPriority().instantiate( new DatabaseLayout( dir ), fileSystem, null, importConfig,
consumer = BatchImporterFactory.withHighestPriority().instantiate( DatabaseLayout.of( dir ), fileSystem, null, importConfig,
new SimpleLogService( logging, logging ), defaultVisible( jobScheduler ), EMPTY, dbConfig,
RecordFormatSelector.selectForConfig( dbConfig, logging ), NO_MONITOR );
ImportTool.printOverview( dir, Collections.emptyList(), Collections.emptyList(), importConfig, System.out );
Expand Down
16 changes: 13 additions & 3 deletions community/io/src/main/java/org/neo4j/io/layout/DatabaseLayout.java
Expand Up @@ -29,13 +29,23 @@ public class DatabaseLayout
private final File databaseDirectory;
private final File databasesDirectory;

public DatabaseLayout( File databaseDirectory )
public static DatabaseLayout of( File databaseDirectory )
{
return new DatabaseLayout( databaseDirectory );
}

public static DatabaseLayout of( File rootDirectory, String databaseName )
{
return new DatabaseLayout( rootDirectory, databaseName );
}

private DatabaseLayout( File databaseDirectory )
{
this.databaseDirectory = databaseDirectory;
this.databasesDirectory = databaseDirectory.getParentFile();
}

public DatabaseLayout( File rootDirectory, String databaseName )
private DatabaseLayout( File rootDirectory, String databaseName )
{
this.databasesDirectory = rootDirectory;
this.databaseDirectory = new File( rootDirectory, databaseName );
Expand Down Expand Up @@ -70,7 +80,7 @@ public File[] listDatabaseFiles( FilenameFilter filter )
@Override
public String toString()
{
return "DatabaseLayout{" + "databaseDirectory=" + databaseDirectory + '}';
return String.valueOf( databaseDirectory );
}

@Override
Expand Down
Expand Up @@ -42,6 +42,6 @@ public File rootDirectory()
//TODO:rename
public DatabaseLayout databaseDirectory( String databaseName )
{
return new DatabaseLayout( rootDirectory, databaseName );
return DatabaseLayout.of( rootDirectory, databaseName );
}
}
Expand Up @@ -105,7 +105,7 @@ public void addParticipant( StoreMigrationParticipant participant )

public void migrateIfNeeded( DatabaseLayout dbDirectoryStructure )
{
DatabaseLayout migrationStructure = new DatabaseLayout( dbDirectoryStructure.databaseDirectory(), MIGRATION_DIRECTORY );
DatabaseLayout migrationStructure = DatabaseLayout.of( dbDirectoryStructure.databaseDirectory(), MIGRATION_DIRECTORY );

cleanupLegacyLeftOverDirsIn( dbDirectoryStructure.databaseDirectory() );

Expand Down
Expand Up @@ -91,7 +91,7 @@ static List<File> matchingFiles( File fileWithRegexInName )
{
try ( FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction() )
{
if ( isExistingDatabase( fileSystem, new DatabaseLayout( value ) ) )
if ( isExistingDatabase( fileSystem, DatabaseLayout.of( value ) ) )
{
throw new IllegalArgumentException( "Directory '" + value + "' already contains a database" );
}
Expand All @@ -106,7 +106,7 @@ static List<File> matchingFiles( File fileWithRegexInName )
{
try ( FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction() )
{
if ( !isExistingDatabase( fileSystem, new DatabaseLayout( dbDir ) ) )
if ( !isExistingDatabase( fileSystem, DatabaseLayout.of( dbDir ) ) )
{
throw new IllegalArgumentException( "Directory '" + dbDir + "' does not contain a database" );
}
Expand Down
Expand Up @@ -246,7 +246,7 @@ public BatchInserterImpl( final File databaseDirectory, final FileSystemAbstract
this.fileSystem = fileSystem;

life = new LifeSupport();
this.directoryStructure = new DatabaseLayout( databaseDirectory );
this.directoryStructure = DatabaseLayout.of( databaseDirectory );
storeLocker = tryLockStore( fileSystem );
ConfiguringPageCacheFactory pageCacheFactory = new ConfiguringPageCacheFactory(
fileSystem, config, PageCacheTracer.NULL, PageCursorTracerSupplier.NULL, NullLog.getInstance(),
Expand Down
Expand Up @@ -134,7 +134,7 @@ private BatchingNeoStores( FileSystemAbstraction fileSystem, PageCache pageCache
this.importConfiguration = importConfiguration;
this.initialIds = initialIds;
this.logProvider = logService.getInternalLogProvider();
this.directoryStructure = new DatabaseLayout( databaseDirectory );
this.directoryStructure = DatabaseLayout.of( databaseDirectory );
this.neo4jConfig = neo4jConfig;
this.pageCache = pageCache;
this.ioTracer = ioTracer;
Expand Down
Expand Up @@ -54,8 +54,8 @@ public class ExplicitIndexMigratorTest
private final FileSystemAbstraction fs = mock( FileSystemAbstraction.class );
private final LogProvider logProvider = mock( LogProvider.class );
private final ProgressReporter progressMonitor = mock( ProgressReporter.class );
private final DatabaseLayout storeLayout = new DatabaseLayout( new File( DatabaseManager.DEFAULT_DATABASE_NAME ) );
private final DatabaseLayout migrationLayout = new DatabaseLayout( new File( StoreUpgrader.MIGRATION_DIRECTORY ) );
private final DatabaseLayout storeLayout = DatabaseLayout.of( new File( DatabaseManager.DEFAULT_DATABASE_NAME ) );
private final DatabaseLayout migrationLayout = DatabaseLayout.of( new File( StoreUpgrader.MIGRATION_DIRECTORY ) );
private final File originalIndexStore = mock( File.class );
private final File migratedIndexStore = new File( "." );

Expand Down
Expand Up @@ -24,8 +24,8 @@
import java.io.File;
import java.io.IOException;

import org.neo4j.internal.kernel.api.schema.IndexProviderDescriptor;
import org.neo4j.dbms.database.DatabaseManager;
import org.neo4j.internal.kernel.api.schema.IndexProviderDescriptor;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.layout.DatabaseLayout;
import org.neo4j.kernel.api.index.IndexDirectoryStructure;
Expand All @@ -43,8 +43,8 @@ public class SchemaIndexMigratorTest
private final FileSystemAbstraction fs = mock( FileSystemAbstraction.class );
private final ProgressReporter progressReporter = mock( ProgressReporter.class );
private final IndexProvider indexProvider = mock( IndexProvider.class );
private final DatabaseLayout databaseLayout = new DatabaseLayout( new File( "store" ), DatabaseManager.DEFAULT_DATABASE_NAME );
private final DatabaseLayout migrationLayout = new DatabaseLayout( new File( "migrationDir" ), DatabaseManager.DEFAULT_DATABASE_NAME );
private final DatabaseLayout databaseLayout = DatabaseLayout.of( new File( "store" ), DatabaseManager.DEFAULT_DATABASE_NAME );
private final DatabaseLayout migrationLayout = DatabaseLayout.of( new File( "migrationDir" ), DatabaseManager.DEFAULT_DATABASE_NAME );

private final SchemaIndexMigrator migrator = new SchemaIndexMigrator( fs, indexProvider );

Expand Down
Expand Up @@ -43,7 +43,7 @@ public class LuceneKernelExtension extends LifecycleAdapter
public LuceneKernelExtension( File databaseDirectory, Config config, Supplier<IndexConfigStore> indexStore,
FileSystemAbstraction fileSystemAbstraction, IndexProviders indexProviders, OperationalMode operationalMode )
{
this.databaseLayout = new DatabaseLayout( databaseDirectory );
this.databaseLayout = DatabaseLayout.of( databaseDirectory );
this.config = config;
this.indexStore = indexStore;
this.fileSystemAbstraction = fileSystemAbstraction;
Expand Down
Expand Up @@ -209,7 +209,7 @@ BackupOutcome executeBackup( HostnamePort hostnamePort, Path to, ConsistencyChec
String host = hostnamePort.getHost();
int port = hostnamePort.getPort();

BackupOutcome outcome = backupProtocolService.doIncrementalBackupOrFallbackToFull( host, port, new DatabaseLayout( to.toFile() ),
BackupOutcome outcome = backupProtocolService.doIncrementalBackupOrFallbackToFull( host, port, DatabaseLayout.of( to.toFile() ),
consistencyCheck, config, timeout, forensics );
systemOut.println( "Done" );
return outcome;
Expand Down
Expand Up @@ -110,7 +110,7 @@ public OnlineBackup backup( String targetDirectory )
public OnlineBackup backup( File targetDirectory )
{
outcome = new BackupProtocolService( out ).doIncrementalBackupOrFallbackToFull(
hostNameOrIp, port, new DatabaseLayout( targetDirectory ), getConsistencyCheck( true ), defaultConfig(), timeoutMillis, forensics );
hostNameOrIp, port, DatabaseLayout.of( targetDirectory ), getConsistencyCheck( true ), defaultConfig(), timeoutMillis, forensics );
return this;
}

Expand Down Expand Up @@ -144,7 +144,7 @@ public OnlineBackup backup( String targetDirectory, boolean verification )
public OnlineBackup backup( File targetDirectory, boolean verification )
{
outcome = new BackupProtocolService( out ).doIncrementalBackupOrFallbackToFull(
hostNameOrIp, port, new DatabaseLayout( targetDirectory ), getConsistencyCheck( verification ), defaultConfig(),
hostNameOrIp, port, DatabaseLayout.of( targetDirectory ), getConsistencyCheck( verification ), defaultConfig(),
timeoutMillis, forensics );
return this;
}
Expand Down Expand Up @@ -178,7 +178,7 @@ public OnlineBackup backup( String targetDirectory, Config tuningConfiguration )
public OnlineBackup backup( File targetDirectory, Config tuningConfiguration )
{
outcome = new BackupProtocolService( out ).doIncrementalBackupOrFallbackToFull(
hostNameOrIp, port, new DatabaseLayout( targetDirectory ), getConsistencyCheck( true ), tuningConfiguration,
hostNameOrIp, port, DatabaseLayout.of( targetDirectory ), getConsistencyCheck( true ), tuningConfiguration,
timeoutMillis, forensics );
return this;
}
Expand Down Expand Up @@ -215,7 +215,7 @@ public OnlineBackup backup( String targetDirectory, Config tuningConfiguration,
public OnlineBackup backup( File targetDirectory, Config tuningConfiguration, boolean verification )
{
outcome = new BackupProtocolService( out ).doIncrementalBackupOrFallbackToFull(
hostNameOrIp, port, new DatabaseLayout( targetDirectory ), getConsistencyCheck( verification ), tuningConfiguration,
hostNameOrIp, port, DatabaseLayout.of( targetDirectory ), getConsistencyCheck( verification ), tuningConfiguration,
timeoutMillis, forensics );
return this;
}
Expand Down Expand Up @@ -417,7 +417,7 @@ public OnlineBackup gatheringForensics( boolean forensics )

private static DatabaseLayout getTargetDatabaseLayout( String targetDirectory )
{
return new DatabaseLayout( Paths.get( targetDirectory ).toFile() );
return DatabaseLayout.of( Paths.get( targetDirectory ).toFile() );
}

private static ConsistencyCheck getConsistencyCheck( boolean verification )
Expand Down
Expand Up @@ -124,7 +124,7 @@ Path findAnAvailableLocationForNewFullBackup( Path desiredBackupLocation )
*/
private Path findAnAvailableBackupLocation( Path file, String pattern )
{
if ( backupExists( new DatabaseLayout( file.toFile() ) ) )
if ( backupExists( DatabaseLayout.of( file.toFile() ) ) )
{
// find alternative name
final AtomicLong counter = new AtomicLong( 0 );
Expand All @@ -133,7 +133,7 @@ private Path findAnAvailableBackupLocation( Path file, String pattern )

return availableAlternativeNames( file, pattern )
.peek( countNumberOfFilesProcessedForPotentialErrorMessage )
.filter( f -> !backupExists( new DatabaseLayout( f.toFile() ) ) )
.filter( f -> !backupExists( DatabaseLayout.of( f.toFile() ) ) )
.findFirst()
.orElseThrow( noFreeBackupLocation( file, counter ) );
}
Expand Down
Expand Up @@ -103,7 +103,7 @@ public void performBackup( OnlineBackupContext onlineBackupContext ) throws Comm
}
if ( requiredArgs.isDoConsistencyCheck() )
{
performConsistencyCheck( onlineBackupContext.getConfig(), requiredArgs, consistencyFlags, new DatabaseLayout( destination.toFile() ) );
performConsistencyCheck( onlineBackupContext.getConfig(), requiredArgs, consistencyFlags, DatabaseLayout.of( destination.toFile() ) );
}
}

Expand Down
Expand Up @@ -83,12 +83,12 @@ private Fallible<BackupStrategyOutcome> performBackupWithoutLifecycle(
log.debug( "User specified address is %s:%s", userSpecifiedAddress.getHostname().toString(), userSpecifiedAddress.getPort().toString() );
Config config = onlineBackupContext.getConfig();

boolean previousBackupExists = backupCopyService.backupExists( new DatabaseLayout( backupLocation.toFile() ) );
boolean previousBackupExists = backupCopyService.backupExists( DatabaseLayout.of( backupLocation.toFile() ) );
if ( previousBackupExists )
{
log.info( "Previous backup found, trying incremental backup." );
Fallible<BackupStageOutcome> state =
backupStrategy.performIncrementalBackup( new DatabaseLayout( backupLocation.toFile() ), config, userSpecifiedAddress );
backupStrategy.performIncrementalBackup( DatabaseLayout.of( backupLocation.toFile() ), config, userSpecifiedAddress );
boolean fullBackupWontWork = BackupStageOutcome.WRONG_PROTOCOL.equals( state.getState() );
boolean incrementalWasSuccessful = BackupStageOutcome.SUCCESS.equals( state.getState() );

Expand Down Expand Up @@ -143,7 +143,7 @@ private Fallible<BackupStageOutcome> fullBackupWithTemporaryFolderResolutions(
Path temporaryFullBackupLocation = backupCopyService.findAnAvailableLocationForNewFullBackup( userSpecifiedBackupLocation );

OptionalHostnamePort address = onlineBackupContext.getRequiredArguments().getAddress();
Fallible<BackupStageOutcome> state = backupStrategy.performFullBackup( new DatabaseLayout( temporaryFullBackupLocation.toFile() ), config, address );
Fallible<BackupStageOutcome> state = backupStrategy.performFullBackup( DatabaseLayout.of( temporaryFullBackupLocation.toFile() ), config, address );

// NOTE temporaryFullBackupLocation can be equal to desired
boolean aBackupAlreadyExisted = !userSpecifiedBackupLocation.equals( temporaryFullBackupLocation );
Expand Down
Expand Up @@ -105,7 +105,7 @@ public void shouldInvokeBackupServiceWhenArgsAreValid() throws Exception
// Then
verify( backupProtocolService ).doIncrementalBackupOrFallbackToFull(
eq( HOST ),
eq( PORT ), eq( new DatabaseLayout( PATH.toFile() ) ),
eq( PORT ), eq( DatabaseLayout.of( PATH.toFile() ) ),
expectedVerifyStoreValue ? eq( ConsistencyCheck.FULL ) : eq( ConsistencyCheck.NONE ),
any( Config.class ),
eq( BackupClient.BIG_READ_TIMEOUT ),
Expand Down

0 comments on commit 8e1c273

Please sign in to comment.