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);
}
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);
}
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);
}
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;
}
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);
}
};
}
Aggregations