Search in sources :

Example 16 with BatchedModifications

use of org.opendaylight.controller.cluster.datastore.messages.BatchedModifications in project controller by opendaylight.

the class ShardCommitCoordinator method createForwardedBatchedModifications.

Collection<BatchedModifications> createForwardedBatchedModifications(final BatchedModifications from, final int maxModificationsPerBatch) {
    CohortEntry cohortEntry = cohortCache.remove(from.getTransactionId());
    if (cohortEntry == null || cohortEntry.getTransaction() == null) {
        return Collections.singletonList(from);
    }
    cohortEntry.applyModifications(from.getModifications());
    final LinkedList<BatchedModifications> newModifications = new LinkedList<>();
    cohortEntry.getTransaction().getSnapshot().applyToCursor(new AbstractBatchedModificationsCursor() {

        @Override
        protected BatchedModifications getModifications() {
            if (newModifications.isEmpty() || newModifications.getLast().getModifications().size() >= maxModificationsPerBatch) {
                newModifications.add(new BatchedModifications(from.getTransactionId(), from.getVersion()));
            }
            return newModifications.getLast();
        }
    });
    BatchedModifications last = newModifications.getLast();
    last.setDoCommitOnReady(from.isDoCommitOnReady());
    last.setReady(from.isReady());
    last.setTotalMessagesSent(newModifications.size());
    return newModifications;
}
Also used : LinkedList(java.util.LinkedList) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications) AbstractBatchedModificationsCursor(org.opendaylight.controller.cluster.datastore.utils.AbstractBatchedModificationsCursor)

Example 17 with BatchedModifications

use of org.opendaylight.controller.cluster.datastore.messages.BatchedModifications in project controller by opendaylight.

the class ShardCommitCoordinator method convertPendingTransactionsToMessages.

Collection<?> convertPendingTransactionsToMessages(final int maxModificationsPerBatch) {
    final Collection<VersionedExternalizableMessage> messages = new ArrayList<>();
    for (ShardDataTreeCohort cohort : dataTree.getAndClearPendingTransactions()) {
        CohortEntry cohortEntry = cohortCache.remove(cohort.getIdentifier());
        if (cohortEntry == null) {
            continue;
        }
        final Deque<BatchedModifications> newMessages = new ArrayDeque<>();
        cohortEntry.getDataTreeModification().applyToCursor(new AbstractBatchedModificationsCursor() {

            @Override
            protected BatchedModifications getModifications() {
                final BatchedModifications lastBatch = newMessages.peekLast();
                if (lastBatch != null && lastBatch.getModifications().size() >= maxModificationsPerBatch) {
                    return lastBatch;
                }
                // Allocate a new message
                final BatchedModifications ret = new BatchedModifications(cohortEntry.getTransactionId(), cohortEntry.getClientVersion());
                newMessages.add(ret);
                return ret;
            }
        });
        final BatchedModifications last = newMessages.peekLast();
        if (last != null) {
            final boolean immediate = cohortEntry.isDoImmediateCommit();
            last.setDoCommitOnReady(immediate);
            last.setReady(true);
            last.setTotalMessagesSent(newMessages.size());
            messages.addAll(newMessages);
            if (!immediate) {
                switch(cohort.getState()) {
                    case CAN_COMMIT_COMPLETE:
                    case CAN_COMMIT_PENDING:
                        messages.add(new CanCommitTransaction(cohortEntry.getTransactionId(), cohortEntry.getClientVersion()));
                        break;
                    case PRE_COMMIT_COMPLETE:
                    case PRE_COMMIT_PENDING:
                        messages.add(new CommitTransaction(cohortEntry.getTransactionId(), cohortEntry.getClientVersion()));
                        break;
                    default:
                        break;
                }
            }
        }
    }
    return messages;
}
Also used : VersionedExternalizableMessage(org.opendaylight.controller.cluster.datastore.messages.VersionedExternalizableMessage) ArrayList(java.util.ArrayList) ArrayDeque(java.util.ArrayDeque) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications) CommitTransaction(org.opendaylight.controller.cluster.datastore.messages.CommitTransaction) CanCommitTransaction(org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction) CanCommitTransaction(org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction) AbstractBatchedModificationsCursor(org.opendaylight.controller.cluster.datastore.utils.AbstractBatchedModificationsCursor)

Example 18 with BatchedModifications

use of org.opendaylight.controller.cluster.datastore.messages.BatchedModifications in project controller by opendaylight.

the class EntityOwnershipShardCommitCoordinator method pruneModifications.

@Nullable
private BatchedModifications pruneModifications(BatchedModifications toPrune) {
    BatchedModifications prunedModifications = new BatchedModifications(toPrune.getTransactionId(), toPrune.getVersion());
    prunedModifications.setDoCommitOnReady(toPrune.isDoCommitOnReady());
    prunedModifications.setReady(toPrune.isReady());
    prunedModifications.setTotalMessagesSent(toPrune.getTotalMessagesSent());
    for (Modification mod : toPrune.getModifications()) {
        if (canForwardModificationToNewLeader(mod)) {
            prunedModifications.addModification(mod);
        }
    }
    return !prunedModifications.getModifications().isEmpty() ? prunedModifications : null;
}
Also used : WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) Modification(org.opendaylight.controller.cluster.datastore.modification.Modification) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications) Nullable(javax.annotation.Nullable)

Example 19 with BatchedModifications

use of org.opendaylight.controller.cluster.datastore.messages.BatchedModifications in project controller by opendaylight.

the class EntityOwnershipShardCommitCoordinator method newInflightCommitWithDifferentTransactionID.

private void newInflightCommitWithDifferentTransactionID() {
    BatchedModifications newBatchedModifications = newBatchedModifications();
    newBatchedModifications.addModifications(inflightCommit.getModifications());
    inflightCommit = newBatchedModifications;
}
Also used : BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)

Example 20 with BatchedModifications

use of org.opendaylight.controller.cluster.datastore.messages.BatchedModifications in project controller by opendaylight.

the class ShardTest method testBatchedModificationsWithOperationFailure.

@Test
public void testBatchedModificationsWithOperationFailure() throws Exception {
    new ShardTestKit(getSystem()) {

        {
            final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testBatchedModificationsWithOperationFailure");
            waitUntilLeader(shard);
            // Test merge with invalid data. An exception should occur when
            // the merge is applied. Note that
            // write will not validate the children for performance reasons.
            final TransactionIdentifier transactionID = nextTransactionId();
            final ContainerNode invalidData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).withChild(ImmutableNodes.leafNode(TestModel.JUNK_QNAME, "junk")).build();
            BatchedModifications batched = new BatchedModifications(transactionID, CURRENT_VERSION);
            batched.addModification(new MergeModification(TestModel.TEST_PATH, invalidData));
            shard.tell(batched, getRef());
            Failure failure = expectMsgClass(duration("5 seconds"), akka.actor.Status.Failure.class);
            final Throwable cause = failure.cause();
            batched = new BatchedModifications(transactionID, DataStoreVersions.CURRENT_VERSION);
            batched.setReady(true);
            batched.setTotalMessagesSent(2);
            shard.tell(batched, getRef());
            failure = expectMsgClass(duration("5 seconds"), akka.actor.Status.Failure.class);
            assertEquals("Failure cause", cause, failure.cause());
        }
    };
}
Also used : FollowerInitialSyncUpStatus(org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications) MergeModification(org.opendaylight.controller.cluster.datastore.modification.MergeModification) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) Failure(akka.actor.Status.Failure) Test(org.junit.Test)

Aggregations

BatchedModifications (org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)31 Test (org.junit.Test)17 WriteModification (org.opendaylight.controller.cluster.datastore.modification.WriteModification)13 ActorRef (akka.actor.ActorRef)12 Failure (akka.actor.Status.Failure)7 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)7 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)7 NormalizedNodeAggregatorTest (org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest)6 TestActorRef (akka.testkit.TestActorRef)5 TestKit (akka.testkit.javadsl.TestKit)5 MergeModification (org.opendaylight.controller.cluster.datastore.modification.MergeModification)5 Timeout (akka.util.Timeout)4 CommitTransactionReply (org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply)4 DOMStoreThreePhaseCommitCohort (org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)4 DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)4 DeleteModification (org.opendaylight.controller.cluster.datastore.modification.DeleteModification)3 FollowerInitialSyncUpStatus (org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus)3 InOrder (org.mockito.InOrder)2 BatchedModificationsReply (org.opendaylight.controller.cluster.datastore.messages.BatchedModificationsReply)2 ReadyLocalTransaction (org.opendaylight.controller.cluster.datastore.messages.ReadyLocalTransaction)2