Search in sources :

Example 1 with GridCacheQueryMarshallable

use of org.apache.ignite.internal.processors.cache.query.GridCacheQueryMarshallable in project ignite by apache.

the class IgniteH2Indexing method send.

/**
     * @param topic Topic.
     * @param topicOrd Topic ordinal for {@link GridTopic}.
     * @param nodes Nodes.
     * @param msg Message.
     * @param specialize Optional closure to specialize message for each node.
     * @param locNodeHnd Handler for local node.
     * @param plc Policy identifying the executor service which will process message.
     * @param runLocParallel Run local handler in parallel thread.
     * @return {@code true} If all messages sent successfully.
     */
public boolean send(Object topic, int topicOrd, Collection<ClusterNode> nodes, Message msg, @Nullable IgniteBiClosure<ClusterNode, Message, Message> specialize, @Nullable final IgniteInClosure2X<ClusterNode, Message> locNodeHnd, byte plc, boolean runLocParallel) {
    boolean ok = true;
    if (specialize == null && msg instanceof GridCacheQueryMarshallable)
        ((GridCacheQueryMarshallable) msg).marshall(marshaller);
    ClusterNode locNode = null;
    for (ClusterNode node : nodes) {
        if (node.isLocal()) {
            if (locNode != null)
                throw new IllegalStateException();
            locNode = node;
            continue;
        }
        try {
            if (specialize != null) {
                msg = specialize.apply(node, msg);
                if (msg instanceof GridCacheQueryMarshallable)
                    ((GridCacheQueryMarshallable) msg).marshall(marshaller);
            }
            ctx.io().sendGeneric(node, topic, topicOrd, msg, plc);
        } catch (IgniteCheckedException e) {
            ok = false;
            U.warn(log, "Failed to send message [node=" + node + ", msg=" + msg + ", errMsg=" + e.getMessage() + "]");
        }
    }
    // Local node goes the last to allow parallel execution.
    if (locNode != null) {
        assert locNodeHnd != null;
        if (specialize != null)
            msg = specialize.apply(locNode, msg);
        if (runLocParallel) {
            final ClusterNode finalLocNode = locNode;
            final Message finalMsg = msg;
            try {
                // We prefer runLocal to runLocalSafe, because the latter can produce deadlock here.
                ctx.closure().runLocal(new GridPlainRunnable() {

                    @Override
                    public void run() {
                        if (!busyLock.enterBusy())
                            return;
                        try {
                            locNodeHnd.apply(finalLocNode, finalMsg);
                        } finally {
                            busyLock.leaveBusy();
                        }
                    }
                }, plc).listen(logger);
            } catch (IgniteCheckedException e) {
                ok = false;
                U.error(log, "Failed to execute query locally.", e);
            }
        } else
            locNodeHnd.apply(locNode, msg);
    }
    return ok;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Message(org.apache.ignite.plugin.extensions.communication.Message) GridCacheQueryMarshallable(org.apache.ignite.internal.processors.cache.query.GridCacheQueryMarshallable) GridPlainRunnable(org.apache.ignite.internal.util.lang.GridPlainRunnable)

Example 2 with GridCacheQueryMarshallable

use of org.apache.ignite.internal.processors.cache.query.GridCacheQueryMarshallable in project ignite by apache.

the class GridReduceQueryExecutor method start.

/**
     * @param ctx Context.
     * @param h2 H2 Indexing.
     * @throws IgniteCheckedException If failed.
     */
public void start(final GridKernalContext ctx, final IgniteH2Indexing h2) throws IgniteCheckedException {
    this.ctx = ctx;
    this.h2 = h2;
    log = ctx.log(GridReduceQueryExecutor.class);
    ctx.io().addMessageListener(GridTopic.TOPIC_QUERY, new GridMessageListener() {

        @Override
        public void onMessage(UUID nodeId, Object msg) {
            if (!busyLock.enterBusy())
                return;
            try {
                if (msg instanceof GridCacheQueryMarshallable)
                    ((GridCacheQueryMarshallable) msg).unmarshall(ctx.config().getMarshaller(), ctx);
                GridReduceQueryExecutor.this.onMessage(nodeId, msg);
            } finally {
                busyLock.leaveBusy();
            }
        }
    });
    ctx.event().addLocalEventListener(new GridLocalEventListener() {

        @Override
        public void onEvent(final Event evt) {
            UUID nodeId = ((DiscoveryEvent) evt).eventNode().id();
            for (ReduceQueryRun r : runs.values()) {
                for (GridMergeIndex idx : r.indexes()) {
                    if (idx.hasSource(nodeId)) {
                        handleNodeLeft(r, nodeId);
                        break;
                    }
                }
            }
        }
    }, EventType.EVT_NODE_FAILED, EventType.EVT_NODE_LEFT);
}
Also used : GridLocalEventListener(org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener) GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) GridCacheQueryMarshallable(org.apache.ignite.internal.processors.cache.query.GridCacheQueryMarshallable) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) UUID(java.util.UUID)

Example 3 with GridCacheQueryMarshallable

use of org.apache.ignite.internal.processors.cache.query.GridCacheQueryMarshallable in project ignite by apache.

the class GridMapQueryExecutor method start.

/**
     * @param ctx Context.
     * @param h2 H2 Indexing.
     * @throws IgniteCheckedException If failed.
     */
public void start(final GridKernalContext ctx, IgniteH2Indexing h2) throws IgniteCheckedException {
    this.ctx = ctx;
    this.h2 = h2;
    log = ctx.log(GridMapQueryExecutor.class);
    final UUID locNodeId = ctx.localNodeId();
    ctx.event().addLocalEventListener(new GridLocalEventListener() {

        @Override
        public void onEvent(final Event evt) {
            UUID nodeId = ((DiscoveryEvent) evt).eventNode().id();
            GridH2QueryContext.clearAfterDeadNode(locNodeId, nodeId);
            NodeResults nodeRess = qryRess.remove(nodeId);
            if (nodeRess == null)
                return;
            nodeRess.cancelAll();
        }
    }, EventType.EVT_NODE_FAILED, EventType.EVT_NODE_LEFT);
    ctx.io().addMessageListener(GridTopic.TOPIC_QUERY, new GridMessageListener() {

        @Override
        public void onMessage(UUID nodeId, Object msg) {
            if (!busyLock.enterBusy())
                return;
            try {
                if (msg instanceof GridCacheQueryMarshallable)
                    ((GridCacheQueryMarshallable) msg).unmarshall(ctx.config().getMarshaller(), ctx);
                GridMapQueryExecutor.this.onMessage(nodeId, msg);
            } finally {
                busyLock.leaveBusy();
            }
        }
    });
}
Also used : GridLocalEventListener(org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener) GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) GridCacheQueryMarshallable(org.apache.ignite.internal.processors.cache.query.GridCacheQueryMarshallable) CacheQueryExecutedEvent(org.apache.ignite.events.CacheQueryExecutedEvent) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) CacheQueryReadEvent(org.apache.ignite.events.CacheQueryReadEvent) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) GridH2ValueCacheObject(org.apache.ignite.internal.processors.query.h2.opt.GridH2ValueCacheObject) UUID(java.util.UUID)

Aggregations

GridCacheQueryMarshallable (org.apache.ignite.internal.processors.cache.query.GridCacheQueryMarshallable)3 UUID (java.util.UUID)2 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)2 Event (org.apache.ignite.events.Event)2 GridMessageListener (org.apache.ignite.internal.managers.communication.GridMessageListener)2 GridLocalEventListener (org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 CacheQueryExecutedEvent (org.apache.ignite.events.CacheQueryExecutedEvent)1 CacheQueryReadEvent (org.apache.ignite.events.CacheQueryReadEvent)1 GridH2ValueCacheObject (org.apache.ignite.internal.processors.query.h2.opt.GridH2ValueCacheObject)1 GridPlainRunnable (org.apache.ignite.internal.util.lang.GridPlainRunnable)1 Message (org.apache.ignite.plugin.extensions.communication.Message)1