use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.
the class TransactionRecordStateTest method transactionRepresentationOf.
private PhysicalTransactionRepresentation transactionRepresentationOf(TransactionRecordState writeTransaction) throws TransactionFailureException {
List<StorageCommand> commands = new ArrayList<>();
writeTransaction.extractCommands(commands);
PhysicalTransactionRepresentation tx = new PhysicalTransactionRepresentation(commands);
tx.setHeader(new byte[0], 0, 0, 0, 0, 0, 0);
return tx;
}
use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.
the class KernelTransactionImplementationTest method shouldUseStartTimeAndTxIdFromWhenStartingTxAsHeader.
@SuppressWarnings("unchecked")
@Test
public void shouldUseStartTimeAndTxIdFromWhenStartingTxAsHeader() throws Exception {
// GIVEN a transaction starting at one point in time
long startingTime = clock.millis();
when(legacyIndexState.hasChanges()).thenReturn(true);
doAnswer(invocation -> {
@SuppressWarnings("unchecked") Collection<StorageCommand> commands = invocation.getArgumentAt(0, Collection.class);
commands.add(mock(Command.class));
return null;
}).when(storageEngine).createCommands(any(Collection.class), any(TransactionState.class), any(StorageStatement.class), any(ResourceLocker.class), anyLong());
try (KernelTransactionImplementation transaction = newTransaction(securityContext())) {
SimpleStatementLocks statementLocks = new SimpleStatementLocks(mock(Locks.Client.class));
transaction.initialize(5L, BASE_TX_COMMIT_TIMESTAMP, statementLocks, KernelTransaction.Type.implicit, AUTH_DISABLED, 0L);
try (KernelStatement statement = transaction.acquireStatement()) {
// which will pull it from the supplier and the mocking above
statement.legacyIndexTxState();
// will have it say that it has changes.
}
// WHEN committing it at a later point
clock.forward(5, MILLISECONDS);
// ...and simulating some other transaction being committed
when(metaDataStore.getLastCommittedTransactionId()).thenReturn(7L);
transaction.success();
}
// THEN start time and last tx when started should have been taken from when the transaction started
assertEquals(5L, commitProcess.transaction.getLatestCommittedTxWhenStarted());
assertEquals(startingTime, commitProcess.transaction.getTimeStarted());
assertEquals(startingTime + 5, commitProcess.transaction.getTimeCommitted());
}
use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.
the class RecoveryCorruptedTransactionLogIT method addCorruptedCommandsToLastLogFile.
private void addCorruptedCommandsToLastLogFile(LogEntryWriterWrapper logEntryWriterWrapper) throws IOException {
PositiveLogFilesBasedLogVersionRepository versionRepository = new PositiveLogFilesBasedLogVersionRepository(logFiles);
LogFiles internalLogFiles = LogFilesBuilder.builder(databaseLayout, fileSystem).withLogVersionRepository(versionRepository).withTransactionIdStore(new SimpleTransactionIdStore()).withStoreId(StoreId.UNKNOWN).withCommandReaderFactory(StorageEngineFactory.defaultStorageEngine().commandReaderFactory()).build();
try (Lifespan lifespan = new Lifespan(internalLogFiles)) {
LogFile transactionLogFile = internalLogFiles.getLogFile();
LogEntryWriter<FlushablePositionAwareChecksumChannel> realLogEntryWriter = transactionLogFile.getTransactionLogWriter().getWriter();
LogEntryWriter<FlushablePositionAwareChecksumChannel> wrappedLogEntryWriter = logEntryWriterWrapper.wrap(realLogEntryWriter);
StaticLogEntryWriterFactory<FlushablePositionAwareChecksumChannel> factory = new StaticLogEntryWriterFactory<>(wrappedLogEntryWriter);
TransactionLogWriter writer = new TransactionLogWriter(realLogEntryWriter.getChannel(), factory);
List<StorageCommand> commands = new ArrayList<>();
commands.add(new Command.PropertyCommand(new PropertyRecord(1), new PropertyRecord(2)));
commands.add(new Command.NodeCommand(new NodeRecord(2), new NodeRecord(3)));
PhysicalTransactionRepresentation transaction = new PhysicalTransactionRepresentation(commands);
transaction.setHeader(new byte[0], 0, 0, 0, 0, ANONYMOUS);
writer.append(transaction, 1000, BASE_TX_CHECKSUM);
}
}
use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.
the class KernelTransactionsTest method newKernelTransactions.
private KernelTransactions newKernelTransactions(boolean testKernelTransactions, TransactionCommitProcess commitProcess, StorageReader firstReader, Config config, StorageReader... otherReaders) throws Throwable {
Locks locks = mock(Locks.class);
Locks.Client client = mock(Locks.Client.class);
when(locks.newClient()).thenReturn(client);
StorageEngine storageEngine = mock(StorageEngine.class);
when(storageEngine.newReader()).thenReturn(firstReader, otherReaders);
when(storageEngine.newCommandCreationContext(any())).thenReturn(mock(CommandCreationContext.class));
doAnswer(invocation -> {
Collection<StorageCommand> argument = invocation.getArgument(0);
argument.add(mock(StorageCommand.class));
return null;
}).when(storageEngine).createCommands(anyCollection(), any(ReadableTransactionState.class), any(StorageReader.class), any(CommandCreationContext.class), any(ResourceLocker.class), any(LockTracer.class), anyLong(), any(TxStateVisitor.Decorator.class), any(CursorContext.class), any(MemoryTracker.class));
return newKernelTransactions(locks, storageEngine, commitProcess, testKernelTransactions, config);
}
use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.
the class LogCommandSerializationV4_3D_3Test method shouldReadAndWriteMetaDataCommand.
@Test
void shouldReadAndWriteMetaDataCommand() throws IOException {
// Given
InMemoryClosableChannel channel = new InMemoryClosableChannel();
MetaDataRecord before = new MetaDataRecord(12);
MetaDataRecord after = new MetaDataRecord(12);
after.initialize(true, 999);
new Command.MetaDataCommand(writer(), before, after).serialize(channel);
// When
CommandReader reader = createReader();
StorageCommand command = reader.read(channel);
assertTrue(command instanceof Command.MetaDataCommand);
Command.MetaDataCommand readCommand = (Command.MetaDataCommand) command;
// Then
assertBeforeAndAfterEquals(readCommand, before, after);
}
Aggregations