Search in sources :

Example 1 with NotLeaderException

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());
    }
}
Also used : ConnectClientSuccess(org.opendaylight.controller.cluster.access.commands.ConnectClientSuccess) NotLeaderException(org.opendaylight.controller.cluster.access.commands.NotLeaderException) ClientIdentifier(org.opendaylight.controller.cluster.access.concepts.ClientIdentifier) ABIVersion(org.opendaylight.controller.cluster.access.ABIVersion) RequestException(org.opendaylight.controller.cluster.access.concepts.RequestException) UnsupportedRequestException(org.opendaylight.controller.cluster.access.concepts.UnsupportedRequestException) RuntimeRequestException(org.opendaylight.controller.cluster.access.concepts.RuntimeRequestException) Failure(akka.actor.Status.Failure)

Example 2 with NotLeaderException

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);
    }
}
Also used : NotLeaderException(org.opendaylight.controller.cluster.access.commands.NotLeaderException) ClientIdentifier(org.opendaylight.controller.cluster.access.concepts.ClientIdentifier) LocalHistoryRequest(org.opendaylight.controller.cluster.access.commands.LocalHistoryRequest) UnsupportedRequestException(org.opendaylight.controller.cluster.access.concepts.UnsupportedRequestException) TransactionRequest(org.opendaylight.controller.cluster.access.commands.TransactionRequest) Nullable(javax.annotation.Nullable)

Example 3 with NotLeaderException

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);
}
Also used : NotLeaderException(org.opendaylight.controller.cluster.access.commands.NotLeaderException) OutOfSequenceEnvelopeException(org.opendaylight.controller.cluster.access.commands.OutOfSequenceEnvelopeException) RuntimeRequestException(org.opendaylight.controller.cluster.access.concepts.RuntimeRequestException) RequestException(org.opendaylight.controller.cluster.access.concepts.RequestException) RetiredGenerationException(org.opendaylight.controller.cluster.access.concepts.RetiredGenerationException)

Example 4 with NotLeaderException

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()));
}
Also used : ConnectClientSuccess(org.opendaylight.controller.cluster.access.commands.ConnectClientSuccess) NotLeaderException(org.opendaylight.controller.cluster.access.commands.NotLeaderException) RequestFailure(org.opendaylight.controller.cluster.access.concepts.RequestFailure)

Aggregations

NotLeaderException (org.opendaylight.controller.cluster.access.commands.NotLeaderException)4 ConnectClientSuccess (org.opendaylight.controller.cluster.access.commands.ConnectClientSuccess)2 ClientIdentifier (org.opendaylight.controller.cluster.access.concepts.ClientIdentifier)2 RequestException (org.opendaylight.controller.cluster.access.concepts.RequestException)2 RuntimeRequestException (org.opendaylight.controller.cluster.access.concepts.RuntimeRequestException)2 UnsupportedRequestException (org.opendaylight.controller.cluster.access.concepts.UnsupportedRequestException)2 Failure (akka.actor.Status.Failure)1 Nullable (javax.annotation.Nullable)1 ABIVersion (org.opendaylight.controller.cluster.access.ABIVersion)1 LocalHistoryRequest (org.opendaylight.controller.cluster.access.commands.LocalHistoryRequest)1 OutOfSequenceEnvelopeException (org.opendaylight.controller.cluster.access.commands.OutOfSequenceEnvelopeException)1 TransactionRequest (org.opendaylight.controller.cluster.access.commands.TransactionRequest)1 RequestFailure (org.opendaylight.controller.cluster.access.concepts.RequestFailure)1 RetiredGenerationException (org.opendaylight.controller.cluster.access.concepts.RetiredGenerationException)1