Search in sources :

Example 1 with RemoteFindPrimary

use of org.opendaylight.controller.cluster.datastore.messages.RemoteFindPrimary in project controller by opendaylight.

the class ShardManager method findPrimary.

private void findPrimary(final FindPrimary message) {
    LOG.debug("{}: In findPrimary: {}", persistenceId(), message);
    final String shardName = message.getShardName();
    final boolean canReturnLocalShardState = !(message instanceof RemoteFindPrimary);
    // First see if the there is a local replica for the shard
    final ShardInformation info = localShards.get(shardName);
    if (info != null && info.isActiveMember()) {
        sendResponse(info, message.isWaitUntilReady(), true, () -> {
            String primaryPath = info.getSerializedLeaderActor();
            Object found = canReturnLocalShardState && info.isLeader() ? new LocalPrimaryShardFound(primaryPath, info.getLocalShardDataTree().get()) : new RemotePrimaryShardFound(primaryPath, info.getLeaderVersion());
            LOG.debug("{}: Found primary for {}: {}", persistenceId(), shardName, found);
            return found;
        });
        return;
    }
    final Collection<String> visitedAddresses;
    if (message instanceof RemoteFindPrimary) {
        visitedAddresses = ((RemoteFindPrimary) message).getVisitedAddresses();
    } else {
        visitedAddresses = new ArrayList<>(1);
    }
    visitedAddresses.add(peerAddressResolver.getShardManagerActorPathBuilder(cluster.getSelfAddress()).toString());
    for (String address : peerAddressResolver.getShardManagerPeerActorAddresses()) {
        if (visitedAddresses.contains(address)) {
            continue;
        }
        LOG.debug("{}: findPrimary for {} forwarding to remote ShardManager {}, visitedAddresses: {}", persistenceId(), shardName, address, visitedAddresses);
        getContext().actorSelection(address).forward(new RemoteFindPrimary(shardName, message.isWaitUntilReady(), visitedAddresses), getContext());
        return;
    }
    LOG.debug("{}: No shard found for {}", persistenceId(), shardName);
    getSender().tell(new PrimaryNotFoundException(String.format("No primary shard found for %s.", shardName)), getSelf());
}
Also used : PrimaryNotFoundException(org.opendaylight.controller.cluster.datastore.exceptions.PrimaryNotFoundException) LocalPrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.LocalPrimaryShardFound) RemotePrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.RemotePrimaryShardFound) RemoteFindPrimary(org.opendaylight.controller.cluster.datastore.messages.RemoteFindPrimary)

Aggregations

PrimaryNotFoundException (org.opendaylight.controller.cluster.datastore.exceptions.PrimaryNotFoundException)1 LocalPrimaryShardFound (org.opendaylight.controller.cluster.datastore.messages.LocalPrimaryShardFound)1 RemoteFindPrimary (org.opendaylight.controller.cluster.datastore.messages.RemoteFindPrimary)1 RemotePrimaryShardFound (org.opendaylight.controller.cluster.datastore.messages.RemotePrimaryShardFound)1