Skip to content

Commit

Permalink
Align naming and minor cleanups.
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaDemianenko committed Aug 21, 2018
1 parent 4b6d65e commit 7e2512f
Show file tree
Hide file tree
Showing 34 changed files with 147 additions and 160 deletions.
Expand Up @@ -118,11 +118,11 @@ public void shouldSucceedWithUpgradeAfterPreviousAttemptDiedDuringMigration()
StoreMigrator failingStoreMigrator = new StoreMigrator( fs, pageCache, CONFIG, logService )
{
@Override
public void migrate( DatabaseLayout sourceLayout, DatabaseLayout targetLayout,
public void migrate( DatabaseLayout directoryLayout, DatabaseLayout migrationLayout,
ProgressReporter progressReporter,
String versionToMigrateFrom, String versionToMigrateTo ) throws IOException
{
super.migrate( sourceLayout, targetLayout, progressReporter, versionToMigrateFrom,
super.migrate( directoryLayout, migrationLayout, progressReporter, versionToMigrateFrom,
versionToMigrateTo );
throw new RuntimeException( "This upgrade is failing" );
}
Expand Down Expand Up @@ -177,10 +177,10 @@ public void shouldSucceedWithUpgradeAfterPreviousAttemptDiedDuringMovingFiles()
StoreMigrator failingStoreMigrator = new StoreMigrator( fs, pageCache, CONFIG, logService )
{
@Override
public void moveMigratedFiles( DatabaseLayout migrationLayout, DatabaseLayout storeLayout, String versionToUpgradeFrom,
public void moveMigratedFiles( DatabaseLayout migrationLayout, DatabaseLayout directoryLayout, String versionToUpgradeFrom,
String versionToMigrateTo ) throws IOException
{
super.moveMigratedFiles( migrationLayout, storeLayout, versionToUpgradeFrom, versionToMigrateTo );
super.moveMigratedFiles( migrationLayout, directoryLayout, versionToUpgradeFrom, versionToMigrateTo );
throw new RuntimeException( "This upgrade is failing" );
}
};
Expand Down
Expand Up @@ -271,6 +271,12 @@ public void neostore_relationshipstore_db()

@Test
public void neostore_relationshiptypestore_db()
{
performTest( databaseLayout.idRelationshipTypeTokenStore() );
}

@Test
public void neostore_relationshiptypestore_db_names()
{
performTest( databaseLayout.idRelationshipTypeTokenNamesStore() );
}
Expand Down
Expand Up @@ -37,7 +37,6 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

import org.neo4j.dbms.database.DatabaseManager;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
Expand Down Expand Up @@ -149,8 +148,7 @@ public void setUpNeoStores()
databaseLayout = dir.databaseLayout();
Config config = Config.defaults();
pageCache = pageCacheRule.getPageCache( fs.get() );
StoreFactory sf = new StoreFactory( databaseLayout, config, new DefaultIdGeneratorFactory( fs.get() ), pageCache,
fs.get(), NullLogProvider.getInstance(), EmptyVersionContextSupplier.EMPTY );
StoreFactory sf = getStoreFactory( config, databaseLayout, fs.get(), NullLogProvider.getInstance() );
sf.openAllNeoStores( true ).close();
propertyKeyTokenHolder = new DelegatingTokenHolder( this::createPropertyKeyToken, TokenHolder.TYPE_PROPERTY_KEY );
}
Expand All @@ -164,8 +162,7 @@ private int createPropertyKeyToken( String name )
public void impossibleToGetStoreFromClosedNeoStoresContainer()
{
Config config = Config.defaults();
StoreFactory sf = new StoreFactory( databaseLayout, config, new DefaultIdGeneratorFactory( fs.get() ), pageCache,
fs.get(), NullLogProvider.getInstance(), EmptyVersionContextSupplier.EMPTY );
StoreFactory sf = getStoreFactory( config, databaseLayout, fs.get(), NullLogProvider.getInstance() );
NeoStores neoStores = sf.openAllNeoStores( true );

assertNotNull( neoStores.getMetaDataStore() );
Expand All @@ -181,8 +178,7 @@ public void impossibleToGetStoreFromClosedNeoStoresContainer()
public void notAllowCreateDynamicStoreWithNegativeBlockSize()
{
Config config = Config.defaults();
StoreFactory sf = new StoreFactory( databaseLayout, config, new DefaultIdGeneratorFactory( fs.get() ), pageCache,
fs.get(), NullLogProvider.getInstance(), EmptyVersionContextSupplier.EMPTY );
StoreFactory sf = getStoreFactory( config, databaseLayout, fs.get(), NullLogProvider.getInstance() );

exception.expect( IllegalArgumentException.class );
exception.expectMessage( "Block size of dynamic array store should be positive integer." );
Expand All @@ -197,8 +193,7 @@ public void notAllowCreateDynamicStoreWithNegativeBlockSize()
public void impossibleToGetNotRequestedStore()
{
Config config = Config.defaults();
StoreFactory sf = new StoreFactory( databaseLayout, config, new DefaultIdGeneratorFactory( fs.get() ), pageCache,
fs.get(), NullLogProvider.getInstance(), EmptyVersionContextSupplier.EMPTY );
StoreFactory sf = getStoreFactory( config, databaseLayout, fs.get(), NullLogProvider.getInstance() );

exception.expect( IllegalStateException.class );
exception.expectMessage(
Expand Down Expand Up @@ -538,8 +533,7 @@ public void setVersion() throws Exception
assertEquals( 10, MetaDataStore.setRecord( pageCache, databaseLayout.metadataStore(), Position.LOG_VERSION, 12 ) );

Config config = Config.defaults();
StoreFactory sf = new StoreFactory( databaseLayout, config, new DefaultIdGeneratorFactory( fileSystem ), pageCache,
fileSystem, LOG_PROVIDER, EmptyVersionContextSupplier.EMPTY );
StoreFactory sf = getStoreFactory( config, databaseLayout, fileSystem, LOG_PROVIDER );

NeoStores neoStores = sf.openAllNeoStores();
assertEquals( 12, neoStores.getMetaDataStore().getCurrentLogVersion() );
Expand Down Expand Up @@ -623,10 +617,7 @@ public void testSetLatestConstraintTx()
@Test
public void shouldInitializeTheTxIdToOne()
{
StoreFactory factory =
new StoreFactory( dir.databaseLayout(), Config.defaults(), new DefaultIdGeneratorFactory( fs.get() ),
pageCache, fs.get(),
LOG_PROVIDER, EmptyVersionContextSupplier.EMPTY );
StoreFactory factory = getStoreFactory( Config.defaults(), dir.databaseLayout(), fs.get(), LOG_PROVIDER );
try ( NeoStores neoStores = factory.openAllNeoStores( true ) )
{
neoStores.getMetaDataStore();
Expand All @@ -644,8 +635,7 @@ public void shouldThrowUnderlyingStorageExceptionWhenFailingToLoadStorage()
{
FileSystemAbstraction fileSystem = fs.get();
DatabaseLayout databaseLayout = dir.databaseLayout();
StoreFactory factory = new StoreFactory( databaseLayout, Config.defaults(), new DefaultIdGeneratorFactory( fileSystem ), pageCache, fileSystem,
LOG_PROVIDER, EmptyVersionContextSupplier.EMPTY );
StoreFactory factory = getStoreFactory( Config.defaults(), databaseLayout, fileSystem, LOG_PROVIDER );

try ( NeoStores neoStores = factory.openAllNeoStores( true ) )
{
Expand Down Expand Up @@ -720,8 +710,7 @@ public void shouldSetHighestTransactionIdWhenNeeded()
{
// GIVEN
FileSystemAbstraction fileSystem = fs.get();
StoreFactory factory = new StoreFactory( databaseLayout, Config.defaults(), new DefaultIdGeneratorFactory( fileSystem ), pageCache, fileSystem,
LOG_PROVIDER, EmptyVersionContextSupplier.EMPTY );
StoreFactory factory = getStoreFactory( Config.defaults(), databaseLayout, fileSystem, LOG_PROVIDER );

try ( NeoStores neoStore = factory.openAllNeoStores( true ) )
{
Expand All @@ -744,8 +733,7 @@ public void shouldNotSetHighestTransactionIdWhenNeeded()
{
// GIVEN
FileSystemAbstraction fileSystem = fs.get();
StoreFactory factory = new StoreFactory( databaseLayout, Config.defaults(), new DefaultIdGeneratorFactory( fileSystem ), pageCache, fileSystem,
LOG_PROVIDER, EmptyVersionContextSupplier.EMPTY );
StoreFactory factory = getStoreFactory( Config.defaults(), databaseLayout, fileSystem, LOG_PROVIDER );

try ( NeoStores neoStore = factory.openAllNeoStores( true ) )
{
Expand All @@ -769,9 +757,7 @@ public void shouldCloseAllTheStoreEvenIfExceptionsAreThrown() throws Exception
// given
FileSystemAbstraction fileSystem = fs.get();
Config defaults = Config.defaults( counts_store_rotation_timeout, "60m" );
StoreFactory factory =
new StoreFactory( databaseLayout, defaults, new DefaultIdGeneratorFactory( fileSystem ), pageCache,
fileSystem, LOG_PROVIDER, EmptyVersionContextSupplier.EMPTY );
StoreFactory factory = getStoreFactory( defaults, databaseLayout, fileSystem, LOG_PROVIDER );
NeoStores neoStore = factory.openAllNeoStores( true );

// let's hack the counts store so it fails to rotate and hence it fails to close as well...
Expand Down Expand Up @@ -1511,4 +1497,11 @@ private <RECEIVER extends PropertyReceiver> void receivePropertyChain( RECEIVER
}
}
}

private StoreFactory getStoreFactory( Config config, DatabaseLayout databaseLayout, FileSystemAbstraction ephemeralFileSystemAbstraction,
NullLogProvider instance )
{
return new StoreFactory( databaseLayout, config, new DefaultIdGeneratorFactory( ephemeralFileSystemAbstraction ), pageCache,
ephemeralFileSystemAbstraction, instance, EmptyVersionContextSupplier.EMPTY );
}
}
Expand Up @@ -328,7 +328,6 @@ private static void forceCheckpoint( CheckPointer checkPointer ) throws IOExcept
checkPointer.forceCheckPoint( new SimpleTriggerInfo( "testForceCheckPoint" ) );
}

//TODO:
private static String getExplicitIndexDirectory( DatabaseLayout databaseLayout )
{
File schemaIndexDirectory = LuceneDataSource.getLuceneIndexStoreDirectory( databaseLayout );
Expand Down
Expand Up @@ -258,7 +258,7 @@ void shouldCountAllIndexFiles() throws Exception
when( indexProvider2.directoryStructure() ).thenReturn( directoryStructure2 );

// Label scan store
File labelScan = testDirectory.databaseLayout().file("labelScanStore" );
File labelScan = testDirectory.databaseLayout().labelScanStore();
createFileOfSize( labelScan, 4 );
when( labelScanStore.getLabelScanStoreFile() ).thenReturn( labelScan );

Expand Down
Expand Up @@ -66,7 +66,7 @@ public interface DatabaseCreationContext
{
String getDatabaseName();

DatabaseLayout getDatabaseDirectoryStructure();
DatabaseLayout getDatabaseLayout();

Config getConfig();

Expand Down
Expand Up @@ -222,7 +222,7 @@ public class NeoStoreDataSource extends LifecycleAdapter
public NeoStoreDataSource( DatabaseCreationContext context )
{
this.databaseName = context.getDatabaseName();
this.databaseLayout = context.getDatabaseDirectoryStructure();
this.databaseLayout = context.getDatabaseLayout();
this.config = context.getConfig();
this.idGeneratorFactory = context.getIdGeneratorFactory();
this.tokenNameLookup = context.getTokenNameLookup();
Expand Down
Expand Up @@ -133,16 +133,16 @@ public static RecordFormats selectForConfig( Config config, LogProvider logProvi
* <p>
* <b>Note:</b> package private only for testing.
*
* @param dbDirectoryStructure directory with the store
* @param databaseLayout directory with the store
* @param fs file system used to access store files
* @param pageCache page cache to read store files
* @return record format of the given store or <code>null</code> if {@link DatabaseLayout#metadataStore()} file not
* found or can't be read
*/
@Nullable
static RecordFormats selectForStore( DatabaseLayout dbDirectoryStructure, FileSystemAbstraction fs, PageCache pageCache, LogProvider logProvider )
static RecordFormats selectForStore( DatabaseLayout databaseLayout, FileSystemAbstraction fs, PageCache pageCache, LogProvider logProvider )
{
File neoStoreFile = dbDirectoryStructure.metadataStore();
File neoStoreFile = databaseLayout.metadataStore();
if ( fs.fileExists( neoStoreFile ) )
{
try
Expand All @@ -156,7 +156,7 @@ static RecordFormats selectForStore( DatabaseLayout dbDirectoryStructure, FileSy
{
if ( format.storeVersion().equals( storeVersion ) )
{
info( logProvider, "Selected " + format + " record format from store " + dbDirectoryStructure.databaseDirectory() );
info( logProvider, "Selected " + format + " record format from store " + databaseLayout.databaseDirectory() );
return format;
}
}
Expand All @@ -175,20 +175,20 @@ static RecordFormats selectForStore( DatabaseLayout dbDirectoryStructure, FileSy
* record format is not configured than {@link #DEFAULT_FORMAT} is selected.
*
* @param config configuration parameters
* @param dbDirectoryStructure database directory structure
* @param databaseLayout database directory structure
* @param fs file system used to access store files
* @param pageCache page cache to read store files
* @return record format from the store (if it can be read) or configured record format or {@link #DEFAULT_FORMAT}
* @throws IllegalArgumentException when configured format is different from the format present in the store
*/
@Nonnull
public static RecordFormats selectForStoreOrConfig(
Config config, DatabaseLayout dbDirectoryStructure, FileSystemAbstraction fs, PageCache pageCache, LogProvider logProvider )
Config config, DatabaseLayout databaseLayout, FileSystemAbstraction fs, PageCache pageCache, LogProvider logProvider )
{
RecordFormats configuredFormat = loadRecordFormat( configuredRecordFormat( config ) );
boolean formatConfigured = configuredFormat != null;

RecordFormats currentFormat = selectForStore( dbDirectoryStructure, fs, pageCache, logProvider );
RecordFormats currentFormat = selectForStore( databaseLayout, fs, pageCache, logProvider );
boolean storeWithFormatExists = currentFormat != null;

if ( formatConfigured && storeWithFormatExists )
Expand Down Expand Up @@ -223,18 +223,18 @@ public static RecordFormats selectForStoreOrConfig(
* Check if store and configured formats are compatible. In case if format is not configured or store does not
* exist yet - we consider formats as compatible.
* @param config configuration parameters
* @param dbDirectoryStructure database directory structure
* @param databaseLayout database directory structure
* @param fs file system used to access store files
* @param pageCache page cache to read store files
* @param logProvider log provider
* @return true if configured and actual format is compatible, false otherwise.
*/
public static boolean isStoreAndConfigFormatsCompatible(
Config config, DatabaseLayout dbDirectoryStructure, FileSystemAbstraction fs, PageCache pageCache, LogProvider logProvider )
Config config, DatabaseLayout databaseLayout, FileSystemAbstraction fs, PageCache pageCache, LogProvider logProvider )
{
RecordFormats configuredFormat = loadRecordFormat( configuredRecordFormat( config ) );

RecordFormats currentFormat = selectForStore( dbDirectoryStructure, fs, pageCache, logProvider );
RecordFormats currentFormat = selectForStore( databaseLayout, fs, pageCache, logProvider );

return (configuredFormat == null) || (currentFormat == null) ||
(currentFormat.getFormatFamily().equals( configuredFormat.getFormatFamily() ) &&
Expand All @@ -247,15 +247,15 @@ public static boolean isStoreAndConfigFormatsCompatible(
* {@link #DEFAULT_FORMAT}.
*
* @param config configuration parameters
* @param directoryStructure database directory structure
* @param databaseLayout database directory structure
* @param fs file system used to access store files
* @param pageCache page cache to read store files
* @return record format from the store (if it can be read) or configured record format or {@link #DEFAULT_FORMAT}
* @see RecordFormats#generation()
*/
@Nonnull
public static RecordFormats selectNewestFormat(
Config config, DatabaseLayout directoryStructure, FileSystemAbstraction fs, PageCache pageCache, LogProvider logProvider )
Config config, DatabaseLayout databaseLayout, FileSystemAbstraction fs, PageCache pageCache, LogProvider logProvider )
{
boolean formatConfigured = StringUtils.isNotEmpty( configuredRecordFormat( config ) );
if ( formatConfigured )
Expand All @@ -265,7 +265,7 @@ public static RecordFormats selectNewestFormat(
}
else
{
RecordFormats result = selectForStore( directoryStructure, fs, pageCache, logProvider );
RecordFormats result = selectForStore( databaseLayout, fs, pageCache, logProvider );
if ( result == null )
{
// format was not explicitly configured and store does not exist, select default format
Expand Down
Expand Up @@ -72,7 +72,7 @@ public AbstractKeyValueStore( FileSystemAbstraction fs, PageCache pages, Databas
monitor = RotationMonitor.NONE;
}
this.format = new Format( headerFields );
this.rotationStrategy = rotation.value().create( fs, pages, format, monitor, databaseLayout, rotation.parameters() );
this.rotationStrategy = rotation.value().create( fs, pages, format, monitor, databaseLayout );
this.rotationTimerFactory = timerFactory;
this.state = new DeadState.Stopped<>( format, getClass().getAnnotation( State.class ).value(),
versionContextSupplier );
Expand Down
Expand Up @@ -37,21 +37,14 @@
{
Strategy value();

String[] parameters() default {".a", ".b"};

enum Strategy
{
LEFT_RIGHT
{
@Override
RotationStrategy create( FileSystemAbstraction fs, PageCache pages, ProgressiveFormat format,
RotationMonitor monitor, DatabaseLayout databaseLayout,
String[] parameters )
RotationMonitor monitor, DatabaseLayout databaseLayout )
{
if ( parameters == null || parameters.length != 2 )
{
throw new IllegalArgumentException( "Expected exactly 2 format parameters." );
}
final File left = databaseLayout.countStoreA();
final File right = databaseLayout.countStoreB();
return new RotationStrategy.LeftRight( fs, pages, format, monitor, left, right );
Expand All @@ -61,14 +54,13 @@ RotationStrategy create( FileSystemAbstraction fs, PageCache pages, ProgressiveF
{
@Override
RotationStrategy create( FileSystemAbstraction fs, PageCache pages, ProgressiveFormat format,
RotationMonitor monitor, DatabaseLayout databaseLayout,
String[] parameters )
RotationMonitor monitor, DatabaseLayout databaseLayout )
{
return new RotationStrategy.Incrementing( fs, pages, format, monitor, databaseLayout );
}
};

abstract RotationStrategy create( FileSystemAbstraction fs, PageCache pages, ProgressiveFormat format,
RotationMonitor monitor, DatabaseLayout databaseLayout, String... parameters );
RotationMonitor monitor, DatabaseLayout databaseLayout );
}
}
Expand Up @@ -28,7 +28,6 @@
* Different operations on a file, for example copy or move, given a {@link FileSystemAbstraction} and
* source/destination.
*/
//TODO:use layouts directly instead
public enum FileOperation
{
COPY
Expand Down

0 comments on commit 7e2512f

Please sign in to comment.