Search in sources :

Example 1 with ShardIdentifier

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

the class ShardManager method changeShardMembersVotingStatus.

private void changeShardMembersVotingStatus(final ChangeServersVotingStatus changeServersVotingStatus, final String shardName, final ActorRef shardActorRef, final ActorRef sender) {
    if (isShardReplicaOperationInProgress(shardName, sender)) {
        return;
    }
    shardReplicaOperationsInProgress.add(shardName);
    DatastoreContext datastoreContext = newShardDatastoreContextBuilder(shardName).build();
    final ShardIdentifier shardId = getShardIdentifier(cluster.getCurrentMemberName(), shardName);
    LOG.debug("{}: Sending ChangeServersVotingStatus message {} to local shard {}", persistenceId(), changeServersVotingStatus, shardActorRef.path());
    Timeout timeout = new Timeout(datastoreContext.getShardLeaderElectionTimeout().duration().$times(2));
    Future<Object> futureObj = ask(shardActorRef, changeServersVotingStatus, timeout);
    futureObj.onComplete(new OnComplete<Object>() {

        @Override
        public void onComplete(final Throwable failure, final Object response) {
            shardReplicaOperationsInProgress.remove(shardName);
            if (failure != null) {
                String msg = String.format("ChangeServersVotingStatus request to local shard %s failed", shardActorRef.path());
                LOG.debug("{}: {}", persistenceId(), msg, failure);
                sender.tell(new Status.Failure(new RuntimeException(msg, failure)), self());
            } else {
                LOG.debug("{}: Received {} from local shard {}", persistenceId(), response, shardActorRef.path());
                ServerChangeReply replyMsg = (ServerChangeReply) response;
                if (replyMsg.getStatus() == ServerChangeStatus.OK) {
                    LOG.debug("{}: ChangeServersVotingStatus succeeded for shard {}", persistenceId(), shardName);
                    sender.tell(new Status.Success(null), getSelf());
                } else if (replyMsg.getStatus() == ServerChangeStatus.INVALID_REQUEST) {
                    sender.tell(new Status.Failure(new IllegalArgumentException(String.format("The requested voting state change for shard %s is invalid. At least one member " + "must be voting", shardId.getShardName()))), getSelf());
                } else {
                    LOG.warn("{}: ChangeServersVotingStatus failed for shard {} with status {}", persistenceId(), shardName, replyMsg.getStatus());
                    Exception error = getServerChangeException(ChangeServersVotingStatus.class, replyMsg.getStatus(), shardActorRef.path().toString(), shardId);
                    sender.tell(new Status.Failure(error), getSelf());
                }
            }
        }
    }, new Dispatchers(context().system().dispatchers()).getDispatcher(Dispatchers.DispatcherType.Client));
}
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) Timeout(akka.util.Timeout) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) SaveSnapshotSuccess(akka.persistence.SaveSnapshotSuccess) DeleteSnapshotsSuccess(akka.persistence.DeleteSnapshotsSuccess) AlreadyExistsException(org.opendaylight.controller.cluster.datastore.exceptions.AlreadyExistsException) PrimaryNotFoundException(org.opendaylight.controller.cluster.datastore.exceptions.PrimaryNotFoundException) NotInitializedException(org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException) TimeoutException(java.util.concurrent.TimeoutException) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) DatastoreContext(org.opendaylight.controller.cluster.datastore.DatastoreContext) ServerChangeReply(org.opendaylight.controller.cluster.raft.messages.ServerChangeReply) SaveSnapshotFailure(akka.persistence.SaveSnapshotFailure) DeleteSnapshotsFailure(akka.persistence.DeleteSnapshotsFailure) Dispatchers(org.opendaylight.controller.cluster.common.actor.Dispatchers)

Example 2 with ShardIdentifier

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

the class ShardManager method removePrefixShardReplica.

private void removePrefixShardReplica(final RemovePrefixShardReplica contextMessage, final String shardName, final String primaryPath, final ActorRef sender) {
    if (isShardReplicaOperationInProgress(shardName, sender)) {
        return;
    }
    shardReplicaOperationsInProgress.add(shardName);
    final ShardIdentifier shardId = getShardIdentifier(contextMessage.getMemberName(), shardName);
    final DatastoreContext datastoreContext = newShardDatastoreContextBuilder(shardName).build();
    // inform ShardLeader to remove this shard as a replica by sending an RemoveServer message
    LOG.debug("{}: Sending RemoveServer message to peer {} for shard {}", persistenceId(), primaryPath, shardId);
    Timeout removeServerTimeout = new Timeout(datastoreContext.getShardLeaderElectionTimeout().duration());
    Future<Object> futureObj = ask(getContext().actorSelection(primaryPath), new RemoveServer(shardId.toString()), removeServerTimeout);
    futureObj.onComplete(new OnComplete<Object>() {

        @Override
        public void onComplete(final Throwable failure, final Object response) {
            if (failure != null) {
                shardReplicaOperationsInProgress.remove(shardName);
                String msg = String.format("RemoveServer request to leader %s for shard %s failed", primaryPath, shardName);
                LOG.debug("{}: {}", persistenceId(), msg, failure);
                // FAILURE
                sender.tell(new Status.Failure(new RuntimeException(msg, failure)), self());
            } else {
                // SUCCESS
                self().tell(new WrappedShardResponse(shardId, response, primaryPath), sender);
            }
        }
    }, new Dispatchers(context().system().dispatchers()).getDispatcher(Dispatchers.DispatcherType.Client));
}
Also used : Timeout(akka.util.Timeout) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) DatastoreContext(org.opendaylight.controller.cluster.datastore.DatastoreContext) RemoveServer(org.opendaylight.controller.cluster.raft.messages.RemoveServer) SaveSnapshotFailure(akka.persistence.SaveSnapshotFailure) DeleteSnapshotsFailure(akka.persistence.DeleteSnapshotsFailure) Dispatchers(org.opendaylight.controller.cluster.common.actor.Dispatchers)

Example 3 with ShardIdentifier

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

the class ShardManager method addShard.

private void addShard(final String shardName, 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);
        DatastoreContext datastoreContext = newShardDatastoreContextBuilder(shardName).customRaftPolicyImplementation(DisableElectionsRaftPolicy.class.getName()).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) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier)

Example 4 with ShardIdentifier

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

the class ShardManager method onPrefixShardRemoved.

private void onPrefixShardRemoved(final PrefixShardRemoved message) {
    LOG.debug("{}: onPrefixShardRemoved : {}", persistenceId(), message);
    final DOMDataTreeIdentifier prefix = message.getPrefix();
    final ShardIdentifier shardId = getShardIdentifier(cluster.getCurrentMemberName(), ClusterUtils.getCleanShardName(prefix.getRootIdentifier()));
    configuration.removePrefixShardConfiguration(prefix);
    removeShard(shardId);
}
Also used : DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier)

Example 5 with ShardIdentifier

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

the class ShardManager method removeShardReplica.

private void removeShardReplica(final RemoveShardReplica contextMessage, final String shardName, final String primaryPath, final ActorRef sender) {
    if (isShardReplicaOperationInProgress(shardName, sender)) {
        return;
    }
    shardReplicaOperationsInProgress.add(shardName);
    final ShardIdentifier shardId = getShardIdentifier(contextMessage.getMemberName(), shardName);
    final DatastoreContext datastoreContext = newShardDatastoreContextBuilder(shardName).build();
    // inform ShardLeader to remove this shard as a replica by sending an RemoveServer message
    LOG.debug("{}: Sending RemoveServer message to peer {} for shard {}", persistenceId(), primaryPath, shardId);
    Timeout removeServerTimeout = new Timeout(datastoreContext.getShardLeaderElectionTimeout().duration());
    Future<Object> futureObj = ask(getContext().actorSelection(primaryPath), new RemoveServer(shardId.toString()), removeServerTimeout);
    futureObj.onComplete(new OnComplete<Object>() {

        @Override
        public void onComplete(final Throwable failure, final Object response) {
            if (failure != null) {
                shardReplicaOperationsInProgress.remove(shardName);
                String msg = String.format("RemoveServer request to leader %s for shard %s failed", primaryPath, shardName);
                LOG.debug("{}: {}", persistenceId(), msg, failure);
                // FAILURE
                sender.tell(new Status.Failure(new RuntimeException(msg, failure)), self());
            } else {
                // SUCCESS
                self().tell(new WrappedShardResponse(shardId, response, primaryPath), sender);
            }
        }
    }, new Dispatchers(context().system().dispatchers()).getDispatcher(Dispatchers.DispatcherType.Client));
}
Also used : Timeout(akka.util.Timeout) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) DatastoreContext(org.opendaylight.controller.cluster.datastore.DatastoreContext) RemoveServer(org.opendaylight.controller.cluster.raft.messages.RemoveServer) SaveSnapshotFailure(akka.persistence.SaveSnapshotFailure) DeleteSnapshotsFailure(akka.persistence.DeleteSnapshotsFailure) Dispatchers(org.opendaylight.controller.cluster.common.actor.Dispatchers)

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