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());
}
Aggregations