Skip to content

Commit

Permalink
Allow CC tests to work with new directory structure.
Browse files Browse the repository at this point in the history
Update directory that returned from SPI to return particular DB
instead of store dir.
  • Loading branch information
MishaDemianenko committed Jul 23, 2018
1 parent bd8b0f6 commit 09033c1
Show file tree
Hide file tree
Showing 26 changed files with 138 additions and 132 deletions.
Expand Up @@ -749,7 +749,7 @@ private ResourceIterator<Node> nodesByLabelAndProperties(
return getNodesByLabelAndPropertyWithoutIndex( statement, labelId, queries );
}

private IndexReference findMatchingIndex( KernelTransaction transaction, int labelId, int[] propertyIds )
private static IndexReference findMatchingIndex( KernelTransaction transaction, int labelId, int[] propertyIds )
{
IndexReference index = transaction.schemaRead().index( labelId, propertyIds );
if ( index != IndexReference.NO_INDEX )
Expand Down Expand Up @@ -780,7 +780,7 @@ private IndexReference findMatchingIndex( KernelTransaction transaction, int lab
}
}

private IndexQuery[] getReorderedIndexQueries( int[] indexPropertyIds, IndexQuery[] queries )
private static IndexQuery[] getReorderedIndexQueries( int[] indexPropertyIds, IndexQuery[] queries )
{
IndexQuery[] orderedQueries = new IndexQuery[queries.length];
for ( int i = 0; i < indexPropertyIds.length; i++ )
Expand All @@ -798,7 +798,7 @@ private IndexQuery[] getReorderedIndexQueries( int[] indexPropertyIds, IndexQuer
return orderedQueries;
}

private boolean hasSamePropertyIds( int[] original, int[] workingCopy, int[] propertyIds )
private static boolean hasSamePropertyIds( int[] original, int[] workingCopy, int[] propertyIds )
{
if ( original.length == propertyIds.length )
{
Expand All @@ -809,7 +809,7 @@ private boolean hasSamePropertyIds( int[] original, int[] workingCopy, int[] pro
return false;
}

private int[] getPropertyIds( IndexQuery[] queries )
private static int[] getPropertyIds( IndexQuery[] queries )
{
int[] propertyIds = new int[queries.length];
for ( int i = 0; i < queries.length; i++ )
Expand All @@ -819,7 +819,7 @@ private int[] getPropertyIds( IndexQuery[] queries )
return propertyIds;
}

private boolean isInvalidQuery( int labelId, IndexQuery[] queries )
private static boolean isInvalidQuery( int labelId, IndexQuery[] queries )
{
boolean invalidQuery = labelId == TokenRead.NO_TOKEN;
for ( IndexQuery query : queries )
Expand All @@ -830,7 +830,7 @@ private boolean isInvalidQuery( int labelId, IndexQuery[] queries )
return invalidQuery;
}

private void assertNoDuplicates( int[] propertyIds, TokenRead tokenRead )
private static void assertNoDuplicates( int[] propertyIds, TokenRead tokenRead )
{
int prev = propertyIds[0];
for ( int i = 1; i < propertyIds.length; i++ )
Expand Down Expand Up @@ -1085,7 +1085,7 @@ private void assertTransactionOpen()
assertTransactionOpen( statementContext.getKernelTransactionBoundToThisThread( true ) );
}

private void assertTransactionOpen( KernelTransaction transaction )
private static void assertTransactionOpen( KernelTransaction transaction )
{
if ( transaction.isTerminated() )
{
Expand Down
Expand Up @@ -131,8 +131,7 @@ public StoreId storeId()
@Override
public File storeDir()
{
//TODO: change to particular data base store dir
return platform.storeDir;
return dataSource.neoStoreDataSource.getDatabaseDirectory();
}

@Override
Expand Down
Expand Up @@ -206,12 +206,13 @@ public EnterpriseCoreEditionModule( final PlatformModule platformModule,
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 LifeSupport life = platformModule.life;

CoreMonitor.register( logging.getInternalLogProvider(), logging.getUserLogProvider(), platformModule.monitors );

final File dataDir = config.get( GraphDatabaseSettings.data_directory );
final ClusterStateDirectory clusterStateDirectory = new ClusterStateDirectory( dataDir, storeDir, false );
final ClusterStateDirectory clusterStateDirectory = new ClusterStateDirectory( dataDir, databaseDirectory, false );
try
{
clusterStateDirectory.initialize( fileSystem );
Expand All @@ -230,8 +231,8 @@ public EnterpriseCoreEditionModule( final PlatformModule platformModule,
watcherService = createFileSystemWatcherService( fileSystem, storeDir, logging,
platformModule.jobScheduler, fileWatcherFileNameFilter() );
dependencies.satisfyDependencies( watcherService );
LogFiles logFiles = buildLocalDatabaseLogFiles( platformModule, fileSystem, storeDir );
LocalDatabase localDatabase = new LocalDatabase( storeDir,
LogFiles logFiles = buildLocalDatabaseLogFiles( platformModule, fileSystem, databaseDirectory );
LocalDatabase localDatabase = new LocalDatabase( databaseDirectory,
new StoreFiles( fileSystem, platformModule.pageCache ),
logFiles,
platformModule.dataSourceManager,
Expand All @@ -243,7 +244,7 @@ public EnterpriseCoreEditionModule( final PlatformModule platformModule,
IdentityModule identityModule = new IdentityModule( platformModule, clusterStateDirectory.get() );

ClusteringModule clusteringModule = getClusteringModule( platformModule, discoveryServiceFactory,
clusterStateDirectory, identityModule, dependencies );
clusterStateDirectory, identityModule, databaseDirectory );

// We need to satisfy the dependency here to keep users of it, such as BoltKernelExtension, happy.
dependencies.satisfyDependency( SslPolicyLoader.create( config, logProvider ) );
Expand Down Expand Up @@ -355,25 +356,23 @@ private UpstreamDatabaseStrategySelector createUpstreamDatabaseStrategySelector(
return new UpstreamDatabaseStrategySelector( defaultStrategy, loader, logProvider );
}

private LogFiles buildLocalDatabaseLogFiles( PlatformModule platformModule, FileSystemAbstraction fileSystem, File storeDir )
private LogFiles buildLocalDatabaseLogFiles( PlatformModule platformModule, FileSystemAbstraction fileSystem, File databaseDirectory )
{
try
{
return LogFilesBuilder.activeFilesBuilder( storeDir, fileSystem, platformModule.pageCache ).withConfig( config ).build();
return LogFilesBuilder.activeFilesBuilder( databaseDirectory, fileSystem, platformModule.pageCache ).withConfig( config ).build();
}
catch ( IOException e )
{
throw new RuntimeException( e );
}
}

protected ClusteringModule getClusteringModule( PlatformModule platformModule,
DiscoveryServiceFactory discoveryServiceFactory,
ClusterStateDirectory clusterStateDirectory,
IdentityModule identityModule, Dependencies dependencies )
protected ClusteringModule getClusteringModule( PlatformModule platformModule, DiscoveryServiceFactory discoveryServiceFactory,
ClusterStateDirectory clusterStateDirectory, IdentityModule identityModule, File databaseDirectory )
{
return new ClusteringModule( discoveryServiceFactory, identityModule.myself(),
platformModule, clusterStateDirectory.get() );
platformModule, clusterStateDirectory.get(), databaseDirectory );
}

protected DuplexPipelineWrapperFactory pipelineWrapperFactory()
Expand All @@ -400,7 +399,7 @@ static Predicate<String> fileWatcherFileNameFilter()
);
}

private MessageLogger<MemberId> createMessageLogger( Config config, LifeSupport life, MemberId myself )
private static MessageLogger<MemberId> createMessageLogger( Config config, LifeSupport life, MemberId myself )
{
final MessageLogger<MemberId> messageLogger;
if ( config.get( CausalClusteringSettings.raft_messages_log_enable ) )
Expand Down Expand Up @@ -461,19 +460,19 @@ private static PrintWriter raftMessagesLog( File logFile )
}
}

private SchemaWriteGuard createSchemaWriteGuard()
private static SchemaWriteGuard createSchemaWriteGuard()
{
return SchemaWriteGuard.ALLOW_ALL_WRITES;
}

private KernelData createKernelData( FileSystemAbstraction fileSystem, PageCache pageCache, File storeDir,
Config config, GraphDatabaseAPI graphAPI, LifeSupport life )
private static KernelData createKernelData( FileSystemAbstraction fileSystem, PageCache pageCache, File storeDir, Config config, GraphDatabaseAPI graphAPI,
LifeSupport life )
{
KernelData kernelData = new KernelData( fileSystem, pageCache, storeDir, config, graphAPI );
return life.add( kernelData );
}

private TransactionHeaderInformationFactory createHeaderInformationFactory()
private static TransactionHeaderInformationFactory createHeaderInformationFactory()
{
return () -> new TransactionHeaderInformation( -1, -1, new byte[0] );
}
Expand Down
Expand Up @@ -58,7 +58,7 @@ public class ClusteringModule
private final ClusterBinder clusterBinder;

public ClusteringModule( DiscoveryServiceFactory discoveryServiceFactory, MemberId myself,
PlatformModule platformModule, File clusterStateDirectory )
PlatformModule platformModule, File clusterStateDirectory, File databaseDirectory )
{
LifeSupport life = platformModule.life;
Config config = platformModule.config;
Expand All @@ -77,7 +77,7 @@ public ClusteringModule( DiscoveryServiceFactory discoveryServiceFactory, Member
dependencies.satisfyDependency( topologyService ); // for tests

CoreBootstrapper coreBootstrapper =
new CoreBootstrapper( platformModule.storeDir, platformModule.pageCache, fileSystem, config, logProvider );
new CoreBootstrapper( databaseDirectory, platformModule.pageCache, fileSystem, config, logProvider );

SimpleStorage<ClusterId> clusterIdStorage =
new SimpleFileStorage<>( fileSystem, clusterStateDirectory, CLUSTER_ID_NAME, new ClusterId.Marshal(),
Expand Down
Expand Up @@ -92,15 +92,15 @@ public class CoreBootstrapper
private static final long FIRST_INDEX = 0L;
private static final long FIRST_TERM = 0L;

private final File storeDir;
private final File databaseDirectory;
private final PageCache pageCache;
private final FileSystemAbstraction fs;
private final Config config;
private final LogProvider logProvider;

CoreBootstrapper( File storeDir, PageCache pageCache, FileSystemAbstraction fs, Config config, LogProvider logProvider )
CoreBootstrapper( File databaseDirectory, PageCache pageCache, FileSystemAbstraction fs, Config config, LogProvider logProvider )
{
this.storeDir = storeDir;
this.databaseDirectory = databaseDirectory;
this.pageCache = pageCache;
this.fs = fs;
this.config = config;
Expand All @@ -109,14 +109,14 @@ public class CoreBootstrapper

public CoreSnapshot bootstrap( Set<MemberId> members ) throws IOException
{
StoreFactory factory = new StoreFactory( storeDir, config,
StoreFactory factory = new StoreFactory( databaseDirectory, config,
new DefaultIdGeneratorFactory( fs ), pageCache, fs, logProvider, EmptyVersionContextSupplier.EMPTY );

NeoStores neoStores = factory.openAllNeoStores( true );
neoStores.close();

CoreSnapshot coreSnapshot = new CoreSnapshot( FIRST_INDEX, FIRST_TERM );
coreSnapshot.add( CoreStateType.ID_ALLOCATION, deriveIdAllocationState( storeDir ) );
coreSnapshot.add( CoreStateType.ID_ALLOCATION, deriveIdAllocationState( databaseDirectory ) );
coreSnapshot.add( CoreStateType.LOCK_TOKEN, new ReplicatedLockTokenState() );
coreSnapshot.add( CoreStateType.RAFT_CORE_STATE,
new RaftCoreState( new MembershipEntry( FIRST_INDEX, members ) ) );
Expand All @@ -127,8 +127,8 @@ public CoreSnapshot bootstrap( Set<MemberId> members ) throws IOException

private void appendNullTransactionLogEntryToSetRaftIndexToMinusOne() throws IOException
{
ReadOnlyTransactionIdStore readOnlyTransactionIdStore = new ReadOnlyTransactionIdStore( pageCache, storeDir );
LogFiles logFiles = LogFilesBuilder.activeFilesBuilder( storeDir, fs, pageCache )
ReadOnlyTransactionIdStore readOnlyTransactionIdStore = new ReadOnlyTransactionIdStore( pageCache, databaseDirectory );
LogFiles logFiles = LogFilesBuilder.activeFilesBuilder( databaseDirectory, fs, pageCache )
.withConfig( config )
.withLastCommittedTransactionIdSupplier( () -> readOnlyTransactionIdStore.getLastClosedTransactionId() - 1 )
.build();
Expand All @@ -149,7 +149,7 @@ private void appendNullTransactionLogEntryToSetRaftIndexToMinusOne() throws IOEx
channel.prepareForFlush().flush();
}

File neoStoreFile = new File( storeDir, MetaDataStore.DEFAULT_NAME );
File neoStoreFile = new File( databaseDirectory, MetaDataStore.DEFAULT_NAME );
MetaDataStore.setRecord( pageCache, neoStoreFile, LAST_TRANSACTION_ID, dummyTransactionId );
}

Expand Down Expand Up @@ -177,7 +177,7 @@ private IdAllocationState deriveIdAllocationState( File dbDir )
return new IdAllocationState( highIds, FIRST_INDEX );
}

private long getHighId( File coreDir, DefaultIdGeneratorFactory factory, IdType idType, String store )
private static long getHighId( File coreDir, DefaultIdGeneratorFactory factory, IdType idType, String store )
{
IdGenerator idGenerator = factory.open( new File( coreDir, idFile( store ) ), idType, () -> -1L, Long.MAX_VALUE );
long highId = idGenerator.getHighId();
Expand Down
Expand Up @@ -163,6 +163,8 @@ public EnterpriseReadReplicaEditionModule( final PlatformModule platformModule,
FileSystemAbstraction fileSystem = platformModule.fileSystem;
PageCache pageCache = platformModule.pageCache;
File storeDir = platformModule.storeDir;
final File databaseDirectory = new File( storeDir, config.get( GraphDatabaseSettings.active_database ) );

LifeSupport life = platformModule.life;

eligibleForIdReuse = IdReuseEligibility.ALWAYS;
Expand Down Expand Up @@ -256,10 +258,10 @@ public EnterpriseReadReplicaEditionModule( final PlatformModule platformModule,
final Supplier<DatabaseHealth> databaseHealthSupplier = dependencies.provideDependency( DatabaseHealth.class );

StoreFiles storeFiles = new StoreFiles( fileSystem, pageCache );
LogFiles logFiles = buildLocalDatabaseLogFiles( platformModule, fileSystem, storeDir, config );
LogFiles logFiles = buildLocalDatabaseLogFiles( platformModule, fileSystem, databaseDirectory, config );

LocalDatabase localDatabase =
new LocalDatabase( storeDir, storeFiles, logFiles, platformModule.dataSourceManager,
new LocalDatabase( databaseDirectory, storeFiles, logFiles, platformModule.dataSourceManager,
databaseHealthSupplier,
watcherService, platformModule.availabilityGuard, logProvider );

Expand Down
Expand Up @@ -50,7 +50,6 @@
import org.neo4j.kernel.NeoStoreDataSource;
import org.neo4j.kernel.impl.store.StoreType;
import org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer;
import org.neo4j.kernel.impl.transaction.state.DataSourceManager;
import org.neo4j.kernel.impl.transaction.state.NeoStoreFileListing;
import org.neo4j.kernel.internal.GraphDatabaseAPI;
import org.neo4j.logging.LogProvider;
Expand Down Expand Up @@ -96,8 +95,8 @@ public class CatchupServerIT
@Before
public void startDb() throws Throwable
{
temporaryDirectory = testDirectory.directory();
graphDb = (GraphDatabaseAPI) new TestGraphDatabaseFactory().setFileSystem( fsa ).newEmbeddedDatabase( testDirectory.graphDbDir() );
temporaryDirectory = testDirectory.directory( "temp" );
graphDb = (GraphDatabaseAPI) new TestGraphDatabaseFactory().setFileSystem( fsa ).newEmbeddedDatabase( testDirectory.directory() );
createLegacyIndex();
createPropertyIndex();
addData( graphDb );
Expand Down Expand Up @@ -257,14 +256,14 @@ private void fileContentEquals( Collection<File> countStore ) throws IOException

private File databaseFileToClientFile( File file ) throws IOException
{
String relativePathToDatabaseDir = relativePath( new File( temporaryDirectory, DataSourceManager.DEFAULT_DATABASE_NAME ), file );
String relativePathToDatabaseDir = relativePath( testDirectory.graphDbDir(), file );
return new File( temporaryDirectory, relativePathToDatabaseDir );
}

private File clientFileToDatabaseFile( File file ) throws IOException
{
String relativePathToDatabaseDir = relativePath( temporaryDirectory, file );
return new File( new File( temporaryDirectory, "graph-db" ), relativePathToDatabaseDir );
return new File( testDirectory.graphDbDir(), relativePathToDatabaseDir );
}

private void fileContentEquals( File fileA, File fileB ) throws IOException
Expand All @@ -282,12 +281,12 @@ private void listOfDownloadedFilesMatchesServer( NeoStoreDataSource neoStoreData
assertThat( givenFile, containsInAnyOrder( expectedStoreFiles.toArray( new String[givenFile.size()] ) ) );
}

private LongSet getExpectedIndexIds( NeoStoreDataSource neoStoreDataSource )
private static LongSet getExpectedIndexIds( NeoStoreDataSource neoStoreDataSource )
{
return neoStoreDataSource.getNeoStoreFileListing().getNeoStoreFileIndexListing().getIndexIds();
}

private List<File> listServerExpectedNonReplayableFiles( NeoStoreDataSource neoStoreDataSource ) throws IOException
private static List<File> listServerExpectedNonReplayableFiles( NeoStoreDataSource neoStoreDataSource ) throws IOException
{
try ( Stream<StoreFileMetadata> countStoreStream = neoStoreDataSource.getNeoStoreFileListing().builder().excludeAll()
.includeNeoStoreFiles().build().stream();
Expand All @@ -313,7 +312,7 @@ private static Predicate<StoreFileMetadata> isCountFile()
return storeFileMetadata -> StoreType.typeOf( storeFileMetadata.file().getName() ).filter( f -> f == StoreType.COUNTS ).isPresent();
}

private void addData( GraphDatabaseAPI graphDb )
private static void addData( GraphDatabaseAPI graphDb )
{
try ( Transaction tx = graphDb.beginTx() )
{
Expand Down

0 comments on commit 09033c1

Please sign in to comment.