Search in sources :

Example 31 with TransactionRepresentation

use of org.neo4j.kernel.impl.transaction.TransactionRepresentation in project neo4j by neo4j.

the class PhysicalLogicalTransactionStoreTest method verifyTransaction.

private static void verifyTransaction(TransactionMetadataCache positionCache, byte[] additionalHeader, long timeStarted, long latestCommittedTxWhenStarted, long timeCommitted, LogicalTransactionStore store) throws IOException {
    try (TransactionCursor cursor = store.getTransactions(TransactionIdStore.BASE_TX_ID + 1)) {
        boolean hasNext = cursor.next();
        assertTrue(hasNext);
        CommittedTransactionRepresentation tx = cursor.get();
        TransactionRepresentation transaction = tx.getTransactionRepresentation();
        assertArrayEquals(additionalHeader, transaction.additionalHeader());
        assertEquals(timeStarted, transaction.getTimeStarted());
        assertEquals(timeCommitted, transaction.getTimeCommitted());
        assertEquals(latestCommittedTxWhenStarted, transaction.getLatestCommittedTxWhenStarted());
    }
    positionCache.clear();
}
Also used : CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation)

Example 32 with TransactionRepresentation

use of org.neo4j.kernel.impl.transaction.TransactionRepresentation in project neo4j by neo4j.

the class LabelAndIndexUpdateBatchingIT method toApply.

private static TransactionToApply toApply(Collection<TransactionRepresentation> transactions) {
    TransactionToApply first = null;
    TransactionToApply last = null;
    for (TransactionRepresentation transactionRepresentation : transactions) {
        TransactionToApply transaction = new TransactionToApply(transactionRepresentation, CursorContext.NULL);
        if (first == null) {
            first = last = transaction;
        } else {
            last.next(transaction);
            last = transaction;
        }
    }
    return first;
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation)

Example 33 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, long txIdToStartOn) throws IOException {
    LogicalTransactionStore txStore = db.getDependencyResolver().resolveDependency(LogicalTransactionStore.class);
    List<TransactionRepresentation> transactions = new ArrayList<>();
    try (TransactionCursor cursor = txStore.getTransactions(txIdToStartOn)) {
        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 34 with TransactionRepresentation

use of org.neo4j.kernel.impl.transaction.TransactionRepresentation in project neo4j by neo4j.

the class LabelAndIndexUpdateBatchingIT method indexShouldIncludeNodesCreatedPreviouslyInBatch.

@Test
void indexShouldIncludeNodesCreatedPreviouslyInBatch() throws Exception {
    // GIVEN a transaction stream leading up to this issue
    // perform the transactions from db-level and extract the transactions as commands
    // so that they can be applied batch-wise they way we'd like to later.
    List<TransactionRepresentation> transactions;
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder().impermanent().build();
    GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    // We don't want to include any transactions that has been run on start-up when applying to the new database later.
    long txIdToStartFrom = getLastClosedTransactionId(db) + 1;
    // a bunch of nodes (to have the index population later on to decide to use label scan for population)
    String nodeN = "our guy";
    String otherNode = "just to create the tokens";
    try {
        try (Transaction tx = db.beginTx()) {
            tx.createNode(LABEL).setProperty(PROPERTY_KEY, otherNode);
            for (int i = 0; i < 10_000; i++) {
                tx.createNode();
            }
            tx.commit();
        }
        // node N
        try (Transaction tx = db.beginTx()) {
            tx.createNode(LABEL).setProperty(PROPERTY_KEY, nodeN);
            tx.commit();
        }
        // uniqueness constraint affecting N
        try (Transaction tx = db.beginTx()) {
            tx.schema().constraintFor(LABEL).assertPropertyIsUnique(PROPERTY_KEY).create();
            tx.commit();
        }
        transactions = extractTransactions(db, txIdToStartFrom);
    } finally {
        managementService.shutdown();
    }
    managementService = new TestDatabaseManagementServiceBuilder().impermanent().build();
    db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    TransactionCommitProcess commitProcess = db.getDependencyResolver().resolveDependency(TransactionCommitProcess.class);
    try {
        int cutoffIndex = findCutoffIndex(transactions);
        commitProcess.commit(toApply(transactions.subList(0, cutoffIndex)), CommitEvent.NULL, EXTERNAL);
        // WHEN applying the two transactions (node N and the constraint) in the same batch
        commitProcess.commit(toApply(transactions.subList(cutoffIndex, transactions.size())), CommitEvent.NULL, EXTERNAL);
        // THEN node N should've ended up in the index too
        try (Transaction tx = db.beginTx()) {
            // just to verify
            assertNotNull(singleOrNull(tx.findNodes(LABEL, PROPERTY_KEY, otherNode)), "Verification node not found");
            assertNotNull(singleOrNull(tx.findNodes(LABEL, PROPERTY_KEY, nodeN)), "Node N not found");
            tx.commit();
        }
    } finally {
        managementService.shutdown();
    }
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) TransactionCommitProcess(org.neo4j.kernel.impl.api.TransactionCommitProcess) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Aggregations

TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)34 TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)14 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)13 PhysicalTransactionRepresentation (org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)9 Test (org.junit.Test)7 Test (org.junit.jupiter.api.Test)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)5 LogicalTransactionStore (org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore)5 LogEntryCommit (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit)5 CursorContext (org.neo4j.io.pagecache.context.CursorContext)4 DbmsLogEntryWriterFactory (org.neo4j.kernel.database.DbmsLogEntryWriterFactory)4 TransactionCursor (org.neo4j.kernel.impl.transaction.log.TransactionCursor)4 LogEntryStart (org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart)4 TransactionId (org.neo4j.storageengine.api.TransactionId)4 RequestContext (org.neo4j.com.RequestContext)3 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)2 Transaction (org.neo4j.graphdb.Transaction)2 TransactionFailureException (org.neo4j.kernel.api.exceptions.TransactionFailureException)2 ReadableClosablePositionAwareChannel (org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)2