use of org.opendaylight.controller.cluster.access.commands.NotLeaderException in project controller by opendaylight.
the class Shard method handleConnectClient.
@SuppressWarnings("checkstyle:IllegalCatch")
private void handleConnectClient(final ConnectClientRequest message) {
try {
final ClientIdentifier clientId = message.getTarget();
final LeaderFrontendState existing = findFrontend(clientId);
if (existing != null) {
existing.touch();
}
if (!isLeader() || !isLeaderActive()) {
LOG.info("{}: not currently leader, rejecting request {}. isLeader: {}, isLeaderActive: {}," + "isLeadershipTransferInProgress: {}.", persistenceId(), message, isLeader(), isLeaderActive(), isLeadershipTransferInProgress());
throw new NotLeaderException(getSelf());
}
final ABIVersion selectedVersion = selectVersion(message);
final LeaderFrontendState frontend;
if (existing == null) {
frontend = new LeaderFrontendState(persistenceId(), clientId, store);
knownFrontends.put(clientId.getFrontendId(), frontend);
LOG.debug("{}: created state {} for client {}", persistenceId(), frontend, clientId);
} else {
frontend = existing;
}
frontend.reconnect();
message.getReplyTo().tell(new ConnectClientSuccess(message.getTarget(), message.getSequence(), getSelf(), ImmutableList.of(), store.getDataTree(), CLIENT_MAX_MESSAGES).toVersion(selectedVersion), ActorRef.noSender());
} catch (RequestException | RuntimeException e) {
message.getReplyTo().tell(new Failure(e), ActorRef.noSender());
}
}
use of org.opendaylight.controller.cluster.access.commands.NotLeaderException in project controller by opendaylight.
the class Shard method handleRequest.
@Nullable
private RequestSuccess<?, ?> handleRequest(final RequestEnvelope envelope, final long now) throws RequestException {
// We are not the leader, hence we want to fail-fast.
if (!isLeader() || paused || !isLeaderActive()) {
LOG.debug("{}: not currently active leader, rejecting request {}. isLeader: {}, isLeaderActive: {}," + "isLeadershipTransferInProgress: {}, paused: {}", persistenceId(), envelope, isLeader(), isLeaderActive(), isLeadershipTransferInProgress(), paused);
throw new NotLeaderException(getSelf());
}
final Request<?, ?> request = envelope.getMessage();
if (request instanceof TransactionRequest) {
final TransactionRequest<?> txReq = (TransactionRequest<?>) request;
final ClientIdentifier clientId = txReq.getTarget().getHistoryId().getClientId();
return getFrontend(clientId).handleTransactionRequest(txReq, envelope, now);
} else if (request instanceof LocalHistoryRequest) {
final LocalHistoryRequest<?> lhReq = (LocalHistoryRequest<?>) request;
final ClientIdentifier clientId = lhReq.getTarget().getClientId();
return getFrontend(clientId).handleLocalHistoryRequest(lhReq, envelope, now);
} else {
LOG.warn("{}: rejecting unsupported request {}", persistenceId(), request);
throw new UnsupportedRequestException(request);
}
}
use of org.opendaylight.controller.cluster.access.commands.NotLeaderException in project controller by opendaylight.
the class ClientActorBehavior method internalOnRequestFailure.
private ClientActorBehavior<T> internalOnRequestFailure(final FailureEnvelope command) {
final AbstractClientConnection<T> conn = getConnection(command);
if (conn != null) {
/*
* We are talking to multiple actors, which may be lagging behind our state significantly. This has
* the effect that we may be receiving responses from a previous connection after we have created a new
* one to a different actor.
*
* Since we are already replaying requests to the new actor, we want to ignore errors reported on the old
* connection -- for example NotLeaderException, which must not cause a new reconnect. Check the envelope's
* sessionId and if it does not match our current connection just ignore it.
*/
final Optional<T> optBackend = conn.getBackendInfo();
if (optBackend.isPresent() && optBackend.get().getSessionId() != command.getSessionId()) {
LOG.debug("{}: Mismatched current connection {} and envelope {}, ignoring response", persistenceId(), conn, command);
return this;
}
}
final RequestFailure<?, ?> failure = command.getMessage();
final RequestException cause = failure.getCause();
if (cause instanceof RetiredGenerationException) {
LOG.error("{}: current generation {} has been superseded", persistenceId(), getIdentifier(), cause);
haltClient(cause);
poison(cause);
return null;
}
if (cause instanceof NotLeaderException) {
if (conn instanceof ReconnectingClientConnection) {
// Already reconnecting, do not churn the logs
return this;
} else if (conn != null) {
LOG.info("{}: connection {} indicated no leadership, reconnecting it", persistenceId(), conn, cause);
return conn.reconnect(this, cause);
}
}
if (cause instanceof OutOfSequenceEnvelopeException) {
if (conn instanceof ReconnectingClientConnection) {
// Already reconnecting, do not churn the logs
return this;
} else if (conn != null) {
LOG.info("{}: connection {} indicated sequencing mismatch on {} sequence {} ({}), reconnecting it", persistenceId(), conn, failure.getTarget(), failure.getSequence(), command.getTxSequence(), cause);
return conn.reconnect(this, cause);
}
}
return onRequestFailure(command);
}
use of org.opendaylight.controller.cluster.access.commands.NotLeaderException in project controller by opendaylight.
the class AbstractShardBackendResolver method onConnectResponse.
private void onConnectResponse(final String shardName, final long cookie, final CompletableFuture<ShardBackendInfo> future, final Object response, final Throwable failure) {
if (failure != null) {
LOG.debug("Connect attempt to {} failed, will retry", shardName, failure);
future.completeExceptionally(wrap("Connection attempt failed", failure));
return;
}
if (response instanceof RequestFailure) {
final Throwable cause = ((RequestFailure<?, ?>) response).getCause().unwrap();
LOG.debug("Connect attempt to {} failed to process", shardName, cause);
final Throwable result = cause instanceof NotLeaderException ? wrap("Leader moved during establishment", cause) : cause;
future.completeExceptionally(result);
return;
}
LOG.debug("Resolved backend information to {}", response);
Preconditions.checkArgument(response instanceof ConnectClientSuccess, "Unhandled response %s", response);
final ConnectClientSuccess success = (ConnectClientSuccess) response;
future.complete(new ShardBackendInfo(success.getBackend(), nextSessionId.getAndIncrement(), success.getVersion(), shardName, UnsignedLong.fromLongBits(cookie), success.getDataTree(), success.getMaxMessages()));
}
Aggregations