* 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 akka.pattern.Patterns.ask;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import org.opendaylight.controller.cluster.raft.messages.ServerRemoved;
import org.opendaylight.controller.cluster.raft.policy.DisableElectionsRaftPolicy;
import org.opendaylight.yangtools.concepts.Registration;
+import org.opendaylight.yangtools.yang.common.Empty;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private DatastoreContextFactory datastoreContextFactory;
- private final SettableFuture<Void> readinessFuture;
+ private final SettableFuture<Empty> readinessFuture;
private final PrimaryShardInfoFutureCache primaryShardInfoCache;
private final String persistenceId;
+ @SuppressFBWarnings(value = "MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR", justification = "Akka class design")
ShardManager(final AbstractShardManagerCreator<?> builder) {
- this.cluster = builder.getCluster();
- this.configuration = builder.getConfiguration();
- this.datastoreContextFactory = builder.getDatastoreContextFactory();
- this.type = datastoreContextFactory.getBaseDatastoreContext().getDataStoreName();
- this.shardDispatcherPath =
- new Dispatchers(context().system().dispatchers()).getDispatcherPath(Dispatchers.DispatcherType.Shard);
- this.readinessFuture = builder.getReadinessFuture();
- this.primaryShardInfoCache = builder.getPrimaryShardInfoCache();
- this.restoreFromSnapshot = builder.getRestoreFromSnapshot();
+ cluster = builder.getCluster();
+ configuration = builder.getConfiguration();
+ datastoreContextFactory = builder.getDatastoreContextFactory();
+ type = datastoreContextFactory.getBaseDatastoreContext().getDataStoreName();
+ shardDispatcherPath = new Dispatchers(context().system().dispatchers())
+ .getDispatcherPath(Dispatchers.DispatcherType.Shard);
+ readinessFuture = builder.getReadinessFuture();
+ primaryShardInfoCache = builder.getPrimaryShardInfoCache();
+ restoreFromSnapshot = builder.getRestoreFromSnapshot();
String possiblePersistenceId = datastoreContextFactory.getBaseDatastoreContext().getShardManagerPersistenceId();
persistenceId = possiblePersistenceId != null ? possiblePersistenceId : "shard-manager-" + type;
cluster.subscribeToMemberEvents(getSelf());
shardManagerMBean = new ShardManagerInfo(getSelf(), cluster.getCurrentMemberName(),
- "shard-manager-" + this.type,
+ "shard-manager-" + type,
datastoreContextFactory.getBaseDatastoreContext().getDataStoreMXBeanType());
shardManagerMBean.registerMBean();
}
}
}
- @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
- justification = "https://github.com/spotbugs/spotbugs/issues/811")
private void removeShardReplica(final RemoveShardReplica contextMessage, final String shardName,
final String primaryPath, final ActorRef sender) {
if (isShardReplicaOperationInProgress(shardName, sender)) {
}
}
- @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
- justification = "https://github.com/spotbugs/spotbugs/issues/811")
private boolean isPreviousShardActorStopInProgress(final String shardName, final Object messageToDefer) {
final CompositeOnComplete<Boolean> stopOnComplete = shardActorsStopping.get(shardName);
if (stopOnComplete == null) {
// the shard with no peers and with elections disabled so it stays as follower. A
// subsequent AddServer request will be needed to make it an active member.
isActiveMember = false;
- peerAddresses = Collections.emptyMap();
+ peerAddresses = Map.of();
shardDatastoreContext = DatastoreContext.newBuilderFrom(shardDatastoreContext)
.customRaftPolicyImplementation(DisableElectionsRaftPolicy.class.getName()).build();
}
private void checkReady() {
if (isReadyWithLeaderId()) {
LOG.info("{}: All Shards are ready - data store {} is ready", persistenceId(), type);
- readinessFuture.set(null);
+ readinessFuture.set(Empty.value());
}
}
message.member().address());
peerAddressResolver.removePeerAddress(memberName);
-
- for (ShardInformation info : localShards.values()) {
- info.peerDown(memberName, getShardIdentifier(memberName, info.getShardName()).toString(), getSelf());
- }
}
private void memberExited(final ClusterEvent.MemberExited message) {
message.member().address());
peerAddressResolver.removePeerAddress(memberName);
-
- for (ShardInformation info : localShards.values()) {
- info.peerDown(memberName, getShardIdentifier(memberName, info.getShardName()).toString(), getSelf());
- }
}
private void memberUp(final ClusterEvent.MemberUp message) {
String shardName = info.getShardName();
String peerId = getShardIdentifier(memberName, shardName).toString();
info.updatePeerAddress(peerId, peerAddressResolver.getShardActorAddress(shardName, memberName), getSelf());
-
- info.peerUp(memberName, peerId, getSelf());
}
}
notifyShardAvailabilityCallbacks(info);
}
-
- info.peerDown(memberName, getShardIdentifier(memberName, info.getShardName()).toString(), getSelf());
}
}
LOG.debug("Marking Leader {} as available.", leaderId);
info.setLeaderAvailable(true);
}
-
- info.peerUp(memberName, getShardIdentifier(memberName, info.getShardName()).toString(), getSelf());
}
}
String peerId = getShardIdentifier(memberName, shardName).toString() ;
String peerAddress = peerAddressResolver.getShardActorAddress(shardName, memberName);
info.updatePeerAddress(peerId, peerAddress, getSelf());
- info.peerUp(memberName, peerId, getSelf());
LOG.debug("{}: updated peer {} on member {} with address {} on shard {} whose actor address is {}",
persistenceId(), peerId, memberName, peerAddress, info.getShardId(), info.getActor());
}
* Create shards that are local to the member on which the ShardManager runs.
*/
private void createLocalShards() {
- MemberName memberName = this.cluster.getCurrentMemberName();
- Collection<String> memberShardNames = this.configuration.getMemberShardNames(memberName);
+ MemberName memberName = cluster.getCurrentMemberName();
+ Collection<String> memberShardNames = configuration.getMemberShardNames(memberName);
Map<String, DatastoreSnapshot.ShardSnapshot> shardSnapshots = new HashMap<>();
if (restoreFromSnapshot != null) {
private Map<String, String> getPeerAddresses(final String shardName, final Collection<MemberName> members) {
Map<String, String> peerAddresses = new HashMap<>();
- MemberName currentMemberName = this.cluster.getCurrentMemberName();
+ MemberName currentMemberName = cluster.getCurrentMemberName();
for (MemberName memberName : members) {
if (!currentMemberName.equals(memberName)) {
LOG.debug("{}: onAddShardReplica: {}", persistenceId(), shardReplicaMsg);
// verify the shard with the specified name is present in the cluster configuration
- if (!this.configuration.isShardConfigured(shardName)) {
+ if (!configuration.isShardConfigured(shardName)) {
LOG.debug("{}: No module configuration exists for shard {}", persistenceId(), shardName);
getSender().tell(new Status.Failure(new IllegalArgumentException(
"No module configuration exists for shard " + shardName)), getSelf());
});
}
- @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
- justification = "https://github.com/spotbugs/spotbugs/issues/811")
private void sendLocalReplicaAlreadyExistsReply(final String shardName, final ActorRef sender) {
LOG.debug("{}: Local shard {} already exists", persistenceId(), shardName);
sender.tell(new Status.Failure(new AlreadyExistsException(
String.format("Local shard %s already exists", shardName))), getSelf());
}
- @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
- justification = "https://github.com/spotbugs/spotbugs/issues/811")
private void addShard(final String shardName, final RemotePrimaryShardFound response, final ActorRef sender) {
if (isShardReplicaOperationInProgress(shardName, sender)) {
return;