Search in sources :

Example 21 with ShardIdentifier

use of org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier in project controller by opendaylight.

the class ShardManager method onSwitchShardBehavior.

private void onSwitchShardBehavior(final SwitchShardBehavior message) {
    final ShardIdentifier identifier = message.getShardId();
    if (identifier != null) {
        final ShardInformation info = localShards.get(identifier.getShardName());
        if (info == null) {
            getSender().tell(new Status.Failure(new IllegalArgumentException("Shard " + identifier + " is not local")), getSelf());
            return;
        }
        switchShardBehavior(info, new SwitchBehavior(message.getNewState(), message.getTerm()));
    } else {
        for (ShardInformation info : localShards.values()) {
            switchShardBehavior(info, new SwitchBehavior(message.getNewState(), message.getTerm()));
        }
    }
    getSender().tell(new Status.Success(null), getSelf());
}
Also used : FollowerInitialSyncUpStatus(org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus) ChangeShardMembersVotingStatus(org.opendaylight.controller.cluster.datastore.messages.ChangeShardMembersVotingStatus) FlipShardMembersVotingStatus(org.opendaylight.controller.cluster.datastore.messages.FlipShardMembersVotingStatus) Status(akka.actor.Status) ServerChangeStatus(org.opendaylight.controller.cluster.raft.messages.ServerChangeStatus) ChangeServersVotingStatus(org.opendaylight.controller.cluster.raft.messages.ChangeServersVotingStatus) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) SwitchBehavior(org.opendaylight.controller.cluster.raft.base.messages.SwitchBehavior)

Example 22 with ShardIdentifier

use of org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier in project controller by opendaylight.

the class ShardManager method onAddPrefixShardReplica.

private void onAddPrefixShardReplica(final AddPrefixShardReplica message) {
    LOG.debug("{}: onAddPrefixShardReplica: {}", persistenceId(), message);
    final ShardIdentifier shardId = getShardIdentifier(cluster.getCurrentMemberName(), ClusterUtils.getCleanShardName(message.getShardPrefix()));
    final String shardName = shardId.getShardName();
    // Create the localShard
    if (schemaContext == null) {
        String msg = String.format("No SchemaContext is available in order to create a local shard instance for %s", shardName);
        LOG.debug("{}: {}", persistenceId(), msg);
        getSender().tell(new Status.Failure(new IllegalStateException(msg)), getSelf());
        return;
    }
    findPrimary(shardName, new AutoFindPrimaryFailureResponseHandler(getSender(), shardName, persistenceId(), getSelf()) {

        @Override
        public void onRemotePrimaryShardFound(final RemotePrimaryShardFound response) {
            final RunnableMessage runnable = (RunnableMessage) () -> addPrefixShard(getShardName(), message.getShardPrefix(), response, getSender());
            if (!isPreviousShardActorStopInProgress(getShardName(), runnable)) {
                getSelf().tell(runnable, getTargetActor());
            }
        }

        @Override
        public void onLocalPrimaryFound(final LocalPrimaryShardFound message) {
            sendLocalReplicaAlreadyExistsReply(getShardName(), getTargetActor());
        }
    });
}
Also used : FollowerInitialSyncUpStatus(org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus) ChangeShardMembersVotingStatus(org.opendaylight.controller.cluster.datastore.messages.ChangeShardMembersVotingStatus) FlipShardMembersVotingStatus(org.opendaylight.controller.cluster.datastore.messages.FlipShardMembersVotingStatus) Status(akka.actor.Status) ServerChangeStatus(org.opendaylight.controller.cluster.raft.messages.ServerChangeStatus) ChangeServersVotingStatus(org.opendaylight.controller.cluster.raft.messages.ChangeServersVotingStatus) LocalPrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.LocalPrimaryShardFound) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) RemotePrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.RemotePrimaryShardFound)

Example 23 with ShardIdentifier

use of org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier in project controller by opendaylight.

the class ShardManager method addPrefixShard.

private void addPrefixShard(final String shardName, final YangInstanceIdentifier shardPrefix, final RemotePrimaryShardFound response, final ActorRef sender) {
    if (isShardReplicaOperationInProgress(shardName, sender)) {
        return;
    }
    shardReplicaOperationsInProgress.add(shardName);
    final ShardInformation shardInfo;
    final boolean removeShardOnFailure;
    ShardInformation existingShardInfo = localShards.get(shardName);
    if (existingShardInfo == null) {
        removeShardOnFailure = true;
        ShardIdentifier shardId = getShardIdentifier(cluster.getCurrentMemberName(), shardName);
        final Builder builder = newShardDatastoreContextBuilder(shardName);
        builder.storeRoot(shardPrefix).customRaftPolicyImplementation(DisableElectionsRaftPolicy.class.getName());
        DatastoreContext datastoreContext = builder.build();
        shardInfo = new ShardInformation(shardName, shardId, getPeerAddresses(shardName), datastoreContext, Shard.builder(), peerAddressResolver);
        shardInfo.setActiveMember(false);
        shardInfo.setSchemaContext(schemaContext);
        localShards.put(shardName, shardInfo);
        shardInfo.setActor(newShardActor(shardInfo));
    } else {
        removeShardOnFailure = false;
        shardInfo = existingShardInfo;
    }
    execAddShard(shardName, shardInfo, response, removeShardOnFailure, sender);
}
Also used : DatastoreContext(org.opendaylight.controller.cluster.datastore.DatastoreContext) Builder(org.opendaylight.controller.cluster.datastore.DatastoreContext.Builder) DisableElectionsRaftPolicy(org.opendaylight.controller.cluster.raft.policy.DisableElectionsRaftPolicy) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier)

Example 24 with ShardIdentifier

use of org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier in project controller by opendaylight.

the class ShardManager method createLocalShards.

/**
 * 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);
    Map<String, DatastoreSnapshot.ShardSnapshot> shardSnapshots = new HashMap<>();
    if (restoreFromSnapshot != null) {
        for (DatastoreSnapshot.ShardSnapshot snapshot : restoreFromSnapshot.getShardSnapshots()) {
            shardSnapshots.put(snapshot.getName(), snapshot);
        }
    }
    // null out to GC
    restoreFromSnapshot = null;
    for (String shardName : memberShardNames) {
        ShardIdentifier shardId = getShardIdentifier(memberName, shardName);
        LOG.debug("{}: Creating local shard: {}", persistenceId(), shardId);
        Map<String, String> peerAddresses = getPeerAddresses(shardName);
        localShards.put(shardName, new ShardInformation(shardName, shardId, peerAddresses, newShardDatastoreContext(shardName), Shard.builder().restoreFromSnapshot(shardSnapshots.get(shardName)), peerAddressResolver));
    }
}
Also used : HashMap(java.util.HashMap) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName) DatastoreSnapshot(org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot)

Example 25 with ShardIdentifier

use of org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier in project controller by opendaylight.

the class ShardManagerInfo method switchShardState.

@Override
public void switchShardState(final String shardId, final String newState, final long term) {
    final ShardIdentifier identifier = ShardIdentifier.fromShardIdString(shardId);
    LOG.info("switchShardState called shardName = {}, newState = {}, term = {}", shardId, newState, term);
    requestSwitchShardState(identifier, newState, term);
}
Also used : ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier)

Aggregations

ShardIdentifier (org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier)31 Test (org.junit.Test)15 ShardTestKit (org.opendaylight.controller.cluster.datastore.ShardTestKit)11 RegisterCandidateLocal (org.opendaylight.controller.cluster.datastore.entityownership.messages.RegisterCandidateLocal)11 DOMEntity (org.opendaylight.mdsal.eos.dom.api.DOMEntity)11 DatastoreContext (org.opendaylight.controller.cluster.datastore.DatastoreContext)6 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)6 ActorRef (akka.actor.ActorRef)3 Status (akka.actor.Status)3 DeleteSnapshotsFailure (akka.persistence.DeleteSnapshotsFailure)3 SaveSnapshotFailure (akka.persistence.SaveSnapshotFailure)3 Timeout (akka.util.Timeout)3 Dispatchers (org.opendaylight.controller.cluster.common.actor.Dispatchers)3 RegisterListenerLocal (org.opendaylight.controller.cluster.datastore.entityownership.messages.RegisterListenerLocal)3 ChangeShardMembersVotingStatus (org.opendaylight.controller.cluster.datastore.messages.ChangeShardMembersVotingStatus)3 FlipShardMembersVotingStatus (org.opendaylight.controller.cluster.datastore.messages.FlipShardMembersVotingStatus)3 PeerDown (org.opendaylight.controller.cluster.datastore.messages.PeerDown)3 DOMEntityOwnershipListener (org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListener)3 TestActorRef (akka.testkit.TestActorRef)2 HashMap (java.util.HashMap)2