Search in sources :

Example 21 with TransactionRepresentation

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;
}
Also used : TransactionCursor(org.neo4j.kernel.impl.transaction.log.TransactionCursor) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) ArrayList(java.util.ArrayList) LogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore)

Example 22 with TransactionRepresentation

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());
    }
}
Also used : LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) OnePhaseCommit(org.neo4j.kernel.impl.transaction.log.entry.OnePhaseCommit) Test(org.junit.Test)

Example 23 with TransactionRepresentation

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());
    }
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) Test(org.junit.Test)

Example 24 with TransactionRepresentation

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);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) NeoStores(org.neo4j.kernel.impl.store.NeoStores) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) NeoStoreBatchTransactionApplier(org.neo4j.kernel.impl.transaction.command.NeoStoreBatchTransactionApplier) InMemoryVersionableReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.InMemoryVersionableReadableClosablePositionAwareChannel) NeoStoreBatchTransactionApplier(org.neo4j.kernel.impl.transaction.command.NeoStoreBatchTransactionApplier) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) CacheAccessBackDoor(org.neo4j.kernel.impl.core.CacheAccessBackDoor) Test(org.junit.Test)

Example 25 with TransactionRepresentation

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);
}
Also used : LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) Command(org.neo4j.kernel.impl.transaction.command.Command) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter) OnePhaseCommit(org.neo4j.kernel.impl.transaction.log.entry.OnePhaseCommit) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) Test(org.junit.Test)

Aggregations

TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)26 Test (org.junit.Test)13 TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)12 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)9 PhysicalTransactionRepresentation (org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)3 RequestContext (org.neo4j.com.RequestContext)3 LogicalTransactionStore (org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore)3 LogEntryCommit (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)2 TransactionFailureException (org.neo4j.kernel.api.exceptions.TransactionFailureException)2 ReadableClosablePositionAwareChannel (org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)2 TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)2 LogEntryStart (org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart)2 OnePhaseCommit (org.neo4j.kernel.impl.transaction.log.entry.OnePhaseCommit)2 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)2 StorageCommand (org.neo4j.storageengine.api.StorageCommand)2 ByteBuf (io.netty.buffer.ByteBuf)1