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);
}
}
}
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);
}
}
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;
}
}
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);
}
}
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);
}
}
Aggregations