Search in sources :

Example 1 with RequestFailureReason

use of org.apache.cassandra.exceptions.RequestFailureReason in project cassandra by apache.

the class ReadCallback method onResponse.

@Override
public void onResponse(Message<ReadResponse> message) {
    assertWaitingFor(message.from());
    Map<ParamType, Object> params = message.header.params();
    InetAddressAndPort from = message.from();
    if (WarningContext.isSupported(params.keySet())) {
        RequestFailureReason reason = getWarningContext().updateCounters(params, from);
        if (reason != null) {
            onFailure(message.from(), reason);
            return;
        }
    }
    resolver.preprocess(message);
    /*
         * Ensure that data is present and the response accumulator has properly published the
         * responses it has received. This may result in not signaling immediately when we receive
         * the minimum number of required results, but it guarantees at least the minimum will
         * be accessible when we do signal. (see CASSANDRA-16807)
         */
    if (resolver.isDataPresent() && resolver.responses.size() >= blockFor)
        condition.signalAll();
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) RequestFailureReason(org.apache.cassandra.exceptions.RequestFailureReason) ParamType(org.apache.cassandra.net.ParamType)

Example 2 with RequestFailureReason

use of org.apache.cassandra.exceptions.RequestFailureReason in project cassandra by apache.

the class WarningContext method updateCounters.

public RequestFailureReason updateCounters(Map<ParamType, Object> params, InetAddressAndPort from) {
    for (Map.Entry<ParamType, Object> entry : params.entrySet()) {
        WarnAbortCounter counter = null;
        RequestFailureReason reason = null;
        switch(entry.getKey()) {
            case ROW_INDEX_SIZE_ABORT:
                reason = RequestFailureReason.READ_SIZE;
            case ROW_INDEX_SIZE_WARN:
                counter = rowIndexTooLarge;
                break;
            case LOCAL_READ_SIZE_ABORT:
                reason = RequestFailureReason.READ_SIZE;
            case LOCAL_READ_SIZE_WARN:
                counter = localReadSize;
                break;
            case TOMBSTONE_ABORT:
                reason = RequestFailureReason.READ_TOO_MANY_TOMBSTONES;
            case TOMBSTONE_WARNING:
                counter = tombstones;
                break;
        }
        if (reason != null) {
            counter.addAbort(from, ((Number) entry.getValue()).longValue());
            return reason;
        }
        if (counter != null)
            counter.addWarning(from, ((Number) entry.getValue()).longValue());
    }
    return null;
}
Also used : RequestFailureReason(org.apache.cassandra.exceptions.RequestFailureReason) Map(java.util.Map) ParamType(org.apache.cassandra.net.ParamType)

Example 3 with RequestFailureReason

use of org.apache.cassandra.exceptions.RequestFailureReason in project cassandra by apache.

the class SimulatedAction method applyToMessage.

Action applyToMessage(IInvokableInstance from, IInvokableInstance to, IMessage message) {
    Executor executor = to.executorFor(message.verb());
    if (executor instanceof ImmediateExecutor)
        executor = to.executor();
    InterceptedExecution.InterceptedTaskExecution task = new InterceptedRunnableExecution((InterceptingExecutor) executor, () -> to.receiveMessageWithInvokingThread(message));
    Verb verb = Verb.fromId(message.verb());
    Modifiers self = verbModifiers.getOrDefault(verb, NONE);
    int fromNum = from.config().num();
    int toNum = to.config().num();
    Deliver deliver;
    if (is(Modifier.RELIABLE) || self.is(Modifier.RELIABLE))
        deliver = DELIVER;
    else
        deliver = simulated.futureScheduler.shouldDeliver(fromNum, toNum);
    Action action;
    switch(deliver) {
        default:
            throw new AssertionError();
        case DELIVER:
            {
                Object description = lazy(() -> String.format("%s(%d) from %s to %s", Verb.fromId(message.verb()), message.id(), message.from(), to.broadcastAddress()));
                OrderOn orderOn = task.executor.orderAppliesAfterScheduling();
                action = applyTo(description, MESSAGE, orderOn, self, verb, task);
                action.setDeadline(simulated.futureScheduler.messageDeadlineNanos(fromNum, toNum));
                break;
            }
        case FAILURE:
        case TIMEOUT:
            {
                task.cancel();
                self = DROP.with(self);
                InetSocketAddress failedOn;
                IInvokableInstance notify;
                if (verb.isResponse()) {
                    failedOn = from.broadcastAddress();
                    notify = to;
                } else {
                    failedOn = to.broadcastAddress();
                    notify = from;
                }
                InterceptedExecution.InterceptedTaskExecution failTask = new InterceptedRunnableExecution((InterceptingExecutor) notify.executorFor(verb.id), () -> notify.unsafeApplyOnThisThread((socketAddress, id, isTimeout) -> {
                    InetAddressAndPort address = InetAddressAndPort.getByAddress(socketAddress);
                    RequestCallbacks.CallbackInfo callback = instance().callbacks.remove(id, address);
                    if (callback != null) {
                        RequestCallback<?> invokeOn = (RequestCallback<?>) callback.callback;
                        RequestFailureReason reason = isTimeout ? RequestFailureReason.TIMEOUT : RequestFailureReason.UNKNOWN;
                        invokeOn.onFailure(address, reason);
                    }
                    return null;
                }, failedOn, message.id(), deliver == TIMEOUT));
                Object description = (lazy(() -> String.format("Report Timeout of %s(%d) from %s to %s", Verb.fromId(message.verb()), message.id(), failedOn, notify.broadcastAddress())));
                OrderOn orderOn = failTask.executor.orderAppliesAfterScheduling();
                action = applyTo(description, MESSAGE, orderOn, self, failTask);
                switch(deliver) {
                    default:
                        throw new AssertionError();
                    case TIMEOUT:
                        long expiresAfterNanos = from.unsafeApplyOnThisThread(id -> Verb.fromId(id).expiresAfterNanos(), (verb.isResponse() ? forVerb : verb).id);
                        action.setDeadline(simulated.futureScheduler.messageTimeoutNanos(expiresAfterNanos));
                        break;
                    case FAILURE:
                        action.setDeadline(simulated.futureScheduler.messageFailureNanos(toNum, fromNum));
                        break;
                }
                break;
            }
    }
    return action;
}
Also used : Actions(org.apache.cassandra.simulator.Actions) START_TASK(org.apache.cassandra.simulator.Action.Modifiers.START_TASK) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) OrderOn(org.apache.cassandra.simulator.OrderOn) DELIVER(org.apache.cassandra.simulator.FutureActionScheduler.Deliver.DELIVER) TASK(org.apache.cassandra.simulator.systems.SimulatedAction.Kind.TASK) LazyToString.lazy(org.apache.cassandra.utils.LazyToString.lazy) START_DAEMON_TASK(org.apache.cassandra.simulator.Action.Modifiers.START_DAEMON_TASK) InterceptedRunnableExecution(org.apache.cassandra.simulator.systems.InterceptedExecution.InterceptedRunnableExecution) ActionList(org.apache.cassandra.simulator.ActionList) RequestCallbacks(org.apache.cassandra.net.RequestCallbacks) Deliver(org.apache.cassandra.simulator.FutureActionScheduler.Deliver) IMessage(org.apache.cassandra.distributed.api.IMessage) ArrayList(java.util.ArrayList) MESSAGE(org.apache.cassandra.simulator.systems.SimulatedAction.Kind.MESSAGE) UNBOUNDED_WAIT(org.apache.cassandra.simulator.systems.InterceptedWait.Kind.UNBOUNDED_WAIT) SIMULATION(org.apache.cassandra.utils.Shared.Scope.SIMULATION) Map(java.util.Map) WAKE_UP_THREAD(org.apache.cassandra.simulator.Action.Modifiers.WAKE_UP_THREAD) TIMEOUT(org.apache.cassandra.simulator.FutureActionScheduler.Deliver.TIMEOUT) MessagingService.instance(org.apache.cassandra.net.MessagingService.instance) START_THREAD(org.apache.cassandra.simulator.Action.Modifiers.START_THREAD) Action(org.apache.cassandra.simulator.Action) Nullable(javax.annotation.Nullable) EnumMap(java.util.EnumMap) Executor(java.util.concurrent.Executor) NONE(org.apache.cassandra.simulator.Action.Modifiers.NONE) DROP(org.apache.cassandra.simulator.Action.Modifiers.DROP) Verb(org.apache.cassandra.net.Verb) RequestFailureReason(org.apache.cassandra.exceptions.RequestFailureReason) RequestCallback(org.apache.cassandra.net.RequestCallback) START_INFINITE_LOOP(org.apache.cassandra.simulator.Action.Modifiers.START_INFINITE_LOOP) InetSocketAddress(java.net.InetSocketAddress) START_SCHEDULED_TASK(org.apache.cassandra.simulator.Action.Modifiers.START_SCHEDULED_TASK) START_TIMEOUT_TASK(org.apache.cassandra.simulator.Action.Modifiers.START_TIMEOUT_TASK) List(java.util.List) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) TriggerListener(org.apache.cassandra.simulator.systems.InterceptedWait.TriggerListener) SCHEDULED_TIMEOUT(org.apache.cassandra.simulator.systems.SimulatedAction.Kind.SCHEDULED_TIMEOUT) Shared(org.apache.cassandra.utils.Shared) LOG(org.apache.cassandra.simulator.Debug.Info.LOG) ImmediateExecutor(org.apache.cassandra.concurrent.ImmediateExecutor) Collections(java.util.Collections) LazyToString(org.apache.cassandra.utils.LazyToString) Deliver(org.apache.cassandra.simulator.FutureActionScheduler.Deliver) Action(org.apache.cassandra.simulator.Action) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) InterceptedRunnableExecution(org.apache.cassandra.simulator.systems.InterceptedExecution.InterceptedRunnableExecution) InetSocketAddress(java.net.InetSocketAddress) OrderOn(org.apache.cassandra.simulator.OrderOn) Executor(java.util.concurrent.Executor) ImmediateExecutor(org.apache.cassandra.concurrent.ImmediateExecutor) RequestFailureReason(org.apache.cassandra.exceptions.RequestFailureReason) RequestCallback(org.apache.cassandra.net.RequestCallback) ImmediateExecutor(org.apache.cassandra.concurrent.ImmediateExecutor) Verb(org.apache.cassandra.net.Verb) RequestCallbacks(org.apache.cassandra.net.RequestCallbacks)

Example 4 with RequestFailureReason

use of org.apache.cassandra.exceptions.RequestFailureReason in project cassandra by apache.

the class ActiveRepairService method cleanUp.

/**
 * Send Verb.CLEANUP_MSG to the given endpoints. This results in removing parent session object from the
 * endpoint's cache.
 * This method does not throw an exception in case of a messaging failure.
 */
public void cleanUp(UUID parentRepairSession, Set<InetAddressAndPort> endpoints) {
    for (InetAddressAndPort endpoint : endpoints) {
        try {
            if (FailureDetector.instance.isAlive(endpoint)) {
                CleanupMessage message = new CleanupMessage(parentRepairSession);
                Message<CleanupMessage> msg = Message.out(Verb.CLEANUP_MSG, message);
                RequestCallback loggingCallback = new RequestCallback() {

                    @Override
                    public void onResponse(Message msg) {
                        logger.trace("Successfully cleaned up {} parent repair session on {}.", parentRepairSession, endpoint);
                    }

                    @Override
                    public void onFailure(InetAddressAndPort from, RequestFailureReason failureReason) {
                        logger.debug("Failed to clean up parent repair session {} on {}. The uncleaned sessions will " + "be removed on a node restart. This should not be a problem unless you see thousands " + "of messages like this.", parentRepairSession, endpoint);
                    }
                };
                MessagingService.instance().sendWithCallback(msg, endpoint, loggingCallback);
            }
        } catch (Exception exc) {
            logger.warn("Failed to send a clean up message to {}", endpoint, exc);
        }
    }
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) RequestFailureReason(org.apache.cassandra.exceptions.RequestFailureReason) RequestCallback(org.apache.cassandra.net.RequestCallback) PrepareMessage(org.apache.cassandra.repair.messages.PrepareMessage) Message(org.apache.cassandra.net.Message) CleanupMessage(org.apache.cassandra.repair.messages.CleanupMessage) RepairMessage(org.apache.cassandra.repair.messages.RepairMessage) CleanupMessage(org.apache.cassandra.repair.messages.CleanupMessage) NoSuchRepairSessionException(org.apache.cassandra.repair.NoSuchRepairSessionException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 5 with RequestFailureReason

use of org.apache.cassandra.exceptions.RequestFailureReason in project cassandra by apache.

the class ActiveRepairService method prepareForRepair.

public UUID prepareForRepair(UUID parentRepairSession, InetAddress coordinator, Set<InetAddress> endpoints, RepairOption options, List<ColumnFamilyStore> columnFamilyStores) {
    // we only want repairedAt for incremental repairs, for non incremental repairs, UNREPAIRED_SSTABLE will preserve repairedAt on streamed sstables
    long repairedAt = options.isIncremental() ? Clock.instance.currentTimeMillis() : ActiveRepairService.UNREPAIRED_SSTABLE;
    registerParentRepairSession(parentRepairSession, coordinator, columnFamilyStores, options.getRanges(), options.isIncremental(), repairedAt, options.isGlobal());
    final CountDownLatch prepareLatch = new CountDownLatch(endpoints.size());
    final AtomicBoolean status = new AtomicBoolean(true);
    final Set<String> failedNodes = Collections.synchronizedSet(new HashSet<String>());
    IAsyncCallbackWithFailure callback = new IAsyncCallbackWithFailure() {

        public void response(MessageIn msg) {
            prepareLatch.countDown();
        }

        public boolean isLatencyForSnitch() {
            return false;
        }

        public void onFailure(InetAddress from, RequestFailureReason failureReason) {
            status.set(false);
            failedNodes.add(from.getHostAddress());
            prepareLatch.countDown();
        }
    };
    List<TableId> tableIds = new ArrayList<>(columnFamilyStores.size());
    for (ColumnFamilyStore cfs : columnFamilyStores) tableIds.add(cfs.metadata.id);
    for (InetAddress neighbour : endpoints) {
        if (FailureDetector.instance.isAlive(neighbour)) {
            PrepareMessage message = new PrepareMessage(parentRepairSession, tableIds, options.getRanges(), options.isIncremental(), repairedAt, options.isGlobal());
            MessageOut<RepairMessage> msg = message.createMessage();
            MessagingService.instance().sendRR(msg, neighbour, callback, DatabaseDescriptor.getRpcTimeout(), true);
        } else {
            status.set(false);
            failedNodes.add(neighbour.getHostAddress());
            prepareLatch.countDown();
        }
    }
    try {
        prepareLatch.await(DatabaseDescriptor.getRpcTimeout(), TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
        removeParentRepairSession(parentRepairSession);
        throw new RuntimeException("Did not get replies from all endpoints. List of failed endpoint(s): " + failedNodes, e);
    }
    if (!status.get()) {
        removeParentRepairSession(parentRepairSession);
        throw new RuntimeException("Did not get positive replies from all endpoints. List of failed endpoint(s): " + failedNodes);
    }
    return parentRepairSession;
}
Also used : TableId(org.apache.cassandra.schema.TableId) IAsyncCallbackWithFailure(org.apache.cassandra.net.IAsyncCallbackWithFailure) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MessageIn(org.apache.cassandra.net.MessageIn) RequestFailureReason(org.apache.cassandra.exceptions.RequestFailureReason) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) InetAddress(java.net.InetAddress)

Aggregations

RequestFailureReason (org.apache.cassandra.exceptions.RequestFailureReason)9 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)7 Map (java.util.Map)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 List (java.util.List)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)2 ParamType (org.apache.cassandra.net.ParamType)2 RequestCallback (org.apache.cassandra.net.RequestCallback)2 TableId (org.apache.cassandra.schema.TableId)2 Test (org.junit.Test)2 ImmutableList (com.google.common.collect.ImmutableList)1 Sets (com.google.common.collect.Sets)1 Uninterruptibles (com.google.common.util.concurrent.Uninterruptibles)1 ByteBuf (io.netty.buffer.ByteBuf)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1