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