use of org.neo4j.kernel.internal.DatabaseHealth in project neo4j by neo4j.
the class NeoStoreDataSourceTest method shouldAlwaysShutdownLifeEvenWhenCheckPointingFails.
@Test
public void shouldAlwaysShutdownLifeEvenWhenCheckPointingFails() throws Exception {
// Given
File storeDir = dir.graphDbDir();
FileSystemAbstraction fs = this.fs.get();
PageCache pageCache = pageCacheRule.getPageCache(fs);
DatabaseHealth databaseHealth = mock(DatabaseHealth.class);
when(databaseHealth.isHealthy()).thenReturn(true);
IOException ex = new IOException("boom!");
doThrow(ex).when(databaseHealth).assertHealthy(// <- this is a trick to simulate a failure during checkpointing
IOException.class);
NeoStoreDataSource dataSource = dsRule.getDataSource(storeDir, fs, pageCache, emptyMap(), databaseHealth);
dataSource.start();
try {
// When
dataSource.stop();
fail("it should have thrown");
} catch (LifecycleException e) {
// Then
assertEquals(ex, e.getCause());
}
}
use of org.neo4j.kernel.internal.DatabaseHealth in project neo4j by neo4j.
the class RecordStorageEngineTest method panicOnExceptionDuringCommandsApply.
@Test
public void panicOnExceptionDuringCommandsApply() throws Exception {
IllegalStateException failure = new IllegalStateException("Too many open files");
RecordStorageEngine engine = storageEngineRule.getWith(fsRule.get(), pageCacheRule.getPageCache(fsRule.get())).databaseHealth(databaseHealth).transactionApplierTransformer(facade -> transactionApplierFacadeTransformer(facade, failure)).build();
CommandsToApply commandsToApply = mock(CommandsToApply.class);
try {
engine.apply(commandsToApply, TransactionApplicationMode.INTERNAL);
fail("Exception expected");
} catch (Exception exception) {
assertSame(failure, Exceptions.rootCause(exception));
}
verify(databaseHealth).panic(any(Throwable.class));
}
use of org.neo4j.kernel.internal.DatabaseHealth in project neo4j by neo4j.
the class NeoStoreDataSource method buildTransactionLogs.
private NeoStoreTransactionLogModule buildTransactionLogs(File storeDir, Config config, LogProvider logProvider, JobScheduler scheduler, FileSystemAbstraction fileSystemAbstraction, StorageEngine storageEngine, LogEntryReader<ReadableClosablePositionAwareChannel> logEntryReader, SynchronizedArrayIdOrderingQueue legacyIndexTransactionOrdering, TransactionIdStore transactionIdStore, LogVersionRepository logVersionRepository) {
TransactionMetadataCache transactionMetadataCache = new TransactionMetadataCache(100_000);
LogHeaderCache logHeaderCache = new LogHeaderCache(1000);
final PhysicalLogFiles logFiles = new PhysicalLogFiles(storeDir, PhysicalLogFile.DEFAULT_NAME, fileSystemAbstraction);
final PhysicalLogFile logFile = life.add(new PhysicalLogFile(fileSystemAbstraction, logFiles, config.get(GraphDatabaseSettings.logical_log_rotation_threshold), transactionIdStore::getLastCommittedTransactionId, logVersionRepository, physicalLogMonitor, logHeaderCache));
final PhysicalLogFileInformation.LogVersionToTimestamp logInformation = version -> {
LogPosition position = LogPosition.start(version);
try (ReadableLogChannel channel = logFile.getReader(position)) {
LogEntry entry;
while ((entry = logEntryReader.readLogEntry(channel)) != null) {
if (entry instanceof LogEntryStart) {
return entry.<LogEntryStart>as().getTimeWritten();
}
}
}
return -1;
};
final LogFileInformation logFileInformation = new PhysicalLogFileInformation(logFiles, logHeaderCache, transactionIdStore::getLastCommittedTransactionId, logInformation);
if (config.get(GraphDatabaseFacadeFactory.Configuration.ephemeral)) {
config = config.withDefaults(stringMap(GraphDatabaseSettings.keep_logical_logs.name(), "1 files"));
}
String pruningConf = config.get(GraphDatabaseSettings.keep_logical_logs);
LogPruneStrategy logPruneStrategy = fromConfigValue(fs, logFileInformation, logFiles, pruningConf);
final LogPruning logPruning = new LogPruningImpl(logPruneStrategy, logProvider);
final LogRotation logRotation = new LogRotationImpl(monitors.newMonitor(LogRotation.Monitor.class), logFile, databaseHealth);
final TransactionAppender appender = life.add(new BatchingTransactionAppender(logFile, logRotation, transactionMetadataCache, transactionIdStore, legacyIndexTransactionOrdering, databaseHealth));
final LogicalTransactionStore logicalTransactionStore = new PhysicalLogicalTransactionStore(logFile, transactionMetadataCache, logEntryReader);
int txThreshold = config.get(GraphDatabaseSettings.check_point_interval_tx);
final CountCommittedTransactionThreshold countCommittedTransactionThreshold = new CountCommittedTransactionThreshold(txThreshold);
long timeMillisThreshold = config.get(GraphDatabaseSettings.check_point_interval_time);
TimeCheckPointThreshold timeCheckPointThreshold = new TimeCheckPointThreshold(timeMillisThreshold, clock);
CheckPointThreshold threshold = CheckPointThresholds.or(countCommittedTransactionThreshold, timeCheckPointThreshold);
final CheckPointerImpl checkPointer = new CheckPointerImpl(transactionIdStore, threshold, storageEngine, logPruning, appender, databaseHealth, logProvider, tracers.checkPointTracer, ioLimiter, storeCopyCheckPointMutex);
long recurringPeriod = Math.min(timeMillisThreshold, TimeUnit.SECONDS.toMillis(10));
CheckPointScheduler checkPointScheduler = new CheckPointScheduler(checkPointer, scheduler, recurringPeriod, databaseHealth);
life.add(checkPointer);
life.add(checkPointScheduler);
return new NeoStoreTransactionLogModule(logicalTransactionStore, logFileInformation, logFiles, logFile, logRotation, checkPointer, appender, legacyIndexTransactionOrdering);
}
use of org.neo4j.kernel.internal.DatabaseHealth in project neo4j by neo4j.
the class Runner method createBatchingTransactionAppender.
private BatchingTransactionAppender createBatchingTransactionAppender(TransactionIdStore transactionIdStore, TransactionMetadataCache transactionMetadataCache, LogFile logFile) {
Log log = NullLog.getInstance();
KernelEventHandlers kernelEventHandlers = new KernelEventHandlers(log);
DatabasePanicEventGenerator panicEventGenerator = new DatabasePanicEventGenerator(kernelEventHandlers);
DatabaseHealth databaseHealth = new DatabaseHealth(panicEventGenerator, log);
LogRotationImpl logRotation = new LogRotationImpl(NOOP_LOGROTATION_MONITOR, logFile, databaseHealth);
return new BatchingTransactionAppender(logFile, logRotation, transactionMetadataCache, transactionIdStore, IdOrderingQueue.BYPASS, databaseHealth);
}
use of org.neo4j.kernel.internal.DatabaseHealth in project neo4j by neo4j.
the class NeoStoreDataSourceTest method databaseHealthShouldBeHealedOnStart.
@Test
public void databaseHealthShouldBeHealedOnStart() throws Throwable {
NeoStoreDataSource theDataSource = null;
try {
DatabaseHealth databaseHealth = new DatabaseHealth(mock(DatabasePanicEventGenerator.class), NullLogProvider.getInstance().getLog(DatabaseHealth.class));
theDataSource = dsRule.getDataSource(dir.graphDbDir(), fs.get(), pageCacheRule.getPageCache(fs.get()), stringMap(), databaseHealth);
databaseHealth.panic(new Throwable());
theDataSource.start();
databaseHealth.assertHealthy(Throwable.class);
} finally {
if (theDataSource != null) {
theDataSource.stop();
theDataSource.shutdown();
}
}
}
Aggregations