use of org.neo4j.kernel.impl.transaction.TransactionRepresentation in project neo4j by neo4j.
the class LabelAndIndexUpdateBatchingIT method extractTransactions.
private static List<TransactionRepresentation> extractTransactions(GraphDatabaseAPI db) throws NoSuchTransactionException, IOException {
LogicalTransactionStore txStore = db.getDependencyResolver().resolveDependency(LogicalTransactionStore.class);
List<TransactionRepresentation> transactions = new ArrayList<>();
try (TransactionCursor cursor = txStore.getTransactions(TransactionIdStore.BASE_TX_ID + 1)) {
cursor.forAll(tx -> transactions.add(tx.getTransactionRepresentation()));
}
return transactions;
}
use of org.neo4j.kernel.impl.transaction.TransactionRepresentation in project neo4j by neo4j.
the class BatchingTransactionAppenderTest method shouldAppendCommittedTransactions.
@Test
public void shouldAppendCommittedTransactions() throws Exception {
// GIVEN
when(logFile.getWriter()).thenReturn(channel);
long nextTxId = 15;
when(transactionIdStore.nextCommittingTransactionId()).thenReturn(nextTxId);
TransactionAppender appender = life.add(new BatchingTransactionAppender(logFile, NO_ROTATION, positionCache, transactionIdStore, BYPASS, databaseHealth));
// WHEN
final byte[] additionalHeader = new byte[] { 1, 2, 5 };
final int masterId = 2, authorId = 1;
final long timeStarted = 12345, latestCommittedTxWhenStarted = nextTxId - 5, timeCommitted = timeStarted + 10;
PhysicalTransactionRepresentation transactionRepresentation = new PhysicalTransactionRepresentation(singleCreateNodeCommand(0));
transactionRepresentation.setHeader(additionalHeader, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted, -1);
LogEntryStart start = new LogEntryStart(0, 0, 0L, latestCommittedTxWhenStarted, null, LogPosition.UNSPECIFIED);
LogEntryCommit commit = new OnePhaseCommit(nextTxId, 0L);
CommittedTransactionRepresentation transaction = new CommittedTransactionRepresentation(start, transactionRepresentation, commit);
appender.append(new TransactionToApply(transactionRepresentation, transaction.getCommitEntry().getTxId()), logAppendEvent);
// THEN
LogEntryReader<ReadableLogChannel> logEntryReader = new VersionAwareLogEntryReader<>();
try (PhysicalTransactionCursor<ReadableLogChannel> reader = new PhysicalTransactionCursor<>(channel, logEntryReader)) {
reader.next();
TransactionRepresentation result = reader.get().getTransactionRepresentation();
assertArrayEquals(additionalHeader, result.additionalHeader());
assertEquals(masterId, result.getMasterId());
assertEquals(authorId, result.getAuthorId());
assertEquals(timeStarted, result.getTimeStarted());
assertEquals(timeCommitted, result.getTimeCommitted());
assertEquals(latestCommittedTxWhenStarted, result.getLatestCommittedTxWhenStarted());
}
}
use of org.neo4j.kernel.impl.transaction.TransactionRepresentation in project neo4j by neo4j.
the class BatchingTransactionAppenderTest method shouldAppendSingleTransaction.
@Test
public void shouldAppendSingleTransaction() throws Exception {
// GIVEN
when(logFile.getWriter()).thenReturn(channel);
long txId = 15;
when(transactionIdStore.nextCommittingTransactionId()).thenReturn(txId);
TransactionAppender appender = life.add(new BatchingTransactionAppender(logFile, NO_ROTATION, positionCache, transactionIdStore, BYPASS, databaseHealth));
// WHEN
TransactionRepresentation transaction = transaction(singleCreateNodeCommand(0), new byte[] { 1, 2, 5 }, 2, 1, 12345, 4545, 12345 + 10);
appender.append(new TransactionToApply(transaction), logAppendEvent);
// THEN
final LogEntryReader<ReadableLogChannel> logEntryReader = new VersionAwareLogEntryReader<>();
try (PhysicalTransactionCursor<ReadableLogChannel> reader = new PhysicalTransactionCursor<>(channel, logEntryReader)) {
reader.next();
TransactionRepresentation tx = reader.get().getTransactionRepresentation();
assertArrayEquals(transaction.additionalHeader(), tx.additionalHeader());
assertEquals(transaction.getMasterId(), tx.getMasterId());
assertEquals(transaction.getAuthorId(), tx.getAuthorId());
assertEquals(transaction.getTimeStarted(), tx.getTimeStarted());
assertEquals(transaction.getTimeCommitted(), tx.getTimeCommitted());
assertEquals(transaction.getLatestCommittedTxWhenStarted(), tx.getLatestCommittedTxWhenStarted());
}
}
use of org.neo4j.kernel.impl.transaction.TransactionRepresentation in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldDeleteDynamicLabelsForDeletedNodeForRecoveredTransaction.
@Test
public void shouldDeleteDynamicLabelsForDeletedNodeForRecoveredTransaction() throws Throwable {
// GIVEN a store that has got a node with a dynamic label record
NeoStores store = neoStoresRule.open();
BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(store, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE);
AtomicLong nodeId = new AtomicLong();
AtomicLong dynamicLabelRecordId = new AtomicLong();
apply(applier, transaction(nodeWithDynamicLabelRecord(store, nodeId, dynamicLabelRecordId)));
assertDynamicLabelRecordInUse(store, dynamicLabelRecordId.get(), true);
// WHEN applying a transaction, which has first round-tripped through a log (written then read)
TransactionRepresentation transaction = transaction(deleteNode(store, nodeId.get()));
InMemoryVersionableReadableClosablePositionAwareChannel channel = new InMemoryVersionableReadableClosablePositionAwareChannel();
writeToChannel(transaction, channel);
CommittedTransactionRepresentation recoveredTransaction = readFromChannel(channel);
// and applying that recovered transaction
apply(applier, recoveredTransaction.getTransactionRepresentation());
// THEN should have the dynamic label record should be deleted as well
assertDynamicLabelRecordInUse(store, dynamicLabelRecordId.get(), false);
}
use of org.neo4j.kernel.impl.transaction.TransactionRepresentation in project neo4j by neo4j.
the class LegacyLogEntryWriterTest method shouldWriteAllTheEntryInSeveralCommitsToTheFile.
@Test
public void shouldWriteAllTheEntryInSeveralCommitsToTheFile() throws IOException {
// given
final LogVersionedStoreChannel channel = mock(LogVersionedStoreChannel.class);
final LogEntryWriter logEntryWriter = mock(LogEntryWriter.class);
final LegacyLogEntryWriter writer = new LegacyLogEntryWriter(fs, liftToFactory(logEntryWriter));
final LogEntryStart start1 = new LogEntryStart(0, 1, 2L, 3L, EMPTY_ADDITIONAL_ARRAY, UNSPECIFIED);
final LogEntryCommand command1 = new LogEntryCommand(new Command.NodeCommand(nodeRecord, nodeRecord));
final LogEntryCommit commit1 = new OnePhaseCommit(42L, 43L);
final LogEntryStart start2 = new LogEntryStart(9, 8, 7L, 6L, EMPTY_ADDITIONAL_ARRAY, UNSPECIFIED);
final LogEntryCommand command2 = new LogEntryCommand(new Command.RelationshipCommand(relRecord, relRecord));
final LogEntryCommit commit2 = new OnePhaseCommit(84L, 85L);
// when
IOCursor<LogEntry> cursor = mockCursor(start1, command1, commit1, start2, command2, commit2);
writer.writeAllLogEntries(channel, cursor);
// then
verify(logEntryWriter, times(1)).writeStartEntry(0, 1, 2L, 3L, EMPTY_ADDITIONAL_ARRAY);
final TransactionRepresentation expected1 = new PhysicalTransactionRepresentation(Arrays.asList(command1.getXaCommand()));
verify(logEntryWriter, times(1)).serialize(eq(expected1));
verify(logEntryWriter, times(1)).writeCommitEntry(42L, 43L);
verify(logEntryWriter, times(1)).writeStartEntry(9, 8, 7L, 6L, EMPTY_ADDITIONAL_ARRAY);
final TransactionRepresentation expected2 = new PhysicalTransactionRepresentation(Arrays.asList(command2.getXaCommand()));
verify(logEntryWriter, times(1)).serialize(eq(expected2));
verify(logEntryWriter, times(1)).writeCommitEntry(84L, 85L);
}
Aggregations