use of org.neo4j.kernel.impl.transaction.log.TransactionAppender 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.impl.transaction.log.TransactionAppender in project neo4j by neo4j.
the class TransactionRepresentationCommitProcessTest method shouldFailWithProperMessageOnAppendException.
@Test
public void shouldFailWithProperMessageOnAppendException() throws Exception {
// GIVEN
TransactionAppender appender = mock(TransactionAppender.class);
IOException rootCause = new IOException("Mock exception");
doThrow(new IOException(rootCause)).when(appender).append(any(TransactionToApply.class), any(LogAppendEvent.class));
StorageEngine storageEngine = mock(StorageEngine.class);
TransactionCommitProcess commitProcess = new TransactionRepresentationCommitProcess(appender, storageEngine);
// WHEN
try {
commitProcess.commit(mockedTransaction(), commitEvent, INTERNAL);
fail("Should have failed, something is wrong with the mocking in this test");
} catch (TransactionFailureException e) {
assertThat(e.getMessage(), containsString("Could not append transaction representation to log"));
assertTrue(contains(e, rootCause.getMessage(), rootCause.getClass()));
}
}
use of org.neo4j.kernel.impl.transaction.log.TransactionAppender in project neo4j by neo4j.
the class InternalTransactionCommitProcessTest method shouldFailWithProperMessageOnAppendException.
@Test
void shouldFailWithProperMessageOnAppendException() throws Exception {
// GIVEN
TransactionAppender appender = mock(TransactionAppender.class);
IOException rootCause = new IOException("Mock exception");
doThrow(new IOException(rootCause)).when(appender).append(any(TransactionToApply.class), any(LogAppendEvent.class));
StorageEngine storageEngine = mock(StorageEngine.class);
TransactionCommitProcess commitProcess = new InternalTransactionCommitProcess(appender, storageEngine);
// WHEN
TransactionFailureException exception = assertThrows(TransactionFailureException.class, () -> commitProcess.commit(mockedTransaction(), commitEvent, INTERNAL));
assertThat(exception.getMessage()).contains("Could not append transaction representation to log");
assertTrue(contains(exception, rootCause.getMessage(), rootCause.getClass()));
}
use of org.neo4j.kernel.impl.transaction.log.TransactionAppender in project neo4j by neo4j.
the class InternalTransactionCommitProcessTest method shouldCloseTransactionRegardlessOfWhetherOrNotItAppliedCorrectly.
@Test
void shouldCloseTransactionRegardlessOfWhetherOrNotItAppliedCorrectly() throws Exception {
// GIVEN
TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
TransactionAppender appender = new TestableTransactionAppender(transactionIdStore);
long txId = 11;
when(transactionIdStore.nextCommittingTransactionId()).thenReturn(txId);
IOException rootCause = new IOException("Mock exception");
StorageEngine storageEngine = mock(StorageEngine.class);
doThrow(new IOException(rootCause)).when(storageEngine).apply(any(TransactionToApply.class), any(TransactionApplicationMode.class));
TransactionCommitProcess commitProcess = new InternalTransactionCommitProcess(appender, storageEngine);
TransactionToApply transaction = mockedTransaction();
// WHEN
TransactionFailureException exception = assertThrows(TransactionFailureException.class, () -> commitProcess.commit(transaction, commitEvent, INTERNAL));
assertThat(exception.getMessage()).contains("Could not apply the transaction to the store");
assertTrue(contains(exception, rootCause.getMessage(), rootCause.getClass()));
// THEN
// we can't verify transactionCommitted since that's part of the TransactionAppender, which we have mocked
verify(transactionIdStore).transactionClosed(eq(txId), anyLong(), anyLong(), any(CursorContext.class));
}
use of org.neo4j.kernel.impl.transaction.log.TransactionAppender in project neo4j by neo4j.
the class Runner method call.
@Override
public Long call() throws Exception {
long lastCommittedTransactionId;
try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
Lifespan life = new Lifespan()) {
TransactionIdStore transactionIdStore = new SimpleTransactionIdStore();
TransactionMetadataCache transactionMetadataCache = new TransactionMetadataCache();
LogFiles logFiles = life.add(createLogFiles(transactionIdStore, fileSystem));
TransactionAppender transactionAppender = life.add(createBatchingTransactionAppender(transactionIdStore, transactionMetadataCache, logFiles));
ExecutorService executorService = Executors.newFixedThreadPool(threads);
try {
List<Future<?>> handlers = new ArrayList<>(threads);
for (int i = 0; i < threads; i++) {
TransactionRepresentationFactory factory = new TransactionRepresentationFactory();
Worker task = new Worker(transactionAppender, factory, condition);
handlers.add(executorService.submit(task));
}
// wait for all the workers to complete
Futures.getAll(handlers);
} finally {
executorService.shutdown();
}
lastCommittedTransactionId = transactionIdStore.getLastCommittedTransactionId();
}
return lastCommittedTransactionId;
}
Aggregations