Skip to content

Commit

Permalink
Propagate database name up to id generator open calls
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaDemianenko committed Aug 14, 2018
1 parent 8cd3841 commit b6d3e9b
Show file tree
Hide file tree
Showing 96 changed files with 391 additions and 450 deletions.
Expand Up @@ -33,6 +33,7 @@
import org.neo4j.consistency.statistics.DefaultCounts;
import org.neo4j.consistency.statistics.Statistics;
import org.neo4j.consistency.statistics.VerboseStatistics;
import org.neo4j.dbms.database.DatabaseManager;
import org.neo4j.graphdb.DependencyResolver;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.factory.GraphDatabaseBuilder;
Expand Down Expand Up @@ -164,7 +165,7 @@ public DirectStoreAccess directStoreAccess()
LogProvider logProvider = NullLogProvider.getInstance();
Config config = Config.defaults();
DefaultIdGeneratorFactory idGeneratorFactory = new DefaultIdGeneratorFactory( fileSystem );
StoreFactory storeFactory = new StoreFactory(
StoreFactory storeFactory = new StoreFactory( DatabaseManager.DEFAULT_DATABASE_NAME,
directory.databaseDir(), config, idGeneratorFactory, pageCache, fileSystem, logProvider, EmptyVersionContextSupplier.EMPTY );
neoStore = storeFactory.openAllNeoStores();
StoreAccess nativeStores;
Expand Down
Expand Up @@ -27,6 +27,7 @@
import org.neo4j.consistency.RecordType;
import org.neo4j.consistency.report.ConsistencySummaryStatistics;
import org.neo4j.consistency.statistics.Statistics;
import org.neo4j.dbms.database.DatabaseManager;
import org.neo4j.graphdb.DependencyResolver;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
Expand Down Expand Up @@ -149,7 +150,7 @@ public void shouldDetectSabotagedRelationshipWhereEverItIs() throws Exception
private StoreFactory newStoreFactory( PageCache pageCache )
{
FileSystemAbstraction fileSystem = fileSystemRule.get();
return new StoreFactory( directory.databaseDir(), getTuningConfiguration(),
return new StoreFactory( DatabaseManager.DEFAULT_DATABASE_NAME, directory.databaseDir(), getTuningConfiguration(),
new DefaultIdGeneratorFactory( fileSystem ), pageCache, fileSystem, NullLogProvider.getInstance(),
EmptyVersionContextSupplier.EMPTY );
}
Expand Down
Expand Up @@ -705,7 +705,7 @@ private GraphDatabaseService beansAPIWithNoMoreLabelIds()
idTypeConfigurationProvider = new CommunityIdTypeConfigurationProvider();

@Override
public IdGenerator open( File fileName, int grabSize, IdType idType, LongSupplier highId, long maxId )
public IdGenerator open( String databaseName, File fileName, int grabSize, IdType idType, LongSupplier highId, long maxId )
{
if ( idType == IdType.LABEL_TOKEN )
{
Expand All @@ -727,7 +727,7 @@ public long nextId()
}
return generator;
}
return super.open( fileName, grabSize, idType, () -> Long.MAX_VALUE, Long.MAX_VALUE );
return super.open( databaseName, fileName, grabSize, idType, () -> Long.MAX_VALUE, Long.MAX_VALUE );
}
};

Expand Down
Expand Up @@ -39,6 +39,7 @@

import org.neo4j.adversaries.ClassGuardedAdversary;
import org.neo4j.adversaries.CountingAdversary;
import org.neo4j.dbms.database.DatabaseManager;
import org.neo4j.graphdb.DependencyResolver;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Label;
Expand Down Expand Up @@ -483,9 +484,9 @@ private static void assertSameStoreContents( EphemeralFileSystemAbstraction fs1,
PageCache pageCache2 = new ConfiguringPageCacheFactory( fs2, defaults(), PageCacheTracer.NULL,
PageCursorTracerSupplier.NULL, NullLog.getInstance(), contextSupplier )
.getOrCreatePageCache();
NeoStores store1 = new StoreFactory( storeDir, defaults(), new DefaultIdGeneratorFactory( fs1 ),
NeoStores store1 = new StoreFactory( DatabaseManager.DEFAULT_DATABASE_NAME, storeDir, defaults(), new DefaultIdGeneratorFactory( fs1 ),
pageCache1, fs1, logProvider, contextSupplier ).openAllNeoStores();
NeoStores store2 = new StoreFactory( storeDir, defaults(), new DefaultIdGeneratorFactory( fs2 ),
NeoStores store2 = new StoreFactory( DatabaseManager.DEFAULT_DATABASE_NAME, storeDir, defaults(), new DefaultIdGeneratorFactory( fs2 ),
pageCache2, fs2, logProvider, contextSupplier ).openAllNeoStores()
)
{
Expand Down
Expand Up @@ -27,6 +27,7 @@
import java.io.File;
import java.util.Collection;

import org.neo4j.dbms.database.DatabaseManager;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Transaction;
Expand Down Expand Up @@ -130,9 +131,9 @@ private GraphDatabaseAPI databaseWithManyPropertyKeys( int propertyKeyCount )
{

PageCache pageCache = pageCacheRule.getPageCache( fileSystemRule.get() );
StoreFactory storeFactory = new StoreFactory( databaseDir, Config.defaults(), new DefaultIdGeneratorFactory( fileSystemRule.get() ), pageCache,
fileSystemRule.get(),
NullLogProvider.getInstance(), EmptyVersionContextSupplier.EMPTY );
StoreFactory storeFactory =
new StoreFactory( DatabaseManager.DEFAULT_DATABASE_NAME, databaseDir, Config.defaults(), new DefaultIdGeneratorFactory( fileSystemRule.get() ),
pageCache, fileSystemRule.get(), NullLogProvider.getInstance(), EmptyVersionContextSupplier.EMPTY );
NeoStores neoStores = storeFactory.openAllNeoStores( true );
PropertyKeyTokenStore store = neoStores.getPropertyKeyTokenStore();
for ( int i = 0; i < propertyKeyCount; i++ )
Expand Down
Expand Up @@ -28,6 +28,7 @@
import java.util.HashMap;
import java.util.Map;

import org.neo4j.dbms.database.DatabaseManager;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.PropertyContainer;
Expand Down Expand Up @@ -76,7 +77,7 @@ public void initialize()
Map<String, String> params = new HashMap<>();
params.put( GraphDatabaseSettings.rebuild_idgenerators_fast.name(), Settings.FALSE );
Config config = Config.defaults( params );
factory = new StoreFactory( testDirectory.databaseDir(), config, new DefaultIdGeneratorFactory( fs ),
factory = new StoreFactory( DatabaseManager.DEFAULT_DATABASE_NAME, testDirectory.databaseDir(), config, new DefaultIdGeneratorFactory( fs ),
pageCacheRule.getPageCache( fs ), fs, NullLogProvider.getInstance(), EmptyVersionContextSupplier.EMPTY );
}

Expand Down
Expand Up @@ -37,6 +37,7 @@
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 @@ -147,8 +148,7 @@ public void setUpNeoStores()
databaseDir = dir.databaseDir();
Config config = Config.defaults();
pageCache = pageCacheRule.getPageCache( fs.get() );
StoreFactory sf = new StoreFactory( databaseDir, config, new DefaultIdGeneratorFactory( fs.get() ), pageCache,
fs.get(), NullLogProvider.getInstance(), EmptyVersionContextSupplier.EMPTY );
StoreFactory sf = getStoreFactory( config, databaseDir, fs.get(), NullLogProvider.getInstance() );
sf.openAllNeoStores( true ).close();
propertyKeyTokenHolder = new DelegatingTokenHolder( this::createPropertyKeyToken, TokenHolder.TYPE_PROPERTY_KEY );
}
Expand All @@ -162,8 +162,7 @@ private int createPropertyKeyToken( String name )
public void impossibleToGetStoreFromClosedNeoStoresContainer()
{
Config config = Config.defaults();
StoreFactory sf = new StoreFactory( databaseDir, config, new DefaultIdGeneratorFactory( fs.get() ), pageCache,
fs.get(), NullLogProvider.getInstance(), EmptyVersionContextSupplier.EMPTY );
StoreFactory sf = getStoreFactory( config, databaseDir, fs.get(), NullLogProvider.getInstance() );
NeoStores neoStores = sf.openAllNeoStores( true );

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

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

exception.expect( IllegalStateException.class );
exception.expectMessage(
Expand Down Expand Up @@ -538,8 +535,7 @@ public void setVersion() throws Exception
MetaDataStore.DEFAULT_NAME ).getAbsoluteFile(), Position.LOG_VERSION, 12 ) );

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

NeoStores neoStores = sf.openAllNeoStores();
assertEquals( 12, neoStores.getMetaDataStore().getCurrentLogVersion() );
Expand Down Expand Up @@ -595,7 +591,7 @@ public void testSetLatestConstraintTx()
{
// given
Config config = Config.defaults();
StoreFactory sf = new StoreFactory( dir.directory(), config, new DefaultIdGeneratorFactory( fs.get() ),
StoreFactory sf = new StoreFactory( DatabaseManager.DEFAULT_DATABASE_NAME, dir.directory(), config, new DefaultIdGeneratorFactory( fs.get() ),
pageCacheRule.getPageCache( fs.get() ), fs.get(), LOG_PROVIDER, EmptyVersionContextSupplier.EMPTY );

// when
Expand Down Expand Up @@ -625,10 +621,7 @@ public void testSetLatestConstraintTx()
public void shouldInitializeTheTxIdToOne()
{
File databaseDir = dir.databaseDir();
StoreFactory factory =
new StoreFactory( databaseDir, Config.defaults(), new DefaultIdGeneratorFactory( fs.get() ),
pageCache, fs.get(),
LOG_PROVIDER, EmptyVersionContextSupplier.EMPTY );
StoreFactory factory = getStoreFactory( Config.defaults(), databaseDir, fs.get(), LOG_PROVIDER );

try ( NeoStores neoStores = factory.openAllNeoStores( true ) )
{
Expand All @@ -647,9 +640,7 @@ public void shouldThrowUnderlyingStorageExceptionWhenFailingToLoadStorage()
{
FileSystemAbstraction fileSystem = fs.get();
File databaseDir = dir.databaseDir();
StoreFactory factory = new StoreFactory(
databaseDir, Config.defaults(), new DefaultIdGeneratorFactory( fileSystem ), pageCache, fileSystem,
LOG_PROVIDER, EmptyVersionContextSupplier.EMPTY );
StoreFactory factory = getStoreFactory( Config.defaults(), databaseDir, fileSystem, LOG_PROVIDER );

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

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

try ( NeoStores neoStore = factory.openAllNeoStores( true ) )
{
Expand All @@ -776,9 +765,7 @@ public void shouldCloseAllTheStoreEvenIfExceptionsAreThrown() throws Exception
// given
FileSystemAbstraction fileSystem = fs.get();
Config defaults = Config.defaults( counts_store_rotation_timeout, "60m" );
StoreFactory factory =
new StoreFactory( databaseDir, defaults, new DefaultIdGeneratorFactory( fileSystem ), pageCache,
fileSystem, LOG_PROVIDER, EmptyVersionContextSupplier.EMPTY );
StoreFactory factory = getStoreFactory( defaults, databaseDir, 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 @@ -836,7 +823,7 @@ public void isPresentAfterCreatingAllStores() throws Exception
FileSystemAbstraction fileSystem = fs.get();
fileSystem.deleteRecursively( databaseDir );
DefaultIdGeneratorFactory idFactory = new DefaultIdGeneratorFactory( fileSystem );
StoreFactory factory = new StoreFactory( databaseDir, Config.defaults(), idFactory, pageCache, fileSystem,
StoreFactory factory = new StoreFactory( DatabaseManager.DEFAULT_DATABASE_NAME, databaseDir, Config.defaults(), idFactory, pageCache, fileSystem,
LOG_PROVIDER, EmptyVersionContextSupplier.EMPTY );

// when
Expand All @@ -854,7 +841,7 @@ public void isPresentFalseAfterCreatingAllButLastStoreType() throws Exception
FileSystemAbstraction fileSystem = fs.get();
fileSystem.deleteRecursively( databaseDir );
DefaultIdGeneratorFactory idFactory = new DefaultIdGeneratorFactory( fileSystem );
StoreFactory factory = new StoreFactory( databaseDir, Config.defaults(), idFactory, pageCache, fileSystem,
StoreFactory factory = new StoreFactory( DatabaseManager.DEFAULT_DATABASE_NAME, databaseDir, Config.defaults(), idFactory, pageCache, fileSystem,
LOG_PROVIDER, EmptyVersionContextSupplier.EMPTY );
StoreType[] allStoreTypes = StoreType.values();
StoreType[] allButLastStoreTypes = Arrays.copyOf( allStoreTypes, allStoreTypes.length - 1 );
Expand All @@ -877,7 +864,7 @@ private static StoreFactory newStoreFactory( File neoStoreDir, PageCache pageCac
RecordFormats recordFormats = RecordFormatSelector.defaultFormat();
Config config = Config.defaults();
IdGeneratorFactory idGeneratorFactory = new DefaultIdGeneratorFactory( fs );
return new StoreFactory( neoStoreDir, config, idGeneratorFactory, pageCache, fs, recordFormats, LOG_PROVIDER,
return new StoreFactory( DatabaseManager.DEFAULT_DATABASE_NAME, neoStoreDir, config, idGeneratorFactory, pageCache, fs, recordFormats, LOG_PROVIDER,
EmptyVersionContextSupplier.EMPTY );
}

Expand Down Expand Up @@ -1518,4 +1505,10 @@ private <RECEIVER extends PropertyReceiver> void receivePropertyChain( RECEIVER
}
}
}

private StoreFactory getStoreFactory( Config config, File databaseDir, FileSystemAbstraction ephemeralFileSystemAbstraction, NullLogProvider instance )
{
return new StoreFactory( DatabaseManager.DEFAULT_DATABASE_NAME, databaseDir, config, new DefaultIdGeneratorFactory( ephemeralFileSystemAbstraction ),
pageCache, ephemeralFileSystemAbstraction, instance, EmptyVersionContextSupplier.EMPTY );
}
}
Expand Up @@ -32,6 +32,7 @@
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;

import org.neo4j.dbms.database.DatabaseManager;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.Transaction;
Expand Down Expand Up @@ -170,8 +171,8 @@ private StoreFactory factory( Integer customThreshold, PageCache pageCache )
{
customConfig.put( GraphDatabaseSettings.dense_node_threshold.name(), "" + customThreshold );
}
return new StoreFactory( directory, Config.defaults( customConfig ), new DefaultIdGeneratorFactory( fs ), pageCache,
fs, NullLogProvider.getInstance(), EmptyVersionContextSupplier.EMPTY );
return new StoreFactory( DatabaseManager.DEFAULT_DATABASE_NAME, directory, Config.defaults( customConfig ), new DefaultIdGeneratorFactory( fs ),
pageCache, fs, NullLogProvider.getInstance(), EmptyVersionContextSupplier.EMPTY );
}

@Test
Expand Down
Expand Up @@ -27,6 +27,7 @@
import java.io.File;
import java.util.concurrent.Future;

import org.neo4j.dbms.database.DatabaseManager;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.PropertyContainer;
Expand Down Expand Up @@ -194,8 +195,9 @@ public void firstRecordOtherThanZeroIfNotFirst()
db.shutdown();

Config config = Config.defaults();
StoreFactory storeFactory = new StoreFactory( testDirectory.databaseDir(), config, new DefaultIdGeneratorFactory( fs.get() ),
pageCacheRule.getPageCache( fs.get() ), fs.get(), NullLogProvider.getInstance(), EmptyVersionContextSupplier.EMPTY );
StoreFactory storeFactory =
new StoreFactory( DatabaseManager.DEFAULT_DATABASE_NAME, testDirectory.databaseDir(), config, new DefaultIdGeneratorFactory( fs.get() ),
pageCacheRule.getPageCache( fs.get() ), fs.get(), NullLogProvider.getInstance(), EmptyVersionContextSupplier.EMPTY );
NeoStores neoStores = storeFactory.openAllNeoStores();
long prop = neoStores.getMetaDataStore().getGraphNextProp();
assertTrue( prop != 0 );
Expand Down
Expand Up @@ -26,6 +26,7 @@

import java.io.File;

import org.neo4j.dbms.database.DatabaseManager;
import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
Expand Down Expand Up @@ -351,7 +352,8 @@ private void rebuildCounts( long lastCommittedTransactionId, ProgressReporter pr

IdGeneratorFactory idGenFactory = new DefaultIdGeneratorFactory( fs );
StoreFactory storeFactory =
new StoreFactory( testDir.databaseDir(), CONFIG, idGenFactory, pageCache, fs, LOG_PROVIDER, EmptyVersionContextSupplier.EMPTY );
new StoreFactory( DatabaseManager.DEFAULT_DATABASE_NAME, testDir.databaseDir(), CONFIG, idGenFactory, pageCache, fs, LOG_PROVIDER,
EmptyVersionContextSupplier.EMPTY );
try ( Lifespan life = new Lifespan();
NeoStores neoStores = storeFactory.openAllNeoStores() )
{
Expand Down

0 comments on commit b6d3e9b

Please sign in to comment.