Search in sources :

Example 1 with TraceSurroundings

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

the class BulkLoadProcessor method processBatch.

/**
 * Processes the incoming batch and writes data to the cache by calling the data converter and output streamer.
 *
 * @param batchData Data from the current batch.
 * @param isLastBatch true if this is the last batch.
 * @throws IgniteIllegalStateException when called after {@link #close()}.
 */
public void processBatch(byte[] batchData, boolean isLastBatch) throws IgniteCheckedException {
    try (TraceSurroundings ignored = MTC.support(tracing.create(SQL_BATCH_PROCESS, qrySpan))) {
        if (isClosed)
            throw new IgniteIllegalStateException("Attempt to process a batch on a closed BulkLoadProcessor");
        Iterable<List<Object>> inputRecords = inputParser.parseBatch(batchData, isLastBatch);
        for (List<Object> record : inputRecords) {
            IgniteBiTuple<?, ?> kv = dataConverter.apply(record);
            outputStreamer.apply(kv);
        }
    }
}
Also used : List(java.util.List) TraceSurroundings(org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings) IgniteIllegalStateException(org.apache.ignite.IgniteIllegalStateException)

Example 2 with TraceSurroundings

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

the class IgniteTxHandler method processNearTxPrepareRequest.

/**
 * @param nearNodeId Sender node ID.
 * @param req Request.
 */
private void processNearTxPrepareRequest(UUID nearNodeId, GridNearTxPrepareRequest req) {
    try (TraceSurroundings ignored = MTC.support(ctx.kernalContext().tracing().create(TX_NEAR_PREPARE_REQ, MTC.span()))) {
        if (txPrepareMsgLog.isDebugEnabled()) {
            txPrepareMsgLog.debug("Received near prepare request [txId=" + req.version() + ", node=" + nearNodeId + ']');
        }
        ClusterNode nearNode = ctx.node(nearNodeId);
        if (nearNode == null) {
            if (txPrepareMsgLog.isDebugEnabled()) {
                txPrepareMsgLog.debug("Received near prepare from node that left grid (will ignore) [" + "txId=" + req.version() + ", node=" + nearNodeId + ']');
            }
            return;
        }
        processNearTxPrepareRequest0(nearNode, req);
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) TraceSurroundings(org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings)

Example 3 with TraceSurroundings

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

the class IgniteTxHandler method processDhtTxPrepareRequest.

/**
 * @param nodeId Sender node ID.
 * @param req Request.
 */
private void processDhtTxPrepareRequest(final UUID nodeId, final GridDhtTxPrepareRequest req) {
    try (TraceSurroundings ignored = MTC.support(ctx.kernalContext().tracing().create(TX_PROCESS_DHT_PREPARE_REQ, MTC.span()))) {
        if (txPrepareMsgLog.isDebugEnabled()) {
            txPrepareMsgLog.debug("Received dht prepare request [txId=" + req.nearXidVersion() + ", dhtTxId=" + req.version() + ", node=" + nodeId + ']');
        }
        assert nodeId != null;
        assert req != null;
        assert req.transactionNodes() != null;
        GridDhtTxRemote dhtTx = null;
        GridNearTxRemote nearTx = null;
        GridDhtTxPrepareResponse res;
        try {
            res = new GridDhtTxPrepareResponse(req.partition(), req.version(), req.futureId(), req.miniId(), req.deployInfo() != null);
            // Start near transaction first.
            nearTx = !F.isEmpty(req.nearWrites()) ? startNearRemoteTx(ctx.deploy().globalLoader(), nodeId, req) : null;
            dhtTx = startRemoteTx(nodeId, req, res);
            // Set evicted keys from near transaction.
            if (nearTx != null)
                res.nearEvicted(nearTx.evicted());
            List<IgniteTxKey> writesCacheMissed = req.nearWritesCacheMissed();
            if (writesCacheMissed != null) {
                Collection<IgniteTxKey> evicted0 = res.nearEvicted();
                if (evicted0 != null)
                    writesCacheMissed.addAll(evicted0);
                res.nearEvicted(writesCacheMissed);
            }
            if (dhtTx != null)
                req.txState(dhtTx.txState());
            else if (nearTx != null)
                req.txState(nearTx.txState());
            if (dhtTx != null && !F.isEmpty(dhtTx.invalidPartitions()))
                res.invalidPartitionsByCacheId(dhtTx.invalidPartitions());
            if (req.onePhaseCommit()) {
                assert req.last();
                if (dhtTx != null) {
                    dhtTx.onePhaseCommit(true);
                    dhtTx.needReturnValue(req.needReturnValue());
                    finish(dhtTx, req);
                }
                if (nearTx != null) {
                    nearTx.onePhaseCommit(true);
                    finish(nearTx, req);
                }
            }
        } catch (IgniteCheckedException e) {
            if (e instanceof IgniteTxRollbackCheckedException)
                U.error(log, "Transaction was rolled back before prepare completed: " + req, e);
            else if (e instanceof IgniteTxOptimisticCheckedException) {
                if (log.isDebugEnabled())
                    log.debug("Optimistic failure for remote transaction (will rollback): " + req);
            } else
                U.error(log, "Failed to process prepare request: " + req, e);
            if (nearTx != null)
                try {
                    nearTx.rollbackRemoteTx();
                } catch (Throwable e1) {
                    e.addSuppressed(e1);
                }
            res = new GridDhtTxPrepareResponse(req.partition(), req.version(), req.futureId(), req.miniId(), e, req.deployInfo() != null);
        }
        if (req.onePhaseCommit()) {
            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) {
                final GridDhtTxPrepareResponse res0 = res;
                final GridDhtTxRemote dhtTx0 = dhtTx;
                final GridNearTxRemote nearTx0 = nearTx;
                completeFut.listen(new CI1<IgniteInternalFuture<IgniteInternalTx>>() {

                    @Override
                    public void apply(IgniteInternalFuture<IgniteInternalTx> fut) {
                        sendReply(nodeId, req, res0, dhtTx0, nearTx0);
                    }
                });
            } else
                sendReply(nodeId, req, res, dhtTx, nearTx);
        } else
            sendReply(nodeId, req, res, dhtTx, nearTx);
        assert req.txState() != null || res.error() != null || (dhtTx == null && nearTx == null) : req + " tx=" + dhtTx + " nearTx=" + nearTx;
    }
}
Also used : GridDhtTxRemote(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxRemote) IgniteTxRollbackCheckedException(org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException) GridDhtTxPrepareResponse(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxPrepareResponse) 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) IgniteTxOptimisticCheckedException(org.apache.ignite.internal.transactions.IgniteTxOptimisticCheckedException) GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException)

Example 4 with TraceSurroundings

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

the class IgniteTxHandler method processNearTxPrepareResponse.

/**
 * @param nodeId Node ID.
 * @param res Response.
 */
private void processNearTxPrepareResponse(UUID nodeId, GridNearTxPrepareResponse res) {
    try (TraceSurroundings ignored = MTC.support(ctx.kernalContext().tracing().create(TX_NEAR_PREPARE_RESP, MTC.span()))) {
        if (txPrepareMsgLog.isDebugEnabled())
            txPrepareMsgLog.debug("Received near prepare response [txId=" + res.version() + ", node=" + nodeId + ']');
        GridNearTxPrepareFutureAdapter fut = (GridNearTxPrepareFutureAdapter) ctx.mvcc().<IgniteInternalTx>versionedFuture(res.version(), res.futureId());
        if (fut == null) {
            U.warn(log, "Failed to find future for near prepare response [txId=" + res.version() + ", node=" + nodeId + ", res=" + res + ']');
            return;
        }
        IgniteInternalTx tx = fut.tx();
        assert tx != null;
        res.txState(tx.txState());
        fut.onResult(nodeId, res);
    }
}
Also used : GridNearTxPrepareFutureAdapter(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxPrepareFutureAdapter) TraceSurroundings(org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings)

Example 5 with TraceSurroundings

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

the class GridDhtColocatedLockFuture method map.

/**
 * Basically, future mapping consists from two parts. First, we must determine the topology version this future
 * will map on. Locking is performed within a user transaction, we must continue to map keys on the same
 * topology version as it started. If topology version is undefined, we get current topology future and wait
 * until it completes so the topology is ready to use.
 * <p/>
 * During the second part we map keys to primary nodes using topology snapshot we obtained during the first
 * part. Note that if primary node leaves grid, the future will fail and transaction will be rolled back.
 */
void map() {
    try (TraceSurroundings ignored = MTC.supportContinual(span = cctx.kernalContext().tracing().create(TX_COLOCATED_LOCK_MAP, MTC.span()))) {
        if (// Possible due to async rollback.
        isDone())
            return;
        if (timeout > 0) {
            timeoutObj = new LockTimeoutObject();
            cctx.time().addTimeoutObject(timeoutObj);
        }
        // Obtain the topology version to use.
        AffinityTopologyVersion topVer = cctx.mvcc().lastExplicitLockTopologyVersion(threadId);
        // If there is another system transaction in progress, use it's topology version to prevent deadlock.
        if (topVer == null && tx != null && tx.system())
            topVer = cctx.tm().lockedTopologyVersion(Thread.currentThread().getId(), tx);
        if (topVer != null && tx != null)
            tx.topologyVersion(topVer);
        if (topVer == null && tx != null)
            topVer = tx.topologyVersionSnapshot();
        if (topVer != null) {
            AffinityTopologyVersion lastChangeVer = cctx.shared().exchange().lastAffinityChangedTopologyVersion(topVer);
            IgniteInternalFuture<AffinityTopologyVersion> affFut = cctx.shared().exchange().affinityReadyFuture(lastChangeVer);
            if (!affFut.isDone()) {
                try {
                    affFut.get();
                } catch (IgniteCheckedException e) {
                    onDone(err);
                    return;
                }
            }
            // Continue mapping on the same topology version as it was before.
            synchronized (this) {
                if (this.topVer == null)
                    this.topVer = topVer;
            }
            cctx.mvcc().addFuture(this);
            map(keys, false, true);
            markInitialized();
            return;
        }
        // Must get topology snapshot and map on that version.
        mapOnTopology(false, null);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) 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