Search in sources :

Example 16 with WriteModification

use of org.opendaylight.controller.cluster.datastore.modification.WriteModification in project controller by opendaylight.

the class EntityOwnershipShard method selectNewOwnerForEntitiesOwnedBy.

private void selectNewOwnerForEntitiesOwnedBy(final Set<String> ownedBy) {
    final List<Modification> modifications = new ArrayList<>();
    searchForEntitiesOwnedBy(ownedBy, (entityTypeNode, entityNode) -> {
        YangInstanceIdentifier entityPath = YangInstanceIdentifier.builder(ENTITY_TYPES_PATH).node(entityTypeNode.getIdentifier()).node(ENTITY_NODE_ID).node(entityNode.getIdentifier()).node(ENTITY_OWNER_NODE_ID).build();
        String newOwner = newOwner(getCurrentOwner(entityPath), getCandidateNames(entityNode), getEntityOwnerElectionStrategy(entityPath));
        if (!newOwner.isEmpty()) {
            LOG.debug("{}: Found entity {}, writing new owner {}", persistenceId(), entityPath, newOwner);
            modifications.add(new WriteModification(entityPath, ImmutableNodes.leafNode(ENTITY_OWNER_NODE_ID, newOwner)));
        } else {
            LOG.debug("{}: Found entity {} but no other candidates - not clearing owner", persistenceId(), entityPath, newOwner);
        }
    });
    commitCoordinator.commitModifications(modifications, this);
}
Also used : WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) Modification(org.opendaylight.controller.cluster.datastore.modification.Modification) DeleteModification(org.opendaylight.controller.cluster.datastore.modification.DeleteModification) MergeModification(org.opendaylight.controller.cluster.datastore.modification.MergeModification) WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) ArrayList(java.util.ArrayList) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 17 with WriteModification

use of org.opendaylight.controller.cluster.datastore.modification.WriteModification in project controller by opendaylight.

the class EntityOwnershipShard method writeNewOwner.

private void writeNewOwner(final YangInstanceIdentifier entityPath, final String newOwner) {
    LOG.debug("{}: Writing new owner {} for entity {}", persistenceId(), newOwner, entityPath);
    commitCoordinator.commitModification(new WriteModification(entityPath.node(ENTITY_OWNER_QNAME), ImmutableNodes.leafNode(ENTITY_OWNER_NODE_ID, newOwner)), this);
}
Also used : WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification)

Example 18 with WriteModification

use of org.opendaylight.controller.cluster.datastore.modification.WriteModification in project controller by opendaylight.

the class EntityOwnershipShard method onVotingStateChangeComplete.

@Override
protected void onVotingStateChangeComplete() {
    // Re-evaluate ownership for all entities - if a member changed from voting to non-voting it should lose
    // ownership and vice versa it now is a candidate to become owner.
    final List<Modification> modifications = new ArrayList<>();
    searchForEntities((entityTypeNode, entityNode) -> {
        YangInstanceIdentifier entityPath = YangInstanceIdentifier.builder(ENTITY_TYPES_PATH).node(entityTypeNode.getIdentifier()).node(ENTITY_NODE_ID).node(entityNode.getIdentifier()).node(ENTITY_OWNER_NODE_ID).build();
        java.util.Optional<String> possibleOwner = entityNode.getChild(ENTITY_OWNER_NODE_ID).map(node -> node.getValue().toString());
        String newOwner = newOwner(possibleOwner.orElse(null), getCandidateNames(entityNode), getEntityOwnerElectionStrategy(entityPath));
        if (!newOwner.equals(possibleOwner.orElse(""))) {
            modifications.add(new WriteModification(entityPath, ImmutableNodes.leafNode(ENTITY_OWNER_NODE_ID, newOwner)));
        }
    });
    commitCoordinator.commitModifications(modifications, this);
}
Also used : WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) Modification(org.opendaylight.controller.cluster.datastore.modification.Modification) DeleteModification(org.opendaylight.controller.cluster.datastore.modification.DeleteModification) MergeModification(org.opendaylight.controller.cluster.datastore.modification.MergeModification) WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) ArrayList(java.util.ArrayList) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 19 with WriteModification

use of org.opendaylight.controller.cluster.datastore.modification.WriteModification in project controller by opendaylight.

the class EntityOwnershipShardCommitCoordinator method canForwardModificationToNewLeader.

private boolean canForwardModificationToNewLeader(Modification mod) {
    // to determine the new owner might be stale.
    if (mod instanceof WriteModification) {
        WriteModification writeMod = (WriteModification) mod;
        boolean canForward = !writeMod.getPath().getLastPathArgument().getNodeType().equals(ENTITY_OWNER_QNAME);
        if (!canForward) {
            log.debug("Not forwarding WRITE modification for {} to new leader", writeMod.getPath());
        }
        return canForward;
    }
    return true;
}
Also used : WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification)

Example 20 with WriteModification

use of org.opendaylight.controller.cluster.datastore.modification.WriteModification in project controller by opendaylight.

the class ShardTest method testTransactionCommitWithSubsequentExpiredCohortEntry.

@Test
public void testTransactionCommitWithSubsequentExpiredCohortEntry() throws Exception {
    dataStoreContextBuilder.shardTransactionCommitTimeoutInSeconds(1);
    new ShardTestKit(getSystem()) {

        {
            final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testTransactionCommitWithSubsequentExpiredCohortEntry");
            waitUntilLeader(shard);
            final FiniteDuration duration = duration("5 seconds");
            final ShardDataTree dataStore = shard.underlyingActor().getDataStore();
            final TransactionIdentifier transactionID1 = nextTransactionId();
            shard.tell(prepareBatchedModifications(transactionID1, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), false), getRef());
            expectMsgClass(duration, ReadyTransactionReply.class);
            // CanCommit the first Tx so it's the current in-progress Tx.
            shard.tell(new CanCommitTransaction(transactionID1, CURRENT_VERSION).toSerializable(), getRef());
            expectMsgClass(duration, CanCommitTransactionReply.class);
            // Ready the second Tx.
            final TransactionIdentifier transactionID2 = nextTransactionId();
            shard.tell(prepareBatchedModifications(transactionID2, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), false), getRef());
            expectMsgClass(duration, ReadyTransactionReply.class);
            // Ready the third Tx.
            final TransactionIdentifier transactionID3 = nextTransactionId();
            final DataTreeModification modification3 = dataStore.newModification();
            new WriteModification(TestModel.TEST2_PATH, ImmutableNodes.containerNode(TestModel.TEST2_QNAME)).apply(modification3);
            modification3.ready();
            final ReadyLocalTransaction readyMessage = new ReadyLocalTransaction(transactionID3, modification3, true);
            shard.tell(readyMessage, getRef());
            // Commit the first Tx. After completing, the second should
            // expire from the queue and the third
            // Tx committed.
            shard.tell(new CommitTransaction(transactionID1, CURRENT_VERSION).toSerializable(), getRef());
            expectMsgClass(duration, CommitTransactionReply.class);
            // Expect commit reply from the third Tx.
            expectMsgClass(duration, CommitTransactionReply.class);
            final NormalizedNode<?, ?> node = readStore(shard, TestModel.TEST2_PATH);
            assertNotNull(TestModel.TEST2_PATH + " not found", node);
        }
    };
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) CanCommitTransaction(org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction) CommitTransaction(org.opendaylight.controller.cluster.datastore.messages.CommitTransaction) ReadyLocalTransaction(org.opendaylight.controller.cluster.datastore.messages.ReadyLocalTransaction) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) CanCommitTransaction(org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction) FiniteDuration(scala.concurrent.duration.FiniteDuration) Test(org.junit.Test)

Aggregations

WriteModification (org.opendaylight.controller.cluster.datastore.modification.WriteModification)30 Test (org.junit.Test)22 ActorRef (akka.actor.ActorRef)16 BatchedModifications (org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)14 MergeModification (org.opendaylight.controller.cluster.datastore.modification.MergeModification)11 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)11 DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)8 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)7 NormalizedNodeAggregatorTest (org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest)7 Timeout (akka.util.Timeout)6 DeleteModification (org.opendaylight.controller.cluster.datastore.modification.DeleteModification)6 TestActorRef (akka.testkit.TestActorRef)4 TestKit (akka.testkit.javadsl.TestKit)4 ReadyLocalTransaction (org.opendaylight.controller.cluster.datastore.messages.ReadyLocalTransaction)4 Modification (org.opendaylight.controller.cluster.datastore.modification.Modification)4 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 CommitTransactionReply (org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply)3 DOMStoreThreePhaseCommitCohort (org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)3