Search in sources :

Example 16 with TransactionRepresentation

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

the class BatchingTxApplierTest method createTxWithId.

private CommittedTransactionRepresentation createTxWithId(long txId) {
    CommittedTransactionRepresentation tx = mock(CommittedTransactionRepresentation.class);
    LogEntryCommit commitEntry = mock(LogEntryCommit.class);
    when(commitEntry.getTxId()).thenReturn(txId);
    TransactionRepresentation txRep = mock(TransactionRepresentation.class);
    when(tx.getTransactionRepresentation()).thenReturn(txRep);
    when(tx.getCommitEntry()).thenReturn(commitEntry);
    return tx;
}
Also used : CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)

Example 17 with TransactionRepresentation

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

the class MasterImplTest method shouldAllowCommitIfClientHoldsNoLocks.

@Test
public void shouldAllowCommitIfClientHoldsNoLocks() throws Throwable {
    // Given
    MasterImpl.SPI spi = mock(MasterImpl.SPI.class);
    Config config = config();
    DefaultConversationSPI conversationSpi = mockedConversationSpi();
    ConversationManager conversationManager = new ConversationManager(conversationSpi, config);
    Client locks = mock(Client.class);
    when(locks.trySharedLock(ResourceTypes.SCHEMA, ResourceTypes.schemaResource())).thenReturn(true);
    when(spi.isAccessible()).thenReturn(true);
    when(spi.getTransactionChecksum(anyLong())).thenReturn(1L);
    when(conversationSpi.acquireClient()).thenReturn(locks);
    mockEmptyResponse(spi);
    MasterImpl master = new MasterImpl(spi, conversationManager, mock(MasterImpl.Monitor.class), config);
    master.start();
    HandshakeResult handshake = master.handshake(1, newStoreIdForCurrentVersion()).response();
    int no_lock_session = -1;
    RequestContext ctx = new RequestContext(handshake.epoch(), 1, no_lock_session, 0, 0);
    TransactionRepresentation tx = mock(TransactionRepresentation.class);
    // When
    master.commit(ctx, tx);
    // Then
    verify(spi).applyPreparedTransaction(tx);
}
Also used : SPI(org.neo4j.kernel.ha.com.master.MasterImpl.SPI) DefaultConversationSPI(org.neo4j.kernel.ha.cluster.DefaultConversationSPI) Monitor(org.neo4j.kernel.ha.com.master.MasterImpl.Monitor) Config(org.neo4j.kernel.configuration.Config) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) RequestContext(org.neo4j.com.RequestContext) Client(org.neo4j.kernel.impl.locking.Locks.Client) Test(org.junit.Test)

Example 18 with TransactionRepresentation

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

the class ReplicatedTransactionCommitProcessTest method tx.

private TransactionToApply tx() {
    TransactionRepresentation tx = mock(TransactionRepresentation.class);
    when(tx.additionalHeader()).thenReturn(new byte[] {});
    return new TransactionToApply(tx);
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation)

Example 19 with TransactionRepresentation

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

the class LabelAndIndexUpdateBatchingIT method indexShouldIncludeNodesCreatedPreviouslyInBatch.

@Test
public 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.
    // a bunch of nodes (to have the index population later on to decide to use label scan for population)
    List<TransactionRepresentation> transactions;
    GraphDatabaseAPI db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabase();
    String nodeN = "our guy";
    String otherNode = "just to create the tokens";
    try {
        try (Transaction tx = db.beginTx()) {
            db.createNode(LABEL).setProperty(PROPERTY_KEY, otherNode);
            for (int i = 0; i < 10_000; i++) {
                db.createNode();
            }
            tx.success();
        }
        // node N
        try (Transaction tx = db.beginTx()) {
            db.createNode(LABEL).setProperty(PROPERTY_KEY, nodeN);
            tx.success();
        }
        // uniqueness constraint affecting N
        try (Transaction tx = db.beginTx()) {
            db.schema().constraintFor(LABEL).assertPropertyIsUnique(PROPERTY_KEY).create();
            tx.success();
        }
        transactions = extractTransactions(db);
    } finally {
        db.shutdown();
    }
    db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabase();
    TransactionCommitProcess commitProcess = db.getDependencyResolver().resolveDependency(TransactionCommitProcess.class);
    try {
        int cutoffIndex = findCutoffIndex(transactions);
        commitProcess.commit(toApply(transactions.subList(0, cutoffIndex)), NULL, EXTERNAL);
        // WHEN applying the two transactions (node N and the constraint) in the same batch
        commitProcess.commit(toApply(transactions.subList(cutoffIndex, transactions.size())), NULL, EXTERNAL);
        // THEN node N should've ended up in the index too
        try (Transaction tx = db.beginTx()) {
            assertNotNull("Verification node not found", // just to verify
            singleOrNull(db.findNodes(LABEL, PROPERTY_KEY, otherNode)));
            assertNotNull("Node N not found", singleOrNull(db.findNodes(LABEL, PROPERTY_KEY, nodeN)));
            tx.success();
        }
    } finally {
        db.shutdown();
    }
}
Also used : 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) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Test(org.junit.Test)

Example 20 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, last = null;
    for (TransactionRepresentation transactionRepresentation : transactions) {
        TransactionToApply transaction = new TransactionToApply(transactionRepresentation);
        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)

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