/** * @param cctx Context. * @param tx Transaction. */ public GridNearPessimisticTxPrepareFuture(GridCacheSharedContext cctx, GridNearTxLocal tx) { super(cctx, tx); assert tx.pessimistic() : tx; }
/** * Checks filter for non-pessimistic transactions. * * @param cctx Cache context. * @param key Key. * @param val Value. * @param filter Filter to check. * @return {@code True} if passed or pessimistic. */ private boolean filter( GridCacheContext cctx, KeyCacheObject key, CacheObject val, CacheEntryPredicate[] filter) { return pessimistic() || (optimistic() && implicit()) || isAll(cctx, key, val, filter); }
/** * Suspends transaction. It could be resumed later. Supported only for optimistic transactions. * * @throws IgniteCheckedException If the transaction is in an incorrect state, or timed out. */ public void suspend() throws IgniteCheckedException { if (log.isDebugEnabled()) log.debug("Suspend near local tx: " + this); if (pessimistic()) throw new UnsupportedOperationException("Suspension is not supported for pessimistic transactions."); if (threadId() != Thread.currentThread().getId()) throw new IgniteCheckedException("Only thread started transaction can suspend it."); synchronized (this) { checkValid(); cctx.tm().suspendTx(this); } }
/** * Resumes transaction (possibly in another thread) if it was previously suspended. * * @param checkTimeout Whether timeout should be checked. * @param threadId Thread id to restore. * @throws IgniteCheckedException If the transaction is in an incorrect state, or timed out. */ private void resume(boolean checkTimeout, long threadId) throws IgniteCheckedException { if (log.isDebugEnabled()) log.debug("Resume near local tx: " + this); if (pessimistic()) throw new UnsupportedOperationException("Resume is not supported for pessimistic transactions."); synchronized (this) { checkValid(checkTimeout); cctx.tm().resumeTx(this, threadId); } }
/** * @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; }
return new GridFinishedFuture<>(rollbackException()); if (pessimistic()) { final Collection<KeyCacheObject> enlisted = Collections.singleton(cacheKey);
return new GridFinishedFuture<>(rollbackException()); if (pessimistic()) { if (log.isDebugEnabled()) log.debug("Before acquiring transaction lock for put on keys: " + enlisted);
final Map<KeyCacheObject, GridCacheVersion> missed = new GridLeanMap<>(pessimistic() ? keysCnt : 0); if (pessimistic() && !readCommitted() && !skipVals) { if (expiryPlc == null) expiryPlc = cacheCtx.expiry();
throw timedOut() ? timeoutException() : rollbackException(); if ((pessimistic() || needReadVer) && !readCommitted() && !skipVals) addActiveCache(cacheCtx, recovery); ver = txEntry.entryReadVersion(); if (ver == null && pessimistic()) { while (true) { try { EntryGetResult getRes = null; if (!pessimistic() || readCommitted() && !skipVals) { IgniteCacheExpiryPolicy accessPlc = optimistic() ? accessPolicy(cacheCtx, txKey, expiryPlc) : null; if (val != null && !pessimistic()) { txEntry.markValid();
boolean skipStore, boolean keepBinary) { assert pessimistic();
assertTrue(txEx.pessimistic());
if (pessimistic()) { if (log.isDebugEnabled()) log.debug("Before acquiring transaction lock for remove on keys: " + enlisted);
enlisted.add(cacheKey); if (!pessimistic() && !implicit()) { txEntry.markValid(); if (!pessimistic()) { txEntry.markValid();
if (tx.pessimistic() && !useCompletedVer) cctx.tm().beforeFinishRemote(n.id(), tx.threadId());
/** * @param cctx Context. * @param tx Transaction. */ public GridNearPessimisticTxPrepareFuture(GridCacheSharedContext cctx, GridNearTxLocal tx) { super(cctx, tx); assert tx.pessimistic() : tx; }
/** * Validate Tx mode. * * @param ctx Cache context. * @throws IgniteCheckedException If tx mode is not supported. */ protected void validateTxMode(GridCacheContext ctx) throws IgniteCheckedException { if(!ctx.mvccEnabled() || pessimistic() && repeatableRead()) return; throw new IgniteCheckedException("Only pessimistic repeatable read transactions are supported at the moment."); }
/** * Checks filter for non-pessimistic transactions. * * @param cctx Cache context. * @param key Key. * @param val Value. * @param filter Filter to check. * @return {@code True} if passed or pessimistic. */ private boolean filter( GridCacheContext cctx, KeyCacheObject key, CacheObject val, CacheEntryPredicate[] filter) { return pessimistic() || (optimistic() && implicit()) || isAll(cctx, key, val, filter); }
/** * Suspends transaction. It could be resumed later. Supported only for optimistic transactions. * * @throws IgniteCheckedException If the transaction is in an incorrect state, or timed out. */ public void suspend() throws IgniteCheckedException { if (log.isDebugEnabled()) log.debug("Suspend near local tx: " + this); if (pessimistic()) throw new UnsupportedOperationException("Suspension is not supported for pessimistic transactions."); if (threadId() != Thread.currentThread().getId()) throw new IgniteCheckedException("Only thread started transaction can suspend it."); synchronized (this) { checkValid(); cctx.tm().suspendTx(this); } }
/** * Resumes transaction (possibly in another thread) if it was previously suspended. * * @param checkTimeout Whether timeout should be checked. * @param threadId Thread id to restore. * @throws IgniteCheckedException If the transaction is in an incorrect state, or timed out. */ private void resume(boolean checkTimeout, long threadId) throws IgniteCheckedException { if (log.isDebugEnabled()) log.debug("Resume near local tx: " + this); if (pessimistic()) throw new UnsupportedOperationException("Resume is not supported for pessimistic transactions."); synchronized (this) { checkValid(checkTimeout); cctx.tm().resumeTx(this, threadId); } }
/** * @param ctx Grid kernal context. * @param txId Transaction ID. * @return Currently started user transaction, or {@code null} if none started. */ @Nullable public static GridNearTxLocal tx(GridKernalContext ctx, @Nullable GridCacheVersion txId) { 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.repeatableRead()) { tx.setRollbackOnly(); throw new IgniteSQLException("Only pessimistic repeatable read transactions are supported at the moment.", IgniteQueryErrorCode.UNSUPPORTED_OPERATION); } if (!tx.isOperationAllowed(true)) { tx.setRollbackOnly(); throw new IgniteSQLException("SQL queries and cache operations " + "may not be used in the same transaction.", IgniteQueryErrorCode.TRANSACTION_TYPE_MISMATCH); } } return tx; }