use of org.neo4j.kernel.impl.api.TransactionToApply in project neo4j by neo4j.
the class BatchingNeoStoresTest method apply.
private static void apply(TxState txState, CommandCreationContext commandCreationContext, RecordStorageEngine storageEngine) throws Exception {
List<StorageCommand> commands = new ArrayList<>();
try (RecordStorageReader storageReader = storageEngine.newReader()) {
storageEngine.createCommands(commands, txState, storageReader, commandCreationContext, ResourceLocker.IGNORE, LockTracer.NONE, BASE_TX_ID, v -> v, NULL, INSTANCE);
CommandsToApply apply = new TransactionToApply(new PhysicalTransactionRepresentation(commands, new byte[0], 0, 0, 0, 0, ANONYMOUS), NULL);
storageEngine.apply(apply, TransactionApplicationMode.INTERNAL);
}
}
use of org.neo4j.kernel.impl.api.TransactionToApply in project neo4j by neo4j.
the class CommitProcessTracingIT method tracePageCacheAccessOnTransactionApply.
@Test
void tracePageCacheAccessOnTransactionApply() throws TransactionFailureException {
var transaction = new PhysicalTransactionRepresentation(List.of(new Command.NodeCountsCommand(1, 2)), EMPTY_BYTE_ARRAY, 0, 0, 0, 0, ANONYMOUS);
var pageCacheTracer = new DefaultPageCacheTracer();
try (var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer("tracePageCacheAccessOnTransactionApply"))) {
assertZeroCursor(cursorContext);
commitProcess.commit(new TransactionToApply(transaction, cursorContext), NULL, EXTERNAL);
assertCursor(cursorContext, 3);
}
}
use of org.neo4j.kernel.impl.api.TransactionToApply in project neo4j by neo4j.
the class TransactionRepresentationFactory method nextTransaction.
TransactionToApply nextTransaction(long txId) {
PhysicalTransactionRepresentation representation = new PhysicalTransactionRepresentation(createRandomCommands());
representation.setHeader(new byte[0], currentTimeMillis(), txId, currentTimeMillis(), 42, ANONYMOUS);
return new TransactionToApply(representation, NULL);
}
use of org.neo4j.kernel.impl.api.TransactionToApply in project neo4j by neo4j.
the class BatchingTransactionAppender method append.
@Override
public long append(TransactionToApply batch, LogAppendEvent logAppendEvent) throws IOException {
// Assigned base tx id just to make compiler happy
long lastTransactionId = TransactionIdStore.BASE_TX_ID;
// Synchronized with logFile to get absolute control over concurrent rotations happening
synchronized (logFile) {
// Assert that kernel is healthy before making any changes
databaseHealth.assertHealthy(IOException.class);
try (SerializeTransactionEvent serialiseEvent = logAppendEvent.beginSerializeTransaction()) {
// Append all transactions in this batch to the log under the same logFile monitor
TransactionToApply tx = batch;
while (tx != null) {
long transactionId = transactionIdStore.nextCommittingTransactionId();
// If we're in a scenario where we're merely replicating transactions, i.e. transaction
// id have already been generated by another entity we simply check that our id
// that we generated match that id. If it doesn't we've run into a problem we can't ยด
// really recover from and would point to a bug somewhere.
matchAgainstExpectedTransactionIdIfAny(transactionId, tx);
TransactionCommitment commitment = appendToLog(tx.transactionRepresentation(), transactionId, logAppendEvent, previousChecksum);
previousChecksum = commitment.getTransactionChecksum();
tx.commitment(commitment, transactionId);
tx.logPosition(commitment.logPosition());
tx = tx.next();
lastTransactionId = transactionId;
}
}
}
// in this batch exist durably on disk.
if (logFile.forceAfterAppend(logAppendEvent)) {
// We got lucky and were the one forcing the log. It's enough if ones of all doing concurrent committers
// checks the need for log rotation.
boolean logRotated = logRotation.rotateLogIfNeeded(logAppendEvent);
logAppendEvent.setLogRotated(logRotated);
}
// Mark all transactions as committed
publishAsCommitted(batch);
return lastTransactionId;
}
use of org.neo4j.kernel.impl.api.TransactionToApply in project neo4j by neo4j.
the class TransactionLogAppendAndRotateIT method shouldKeepTransactionsIntactWhenConcurrentlyRotationAndAppending.
@Test
void shouldKeepTransactionsIntactWhenConcurrentlyRotationAndAppending() throws Throwable {
// GIVEN
LogVersionRepository logVersionRepository = new SimpleLogVersionRepository();
LogFiles logFiles = LogFilesBuilder.builder(databaseLayout, fileSystem).withLogVersionRepository(logVersionRepository).withRotationThreshold(ByteUnit.mebiBytes(1)).withTransactionIdStore(new SimpleTransactionIdStore()).withLogEntryReader(logEntryReader()).withStoreId(StoreId.UNKNOWN).build();
life.add(logFiles);
final AtomicBoolean end = new AtomicBoolean();
AllTheMonitoring monitoring = new AllTheMonitoring(end, 100);
TransactionIdStore txIdStore = new SimpleTransactionIdStore();
TransactionMetadataCache metadataCache = new TransactionMetadataCache();
monitoring.setLogFile(logFiles.getLogFile());
Health health = new DatabaseHealth(mock(DatabasePanicEventGenerator.class), NullLog.getInstance());
LogRotation rotation = transactionLogRotation(logFiles, Clock.systemUTC(), health, monitoring);
final TransactionAppender appender = life.add(new BatchingTransactionAppender(logFiles, rotation, metadataCache, txIdStore, health));
// WHEN
Race race = new Race();
for (int i = 0; i < 4; i++) {
race.addContestant(() -> {
while (!end.get()) {
try {
appender.append(new TransactionToApply(sillyTransaction(1_000), CursorContext.NULL), LogAppendEvent.NULL);
} catch (Exception e) {
e.printStackTrace(System.out);
end.set(true);
fail(e.getMessage(), e);
}
}
});
}
race.addContestant(endAfterMax(250, MILLISECONDS, end, monitoring));
race.go();
// THEN
assertTrue(monitoring.numberOfRotations() > 0);
}
Aggregations