Search in sources :

Example 1 with MvccMessage

use of org.apache.ignite.internal.processors.cache.mvcc.msg.MvccMessage in project ignite by apache.

the class GridIoManager method processRegularMessage.

/**
 * @param nodeId Node ID.
 * @param msg Message.
 * @param plc Execution policy.
 * @param msgC Closure to call when message processing finished.
 * @throws IgniteCheckedException If failed.
 */
private void processRegularMessage(final UUID nodeId, final GridIoMessage msg, final byte plc, final IgniteRunnable msgC) throws IgniteCheckedException {
    Runnable c = new TraceRunnable(ctx.tracing(), COMMUNICATION_REGULAR_PROCESS) {

        @Override
        public void execute() {
            try {
                MTC.span().addTag(SpanTags.MESSAGE, () -> traceName(msg));
                threadProcessingMessage(true, msgC);
                processRegularMessage0(msg, nodeId);
            } finally {
                threadProcessingMessage(false, null);
                msgC.run();
            }
        }

        @Override
        public String toString() {
            return "Message closure [msg=" + msg + ']';
        }
    };
    MTC.span().addLog(() -> "Regular process queued");
    if (msg.topicOrdinal() == TOPIC_IO_TEST.ordinal()) {
        IgniteIoTestMessage msg0 = (IgniteIoTestMessage) msg.message();
        if (msg0.processFromNioThread())
            c.run();
        else
            ctx.pools().getStripedExecutorService().execute(-1, c);
        return;
    }
    if (msg.topicOrdinal() == TOPIC_CACHE_COORDINATOR.ordinal()) {
        MvccMessage msg0 = (MvccMessage) msg.message();
        // see IGNITE-8609
        /*if (msg0.processedFromNioThread())
                c.run();
            else*/
        ctx.pools().getStripedExecutorService().execute(-1, c);
        return;
    }
    // Store partition to avoid possible recalculation.
    final int part = msg.partition();
    if (plc == GridIoPolicy.SYSTEM_POOL && part != GridIoMessage.STRIPE_DISABLED_PART) {
        ctx.pools().getStripedExecutorService().execute(part, c);
        return;
    }
    if (plc == GridIoPolicy.DATA_STREAMER_POOL && part != GridIoMessage.STRIPE_DISABLED_PART) {
        ctx.pools().getDataStreamerExecutorService().execute(part, c);
        return;
    }
    if (msg.topicOrdinal() == TOPIC_IO_TEST.ordinal()) {
        IgniteIoTestMessage msg0 = (IgniteIoTestMessage) msg.message();
        if (msg0.processFromNioThread()) {
            c.run();
            return;
        }
    }
    try {
        String execName = msg.executorName();
        if (execName != null) {
            Executor exec = pools.customExecutor(execName);
            if (exec != null) {
                exec.execute(c);
                return;
            } else {
                LT.warn(log, "Custom executor doesn't exist (message will be processed in default " + "thread pool): " + execName);
            }
        }
        pools.poolForPolicy(plc).execute(c);
    } catch (RejectedExecutionException e) {
        if (!ctx.isStopping()) {
            U.error(log, "Failed to process regular message due to execution rejection. Will attempt to process " + "message in the listener thread instead.", e);
            c.run();
        } else if (log.isDebugEnabled())
            log.debug("Failed to process regular message due to execution rejection: " + msg);
    }
}
Also used : Executor(java.util.concurrent.Executor) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) MvccMessage(org.apache.ignite.internal.processors.cache.mvcc.msg.MvccMessage) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Aggregations

Executor (java.util.concurrent.Executor)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 MvccMessage (org.apache.ignite.internal.processors.cache.mvcc.msg.MvccMessage)1 IgniteRunnable (org.apache.ignite.lang.IgniteRunnable)1