/** * Associate the transactional state with this thread. Should be only used by * tests. * * @param txState * the transactional state. */ public TXContext masqueradeAs(TXStateInterface txState) { return setTXState(txState); }
final TXContext setTXState(final TXStateInterface tx) { // the thread that created the TXStateInterface may be different from the // current thread so cannot rely on the context inside the TXStateProxy final TXContext context = getOrCreateTXContext(); setTXState(tx, context); return context; }
/** * Remove the association created by {@link #masqueradeAs(TransactionMessage)} * @param tx */ public void unmasquerade(TXStateProxy tx) { if (tx != null) { setTXState(null); tx.getLock().unlock(); } }
/** * Associate the transactional state with this thread. * @param txState the transactional state. */ public void masqueradeAs(TXStateProxy txState) { assert txState != null; if (!txState.getLock().isHeldByCurrentThread()) { txState.getLock().lock(); } setTXState(txState); }
/** * If the current thread is in a transaction then suspend will * cause it to no longer be in a transaction. * @return the state of the transaction or null. Pass this value * to {@link TXManagerImpl#resume} to reactivate the suspended transaction. */ public final TXStateProxy internalSuspend() { TXStateProxy result = getTXState(); if (result != null) { result.suspend(); setTXState(null); } return result; } /**
public Object call() throws Exception { TXManagerImpl mgr = getGemfireCache().getTxManager(); Region<Object, Object> custRegion = getCache().getRegion(CUSTOMER); assertEquals(expectedCustomerUpdate, custRegion.get(expectedCustId)); // check in the other active transaction // force other active transaction TXStateInterface tx = mgr.getHostedTXState(txId1); TXStateInterface txOrig = mgr.getTXState(); mgr.setTXState(tx); assertEquals(expectedCustomer, custRegion.get(expectedCustId)); mgr.setTXState(txOrig); return null; } });
/** * Activates the specified transaction on the calling thread. * @param tx the transaction to activate. * @throws IllegalStateException if this thread already has an active transaction */ public final void resume(TXStateProxy tx) { if (tx != null) { TransactionId tid = getTransactionId(); if (tid != null) { throw new java.lang.IllegalStateException(LocalizedStrings.TXManagerImpl_TRANSACTION_0_ALREADY_IN_PROGRESS.toLocalizedString(tid)); } if (tx instanceof TXState) { throw new java.lang.IllegalStateException("Found instance of TXState: " + tx); } setTXState(tx); tx.resume(); SystemTimerTask task = this.expiryTasks.remove(tx.getTransactionId()); if (task != null) { task.cancel(); } } }
/** Build a new {@link TXId}, use it as part of the transaction * state and associate with the current thread using a {@link * ThreadLocal}. Flag the transaction to be enlisted with a JTA * Transaction. Should only be called in a context where we know * there is no existing transaction. */ public TXStateProxy beginJTA() { checkClosed(); TXId id = new TXId(this.distributionMgrId, this.uniqId.incrementAndGet()); TXStateProxy newState = null; if (isDistributed()) { newState = new DistTXStateProxyImplOnCoordinator(this, id, true); } else { newState = new TXStateProxyImpl(this, id, true); } setTXState(newState); return newState; }
/** Build a new {@link TXId}, use it as part of the transaction * state and associate with the current thread using a {@link * ThreadLocal}. */ public void begin() { checkClosed(); { TransactionId tid = getTransactionId(); if (tid != null) { throw new java.lang.IllegalStateException(LocalizedStrings.TXManagerImpl_TRANSACTION_0_ALREADY_IN_PROGRESS.toLocalizedString(tid)); } } TXId id = new TXId(this.distributionMgrId, this.uniqId.incrementAndGet()); TXStateProxyImpl proxy = null; if (isDistributed()) { proxy = new DistTXStateProxyImplOnCoordinator(this, id, null); } else { proxy = new TXStateProxyImpl(this, id, null); } setTXState(proxy); this.localTxMap.put(id, proxy); }
public Object call() throws Exception { Region<Object, Object> custRegion = getCache().getRegion(CUSTOMER); TXManagerImpl mgr = getGemfireCache().getTxManager(); TXStateInterface tx = mgr.getHostedTXState(txId2); // force expected transaction TXStateInterface txOrig = mgr.getTXState(); mgr.setTXState(tx); tx = mgr.internalSuspend(); assertNull(custRegion.get(expectedCustId)); mgr.resume(tx); assertEquals(expectedCustomer, custRegion.get(expectedCustId)); mgr.setTXState(txOrig); return null; } });
private final void jtaEnlistmentFailureCleanup(TXStateInterface tx, Exception reason) { if (cache == null) { return; } cache.getTXMgr().setTXState(null); if (tx != null) { tx.rollback(); } String jtaTransName = null; try { jtaTransName = cache.getJTATransactionManager().getTransaction() .toString(); } catch (VirtualMachineError err) { SystemFailure.initiateFailure(err); // If this ever returns, rethrow the error. We're poisoned // now, so don't let this thread continue. throw err; } catch (Throwable ignore) { // Whenever you catch Error or Throwable, you must also // catch VirtualMachineError (see above). However, there is // _still_ a possibility that you are dealing with a cascading // error condition, so you also need to check to see if the JVM // is still usable: SystemFailure.checkFailure(); } throw new FailedSynchronizationException(LocalizedStrings.LocalRegion_FAILED_ENLISTEMENT_WITH_TRANSACTION_0.toLocalizedString(jtaTransName), reason); }
@Override public void afterCompletion(int status) { RemoteCommitResponse response = JtaAfterCompletionMessage.send(this.proxy.getCache(), this.proxy.getTxId().getUniqId(),getOriginatingMember(), status, this.target); try { this.proxy.getTxMgr().setTXState(null); this.commitMessage = response.waitForResponse(); if (logger.isDebugEnabled()) { logger.debug("afterCompletion received commit response of {}", this.commitMessage); } } catch (Exception e) { throw new TransactionException(e); //TODO throw a better exception } finally { cleanup(); } }
public Object call() throws Exception { Region<Object, Object> custRegion = getCache().getRegion(CUSTOMER); Region<Object, Object> orderRegion = getCache().getRegion(ORDER); Region<Object, Object> refRegion = getCache().getRegion(D_REFERENCE); TXManagerImpl mgr = getGemfireCache().getTxManager(); TXStateInterface tx = mgr.getHostedTXState(txId); // force expected transaction TXStateInterface txOrig = mgr.getTXState(); mgr.setTXState(tx); assertEquals(expectedCustomer, custRegion.get(expectedCustId)); assertEquals(expectedOrder, orderRegion.get(expectedOrderId)); assertEquals(expectedCustomer, refRegion.get(expectedCustId)); mgr.internalSuspend(); assertNull(custRegion.get(expectedCustId)); assertNull(orderRegion.get(expectedOrderId)); assertNull(refRegion.get(expectedCustId)); mgr.setTXState(txOrig); return null; } });
com.gemstone.gemfire.internal.cache.locks.LockingPolicy.SNAPSHOT, true); txManager.setTXState(state, context); context.setSnapshotTXState(state); tc.setActiveTXState(state, false);
setTXState(val); return val;
/** perform local cache modifications using the server's TXCommitMessage */ private void afterServerCommit(TXCommitMessage txcm) { if (this.internalAfterSendCommit != null) { this.internalAfterSendCommit.run(); } GemFireCacheImpl cache = GemFireCacheImpl.getInstance(); if (cache == null) { // fixes bug 42933 return; } cache.getCancelCriterion().checkCancelInProgress(null); InternalDistributedSystem ds = cache.getDistributedSystem(); DM dm = ds.getDistributionManager(); txcm.setDM(dm); txcm.setAckRequired(false); txcm.setDisableListeners(true); cache.getTxManager().setTXState(null); txcm.hookupRegions(dm); txcm.basicProcess(); }
/** Roll back the transaction associated with the current * thread. When this method completes, the thread is no longer * associated with a transaction. */ public void rollback() { checkClosed(); TXStateProxy tx = getTXState(); if (tx == null) { throw new IllegalStateException(LocalizedStrings.TXManagerImpl_THREAD_DOES_NOT_HAVE_AN_ACTIVE_TRANSACTION.toLocalizedString()); } tx.checkJTA(LocalizedStrings.TXManagerImpl_CAN_NOT_ROLLBACK_THIS_TRANSACTION_IS_ENLISTED_WITH_A_JTA_TRANSACTION_USE_THE_JTA_MANAGER_TO_PERFORM_THE_ROLLBACK.toLocalizedString()); final long opStart = CachePerfStats.getStatTime(); final long lifeTime = opStart - tx.getBeginTime(); setTXState(null); tx.rollback(); saveTXStateForClientFailover(tx); cleanup(tx.getTransactionId()); noteRollbackSuccess(opStart, lifeTime, tx); }
"Gemfire Transaction afterCompletion called with illegal state."); try { this.proxy.getTxMgr().setTXState(null); commit(); } catch (CommitConflictException error) { case Status.STATUS_ROLLEDBACK: this.jtaLifeTime = opStart - getBeginTime(); this.proxy.getTxMgr().setTXState(null); rollback(); this.proxy.getTxMgr().noteRollbackSuccess(opStart, this.jtaLifeTime, this);
final long lifeTime = opStart - tx.getBeginTime(); try { setTXState(null); tx.commit(); } catch (CommitConflictException ex) { } catch (UnsupportedOperationInTransactionException e) { setTXState(tx); throw e; } catch (RuntimeException e) {
setTXState(tx, selfContext); proxy.rollback(null); } catch (Throwable ignored) {