Search in sources :

Example 1 with AbstractDataStore

use of org.opendaylight.controller.cluster.datastore.AbstractDataStore in project controller by opendaylight.

the class DistributedShardedDOMDataTree method createShardFrontend.

private void createShardFrontend(final DOMDataTreeIdentifier prefix) {
    LOG.debug("{}: Creating CDS shard for prefix: {}", memberName, prefix);
    final String shardName = ClusterUtils.getCleanShardName(prefix.getRootIdentifier());
    final AbstractDataStore distributedDataStore = prefix.getDatastoreType().equals(org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION) ? distributedConfigDatastore : distributedOperDatastore;
    try (DOMDataTreeProducer producer = localCreateProducer(Collections.singletonList(prefix))) {
        final Entry<DataStoreClient, ActorRef> entry = createDatastoreClient(shardName, distributedDataStore.getActorContext());
        final DistributedShardFrontend shard = new DistributedShardFrontend(distributedDataStore, entry.getKey(), prefix);
        final DOMDataTreeShardRegistration<DOMDataTreeShard> reg = shardedDOMDataTree.registerDataTreeShard(prefix, shard, producer);
        synchronized (shards) {
            shards.store(prefix, reg);
        }
    } catch (final DOMDataTreeShardingConflictException e) {
        LOG.error("{}: Prefix {} is already occupied by another shard", distributedConfigDatastore.getActorContext().getClusterWrapper().getCurrentMemberName(), prefix, e);
    } catch (DOMDataTreeProducerException e) {
        LOG.error("Unable to close producer", e);
    } catch (DOMDataTreeShardCreationFailedException e) {
        LOG.error("Unable to create datastore client for shard {}", prefix, e);
    }
}
Also used : DOMDataTreeProducerException(org.opendaylight.mdsal.dom.api.DOMDataTreeProducerException) ActorRef(akka.actor.ActorRef) DOMDataTreeProducer(org.opendaylight.mdsal.dom.api.DOMDataTreeProducer) AbstractDataStore(org.opendaylight.controller.cluster.datastore.AbstractDataStore) DOMDataTreeShard(org.opendaylight.mdsal.dom.api.DOMDataTreeShard) DOMDataTreeShardingConflictException(org.opendaylight.mdsal.dom.api.DOMDataTreeShardingConflictException) DataStoreClient(org.opendaylight.controller.cluster.databroker.actors.dds.DataStoreClient)

Example 2 with AbstractDataStore

use of org.opendaylight.controller.cluster.datastore.AbstractDataStore in project controller by opendaylight.

the class DistributedEntityOwnershipIntegrationTest method testLeaderEntityOwnersReassignedAfterShutdown.

@Test
public void testLeaderEntityOwnersReassignedAfterShutdown() throws Exception {
    followerDatastoreContextBuilder.shardElectionTimeoutFactor(5).customRaftPolicyImplementation(DisableElectionsRaftPolicy.class.getName());
    String name = "testLeaderEntityOwnersReassignedAfterShutdown";
    MemberNode leaderNode = MemberNode.builder(memberNodes).akkaConfig("Member1").testName(name).moduleShardsConfig(MODULE_SHARDS_CONFIG).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(leaderDatastoreContextBuilder).build();
    MemberNode follower1Node = MemberNode.builder(memberNodes).akkaConfig("Member2").testName(name).moduleShardsConfig(MODULE_SHARDS_CONFIG).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(followerDatastoreContextBuilder).build();
    MemberNode follower2Node = MemberNode.builder(memberNodes).akkaConfig("Member3").testName(name).moduleShardsConfig(MODULE_SHARDS_CONFIG).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(followerDatastoreContextBuilder).build();
    AbstractDataStore leaderDistributedDataStore = leaderNode.configDataStore();
    leaderDistributedDataStore.waitTillReady();
    follower1Node.configDataStore().waitTillReady();
    follower2Node.configDataStore().waitTillReady();
    follower1Node.waitForMembersUp("member-1", "member-3");
    final DOMEntityOwnershipService leaderEntityOwnershipService = newOwnershipService(leaderDistributedDataStore);
    final DOMEntityOwnershipService follower1EntityOwnershipService = newOwnershipService(follower1Node.configDataStore());
    final DOMEntityOwnershipService follower2EntityOwnershipService = newOwnershipService(follower2Node.configDataStore());
    leaderNode.kit().waitUntilLeader(leaderNode.configDataStore().getActorContext(), ENTITY_OWNERSHIP_SHARD_NAME);
    // Register follower1 candidate for entity1 and verify it becomes owner
    follower1EntityOwnershipService.registerCandidate(ENTITY1);
    verifyOwner(leaderDistributedDataStore, ENTITY1, "member-2");
    // Register leader candidate for entity1
    leaderEntityOwnershipService.registerCandidate(ENTITY1);
    verifyCandidates(leaderDistributedDataStore, ENTITY1, "member-2", "member-1");
    verifyOwner(leaderDistributedDataStore, ENTITY1, "member-2");
    // Register leader candidate for entity2 and verify it becomes owner
    leaderEntityOwnershipService.registerCandidate(ENTITY2);
    verifyOwner(leaderDistributedDataStore, ENTITY2, "member-1");
    // Register follower2 candidate for entity2
    follower2EntityOwnershipService.registerCandidate(ENTITY2);
    verifyCandidates(leaderDistributedDataStore, ENTITY2, "member-1", "member-3");
    verifyOwner(leaderDistributedDataStore, ENTITY2, "member-1");
    // Re-enable elections on all remaining followers so one becomes the new leader
    ActorRef follower1Shard = IntegrationTestKit.findLocalShard(follower1Node.configDataStore().getActorContext(), ENTITY_OWNERSHIP_SHARD_NAME);
    follower1Shard.tell(DatastoreContext.newBuilderFrom(followerDatastoreContextBuilder.build()).customRaftPolicyImplementation(null).build(), ActorRef.noSender());
    ActorRef follower2Shard = IntegrationTestKit.findLocalShard(follower2Node.configDataStore().getActorContext(), ENTITY_OWNERSHIP_SHARD_NAME);
    follower2Shard.tell(DatastoreContext.newBuilderFrom(followerDatastoreContextBuilder.build()).customRaftPolicyImplementation(null).build(), ActorRef.noSender());
    // Shutdown the leader and verify its removed from the candidate list
    leaderNode.cleanup();
    follower1Node.waitForMemberDown("member-1");
    follower2Node.waitForMemberDown("member-1");
    // Verify the prior leader's entity owners are re-assigned.
    verifyCandidates(follower1Node.configDataStore(), ENTITY1, "member-2", "member-1");
    verifyCandidates(follower1Node.configDataStore(), ENTITY2, "member-1", "member-3");
    verifyOwner(follower1Node.configDataStore(), ENTITY1, "member-2");
    verifyOwner(follower1Node.configDataStore(), ENTITY2, "member-3");
}
Also used : DOMEntityOwnershipService(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipService) MemberNode(org.opendaylight.controller.cluster.datastore.MemberNode) ActorRef(akka.actor.ActorRef) DisableElectionsRaftPolicy(org.opendaylight.controller.cluster.raft.policy.DisableElectionsRaftPolicy) AbstractDataStore(org.opendaylight.controller.cluster.datastore.AbstractDataStore) Test(org.junit.Test)

Example 3 with AbstractDataStore

use of org.opendaylight.controller.cluster.datastore.AbstractDataStore in project controller by opendaylight.

the class DistributedEntityOwnershipIntegrationTest method testOwnerSelectedOnRapidRegisteringAndUnregisteringOfCandidates.

@Test
public void testOwnerSelectedOnRapidRegisteringAndUnregisteringOfCandidates() throws Exception {
    String name = "testOwnerSelectedOnRapidRegisteringAndUnregisteringOfCandidates";
    MemberNode leaderNode = MemberNode.builder(memberNodes).akkaConfig("Member1").testName(name).moduleShardsConfig(MODULE_SHARDS_CONFIG).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(leaderDatastoreContextBuilder).build();
    MemberNode follower1Node = MemberNode.builder(memberNodes).akkaConfig("Member2").testName(name).moduleShardsConfig(MODULE_SHARDS_CONFIG).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(followerDatastoreContextBuilder).build();
    MemberNode follower2Node = MemberNode.builder(memberNodes).akkaConfig("Member3").testName(name).moduleShardsConfig(MODULE_SHARDS_CONFIG).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(followerDatastoreContextBuilder).build();
    AbstractDataStore leaderDistributedDataStore = leaderNode.configDataStore();
    leaderDistributedDataStore.waitTillReady();
    follower1Node.configDataStore().waitTillReady();
    follower2Node.configDataStore().waitTillReady();
    final DOMEntityOwnershipService leaderEntityOwnershipService = newOwnershipService(leaderDistributedDataStore);
    final DOMEntityOwnershipService follower1EntityOwnershipService = newOwnershipService(follower1Node.configDataStore());
    newOwnershipService(follower2Node.configDataStore());
    leaderNode.kit().waitUntilLeader(leaderNode.configDataStore().getActorContext(), ENTITY_OWNERSHIP_SHARD_NAME);
    // Register leader candidate for entity1 and verify it becomes owner
    final DOMEntityOwnershipCandidateRegistration leaderEntity1Reg = leaderEntityOwnershipService.registerCandidate(ENTITY1);
    verifyCandidates(leaderDistributedDataStore, ENTITY1, "member-1");
    verifyOwner(leaderDistributedDataStore, ENTITY1, "member-1");
    follower1EntityOwnershipService.registerCandidate(ENTITY1);
    leaderEntity1Reg.close();
    verifyCandidates(leaderDistributedDataStore, ENTITY1, "member-2");
    verifyOwner(leaderDistributedDataStore, ENTITY1, "member-2");
}
Also used : DOMEntityOwnershipService(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipService) MemberNode(org.opendaylight.controller.cluster.datastore.MemberNode) DOMEntityOwnershipCandidateRegistration(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipCandidateRegistration) AbstractDataStore(org.opendaylight.controller.cluster.datastore.AbstractDataStore) Test(org.junit.Test)

Example 4 with AbstractDataStore

use of org.opendaylight.controller.cluster.datastore.AbstractDataStore in project controller by opendaylight.

the class DistributedEntityOwnershipIntegrationTest method testOwnerSelectedOnRapidUnregisteringAndRegisteringOfCandidates.

@Test
public void testOwnerSelectedOnRapidUnregisteringAndRegisteringOfCandidates() throws Exception {
    String name = "testOwnerSelectedOnRapidUnregisteringAndRegisteringOfCandidates";
    MemberNode leaderNode = MemberNode.builder(memberNodes).akkaConfig("Member1").testName(name).moduleShardsConfig(MODULE_SHARDS_CONFIG).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(leaderDatastoreContextBuilder).build();
    MemberNode follower1Node = MemberNode.builder(memberNodes).akkaConfig("Member2").testName(name).moduleShardsConfig(MODULE_SHARDS_CONFIG).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(followerDatastoreContextBuilder).build();
    MemberNode follower2Node = MemberNode.builder(memberNodes).akkaConfig("Member3").testName(name).moduleShardsConfig(MODULE_SHARDS_CONFIG).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(followerDatastoreContextBuilder).build();
    AbstractDataStore leaderDistributedDataStore = leaderNode.configDataStore();
    leaderDistributedDataStore.waitTillReady();
    follower1Node.configDataStore().waitTillReady();
    follower2Node.configDataStore().waitTillReady();
    final DOMEntityOwnershipService leaderEntityOwnershipService = newOwnershipService(leaderDistributedDataStore);
    final DOMEntityOwnershipService follower1EntityOwnershipService = newOwnershipService(follower1Node.configDataStore());
    newOwnershipService(follower2Node.configDataStore());
    leaderNode.kit().waitUntilLeader(leaderNode.configDataStore().getActorContext(), ENTITY_OWNERSHIP_SHARD_NAME);
    // Register leader candidate for entity1 and verify it becomes owner
    DOMEntityOwnershipCandidateRegistration leaderEntity1Reg = leaderEntityOwnershipService.registerCandidate(ENTITY1);
    verifyCandidates(leaderDistributedDataStore, ENTITY1, "member-1");
    verifyOwner(leaderDistributedDataStore, ENTITY1, "member-1");
    leaderEntity1Reg.close();
    follower1EntityOwnershipService.registerCandidate(ENTITY1);
    verifyCandidates(leaderDistributedDataStore, ENTITY1, "member-2");
    verifyOwner(leaderDistributedDataStore, ENTITY1, "member-2");
}
Also used : DOMEntityOwnershipService(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipService) MemberNode(org.opendaylight.controller.cluster.datastore.MemberNode) DOMEntityOwnershipCandidateRegistration(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipCandidateRegistration) AbstractDataStore(org.opendaylight.controller.cluster.datastore.AbstractDataStore) Test(org.junit.Test)

Example 5 with AbstractDataStore

use of org.opendaylight.controller.cluster.datastore.AbstractDataStore in project controller by opendaylight.

the class DistributedEntityOwnershipIntegrationTest method testEntityOwnershipWithNonVotingMembers.

@Test
public void testEntityOwnershipWithNonVotingMembers() throws Exception {
    followerDatastoreContextBuilder.shardElectionTimeoutFactor(5).customRaftPolicyImplementation(DisableElectionsRaftPolicy.class.getName());
    String name = "testEntityOwnershipWithNonVotingMembers";
    final MemberNode member1LeaderNode = MemberNode.builder(memberNodes).akkaConfig("Member1").useAkkaArtery(false).testName(name).moduleShardsConfig(MODULE_SHARDS_5_NODE_CONFIG).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(leaderDatastoreContextBuilder).build();
    final MemberNode member2FollowerNode = MemberNode.builder(memberNodes).akkaConfig("Member2").useAkkaArtery(false).testName(name).moduleShardsConfig(MODULE_SHARDS_5_NODE_CONFIG).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(followerDatastoreContextBuilder).build();
    final MemberNode member3FollowerNode = MemberNode.builder(memberNodes).akkaConfig("Member3").useAkkaArtery(false).testName(name).moduleShardsConfig(MODULE_SHARDS_5_NODE_CONFIG).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(followerDatastoreContextBuilder).build();
    final MemberNode member4FollowerNode = MemberNode.builder(memberNodes).akkaConfig("Member4").useAkkaArtery(false).testName(name).moduleShardsConfig(MODULE_SHARDS_5_NODE_CONFIG).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(followerDatastoreContextBuilder).build();
    final MemberNode member5FollowerNode = MemberNode.builder(memberNodes).akkaConfig("Member5").useAkkaArtery(false).testName(name).moduleShardsConfig(MODULE_SHARDS_5_NODE_CONFIG).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(followerDatastoreContextBuilder).build();
    AbstractDataStore leaderDistributedDataStore = member1LeaderNode.configDataStore();
    leaderDistributedDataStore.waitTillReady();
    member2FollowerNode.configDataStore().waitTillReady();
    member3FollowerNode.configDataStore().waitTillReady();
    member4FollowerNode.configDataStore().waitTillReady();
    member5FollowerNode.configDataStore().waitTillReady();
    member1LeaderNode.waitForMembersUp("member-2", "member-3", "member-4", "member-5");
    final DOMEntityOwnershipService member3EntityOwnershipService = newOwnershipService(member3FollowerNode.configDataStore());
    final DOMEntityOwnershipService member4EntityOwnershipService = newOwnershipService(member4FollowerNode.configDataStore());
    final DOMEntityOwnershipService member5EntityOwnershipService = newOwnershipService(member5FollowerNode.configDataStore());
    newOwnershipService(member1LeaderNode.configDataStore());
    member1LeaderNode.kit().waitUntilLeader(member1LeaderNode.configDataStore().getActorContext(), ENTITY_OWNERSHIP_SHARD_NAME);
    // Make member4 and member5 non-voting
    Future<Object> future = Patterns.ask(leaderDistributedDataStore.getActorContext().getShardManager(), new ChangeShardMembersVotingStatus(ENTITY_OWNERSHIP_SHARD_NAME, ImmutableMap.of("member-4", false, "member-5", false)), new Timeout(10, TimeUnit.SECONDS));
    Object response = Await.result(future, FiniteDuration.apply(10, TimeUnit.SECONDS));
    if (response instanceof Throwable) {
        throw new AssertionError("ChangeShardMembersVotingStatus failed", (Throwable) response);
    }
    assertNull("Expected null Success response. Actual " + response, response);
    // Register member4 candidate for entity1 - it should not become owner since it's non-voting
    member4EntityOwnershipService.registerCandidate(ENTITY1);
    verifyCandidates(leaderDistributedDataStore, ENTITY1, "member-4");
    // Register member5 candidate for entity2 - it should not become owner since it's non-voting
    member5EntityOwnershipService.registerCandidate(ENTITY2);
    verifyCandidates(leaderDistributedDataStore, ENTITY2, "member-5");
    Uninterruptibles.sleepUninterruptibly(500, TimeUnit.MILLISECONDS);
    verifyOwner(leaderDistributedDataStore, ENTITY1, "");
    verifyOwner(leaderDistributedDataStore, ENTITY2, "");
    // Register member3 candidate for entity1 - it should become owner since it's voting
    member3EntityOwnershipService.registerCandidate(ENTITY1);
    verifyCandidates(leaderDistributedDataStore, ENTITY1, "member-4", "member-3");
    verifyOwner(leaderDistributedDataStore, ENTITY1, "member-3");
    // Switch member4 and member5 back to voting and member3 non-voting. This should result in member4 and member5
    // to become entity owners.
    future = Patterns.ask(leaderDistributedDataStore.getActorContext().getShardManager(), new ChangeShardMembersVotingStatus(ENTITY_OWNERSHIP_SHARD_NAME, ImmutableMap.of("member-3", false, "member-4", true, "member-5", true)), new Timeout(10, TimeUnit.SECONDS));
    response = Await.result(future, FiniteDuration.apply(10, TimeUnit.SECONDS));
    if (response instanceof Throwable) {
        throw new AssertionError("ChangeShardMembersVotingStatus failed", (Throwable) response);
    }
    assertNull("Expected null Success response. Actual " + response, response);
    verifyOwner(leaderDistributedDataStore, ENTITY1, "member-4");
    verifyOwner(leaderDistributedDataStore, ENTITY2, "member-5");
}
Also used : ChangeShardMembersVotingStatus(org.opendaylight.controller.cluster.datastore.messages.ChangeShardMembersVotingStatus) DOMEntityOwnershipService(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipService) MemberNode(org.opendaylight.controller.cluster.datastore.MemberNode) Timeout(akka.util.Timeout) DisableElectionsRaftPolicy(org.opendaylight.controller.cluster.raft.policy.DisableElectionsRaftPolicy) AbstractDataStore(org.opendaylight.controller.cluster.datastore.AbstractDataStore) Test(org.junit.Test)

Aggregations

AbstractDataStore (org.opendaylight.controller.cluster.datastore.AbstractDataStore)9 Test (org.junit.Test)8 MemberNode (org.opendaylight.controller.cluster.datastore.MemberNode)8 DOMEntityOwnershipService (org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipService)8 DOMEntityOwnershipCandidateRegistration (org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipCandidateRegistration)5 ActorRef (akka.actor.ActorRef)3 DisableElectionsRaftPolicy (org.opendaylight.controller.cluster.raft.policy.DisableElectionsRaftPolicy)3 Failure (akka.actor.Status.Failure)1 Timeout (akka.util.Timeout)1 DataStoreClient (org.opendaylight.controller.cluster.databroker.actors.dds.DataStoreClient)1 AddShardReplica (org.opendaylight.controller.cluster.datastore.messages.AddShardReplica)1 ChangeShardMembersVotingStatus (org.opendaylight.controller.cluster.datastore.messages.ChangeShardMembersVotingStatus)1 DOMDataTreeProducer (org.opendaylight.mdsal.dom.api.DOMDataTreeProducer)1 DOMDataTreeProducerException (org.opendaylight.mdsal.dom.api.DOMDataTreeProducerException)1 DOMDataTreeShard (org.opendaylight.mdsal.dom.api.DOMDataTreeShard)1 DOMDataTreeShardingConflictException (org.opendaylight.mdsal.dom.api.DOMDataTreeShardingConflictException)1 EntityOwnershipState (org.opendaylight.mdsal.eos.common.api.EntityOwnershipState)1 DOMEntityOwnershipChange (org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipChange)1