Search in sources :

Example 31 with TraceSurroundings

use of org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings in project ignite by apache.

the class IgniteTxHandler method processDhtTxFinishRequest.

/**
 * @param nodeId Node ID.
 * @param req Request.
 */
@SuppressWarnings({ "unchecked" })
private void processDhtTxFinishRequest(final UUID nodeId, final GridDhtTxFinishRequest req) {
    try (TraceSurroundings ignored = MTC.support(ctx.kernalContext().tracing().create(TX_PROCESS_DHT_FINISH_REQ, MTC.span()))) {
        assert nodeId != null;
        assert req != null;
        if (req.checkCommitted()) {
            boolean committed = req.waitRemoteTransactions() || !ctx.tm().addRolledbackTx(null, req.version());
            if (!committed || req.syncMode() != FULL_SYNC)
                sendReply(nodeId, req, committed, null);
            else {
                IgniteInternalFuture<?> fut = ctx.tm().remoteTxFinishFuture(req.version());
                fut.listen(new CI1<IgniteInternalFuture<?>>() {

                    @Override
                    public void apply(IgniteInternalFuture<?> fut) {
                        sendReply(nodeId, req, true, null);
                    }
                });
            }
            return;
        }
        // Always add version to rollback history to prevent races with rollbacks.
        if (!req.commit())
            ctx.tm().addRolledbackTx(null, req.version());
        GridDhtTxRemote dhtTx = ctx.tm().tx(req.version());
        GridNearTxRemote nearTx = ctx.tm().nearTx(req.version());
        IgniteInternalTx anyTx = U.<IgniteInternalTx>firstNotNull(dhtTx, nearTx);
        final GridCacheVersion nearTxId = anyTx != null ? anyTx.nearXidVersion() : null;
        if (txFinishMsgLog.isDebugEnabled())
            txFinishMsgLog.debug("Received dht finish request [txId=" + nearTxId + ", dhtTxId=" + req.version() + ", node=" + nodeId + ']');
        if (anyTx == null && req.commit())
            ctx.tm().addCommittedTx(null, req.version(), null);
        if (dhtTx != null)
            finish(nodeId, dhtTx, req);
        else {
            try {
                applyPartitionsUpdatesCounters(req.updateCounters(), !req.commit(), false);
            } catch (IgniteCheckedException e) {
                throw new IgniteException(e);
            }
        }
        if (nearTx != null)
            finish(nodeId, nearTx, req);
        if (req.replyRequired()) {
            IgniteInternalFuture completeFut;
            IgniteInternalFuture<IgniteInternalTx> dhtFin = dhtTx == null ? null : dhtTx.done() ? null : dhtTx.finishFuture();
            final IgniteInternalFuture<IgniteInternalTx> nearFin = nearTx == null ? null : nearTx.done() ? null : nearTx.finishFuture();
            if (dhtFin != null && nearFin != null) {
                GridCompoundFuture fut = new GridCompoundFuture();
                fut.add(dhtFin);
                fut.add(nearFin);
                fut.markInitialized();
                completeFut = fut;
            } else
                completeFut = dhtFin != null ? dhtFin : nearFin;
            if (completeFut != null) {
                completeFut.listen(new CI1<IgniteInternalFuture<IgniteInternalTx>>() {

                    @Override
                    public void apply(IgniteInternalFuture<IgniteInternalTx> fut) {
                        sendReply(nodeId, req, true, nearTxId);
                    }
                });
            } else
                sendReply(nodeId, req, true, nearTxId);
        } else
            sendReply(nodeId, req, true, null);
        assert req.txState() != null || (dhtTx == null && nearTx == null) : req + " tx=" + dhtTx + " nearTx=" + nearTx;
    }
}
Also used : GridDhtTxRemote(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxRemote) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) TraceSurroundings(org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings) GridNearTxRemote(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxRemote) GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException)

Example 32 with TraceSurroundings

use of org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings in project ignite by apache.

the class IgniteTxHandler method processDhtTxFinishResponse.

/**
 * @param nodeId Node ID.
 * @param res Response.
 */
private void processDhtTxFinishResponse(UUID nodeId, GridDhtTxFinishResponse res) {
    try (TraceSurroundings ignored = MTC.support(ctx.kernalContext().tracing().create(TX_PROCESS_DHT_FINISH_RESP, MTC.span()))) {
        assert nodeId != null;
        assert res != null;
        if (res.checkCommitted()) {
            GridNearTxFinishFuture fut = (GridNearTxFinishFuture) ctx.mvcc().<IgniteInternalTx>future(res.futureId());
            if (fut == null) {
                if (txFinishMsgLog.isDebugEnabled()) {
                    txFinishMsgLog.debug("Failed to find future for dht finish check committed response [txId=null" + ", dhtTxId=" + res.xid() + ", node=" + nodeId + ", res=" + res + ']');
                }
                return;
            } else if (txFinishMsgLog.isDebugEnabled()) {
                txFinishMsgLog.debug("Received dht finish check committed response [txId=" + fut.tx().nearXidVersion() + ", dhtTxId=" + res.xid() + ", node=" + nodeId + ']');
            }
            fut.onResult(nodeId, res);
        } else {
            GridDhtTxFinishFuture fut = (GridDhtTxFinishFuture) ctx.mvcc().<IgniteInternalTx>future(res.futureId());
            if (fut == null) {
                if (txFinishMsgLog.isDebugEnabled()) {
                    txFinishMsgLog.debug("Failed to find future for dht finish response [txId=null" + ", dhtTxId=" + res.xid() + ", node=" + nodeId + ", res=" + res);
                }
                return;
            } else if (txFinishMsgLog.isDebugEnabled()) {
                txFinishMsgLog.debug("Received dht finish response [txId=" + fut.tx().nearXidVersion() + ", dhtTxId=" + res.xid() + ", node=" + nodeId + ']');
            }
            fut.onResult(nodeId, res);
        }
    }
}
Also used : GridDhtTxFinishFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxFinishFuture) GridNearTxFinishFuture(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxFinishFuture) TraceSurroundings(org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings)

Example 33 with TraceSurroundings

use of org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings in project ignite by apache.

the class IgniteTxHandler method processNearTxFinishResponse.

/**
 * @param nodeId Node ID.
 * @param res Response.
 */
private void processNearTxFinishResponse(UUID nodeId, GridNearTxFinishResponse res) {
    try (TraceSurroundings ignored = MTC.support(ctx.kernalContext().tracing().create(TX_NEAR_FINISH_RESP, MTC.span()))) {
        if (txFinishMsgLog.isDebugEnabled())
            txFinishMsgLog.debug("Received near finish response [txId=" + res.xid() + ", node=" + nodeId + ']');
        GridNearTxFinishFuture fut = (GridNearTxFinishFuture) ctx.mvcc().<IgniteInternalTx>future(res.futureId());
        if (fut == null) {
            if (txFinishMsgLog.isDebugEnabled()) {
                txFinishMsgLog.debug("Failed to find future for near finish response [txId=" + res.xid() + ", node=" + nodeId + ", res=" + res + ']');
            }
            return;
        }
        fut.onResult(nodeId, res);
    }
}
Also used : GridNearTxFinishFuture(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxFinishFuture) TraceSurroundings(org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings)

Example 34 with TraceSurroundings

use of org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings in project ignite by apache.

the class TestRecordingCommunicationSpi method stopBlock.

/**
 * Stops block messages and sends all already blocked messages if sndMsgs is 'true' optionally filtered by
 * unblockPred.
 *
 * @param sndMsgs If {@code true} sends blocked messages.
 * @param unblockPred If not null unblocks only messages allowed by predicate.
 * @param clearFilters {@code true} to clear filters.
 * @param rmvBlockedMsgs {@code true} to remove blocked messages. Sometimes useful in conjunction with {@code
 * sndMsgs=false}.
 */
public void stopBlock(boolean sndMsgs, @Nullable IgnitePredicate<BlockedMessageDescriptor> unblockPred, boolean clearFilters, boolean rmvBlockedMsgs) {
    synchronized (this) {
        if (clearFilters) {
            blockCls.clear();
            blockP = null;
        }
        Iterator<BlockedMessageDescriptor> iter = blockedMsgs.iterator();
        while (iter.hasNext()) {
            BlockedMessageDescriptor blockedMsg = iter.next();
            // It is important what predicate if called only once for each message.
            if (unblockPred != null && !unblockPred.apply(blockedMsg))
                continue;
            if (sndMsgs) {
                try (TraceSurroundings ignored = MTC.supportContinual(blockedMsg.span())) {
                    ignite.log().info("Send blocked message " + blockedMsg);
                    super.sendMessage(blockedMsg.destinationNode(), blockedMsg.ioMessage());
                } catch (Throwable e) {
                    U.error(ignite.log(), "Failed to send blocked message: " + blockedMsg, e);
                }
            }
            if (rmvBlockedMsgs)
                iter.remove();
        }
    }
}
Also used : TraceSurroundings(org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings)

Example 35 with TraceSurroundings

use of org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings in project ignite by apache.

the class DmlBatchSender method sendBatch.

/**
 * Send the batch.
 *
 * @param batch Batch.
 */
private void sendBatch(Batch batch) {
    try (TraceSurroundings ignored = MTC.support(cctx.kernalContext().tracing().create(SQL_CACHE_UPDATE, MTC.span()).addTag(SQL_CACHE_UPDATES, () -> Integer.toString(batch.size())))) {
        DmlPageProcessingResult pageRes = processPage(cctx, batch);
        batch.clear();
        updateCnt += pageRes.count();
        if (failedKeys == null)
            failedKeys = new ArrayList<>();
        failedKeys.addAll(F.asList(pageRes.errorKeys()));
        if (pageRes.error() != null) {
            MTC.span().addTag(ERROR, pageRes.error()::getMessage);
            if (err == null)
                err = pageRes.error();
            else
                err.setNextException(pageRes.error());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) TraceSurroundings(org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings)

Aggregations

TraceSurroundings (org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings)49 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)18 QueryCancelledException (org.apache.ignite.cache.query.QueryCancelledException)11 SQLException (java.sql.SQLException)10 IgniteException (org.apache.ignite.IgniteException)10 ArrayList (java.util.ArrayList)9 CacheException (javax.cache.CacheException)8 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)7 List (java.util.List)6 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)6 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)6 Collections.singletonList (java.util.Collections.singletonList)5 ClusterTopologyServerNotFoundException (org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException)5 BatchUpdateException (java.sql.BatchUpdateException)4 CacheServerNotFoundException (org.apache.ignite.cache.CacheServerNotFoundException)4 QueryRetryException (org.apache.ignite.cache.query.QueryRetryException)4 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)4 IgniteClusterReadOnlyException (org.apache.ignite.internal.processors.cache.distributed.dht.IgniteClusterReadOnlyException)4 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)4 QueryContext (org.apache.ignite.internal.processors.query.h2.opt.QueryContext)4