use of org.neo4j.kernel.NeoStoreDataSource in project neo4j by neo4j.
the class TransactionLogCatchUpWriterTest method simulateStoreCopy.
private org.neo4j.kernel.impl.store.StoreId simulateStoreCopy() throws IOException {
// create an empty store
org.neo4j.kernel.impl.store.StoreId storeId;
NeoStoreDataSource ds = dsRule.getDataSource(storeDir, fs, pageCache, emptyMap());
try (Lifespan ignored = new Lifespan(ds)) {
storeId = ds.getStoreId();
}
// we don't have log files after a store copy
PhysicalLogFiles logFiles = new PhysicalLogFiles(storeDir, fsRule.get());
logFiles.accept((file, version) -> file.delete());
return storeId;
}
use of org.neo4j.kernel.NeoStoreDataSource in project neo4j by neo4j.
the class DefaultMasterImplSPITest method flushStoreFilesWithCorrectCheckpointTriggerName.
@Test
public void flushStoreFilesWithCorrectCheckpointTriggerName() throws IOException {
CheckPointer checkPointer = mock(CheckPointer.class);
NeoStoreDataSource dataSource = mock(NeoStoreDataSource.class);
when(dataSource.listStoreFiles(anyBoolean())).thenReturn(Iterators.emptyIterator());
DefaultMasterImplSPI master = new DefaultMasterImplSPI(mock(GraphDatabaseAPI.class, RETURNS_MOCKS), mock(FileSystemAbstraction.class), new Monitors(), mock(LabelTokenHolder.class), mock(PropertyKeyTokenHolder.class), mock(RelationshipTypeTokenHolder.class), mock(IdGeneratorFactory.class), mock(TransactionCommitProcess.class), checkPointer, mock(TransactionIdStore.class), mock(LogicalTransactionStore.class), dataSource, mock(PageCache.class), new StoreCopyCheckPointMutex());
master.flushStoresAndStreamStoreFiles(mock(StoreWriter.class));
TriggerInfo expectedTriggerInfo = new SimpleTriggerInfo(DefaultMasterImplSPI.STORE_COPY_CHECKPOINT_TRIGGER);
verify(checkPointer).tryCheckPoint(expectedTriggerInfo);
}
use of org.neo4j.kernel.NeoStoreDataSource in project neo4j by neo4j.
the class SwitchToSlaveBranchThenCopyTest method newSwitchToSlaveSpy.
@SuppressWarnings("unchecked")
private SwitchToSlaveBranchThenCopy newSwitchToSlaveSpy(PageCache pageCacheMock, StoreCopyClient storeCopyClient) throws IOException {
ClusterMembers clusterMembers = mock(ClusterMembers.class);
ClusterMember master = mock(ClusterMember.class);
when(master.getStoreId()).thenReturn(storeId);
when(master.getHARole()).thenReturn(HighAvailabilityModeSwitcher.MASTER);
when(master.hasRole(eq(HighAvailabilityModeSwitcher.MASTER))).thenReturn(true);
when(master.getInstanceId()).thenReturn(new InstanceId(1));
when(clusterMembers.getMembers()).thenReturn(singletonList(master));
Dependencies resolver = new Dependencies();
resolver.satisfyDependencies(requestContextFactory, clusterMembers, mock(TransactionObligationFulfiller.class), mock(OnlineBackupKernelExtension.class), mock(IndexConfigStore.class), mock(TransactionCommittingResponseUnpacker.class), mock(DataSourceManager.class), mock(StoreLockerLifecycleAdapter.class), mock(FileSystemWatcherService.class));
NeoStoreDataSource dataSource = mock(NeoStoreDataSource.class);
when(dataSource.getStoreId()).thenReturn(storeId);
TransactionStats transactionCounters = mock(TransactionStats.class);
when(transactionCounters.getNumberOfActiveTransactions()).thenReturn(0L);
Response<HandshakeResult> response = mock(Response.class);
when(response.response()).thenReturn(new HandshakeResult(42, 2));
when(masterClient.handshake(anyLong(), any(StoreId.class))).thenReturn(response);
when(masterClient.getProtocolVersion()).thenReturn(MasterClient320.PROTOCOL_VERSION);
TransactionIdStore transactionIdStoreMock = mock(TransactionIdStore.class);
// note that the checksum (the second member of the array) is the same as the one in the handshake mock above
when(transactionIdStoreMock.getLastCommittedTransaction()).thenReturn(new TransactionId(42, 42, 42));
MasterClientResolver masterClientResolver = mock(MasterClientResolver.class);
when(masterClientResolver.instantiate(anyString(), anyInt(), anyString(), any(Monitors.class), any(StoreId.class), any(LifeSupport.class))).thenReturn(masterClient);
return spy(new SwitchToSlaveBranchThenCopy(new File(""), NullLogService.getInstance(), configMock(), resolver, mock(HaIdGeneratorFactory.class), mock(DelegateInvocationHandler.class), mock(ClusterMemberAvailability.class), requestContextFactory, pullerFactory, masterClientResolver, mock(SwitchToSlave.Monitor.class), storeCopyClient, Suppliers.singleton(dataSource), Suppliers.singleton(transactionIdStoreMock), slave -> {
SlaveServer server = mock(SlaveServer.class);
InetSocketAddress inetSocketAddress = InetSocketAddress.createUnresolved("localhost", 42);
when(server.getSocketAddress()).thenReturn(inetSocketAddress);
return server;
}, updatePuller, pageCacheMock, mock(Monitors.class), transactionCounters));
}
use of org.neo4j.kernel.NeoStoreDataSource in project neo4j by neo4j.
the class EditionModule method doAfterRecoveryAndStartup.
protected void doAfterRecoveryAndStartup(DatabaseInfo databaseInfo, DependencyResolver dependencyResolver) {
DiagnosticsManager diagnosticsManager = dependencyResolver.resolveDependency(DiagnosticsManager.class);
NeoStoreDataSource neoStoreDataSource = dependencyResolver.resolveDependency(NeoStoreDataSource.class);
diagnosticsManager.prependProvider(new KernelDiagnostics.Versions(databaseInfo, neoStoreDataSource.getStoreId()));
neoStoreDataSource.registerDiagnosticsWith(diagnosticsManager);
diagnosticsManager.appendProvider(new KernelDiagnostics.StoreFiles(neoStoreDataSource.getStoreDir()));
}
use of org.neo4j.kernel.NeoStoreDataSource in project neo4j by neo4j.
the class GraphDatabaseFacadeFactory method initFacade.
/**
* Instantiate a graph database given configuration, dependencies, and a custom implementation of {@link org
* .neo4j.kernel.impl.factory.GraphDatabaseFacade}.
*
* @param storeDir the directory where the Neo4j data store is located
* @param config configuration
* @param dependencies the dependencies required to construct the {@link GraphDatabaseFacade}
* @param graphDatabaseFacade the already created facade which needs initialisation
* @return the initialised {@link GraphDatabaseFacade}
*/
public GraphDatabaseFacade initFacade(File storeDir, Config config, final Dependencies dependencies, final GraphDatabaseFacade graphDatabaseFacade) {
PlatformModule platform = createPlatform(storeDir, config, dependencies, graphDatabaseFacade);
EditionModule edition = editionFactory.apply(platform);
AtomicReference<QueryExecutionEngine> queryEngine = new AtomicReference<>(noEngine());
final DataSourceModule dataSource = createDataSource(platform, edition, queryEngine::get);
Logger msgLog = platform.logging.getInternalLog(getClass()).infoLogger();
CoreAPIAvailabilityGuard coreAPIAvailabilityGuard = edition.coreAPIAvailabilityGuard;
ClassicCoreSPI spi = new ClassicCoreSPI(platform, dataSource, msgLog, coreAPIAvailabilityGuard);
graphDatabaseFacade.init(spi, dataSource.guard, dataSource.threadToTransactionBridge, platform.config);
// Start it
platform.dataSourceManager.addListener(new DataSourceManager.Listener() {
private QueryExecutionEngine engine;
@Override
public void registered(NeoStoreDataSource dataSource) {
if (engine == null) {
engine = QueryEngineProvider.initialize(platform.dependencies, platform.graphDatabaseFacade, dependencies.executionEngines());
}
queryEngine.set(engine);
}
@Override
public void unregistered(NeoStoreDataSource dataSource) {
queryEngine.set(noEngine());
}
});
Throwable error = null;
try {
// Done after create to avoid a redundant
// "database is now unavailable"
enableAvailabilityLogging(platform.availabilityGuard, msgLog);
platform.life.start();
} catch (final Throwable throwable) {
error = new RuntimeException("Error starting " + getClass().getName() + ", " + platform.storeDir, throwable);
} finally {
if (error != null) {
try {
graphDatabaseFacade.shutdown();
} catch (Throwable shutdownError) {
error = Exceptions.withSuppressed(shutdownError, error);
}
}
}
if (error != null) {
msgLog.log("Failed to start database", error);
throw Exceptions.launderedException(error);
}
return graphDatabaseFacade;
}
Aggregations