Skip to content

Commit

Permalink
Remove StoreIdSupplier, use LocalDatabase instead
Browse files Browse the repository at this point in the history
  • Loading branch information
davidegrohmann committed Jul 4, 2016
1 parent b0f7d9f commit 1e19778
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 58 deletions.

This file was deleted.

Expand Up @@ -29,15 +29,16 @@
import org.neo4j.coreedge.server.StoreId;
import org.neo4j.kernel.NeoStoreDataSource;
import org.neo4j.kernel.impl.transaction.log.TransactionIdStore;
import org.neo4j.kernel.impl.transaction.state.DataSourceManager;
import org.neo4j.kernel.internal.DatabaseHealth;

public class LocalDatabase
public class LocalDatabase implements Supplier<StoreId>
{
private final File storeDir;

private final CopiedStoreRecovery copiedStoreRecovery;
private final StoreFiles storeFiles;
private Supplier<NeoStoreDataSource> neoDataSourceSupplier;
private final DataSourceManager dataSourceManager;
private final Supplier<TransactionIdStore> transactionIdStoreSupplier;
private final Supplier<DatabaseHealth> databaseHealthSupplier;

Expand All @@ -47,34 +48,34 @@ public class LocalDatabase
public LocalDatabase(
File storeDir,
CopiedStoreRecovery copiedStoreRecovery, StoreFiles storeFiles,
Supplier<NeoStoreDataSource> neoDataSourceSupplier,
DataSourceManager dataSourceManager,
Supplier<TransactionIdStore> transactionIdStoreSupplier,
Supplier<DatabaseHealth> databaseHealthSupplier )
{
this.storeDir = storeDir;
this.copiedStoreRecovery = copiedStoreRecovery;
this.storeFiles = storeFiles;
this.neoDataSourceSupplier = neoDataSourceSupplier;
this.dataSourceManager = dataSourceManager;
this.transactionIdStoreSupplier = transactionIdStoreSupplier;
this.databaseHealthSupplier = databaseHealthSupplier;
}

public void start() throws IOException
{
neoDataSourceSupplier.get().start();
dataSourceManager.getDataSource().start();
}

public void stop()
{
clearCache();
neoDataSourceSupplier.get().stop();
dataSourceManager.getDataSource().stop();
}

public StoreId storeId()
{
if ( storeId == null )
{
org.neo4j.kernel.impl.store.StoreId kernelStoreId = neoDataSourceSupplier.get().getStoreId();
org.neo4j.kernel.impl.store.StoreId kernelStoreId = dataSourceManager.getDataSource().getStoreId();
storeId = new StoreId( kernelStoreId.getCreationTime(),
kernelStoreId.getRandomId(), kernelStoreId.getUpgradeTime(), kernelStoreId.getUpgradeId() );
}
Expand Down Expand Up @@ -132,4 +133,10 @@ private void clearCache()
storeId = null;
databaseHealth = null;
}

@Override
public StoreId get()
{
return storeId();
}
}
Expand Up @@ -30,7 +30,6 @@
import org.neo4j.coreedge.catchup.CatchupServer;
import org.neo4j.coreedge.catchup.CheckpointerSupplier;
import org.neo4j.coreedge.catchup.DataSourceSupplier;
import org.neo4j.coreedge.catchup.StoreIdSupplier;
import org.neo4j.coreedge.catchup.storecopy.LocalDatabase;
import org.neo4j.coreedge.catchup.storecopy.StoreFiles;
import org.neo4j.coreedge.catchup.storecopy.core.CoreToCoreClient;
Expand Down Expand Up @@ -284,7 +283,7 @@ public void registerProcedures( Procedures procedures )

LocalDatabase localDatabase = new LocalDatabase( platformModule.storeDir, copiedStoreRecovery,
new StoreFiles( new DefaultFileSystemAbstraction() ),
dependencies.provideDependency( NeoStoreDataSource.class ),
platformModule.dataSourceManager,
platformModule.dependencies.provideDependency( TransactionIdStore.class ), databaseHealthSupplier );

final DelayedRenewableTimeoutService raftTimeoutService =
Expand Down Expand Up @@ -446,7 +445,7 @@ public void registerProcedures( Procedures procedures )

this.lockManager = dependencies.satisfyDependency( lockManager );

CatchupServer catchupServer = new CatchupServer( logProvider, new StoreIdSupplier( platformModule ),
CatchupServer catchupServer = new CatchupServer( logProvider, localDatabase,
platformModule.dependencies.provideDependency( TransactionIdStore.class ),
platformModule.dependencies.provideDependency( LogicalTransactionStore.class ),
new DataSourceSupplier( platformModule ), new CheckpointerSupplier( platformModule.dependencies ),
Expand Down
Expand Up @@ -197,7 +197,7 @@ edgeToCoreClient, new ConnectToRandomCoreServer( discoveryService ),
new LocalDatabase( platformModule.storeDir,
new CopiedStoreRecovery( config, platformModule.kernelExtensions.listFactories(), platformModule.pageCache ),
new StoreFiles( new DefaultFileSystemAbstraction() ),
dependencies.provideDependency( NeoStoreDataSource.class ),
platformModule.dataSourceManager,
dependencies.provideDependency( TransactionIdStore.class ),
databaseHealthSupplier),
txPulling, platformModule.dataSourceManager, new ConnectToRandomCoreServer( discoveryService ),
Expand Down
Expand Up @@ -28,6 +28,7 @@
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.NeoStoreDataSource;
import org.neo4j.kernel.impl.transaction.log.TransactionIdStore;
import org.neo4j.kernel.impl.transaction.state.DataSourceManager;
import org.neo4j.kernel.internal.DatabaseHealth;

import static junit.framework.TestCase.assertEquals;
Expand All @@ -44,13 +45,14 @@ public void shouldRetrieveStoreId() throws Throwable
StoreId storeId = new StoreId( 1, 2, 3, 4 );

// when
DataSourceManager dataSourceManager = mock( DataSourceManager.class );
NeoStoreDataSource neoStoreDataSource = mock( NeoStoreDataSource.class );
when( dataSourceManager.getDataSource() ).thenReturn( neoStoreDataSource );
when( neoStoreDataSource.getStoreId() ).thenReturn( new org.neo4j.kernel.impl.store.StoreId( 1, 2, 5, 3, 4 ) );

LocalDatabase localDatabase = new LocalDatabase( new File( "directory" ),
mock( CopiedStoreRecovery.class ),
new StoreFiles( mock( FileSystemAbstraction.class ) ),
singleton( neoStoreDataSource ), singleton( mock( TransactionIdStore.class ) ), () -> mock( DatabaseHealth.class ) );
LocalDatabase localDatabase = new LocalDatabase( new File( "directory" ), mock( CopiedStoreRecovery.class ),
new StoreFiles( mock( FileSystemAbstraction.class ) ), dataSourceManager,
singleton( mock( TransactionIdStore.class ) ), () -> mock( DatabaseHealth.class ) );

// then
assertEquals( storeId, localDatabase.storeId() );
Expand Down

0 comments on commit 1e19778

Please sign in to comment.