use of org.neo4j.kernel.impl.transaction.log.TransactionIdStore in project neo4j by neo4j.
the class BoltFactoryImplTest method txIdStoreRefreshedAfterRestart.
@Test
public void txIdStoreRefreshedAfterRestart() throws Throwable {
GraphDatabaseAPI db = newDbMock();
DependencyResolver dependencyResolver = db.getDependencyResolver();
TransactionIdStore txIdStoreBeforeRestart = mock(TransactionIdStore.class);
when(txIdStoreBeforeRestart.getLastClosedTransactionId()).thenReturn(42L);
TransactionIdStore txIdStoreAfterRestart = mock(TransactionIdStore.class);
when(txIdStoreAfterRestart.getLastClosedTransactionId()).thenReturn(4242L);
when(dependencyResolver.resolveDependency(TransactionIdStore.class)).thenReturn(txIdStoreBeforeRestart).thenReturn(txIdStoreAfterRestart);
BoltFactoryImpl boltFactory = newBoltFactory(db);
boltFactory.start();
BoltStateMachine stateMachine1 = boltFactory.newMachine(CONNECTION_DESCRIPTOR, mock(Runnable.class), CLOCK);
assertEquals(42, stateMachine1.spi.transactionSpi().newestEncounteredTxId());
boltFactory.stop();
boltFactory.start();
BoltStateMachine stateMachine2 = boltFactory.newMachine(CONNECTION_DESCRIPTOR, mock(Runnable.class), CLOCK);
assertEquals(4242, stateMachine2.spi.transactionSpi().newestEncounteredTxId());
}
use of org.neo4j.kernel.impl.transaction.log.TransactionIdStore in project neo4j by neo4j.
the class TransactionStateMachineSPITest method throwsWhenTxAwaitDurationExpires.
@Test
public void throwsWhenTxAwaitDurationExpires() throws Exception {
long lastClosedTransactionId = 100;
TransactionIdStore txIdStore = fixedTxIdStore(lastClosedTransactionId);
Duration txAwaitDuration = Duration.ofSeconds(42);
FakeClock clock = new FakeClock();
AvailabilityGuard availabilityGuard = spy(new AvailabilityGuard(clock, NullLog.getInstance()));
when(availabilityGuard.isAvailable()).then(invocation -> {
boolean available = (boolean) invocation.callRealMethod();
clock.forward(txAwaitDuration.getSeconds() + 1, SECONDS);
return available;
});
TransactionStateMachineSPI txSpi = createTxSpi(txIdStore, txAwaitDuration, availabilityGuard, clock);
Future<Void> result = otherThread.execute(state -> {
txSpi.awaitUpToDate(lastClosedTransactionId + 42);
return null;
});
try {
result.get(20, SECONDS);
} catch (Exception e) {
assertThat(e, instanceOf(ExecutionException.class));
assertThat(e.getCause(), instanceOf(TransactionFailureException.class));
}
}
use of org.neo4j.kernel.impl.transaction.log.TransactionIdStore in project neo4j by neo4j.
the class TransactionStateMachineSPITest method fixedTxIdStore.
private static TransactionIdStore fixedTxIdStore(long lastClosedTransactionId) {
TransactionIdStore txIdStore = mock(TransactionIdStore.class);
when(txIdStore.getLastClosedTransactionId()).thenReturn(lastClosedTransactionId);
return txIdStore;
}
use of org.neo4j.kernel.impl.transaction.log.TransactionIdStore 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 DeadSimpleTransactionIdStore();
TransactionMetadataCache transactionMetadataCache = new TransactionMetadataCache(100_000);
LogHeaderCache logHeaderCache = new LogHeaderCache(1000);
LogFile logFile = life.add(createPhysicalLogFile(transactionIdStore, logHeaderCache, fileSystem));
TransactionAppender transactionAppender = life.add(createBatchingTransactionAppender(transactionIdStore, transactionMetadataCache, logFile));
ExecutorService executorService = Executors.newFixedThreadPool(threads);
try {
Future<?>[] handlers = new Future[threads];
for (int i = 0; i < threads; i++) {
TransactionRepresentationFactory factory = new TransactionRepresentationFactory();
Worker task = new Worker(transactionAppender, factory, condition);
handlers[i] = executorService.submit(task);
}
// wait for all the workers to complete
for (Future<?> handle : handlers) {
handle.get();
}
} finally {
executorService.shutdown();
}
lastCommittedTransactionId = transactionIdStore.getLastCommittedTransactionId();
}
return lastCommittedTransactionId;
}
use of org.neo4j.kernel.impl.transaction.log.TransactionIdStore 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);
}
Aggregations