use of org.neo4j.kernel.impl.util.Dependencies in project neo4j by neo4j.
the class NeoStoreDataSource method start.
@Override
public void start() throws IOException {
dependencies = new Dependencies();
life = new LifeSupport();
schemaIndexProvider = dependencyResolver.resolveDependency(SchemaIndexProvider.class, HighestSelectionStrategy.getInstance());
labelScanStoreProvider = dependencyResolver.resolveDependency(LabelScanStoreProvider.class, new NamedLabelScanStoreSelectionStrategy(config));
dependencyResolver.resolveDependency(LabelScanStoreProvider.class, new DeleteStoresFromOtherLabelScanStoreProviders(labelScanStoreProvider));
IndexConfigStore indexConfigStore = new IndexConfigStore(storeDir, fs);
dependencies.satisfyDependency(lockService);
dependencies.satisfyDependency(indexConfigStore);
life.add(indexConfigStore);
// Monitor listeners
LoggingLogFileMonitor loggingLogMonitor = new LoggingLogFileMonitor(msgLog);
monitors.addMonitorListener(loggingLogMonitor);
life.add(new Delegate(Lifecycles.multiple(indexProviders.values())));
// Upgrade the store before we begin
RecordFormats formats = selectStoreFormats(config, storeDir, fs, pageCache, logService);
upgradeStore(formats);
// Build all modules and their services
StorageEngine storageEngine = null;
try {
UpdateableSchemaState updateableSchemaState = new KernelSchemaStateStore(logProvider);
SynchronizedArrayIdOrderingQueue legacyIndexTransactionOrdering = new SynchronizedArrayIdOrderingQueue(20);
storageEngine = buildStorageEngine(propertyKeyTokenHolder, labelTokens, relationshipTypeTokens, legacyIndexProviderLookup, indexConfigStore, updateableSchemaState::clear, legacyIndexTransactionOrdering);
LogEntryReader<ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader<>(storageEngine.commandReaderFactory());
TransactionIdStore transactionIdStore = dependencies.resolveDependency(TransactionIdStore.class);
LogVersionRepository logVersionRepository = dependencies.resolveDependency(LogVersionRepository.class);
NeoStoreTransactionLogModule transactionLogModule = buildTransactionLogs(storeDir, config, logProvider, scheduler, fs, storageEngine, logEntryReader, legacyIndexTransactionOrdering, transactionIdStore, logVersionRepository);
transactionLogModule.satisfyDependencies(dependencies);
buildRecovery(fs, transactionIdStore, logVersionRepository, monitors.newMonitor(Recovery.Monitor.class), monitors.newMonitor(PositionToRecoverFrom.Monitor.class), transactionLogModule.logFiles(), startupStatistics, storageEngine, logEntryReader, transactionLogModule.logicalTransactionStore());
// At the time of writing this comes from the storage engine (IndexStoreView)
PropertyAccessor propertyAccessor = dependencies.resolveDependency(PropertyAccessor.class);
final NeoStoreKernelModule kernelModule = buildKernel(transactionLogModule.transactionAppender(), dependencies.resolveDependency(IndexingService.class), storageEngine.storeReadLayer(), updateableSchemaState, dependencies.resolveDependency(LabelScanStore.class), storageEngine, indexConfigStore, transactionIdStore, availabilityGuard, clock, propertyAccessor);
kernelModule.satisfyDependencies(dependencies);
// Do these assignments last so that we can ensure no cyclical dependencies exist
this.storageEngine = storageEngine;
this.transactionLogModule = transactionLogModule;
this.kernelModule = kernelModule;
dependencies.satisfyDependency(this);
dependencies.satisfyDependency(updateableSchemaState);
dependencies.satisfyDependency(storageEngine.storeReadLayer());
dependencies.satisfyDependency(logEntryReader);
dependencies.satisfyDependency(storageEngine);
} catch (Throwable e) {
// Something unexpected happened during startup
msgLog.warn("Exception occurred while setting up store modules. Attempting to close things down.", e);
try {
// Close the neostore, so that locks are released properly
if (storageEngine != null) {
storageEngine.forceClose();
}
} catch (Exception closeException) {
msgLog.error("Couldn't close neostore after startup failure", closeException);
}
throw Exceptions.launderedException(e);
}
// NOTE: please make sure this is performed after having added everything to the life, in fact we would like
// to perform the checkpointing as first step when the life is shutdown.
life.add(lifecycleToTriggerCheckPointOnShutdown());
try {
life.start();
} catch (Throwable e) {
// Something unexpected happened during startup
msgLog.warn("Exception occurred while starting the datasource. Attempting to close things down.", e);
try {
life.shutdown();
// Close the neostore, so that locks are released properly
storageEngine.forceClose();
} catch (Exception closeException) {
msgLog.error("Couldn't close neostore after startup failure", closeException);
}
throw Exceptions.launderedException(e);
}
/*
* At this point recovery has completed and the datasource is ready for use. Whatever panic might have
* happened before has been healed. So we can safely set the kernel health to ok.
* This right now has any real effect only in the case of internal restarts (for example, after a store copy
* in the case of HA). Standalone instances will have to be restarted by the user, as is proper for all
* kernel panics.
*/
databaseHealth.healed();
}
use of org.neo4j.kernel.impl.util.Dependencies in project neo4j by neo4j.
the class BackupServiceIT method shouldContainTransactionsThatHappenDuringBackupProcess.
@Test
public void shouldContainTransactionsThatHappenDuringBackupProcess() throws Throwable {
// given
defaultBackupPortHostParams();
Config defaultConfig = dbRule.getConfigCopy();
dbRule.setConfig(OnlineBackupSettings.online_backup_enabled, "false");
Config withOnlineBackupDisabled = dbRule.getConfigCopy();
final Barrier.Control barrier = new Barrier.Control();
final GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI();
// create some data
createAndIndexNode(db, 1);
final DependencyResolver resolver = db.getDependencyResolver();
long expectedLastTxId = resolver.resolveDependency(TransactionIdStore.class).getLastClosedTransactionId();
// This monitor is added server-side...
monitors.addMonitorListener(new StoreSnoopingMonitor(barrier));
Dependencies dependencies = new Dependencies(resolver);
dependencies.satisfyDependencies(defaultConfig, monitors, NullLogProvider.getInstance());
OnlineBackupKernelExtension backup = (OnlineBackupKernelExtension) new OnlineBackupExtensionFactory().newInstance(new SimpleKernelContext(storeDir, DatabaseInfo.UNKNOWN, dependencies), DependenciesProxy.dependencies(dependencies, OnlineBackupExtensionFactory.Dependencies.class));
backup.start();
// when
BackupService backupService = backupService();
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.execute(() -> {
barrier.awaitUninterruptibly();
createAndIndexNode(db, 1);
resolver.resolveDependency(StorageEngine.class).flushAndForce(limiter);
barrier.release();
});
BackupService.BackupOutcome backupOutcome = backupService.doFullBackup(BACKUP_HOST, backupPort, backupDir.getAbsoluteFile(), ConsistencyCheck.FULL, withOnlineBackupDisabled, BackupClient.BIG_READ_TIMEOUT, false);
backup.stop();
executor.shutdown();
executor.awaitTermination(30, TimeUnit.SECONDS);
// then
checkPreviousCommittedTxIdFromLog(0, expectedLastTxId);
File neoStore = new File(storeDir, MetaDataStore.DEFAULT_NAME);
long txIdFromOrigin = MetaDataStore.getRecord(resolver.resolveDependency(PageCache.class), neoStore, Position.LAST_TRANSACTION_ID);
checkLastCommittedTxIdInLogAndNeoStore(expectedLastTxId + 1, txIdFromOrigin);
assertEquals(DbRepresentation.of(db), getBackupDbRepresentation());
assertTrue(backupOutcome.isConsistent());
}
use of org.neo4j.kernel.impl.util.Dependencies in project neo4j by neo4j.
the class BackupServiceIT method backupsShouldBeMentionedInServerConsoleLog.
@Test
public void backupsShouldBeMentionedInServerConsoleLog() throws Throwable {
// given
defaultBackupPortHostParams();
Config config = dbRule.getConfigCopy();
dbRule.setConfig(OnlineBackupSettings.online_backup_enabled, "false");
Config withOnlineBackupDisabled = dbRule.getConfigCopy();
createAndIndexNode(dbRule, 1);
final Log log = mock(Log.class);
LogProvider logProvider = new LogProvider() {
@Override
public Log getLog(Class loggingClass) {
return log;
}
@Override
public Log getLog(String name) {
return log;
}
};
Logger logger = mock(Logger.class);
when(log.infoLogger()).thenReturn(logger);
LogService logService = mock(LogService.class);
when(logService.getInternalLogProvider()).thenReturn(logProvider);
Dependencies dependencies = new Dependencies(dbRule.getDependencyResolver());
dependencies.satisfyDependencies(config, monitors, logService);
OnlineBackupKernelExtension backup = (OnlineBackupKernelExtension) new OnlineBackupExtensionFactory().newInstance(new SimpleKernelContext(storeDir, DatabaseInfo.UNKNOWN, dependencies), DependenciesProxy.dependencies(dependencies, OnlineBackupExtensionFactory.Dependencies.class));
backup.start();
// when
backupService().doFullBackup(BACKUP_HOST, backupPort, backupDir, ConsistencyCheck.NONE, withOnlineBackupDisabled, BackupClient.BIG_READ_TIMEOUT, false);
// then
verify(logger).log("Full backup started...");
verify(logger).log("Full backup finished.");
// when
createAndIndexNode(dbRule, 2);
backupService().doIncrementalBackupOrFallbackToFull(BACKUP_HOST, backupPort, backupDir, ConsistencyCheck.NONE, withOnlineBackupDisabled, BackupClient.BIG_READ_TIMEOUT, false);
backup.stop();
// then
verify(logger).log("Incremental backup started...");
verify(logger).log("Incremental backup finished.");
}
use of org.neo4j.kernel.impl.util.Dependencies in project neo4j by neo4j.
the class ArbiterBootstrapper method start.
@SafeVarargs
@Override
public final int start(File homeDir, Optional<File> configFile, Pair<String, String>... configOverrides) {
Config config = getConfig(configFile, configOverrides);
try {
DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
life.add(new FileSystemLifecycleAdapter(fileSystem));
life.add(new Neo4jJobScheduler());
new ClusterClientModule(life, new Dependencies(), new Monitors(), config, logService(fileSystem, config), new NotElectableElectionCredentialsProvider());
} catch (LifecycleException e) {
@SuppressWarnings({ "ThrowableResultOfMethodCallIgnored", "unchecked" }) Throwable cause = peel(e, Predicates.<Throwable>instanceOf(LifecycleException.class));
if (cause instanceof ChannelException) {
System.err.println("ERROR: " + cause.getMessage() + (cause.getCause() != null ? ", caused by:" + cause.getCause().getMessage() : ""));
} else {
System.err.println("ERROR: Unknown error");
throw e;
}
}
addShutdownHook();
life.start();
return 0;
}
use of org.neo4j.kernel.impl.util.Dependencies in project neo4j by neo4j.
the class ArbiterBootstrapperIT method before.
@Before
public void before() throws Exception {
directory = testDirectory.directory("temp");
life = new LifeSupport();
// So that the clients get started as they are added
life.start();
clients = new ClusterClient[2];
for (int i = 1; i <= clients.length; i++) {
Map<String, String> config = stringMap();
config.put(cluster_server.name(), ":" + (5000 + i));
config.put(server_id.name(), "" + i);
config.put(initial_hosts.name(), ":5001");
LifeSupport moduleLife = new LifeSupport();
ClusterClientModule clusterClientModule = new ClusterClientModule(moduleLife, new Dependencies(), new Monitors(), Config.embeddedDefaults(config), NullLogService.getInstance(), new ServerIdElectionCredentialsProvider());
ClusterClient client = clusterClientModule.clusterClient;
CountDownLatch latch = new CountDownLatch(1);
client.addClusterListener(new ClusterListener.Adapter() {
@Override
public void enteredCluster(ClusterConfiguration configuration) {
latch.countDown();
client.removeClusterListener(this);
}
});
life.add(moduleLife);
clients[i - 1] = client;
assertTrue("Didn't join the cluster", latch.await(20, SECONDS));
}
}
Aggregations