Search in sources :

Example 1 with TransactionCursor

use of org.neo4j.kernel.impl.transaction.log.TransactionCursor in project neo4j by neo4j.

the class ProduceNoopCommandsIT method listNoopCommands.

@AfterEach
void listNoopCommands() throws IOException {
    LogicalTransactionStore txStore = ((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(LogicalTransactionStore.class);
    try (TransactionCursor transactions = txStore.getTransactions(TransactionIdStore.BASE_TX_ID + 1)) {
        while (transactions.next()) {
            CommittedTransactionRepresentation tx = transactions.get();
            TransactionRepresentation transactionRepresentation = tx.getTransactionRepresentation();
            if (hasNoOpCommand(transactionRepresentation)) {
                StringBuilder error = new StringBuilder("Tx contains no-op commands, " + tx.getStartEntry());
                printNoOpCommands(transactionRepresentation, error);
                error.append(format("%n%s", tx.getCommitEntry()));
                fail(error.toString());
            }
        }
    }
}
Also used : CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) TransactionCursor(org.neo4j.kernel.impl.transaction.log.TransactionCursor) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) LogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore) AfterEach(org.junit.jupiter.api.AfterEach)

Example 2 with TransactionCursor

use of org.neo4j.kernel.impl.transaction.log.TransactionCursor in project neo4j by neo4j.

the class DatabaseUpgradeTransactionIT method assertUpgradeTransactionInOrder.

private void assertUpgradeTransactionInOrder(KernelVersion from, KernelVersion to, long fromTxId) throws Exception {
    LogicalTransactionStore lts = db.getDependencyResolver().resolveDependency(LogicalTransactionStore.class);
    ArrayList<KernelVersion> transactionVersions = new ArrayList<>();
    ArrayList<CommittedTransactionRepresentation> transactions = new ArrayList<>();
    try (TransactionCursor transactionCursor = lts.getTransactions(fromTxId + 1)) {
        while (transactionCursor.next()) {
            CommittedTransactionRepresentation representation = transactionCursor.get();
            transactions.add(representation);
            transactionVersions.add(representation.getStartEntry().getVersion());
        }
    }
    // at least upgrade transaction and the triggering transaction
    assertThat(transactionVersions).hasSizeGreaterThanOrEqualTo(2);
    // Sorted means everything is in order
    assertThat(transactionVersions).isSortedAccordingTo(Comparator.comparingInt(KernelVersion::version));
    // First should be "from" version
    assertThat(transactionVersions.get(0)).isEqualTo(from);
    // And last the "to" version
    assertThat(transactionVersions.get(transactionVersions.size() - 1)).isEqualTo(to);
    CommittedTransactionRepresentation upgradeTransaction = transactions.get(transactionVersions.indexOf(to));
    PhysicalTransactionRepresentation physicalRep = (PhysicalTransactionRepresentation) upgradeTransaction.getTransactionRepresentation();
    physicalRep.accept(element -> {
        assertThat(element).isInstanceOf(Command.MetaDataCommand.class);
        return true;
    });
}
Also used : KernelVersion(org.neo4j.kernel.KernelVersion) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) TransactionCursor(org.neo4j.kernel.impl.transaction.log.TransactionCursor) Command(org.neo4j.internal.recordstorage.Command) ArrayList(java.util.ArrayList) LogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)

Example 3 with TransactionCursor

use of org.neo4j.kernel.impl.transaction.log.TransactionCursor in project neo4j by neo4j.

the class ReversedMultiFileTransactionCursorTest method shouldReadSingleVersionReversed.

@Test
void shouldReadSingleVersionReversed() throws Exception {
    // GIVEN
    TransactionCursor cursor = new ReversedMultiFileTransactionCursor(logFile, log(5), 0, start());
    // WHEN
    CommittedTransactionRepresentation[] reversed = exhaust(cursor);
    // THEN
    assertTransactionRange(reversed, 5, 0);
}
Also used : CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) TransactionCursor(org.neo4j.kernel.impl.transaction.log.TransactionCursor) Test(org.junit.jupiter.api.Test)

Example 4 with TransactionCursor

use of org.neo4j.kernel.impl.transaction.log.TransactionCursor in project neo4j by neo4j.

the class ReversedMultiFileTransactionCursorTest method shouldHandleEmptySingleLogVersion.

@Test
void shouldHandleEmptySingleLogVersion() throws Exception {
    // GIVEN
    TransactionCursor cursor = new ReversedMultiFileTransactionCursor(logFile, log(0), 0, start());
    // WHEN
    CommittedTransactionRepresentation[] reversed = exhaust(cursor);
    // THEN
    assertTransactionRange(reversed, 0, 0);
}
Also used : CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) TransactionCursor(org.neo4j.kernel.impl.transaction.log.TransactionCursor) Test(org.junit.jupiter.api.Test)

Example 5 with TransactionCursor

use of org.neo4j.kernel.impl.transaction.log.TransactionCursor in project neo4j by neo4j.

the class ReversedMultiFileTransactionCursorTest method shouldRespectStartLogPosition.

@Test
void shouldRespectStartLogPosition() throws Exception {
    // GIVEN
    TransactionCursor cursor = new ReversedMultiFileTransactionCursor(logFile, log(5, 6, 8), 2, new LogPosition(1, CURRENT_FORMAT_LOG_HEADER_SIZE + 3));
    // WHEN
    CommittedTransactionRepresentation[] reversed = exhaust(cursor);
    // THEN
    assertTransactionRange(reversed, 5 + 6 + 8, 5 + 3);
}
Also used : CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) TransactionCursor(org.neo4j.kernel.impl.transaction.log.TransactionCursor) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.jupiter.api.Test)

Aggregations

TransactionCursor (org.neo4j.kernel.impl.transaction.log.TransactionCursor)15 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)13 Test (org.junit.jupiter.api.Test)6 LogicalTransactionStore (org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore)6 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Test (org.junit.Test)1 AfterEach (org.junit.jupiter.api.AfterEach)1 Response (org.neo4j.com.Response)1 Visitor (org.neo4j.helpers.collection.Visitor)1 Command (org.neo4j.internal.recordstorage.Command)1 KernelVersion (org.neo4j.kernel.KernelVersion)1 DeadSimpleTransactionIdStore (org.neo4j.kernel.impl.transaction.DeadSimpleTransactionIdStore)1 NoSuchTransactionException (org.neo4j.kernel.impl.transaction.log.NoSuchTransactionException)1 PhysicalTransactionRepresentation (org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)1 ReadOnlyTransactionIdStore (org.neo4j.kernel.impl.transaction.log.ReadOnlyTransactionIdStore)1 ReadOnlyTransactionStore (org.neo4j.kernel.impl.transaction.log.ReadOnlyTransactionStore)1