/** * @return Transaction for current thread. */ public <T> T tx() { IgniteInternalTx tx = txContext(); return tx != null ? (T)tx : (T)tx(null, Thread.currentThread().getId()); }
/** * @param cctx Cache context. * @return User transaction for current thread. */ @Nullable GridNearTxLocal userTx(GridCacheContext cctx) { IgniteInternalTx tx = tx(cctx, Thread.currentThread().getId()); if (activeUserTx(tx)) return (GridNearTxLocal)tx; return null; }
GridDhtTxRemote dhtTx = cctx.tm().tx(dhtVer);
/** * @return Local transaction. */ @Nullable public IgniteTxLocalAdapter localTx() { IgniteTxLocalAdapter tx = tx(); return tx != null && tx.local() ? tx : null; }
GridDhtTxRemote dhtTx = cctx.tm().tx(dhtVer);
/** * @return User transaction for current thread. */ @Nullable public GridNearTxLocal userTx() { IgniteInternalTx tx = txContext(); if (activeUserTx(tx)) return (GridNearTxLocal)tx; tx = tx(null, Thread.currentThread().getId()); if (activeUserTx(tx)) return (GridNearTxLocal)tx; return null; }
/** * @param cctx Cache context. * @return Transaction for current thread. */ public GridNearTxLocal threadLocalTx(GridCacheContext cctx) { IgniteInternalTx tx = tx(cctx, Thread.currentThread().getId()); if (tx != null && tx.local() && (!tx.dht() || tx.colocated()) && !tx.implicit()) { assert tx instanceof GridNearTxLocal : tx; return (GridNearTxLocal)tx; } return null; }
assert req.version() != null && req.op() != null; GridDhtTxRemote tx = ctx.tm().tx(req.version());
/** {@inheritDoc} */ @Override public String toString() { if (!pendingLocks.isEmpty()) { Map<GridCacheVersion, IgniteInternalTx> txs = new HashMap<>(1, 1.0f); for (Collection<GridCacheMvccCandidate> cands : pendingLocks.values()) for (GridCacheMvccCandidate c : cands) txs.put(c.version(), cctx.tm().tx(c.version())); return S.toString(FinishLockFuture.class, this, "txs=" + txs + ", super=" + super.toString()); } else return S.toString(FinishLockFuture.class, this, super.toString()); } }
/** * For all remote candidates standing behind the candidate being salvaged marks their transactions * as system invalidate and marks these candidates as owned and used. * * @param ver Version to salvage. */ public void salvageRemote(GridCacheVersion ver) { assert ver != null; GridCacheMvccCandidate cand = candidate(rmts, ver); if (cand != null) { assert rmts != null; assert !rmts.isEmpty(); for (Iterator<GridCacheMvccCandidate> iter = rmts.iterator(); iter.hasNext(); ) { GridCacheMvccCandidate rmt = iter.next(); // For salvaged candidate doneRemote will be called explicitly. if (rmt == cand) break; // Only Near and DHT remote candidates should be released. assert !rmt.nearLocal(); IgniteInternalTx tx = cctx.tm().tx(rmt.version()); if (tx != null) { tx.systemInvalidate(true); rmt.setOwner(); rmt.setUsed(); } else iter.remove(); } } }
/** * @param ctx Grid kernal context. * @param txId Transaction ID. * @return Currently started user transaction, or {@code null} if none started. * @throws UnsupportedTxModeException If transaction mode is not supported when MVCC is enabled. * @throws NonMvccTransactionException If started transaction spans non MVCC caches. */ @Nullable public static GridNearTxLocal currentTx(GridKernalContext ctx, @Nullable GridCacheVersion txId) throws UnsupportedTxModeException, NonMvccTransactionException { IgniteTxManager tm = ctx.cache().context().tm(); IgniteInternalTx tx0 = txId == null ? tm.tx() : tm.tx(txId); GridNearTxLocal tx = tx0 != null && tx0.user() ? (GridNearTxLocal)tx0 : null; if (tx != null) { if (!tx.pessimistic()) { tx.setRollbackOnly(); throw new UnsupportedTxModeException(); } if (!tx.isOperationAllowed(true)) { tx.setRollbackOnly(); throw new NonMvccTransactionException(); } } return tx; }
final GridFutureAdapter<Boolean> resFut = new GridFutureAdapter<>(); final IgniteInternalTx tx = cctx.tm().tx(xidVer);
/** {@inheritDoc} */ @Override public IgniteCache<K, V> withAllowAtomicOpsInTx() { if (context().atomic() && !opCtx.allowedAtomicOpsInTx() && context().tm().tx() != null) { throw new IllegalStateException("Enabling atomic operations during active transaction is not allowed. " + "Enable atomic operations before transaction start."); } CacheOperationGate opGate = onEnter(); try { boolean allowed = opCtx.allowedAtomicOpsInTx(); if (allowed) return this; return new GatewayProtectedCacheProxy<>(delegate, opCtx.setAllowAtomicOpsInTx(), lock); } finally { onLeave(opGate); } }
/** * @param nodeId Node ID. * @param req Request. * @return Future. */ @Nullable private IgniteInternalFuture<IgniteInternalTx> processNearTxFinishRequest( UUID nodeId, GridNearTxFinishRequest req ) { if (txFinishMsgLog.isDebugEnabled()) txFinishMsgLog.debug("Received near finish request [txId=" + req.version() + ", node=" + nodeId + ']'); IgniteInternalFuture<IgniteInternalTx> fut = finish(nodeId, null, req); assert req.txState() != null || fut == null || fut.error() != null || (ctx.tm().tx(req.version()) == null && ctx.tm().nearTx(req.version()) == null) : "[req=" + req + ", fut=" + fut + "]"; return fut; }
/** */ private void handleDeadlockProbeForNear(DeadlockProbe probe) { // a probe is simply discarded if next wait-for edge is not found ProbedTx blocker = probe.blocker(); GridNearTxLocal nearTx = cctx.tm().tx(blocker.nearXidVersion()); if (nearTx == null) return; // probe each blocker for (UUID pendingNodeId : getPendingResponseNodes(nearTx)) { sendProbe( pendingNodeId, probe.initiatorVersion(), probe.waitChain(), // real start time is filled here blocker.withStartTime(nearTx.startTime()), false); } }
IgniteInternalTx tx = ctx.cache().context().tm().tx();
/** * @param nearNode Sender node. * @param req Request. */ private void processNearTxPrepareRequest0(ClusterNode nearNode, GridNearTxPrepareRequest req) { IgniteInternalFuture<GridNearTxPrepareResponse> fut; if (req.firstClientRequest() && req.allowWaitTopologyFuture()) { for (;;) { if (waitForExchangeFuture(nearNode, req)) return; fut = prepareNearTx(nearNode, req); if (fut != null) break; } } else fut = prepareNearTx(nearNode, req); assert req.txState() != null || fut == null || fut.error() != null || (ctx.tm().tx(req.version()) == null && ctx.tm().nearTx(req.version()) == null); }
/** * Callback invoked whenever a member of a transaction acquires * lock ownership. * * @param entry Cache entry. * @param owner Candidate that won ownership. * @return {@code True} if transaction was notified, {@code false} otherwise. */ public boolean onOwnerChanged(GridCacheEntryEx entry, GridCacheMvccCandidate owner) { // We only care about acquired locks. if (owner != null) { IgniteTxAdapter tx = tx(owner.version()); if (tx == null) tx = nearTx(owner.version()); if (tx != null) { if (!tx.local()) { if (log.isDebugEnabled()) log.debug("Found transaction for owner changed event [owner=" + owner + ", entry=" + entry + ", tx=" + tx + ']'); tx.onOwnerChanged(entry, owner); return true; } else if (log.isDebugEnabled()) log.debug("Ignoring local transaction for owner change event: " + tx); } else if (log.isDebugEnabled()) log.debug("Transaction not found for owner changed event [owner=" + owner + ", entry=" + entry + ']'); } return false; }
/** * @param node Node. */ private void checkNoTx(Ignite node) { IgniteTransactions txs = node.transactions(); assertNull(txs.tx()); assertNull(((IgniteKernal)node).context().cache().context().tm().tx()); } }
/** * Check if flags in correct state. * * @param msg Message. */ private void checkSyncFlags(GridIoMessage msg) { if (!commSpiEnabled) return; Object o = msg.message(); if (!(o instanceof GridDistributedLockRequest)) return; IgniteKernal g = (IgniteKernal)G.ignite(ignite.configuration().getNodeId()); GridCacheContext<Object, Object> cacheCtx = g.internalCache(REPLICATED_ASYNC_CACHE_NAME).context(); IgniteTxManager tm = cacheCtx.tm(); GridCacheVersion v = ((GridCacheVersionable)o).version(); IgniteInternalTx t = tm.tx(v); if (t.hasWriteKey(cacheCtx.txKey(cacheCtx.toCacheKeyObject("x1")))) assertEquals("Invalid tx flags: " + t, FULL_ASYNC, ((IgniteTxLocalAdapter)t).syncMode()); else if (t.hasWriteKey(cacheCtx.txKey(cacheCtx.toCacheKeyObject("x2")))) assertEquals("Invalid tx flags: " + t, FULL_SYNC, ((IgniteTxLocalAdapter)t).syncMode()); else if (t.hasWriteKey(cacheCtx.txKey(cacheCtx.toCacheKeyObject("x3")))) assertEquals("Invalid tx flags: " + t, FULL_ASYNC, ((IgniteTxLocalAdapter)t).syncMode()); else if (t.hasWriteKey(cacheCtx.txKey(cacheCtx.toCacheKeyObject("x4")))) assertEquals("Invalid tx flags: " + t, FULL_SYNC, ((IgniteTxLocalAdapter)t).syncMode()); } }