use of org.opendaylight.controller.cluster.datastore.exceptions.PrimaryNotFoundException in project controller by opendaylight.
the class ActorContext method findPrimaryShardAsync.
public Future<PrimaryShardInfo> findPrimaryShardAsync(final String shardName) {
Future<PrimaryShardInfo> ret = primaryShardInfoCache.getIfPresent(shardName);
if (ret != null) {
return ret;
}
Future<Object> future = executeOperationAsync(shardManager, new FindPrimary(shardName, true), shardInitializationTimeout);
return future.transform(new Mapper<Object, PrimaryShardInfo>() {
@Override
public PrimaryShardInfo checkedApply(Object response) throws UnknownMessageException {
if (response instanceof RemotePrimaryShardFound) {
LOG.debug("findPrimaryShardAsync received: {}", response);
RemotePrimaryShardFound found = (RemotePrimaryShardFound) response;
return onPrimaryShardFound(shardName, found.getPrimaryPath(), found.getPrimaryVersion(), null);
} else if (response instanceof LocalPrimaryShardFound) {
LOG.debug("findPrimaryShardAsync received: {}", response);
LocalPrimaryShardFound found = (LocalPrimaryShardFound) response;
return onPrimaryShardFound(shardName, found.getPrimaryPath(), DataStoreVersions.CURRENT_VERSION, found.getLocalShardDataTree());
} else if (response instanceof NotInitializedException) {
throw (NotInitializedException) response;
} else if (response instanceof PrimaryNotFoundException) {
throw (PrimaryNotFoundException) response;
} else if (response instanceof NoShardLeaderException) {
throw (NoShardLeaderException) response;
}
throw new UnknownMessageException(String.format("FindPrimary returned unkown response: %s", response));
}
}, FIND_PRIMARY_FAILURE_TRANSFORMER, getClientDispatcher());
}
use of org.opendaylight.controller.cluster.datastore.exceptions.PrimaryNotFoundException in project controller by opendaylight.
the class TransactionProxyTest method testExceptionOnInitialCreateTransaction.
private void testExceptionOnInitialCreateTransaction(final Exception exToThrow, final Invoker invoker) throws Exception {
ActorRef actorRef = getSystem().actorOf(Props.create(DoNothingActor.class));
if (exToThrow instanceof PrimaryNotFoundException) {
doReturn(Futures.failed(exToThrow)).when(mockActorContext).findPrimaryShardAsync(anyString());
} else {
doReturn(primaryShardInfoReply(getSystem(), actorRef)).when(mockActorContext).findPrimaryShardAsync(anyString());
}
doReturn(Futures.failed(exToThrow)).when(mockActorContext).executeOperationAsync(any(ActorSelection.class), any(), any(Timeout.class));
TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_ONLY);
propagateReadFailedExceptionCause(invoker.invoke(transactionProxy));
}
use of org.opendaylight.controller.cluster.datastore.exceptions.PrimaryNotFoundException in project controller by opendaylight.
the class ShardManagerTest method testRemoveShardReplicaForNonExistentShard.
@Test
public void testRemoveShardReplicaForNonExistentShard() throws Exception {
new TestKit(getSystem()) {
{
ActorRef shardManager = actorFactory.createActor(newShardMgrProps(new ConfigurationImpl(new EmptyModuleShardConfigProvider())).withDispatcher(Dispatchers.DefaultDispatcherId()));
shardManager.tell(new RemoveShardReplica("model-inventory", MEMBER_1), getRef());
Status.Failure resp = expectMsgClass(duration("10 seconds"), Status.Failure.class);
assertEquals("Failure obtained", true, resp.cause() instanceof PrimaryNotFoundException);
}
};
}
use of org.opendaylight.controller.cluster.datastore.exceptions.PrimaryNotFoundException 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());
}
use of org.opendaylight.controller.cluster.datastore.exceptions.PrimaryNotFoundException in project controller by opendaylight.
the class TransactionProxyTest method completeOperation.
private void completeOperation(final TransactionProxyOperation operation, final boolean shardFound) {
ActorSystem actorSystem = getSystem();
ActorRef shardActorRef = actorSystem.actorOf(Props.create(DoNothingActor.class));
doReturn(actorSystem.actorSelection(shardActorRef.path())).when(mockActorContext).actorSelection(shardActorRef.path().toString());
if (shardFound) {
doReturn(Futures.successful(newPrimaryShardInfo(shardActorRef))).when(mockActorContext).findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
} else {
doReturn(Futures.failed(new PrimaryNotFoundException("test"))).when(mockActorContext).findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
}
ActorRef txActorRef = actorSystem.actorOf(Props.create(DoNothingActor.class));
String actorPath = txActorRef.path().toString();
CreateTransactionReply createTransactionReply = new CreateTransactionReply(actorPath, nextTransactionId(), DataStoreVersions.CURRENT_VERSION);
doReturn(actorSystem.actorSelection(actorPath)).when(mockActorContext).actorSelection(actorPath);
doReturn(Futures.successful(createTransactionReply)).when(mockActorContext).executeOperationAsync(eq(actorSystem.actorSelection(shardActorRef.path())), eqCreateTransaction(memberName, READ_WRITE), any(Timeout.class));
TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);
long start = System.nanoTime();
operation.run(transactionProxy);
long end = System.nanoTime();
long expected = TimeUnit.MILLISECONDS.toNanos(mockActorContext.getDatastoreContext().getOperationTimeoutInMillis());
Assert.assertTrue(String.format("Expected elapsed time: %s. Actual: %s", expected, end - start), end - start <= expected);
}
Aggregations