use of org.neo4j.kernel.impl.transaction.log.TransactionIdStore in project neo4j by neo4j.
the class NoChangeWriteTransactionTest method shouldDetectNoChangesInCommitsAlsoForTheIndexes.
@Test
public void shouldDetectNoChangesInCommitsAlsoForTheIndexes() throws Exception {
// GIVEN a transaction that has seen some changes, where all those changes result in a net 0 change set
// a good way of producing such state is to add a label to an existing node, and then remove it.
GraphDatabaseAPI db = dbr.getGraphDatabaseAPI();
TransactionIdStore txIdStore = db.getDependencyResolver().resolveDependency(TransactionIdStore.class);
long startTxId = txIdStore.getLastCommittedTransactionId();
Node node = createEmptyNode(db);
Index<Node> index = createNodeIndex(db);
try (Transaction tx = db.beginTx()) {
node.addLabel(TestLabels.LABEL_ONE);
node.removeLabel(TestLabels.LABEL_ONE);
index.add(node, "key", "value");
index.remove(node, "key", "value");
tx.success();
}
// WHEN closing that transaction
// THEN it should not have been committed
assertEquals("Expected last txId to be what it started at + 3 " + "(1 for the empty node, 1 for index, and one for the label)", startTxId + 3, txIdStore.getLastCommittedTransactionId());
}
use of org.neo4j.kernel.impl.transaction.log.TransactionIdStore in project neo4j by neo4j.
the class NoChangeWriteTransactionTest method shouldIdentifyTransactionWithNetZeroChangesAsReadOnly.
@Test
public void shouldIdentifyTransactionWithNetZeroChangesAsReadOnly() throws Exception {
// GIVEN a transaction that has seen some changes, where all those changes result in a net 0 change set
// a good way of producing such state is to add a label to an existing node, and then remove it.
GraphDatabaseAPI db = dbr.getGraphDatabaseAPI();
TransactionIdStore txIdStore = db.getDependencyResolver().resolveDependency(TransactionIdStore.class);
long startTxId = txIdStore.getLastCommittedTransactionId();
Node node = createEmptyNode(db);
try (Transaction tx = db.beginTx()) {
node.addLabel(TestLabels.LABEL_ONE);
node.removeLabel(TestLabels.LABEL_ONE);
tx.success();
}
// WHEN closing that transaction
// THEN it should not have been committed
assertEquals("Expected last txId to be what it started at + 2 (1 for the empty node, and one for the label)", startTxId + 2, txIdStore.getLastCommittedTransactionId());
}
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);
}
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 TxPullRequestHandlerTest method shouldRespondWithCompleteStreamOfTransactions.
@Test
public void shouldRespondWithCompleteStreamOfTransactions() throws Exception {
// given
StoreId storeId = new StoreId(1, 2, 3, 4);
TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
when(transactionIdStore.getLastCommittedTransactionId()).thenReturn(15L);
LogicalTransactionStore logicalTransactionStore = mock(LogicalTransactionStore.class);
when(logicalTransactionStore.getTransactions(14L)).thenReturn(txCursor(cursor(tx(14), tx(15))));
TxPullRequestHandler txPullRequestHandler = new TxPullRequestHandler(new CatchupServerProtocol(), () -> storeId, () -> true, () -> transactionIdStore, () -> logicalTransactionStore, BATCH_SIZE, new Monitors(), NullLogProvider.getInstance());
// when
txPullRequestHandler.channelRead0(context, new TxPullRequest(13, storeId));
// then
verify(context, times(2)).write(ResponseMessageType.TX);
verify(context).write(new TxPullResponse(storeId, tx(14)));
verify(context).write(new TxPullResponse(storeId, tx(15)));
verify(context).write(ResponseMessageType.TX_STREAM_FINISHED);
verify(context).write(new TxStreamFinishedResponse(SUCCESS_END_OF_STREAM, 15L));
}
Aggregations