import org.opendaylight.controller.cluster.databroker.actors.dds.DataStoreClient;
import org.opendaylight.controller.cluster.databroker.actors.dds.DistributedDataStoreClientActor;
import org.opendaylight.controller.cluster.datastore.config.Configuration;
-import org.opendaylight.controller.cluster.datastore.identifiers.ShardManagerIdentifier;
import org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot;
import org.opendaylight.controller.cluster.datastore.shardmanager.AbstractShardManagerCreator;
import org.opendaylight.controller.cluster.datastore.shardmanager.ShardManagerCreator;
+import org.opendaylight.controller.cluster.datastore.shardmanager.ShardManagerIdentifier;
import org.opendaylight.controller.cluster.datastore.utils.ActorUtils;
import org.opendaylight.controller.cluster.datastore.utils.PrimaryShardInfoFutureCache;
import org.opendaylight.mdsal.dom.api.DOMDataBroker.CommitCohortExtension;
requireNonNull(configuration, "configuration should not be null");
requireNonNull(datastoreContextFactory, "datastoreContextFactory should not be null");
- String shardManagerId = ShardManagerIdentifier.builder()
- .type(datastoreContextFactory.getBaseDatastoreContext().getDataStoreName()).build().toString();
-
+ final var baseDatastoreContext = datastoreContextFactory.getBaseDatastoreContext();
+ final var shardManagerId = new ShardManagerIdentifier(baseDatastoreContext.getDataStoreName());
LOG.info("Creating ShardManager : {}", shardManagerId);
- String shardDispatcher =
- new Dispatchers(actorSystem.dispatchers()).getDispatcherPath(Dispatchers.DispatcherType.Shard);
-
- PrimaryShardInfoFutureCache primaryShardInfoCache = new PrimaryShardInfoFutureCache();
-
- AbstractShardManagerCreator<?> creator = getShardManagerCreator().cluster(cluster).configuration(configuration)
- .datastoreContextFactory(datastoreContextFactory)
- .readinessFuture(readinessFuture)
- .primaryShardInfoCache(primaryShardInfoCache)
- .restoreFromSnapshot(restoreFromSnapshot)
- .distributedDataStore(this);
-
- actorUtils = new ActorUtils(actorSystem, createShardManager(actorSystem, creator, shardDispatcher,
- shardManagerId), cluster, configuration, datastoreContextFactory.getBaseDatastoreContext(),
- primaryShardInfoCache);
+ final var shardDispatcher = new Dispatchers(actorSystem.dispatchers())
+ .getDispatcherPath(Dispatchers.DispatcherType.Shard);
+ final var primaryShardInfoCache = new PrimaryShardInfoFutureCache();
+ final var creator = getShardManagerCreator()
+ .cluster(cluster)
+ .configuration(configuration)
+ .datastoreContextFactory(datastoreContextFactory)
+ .readinessFuture(readinessFuture)
+ .primaryShardInfoCache(primaryShardInfoCache)
+ .restoreFromSnapshot(restoreFromSnapshot)
+ .distributedDataStore(this);
+
+ actorUtils = new ActorUtils(actorSystem,
+ createShardManager(actorSystem, creator, shardDispatcher, shardManagerId), cluster, configuration,
+ baseDatastoreContext, primaryShardInfoCache);
final Props clientProps = DistributedDataStoreClientActor.props(cluster.getCurrentMemberName(),
datastoreContextFactory.getBaseDatastoreContext().getDataStoreName(), actorUtils);
identifier = client.getIdentifier();
LOG.debug("Distributed data store client {} started", identifier);
- datastoreConfigMXBean = new DatastoreConfigurationMXBeanImpl(
- datastoreContextFactory.getBaseDatastoreContext().getDataStoreMXBeanType());
- datastoreConfigMXBean.setContext(datastoreContextFactory.getBaseDatastoreContext());
+ datastoreConfigMXBean = new DatastoreConfigurationMXBeanImpl(baseDatastoreContext.getDataStoreMXBeanType());
+ datastoreConfigMXBean.setContext(baseDatastoreContext);
datastoreConfigMXBean.registerMBean();
- datastoreInfoMXBean = new DatastoreInfoMXBeanImpl(datastoreContextFactory.getBaseDatastoreContext()
- .getDataStoreMXBeanType(), actorUtils);
+ datastoreInfoMXBean = new DatastoreInfoMXBeanImpl(baseDatastoreContext.getDataStoreMXBeanType(), actorUtils);
datastoreInfoMXBean.registerMBean();
}
@SuppressWarnings("checkstyle:IllegalCatch")
private static ActorRef createShardManager(final ActorSystem actorSystem,
final AbstractShardManagerCreator<?> creator, final String shardDispatcher,
- final String shardManagerId) {
+ final ShardManagerIdentifier shardManagerId) {
Exception lastException = null;
for (int i = 0; i < 100; i++) {
try {
- return actorSystem.actorOf(creator.props().withDispatcher(shardDispatcher), shardManagerId);
+ return actorSystem.actorOf(creator.props().withDispatcher(shardDispatcher),
+ shardManagerId.toActorName());
} catch (Exception e) {
lastException = e;
Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
- LOG.debug("Could not create actor {} because of {} - waiting for sometime before retrying "
- + "(retry count = {})", shardManagerId, e.getMessage(), i);
+ LOG.debug(
+ "Could not create actor {} because of {} - waiting for sometime before retrying (retry count = {})",
+ shardManagerId, e.getMessage(), i);
}
}
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.controller.cluster.datastore.identifiers;
-
-public class ShardManagerIdentifier {
- private final String type;
-
- public ShardManagerIdentifier(final String type) {
- this.type = type;
- }
-
- @Override
- public boolean equals(final Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null || getClass() != obj.getClass()) {
- return false;
- }
- return type.equals(((ShardManagerIdentifier) obj).type);
- }
-
- @Override
- public int hashCode() {
- return type.hashCode();
- }
-
- @Override public String toString() {
- return "shardmanager-" + type;
- }
-
- public static Builder builder() {
- return new Builder();
- }
-
- public static class Builder {
- private String type;
-
- public Builder type(final String newType) {
- type = newType;
- return this;
- }
-
- public ShardManagerIdentifier build() {
- return new ShardManagerIdentifier(type);
- }
- }
-}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.cluster.datastore.shardmanager;
+
+import static java.util.Objects.requireNonNull;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
+@NonNullByDefault
+public record ShardManagerIdentifier(String type) {
+ public ShardManagerIdentifier {
+ requireNonNull(type);
+ }
+
+ public String toActorName() {
+ return "shardmanager-" + type;
+ }
+
+ @Override
+ public String toString() {
+ return toActorName();
+ }
+}
import static java.util.Objects.requireNonNull;
import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Map;
+import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
import org.apache.pekko.actor.Address;
import org.apache.pekko.actor.AddressFromURIString;
import org.opendaylight.controller.cluster.access.concepts.MemberName;
import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier;
-import org.opendaylight.controller.cluster.datastore.identifiers.ShardManagerIdentifier;
import org.opendaylight.controller.cluster.raft.PeerAddressResolver;
/**
class ShardPeerAddressResolver implements PeerAddressResolver {
// Stores a mapping between a member name and the address of the member. The map is concurrent as it
// will be accessed by multiple threads via the public resolve method.
- private final ConcurrentMap<MemberName, Address> memberNameToAddress = new ConcurrentHashMap<>();
- private final String shardManagerIdentifier;
+ private final ConcurrentHashMap<MemberName, Address> memberNameToAddress = new ConcurrentHashMap<>();
+ private final ShardManagerIdentifier shardManagerIdentifier;
private final String shardManagerType;
private final MemberName localMemberName;
ShardPeerAddressResolver(final String shardManagerType, final MemberName localMemberName) {
- this.shardManagerIdentifier = ShardManagerIdentifier.builder().type(shardManagerType).build().toString();
+ shardManagerIdentifier = new ShardManagerIdentifier(shardManagerType);
this.shardManagerType = shardManagerType;
this.localMemberName = requireNonNull(localMemberName);
}
}
Set<MemberName> getPeerMembers() {
- return this.memberNameToAddress.keySet();
+ return memberNameToAddress.keySet();
}
Address getPeerAddress(final MemberName memberName) {
return memberNameToAddress.get(memberName);
}
- Collection<String> getShardManagerPeerActorAddresses() {
- Collection<String> peerAddresses = new ArrayList<>();
- for (Map.Entry<MemberName, Address> entry: memberNameToAddress.entrySet()) {
+ List<String> getShardManagerPeerActorAddresses() {
+ final var peerAddresses = new ArrayList<String>();
+ for (var entry: memberNameToAddress.entrySet()) {
if (!localMemberName.equals(entry.getKey())) {
peerAddresses.add(getShardManagerActorPathBuilder(entry.getValue()).toString());
}
}
String getShardActorAddress(final String shardName, final MemberName memberName) {
- Address memberAddress = memberNameToAddress.get(memberName);
- if (memberAddress != null) {
- return getShardManagerActorPathBuilder(memberAddress).append("/").append(
- getShardIdentifier(memberName, shardName)).toString();
- }
-
- return null;
+ final var memberAddress = memberNameToAddress.get(memberName);
+ return memberAddress == null ? null : getShardManagerActorPathBuilder(memberAddress)
+ .append("/").append(getShardIdentifier(memberName, shardName))
+ .toString();
}
StringBuilder getShardManagerActorPathBuilder(final Address address) {
- return new StringBuilder().append(address.toString()).append("/user/").append(shardManagerIdentifier);
+ return new StringBuilder().append(address.toString())
+ .append("/user/").append(shardManagerIdentifier.toActorName());
}
@Override
return null;
}
- ShardIdentifier shardId = ShardIdentifier.fromShardIdString(peerId);
+ final var shardId = ShardIdentifier.fromShardIdString(peerId);
return getShardActorAddress(shardId.getShardName(), shardId.getMemberName());
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.controller.cluster.datastore.identifiers;
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-public class ShardManagerIdentifierTest {
+import org.junit.jupiter.api.Test;
+import org.opendaylight.controller.cluster.datastore.shardmanager.ShardManagerIdentifier;
+class ShardManagerIdentifierTest {
@Test
- public void testIdentifier() {
- assertEquals("shardmanager-operational", ShardManagerIdentifier.builder().type("operational")
- .build().toString());
+ void testIdentifier() {
+ final var id = new ShardManagerIdentifier("operational");
+ assertEquals("shardmanager-operational", id.toActorName());
+ assertEquals("shardmanager-operational", id.toString());
}
}
import org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException;
import org.opendaylight.controller.cluster.datastore.exceptions.PrimaryNotFoundException;
import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier;
-import org.opendaylight.controller.cluster.datastore.identifiers.ShardManagerIdentifier;
import org.opendaylight.controller.cluster.datastore.messages.ActorInitialized;
import org.opendaylight.controller.cluster.datastore.messages.AddShardReplica;
import org.opendaylight.controller.cluster.datastore.messages.ChangeShardMembersVotingStatus;
.dataStoreName(shardMrgIDSuffix).shardInitializationTimeout(600, TimeUnit.MILLISECONDS)
.shardHeartbeatIntervalInMillis(100).shardElectionTimeoutFactor(6);
- private final String shardMgrID = ShardManagerIdentifier.builder().type(shardMrgIDSuffix).build().toString();
+ private final String shardMgrID = new ShardManagerIdentifier(shardMrgIDSuffix).toActorName();
@BeforeClass
public static void beforeClass() {
@Test
public void testOnReceiveFindPrimaryForRemoteShard() {
LOG.info("testOnReceiveFindPrimaryForRemoteShard starting");
- String shardManagerID = ShardManagerIdentifier.builder().type(shardMrgIDSuffix).build().toString();
+ final var shardManagerID = new ShardManagerIdentifier(shardMrgIDSuffix).toActorName();
// Create an ActorSystem ShardManager actor for member-1.
Cluster.get(system1).join(AddressFromURIString.parse("pekko://cluster-test@127.0.0.1:2558"));
final TestActorRef<TestShardManager> shardManager1 = TestActorRef.create(system1,
- newTestShardMgrBuilderWithMockShardActor().cluster(
- new ClusterWrapperImpl(system1)).props().withDispatcher(
- Dispatchers.DefaultDispatcherId()), shardManagerID);
+ newTestShardMgrBuilderWithMockShardActor()
+ .cluster(new ClusterWrapperImpl(system1))
+ .props().withDispatcher(Dispatchers.DefaultDispatcherId()),
+ shardManagerID);
// Create an ActorSystem ShardManager actor for member-2.
.put("astronauts", Arrays.asList("member-2")).build());
final TestActorRef<TestShardManager> shardManager2 = TestActorRef.create(system2,
- newTestShardMgrBuilder(mockConfig2).shardActor(mockShardActor2).cluster(
- new ClusterWrapperImpl(system2)).props().withDispatcher(
- Dispatchers.DefaultDispatcherId()), shardManagerID);
+ newTestShardMgrBuilder(mockConfig2).shardActor(mockShardActor2)
+ .cluster(new ClusterWrapperImpl(system2))
+ .props().withDispatcher(Dispatchers.DefaultDispatcherId()),
+ shardManagerID);
final TestKit kit = new TestKit(system1);
shardManager1.tell(new UpdateSchemaContext(TEST_SCHEMA_CONTEXT), kit.getRef());
@Test
public void testShardAvailabilityOnChangeOfMemberReachability() {
LOG.info("testShardAvailabilityOnChangeOfMemberReachability starting");
- String shardManagerID = ShardManagerIdentifier.builder().type(shardMrgIDSuffix).build().toString();
+ String shardManagerID = new ShardManagerIdentifier(shardMrgIDSuffix).toActorName();
// Create an ActorSystem ShardManager actor for member-1.
@Test
public void testShardAvailabilityChangeOnMemberUnreachableAndLeadershipChange() {
LOG.info("testShardAvailabilityChangeOnMemberUnreachableAndLeadershipChange starting");
- String shardManagerID = ShardManagerIdentifier.builder().type(shardMrgIDSuffix).build().toString();
+ String shardManagerID = new ShardManagerIdentifier(shardMrgIDSuffix).toActorName();
// Create an ActorSystem ShardManager actor for member-1.
@Test
public void testShardAvailabilityChangeOnMemberWithNameContainedInLeaderIdUnreachable() {
LOG.info("testShardAvailabilityChangeOnMemberWithNameContainedInLeaderIdUnreachable starting");
- String shardManagerID = ShardManagerIdentifier.builder().type(shardMrgIDSuffix).build().toString();
+ String shardManagerID = new ShardManagerIdentifier(shardMrgIDSuffix).toActorName();
MockConfiguration mockConfig = new MockConfiguration(ImmutableMap.<String, List<String>>builder()
.put("default", Arrays.asList("member-256", "member-2")).build());
ImmutableMap.<String, List<String>>builder().put("default", Arrays.asList("member-1", "member-2"))
.put("astronauts", Arrays.asList("member-2")).build());
- final String shardManagerID = ShardManagerIdentifier.builder().type(shardMrgIDSuffix).build().toString();
+ final String shardManagerID = new ShardManagerIdentifier(shardMrgIDSuffix).toActorName();
datastoreContextBuilder.shardManagerPersistenceId(shardManagerID);
// Create an ActorSystem ShardManager actor for member-1.
ImmutableMap.<String, List<String>>builder().put("default", Arrays.asList("member-1", "member-2"))
.put("astronauts", Arrays.asList("member-1")).build());
- String shardManagerID = ShardManagerIdentifier.builder().type(shardMrgIDSuffix).build().toString();
+ String shardManagerID = new ShardManagerIdentifier(shardMrgIDSuffix).toActorName();
// Create an ActorSystem ShardManager actor for member-1.
final ActorSystem system1 = newActorSystem("Member1");