@Override public void setTarget(DistributedMember target) { assert this.target == null; getRealDeal(target); if (this.target == null && isRealDealLocal()) { assert target.equals(getCache().getDistributedSystem().getDistributedMember()); this.target = target; } }
public boolean isOverTransactionTimeoutLimit() { if (getCurrentTime() - getLastOperationTimeFromClient() > TimeUnit.SECONDS .toMillis(txMgr.getTransactionTimeToLive())) { return true; } return false; }
void scheduleToRemoveExpiredClientTransaction(TXId txId) { synchronized (this.hostedTXStates) { TXStateProxy result = hostedTXStates.get(txId); if (result != null) { if (((TXStateProxyImpl) result).isOverTransactionTimeoutLimit()) { result.close(); hostedTXStates.remove(txId); } } } }
@Override public boolean containsKey(KeyInfo keyInfo, LocalRegion localRegion) { try { this.operationCount++; boolean retVal = getRealDeal(keyInfo, localRegion).containsKey(keyInfo, localRegion); trackBucketForTx(keyInfo); return retVal; } catch (TransactionDataRebalancedException | PrimaryBucketException re) { throw getTransactionException(keyInfo, re); } }
@Override public int getChanges() { assertBootstrapped(); return getRealDeal(null, null).getChanges(); }
@Test public void isOverTransactionTimeoutLimitReturnsTrueIfHavingRecentOperation() { TXStateProxyImpl tx = spy(new TXStateProxyImpl(cache, txManager, txId, false)); doReturn(0L).when(tx).getLastOperationTimeFromClient(); doReturn(1001L).when(tx).getCurrentTime(); when(txManager.getTransactionTimeToLive()).thenReturn(1); assertThat(tx.isOverTransactionTimeoutLimit()).isEqualTo(true); }
@Override public Set getBucketKeys(LocalRegion localRegion, int bucketId, boolean allowTombstones) { boolean resetTxState = isTransactionInternalSuspendNeeded(localRegion); TXStateProxy txp = null; if (resetTxState) { txp = getTxMgr().pauseTransaction(); } try { if (resetTxState) { return localRegion.getSharedDataView().getBucketKeys(localRegion, bucketId, false); } return getRealDeal(null, localRegion).getBucketKeys(localRegion, bucketId, false); } finally { if (resetTxState) { getTxMgr().unpauseTransaction(txp); } } }
@Test public void setTargetWillSetTXStateStubIfTargetIsDifferentFromLocalMember() { TXStateProxyImpl tx = spy(new TXStateProxyImpl(cache, txManager, txId, false)); assertThat(tx.hasRealDeal()).isFalse(); assertThat(tx.getTarget()).isNull(); DistributedMember remoteMember = mock(InternalDistributedMember.class); tx.setTarget(remoteMember); assertThat(tx.getTarget()).isEqualTo(remoteMember); assertThat(tx.isRealDealLocal()).isFalse(); assertThat(tx.hasRealDeal()).isTrue(); }
@Test public void setTargetToItSelfIfRealDealIsTXStateAndTargetIsSameAsLocalMember() { TXStateProxyImpl tx = spy(new TXStateProxyImpl(cache, txManager, txId, false)); tx.setLocalTXState(new TXState(tx, true)); assertThat(tx.isRealDealLocal()).isTrue(); assertThat(tx.getTarget()).isNull(); tx.setTarget(member); assertThat(tx.getTarget()).isEqualTo(member); assertThat(tx.isRealDealLocal()).isTrue(); }
public void forceLocalBootstrap() { getRealDeal(null, null); }
@Override @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "UL_UNRELEASED_LOCK", justification = "This method unlocks and then conditionally undoes the unlock in the finally-block. Review again at later time.") public int entryCount(LocalRegion localRegion) { // if size is the first operation in the transaction, then reset the txState boolean resetTXState = this.realDeal == null; TXStateProxy txp = null; boolean txUnlocked = false; if (resetTXState) { txp = getTxMgr().pauseTransaction(); } else { if (getLock().isHeldByCurrentThread()) { txUnlocked = true; // bug #42945 - hang trying to compute size for PR getLock().unlock(); } } try { if (resetTXState) { return localRegion.getSharedDataView().entryCount(localRegion); } return getRealDeal(null, localRegion).entryCount(localRegion); } finally { if (resetTXState) { getTxMgr().unpauseTransaction(txp); } else if (txUnlocked) { getLock().lock(); } } }
TXStateProxyImpl proxy = new TXStateProxyImpl(cache, txManager, txId, null); assertNotNull(proxy.getRealDeal(host)); assertEquals(proxy.getTarget(), host);
@Test public void getCacheReturnsInjectedCache() { TXStateProxyImpl tx = new TXStateProxyImpl(cache, txManager, txId, false); assertThat(tx.getCache()).isSameAs(cache); }
void cleanupTransactionIfNoLongerHost(TXStateProxy tx) { synchronized (hostedTXStates) { if (!hostedTXStates.containsKey(tx.getTxId())) { // clean up the transaction if no longer the host of the transaction // this could occur when a failover command removed the transaction. if (tx.isRealDealLocal()) { ((TXStateProxyImpl) tx).getLocalRealDeal().cleanup(); } } } }
proxy = new DistTXStateProxyImplOnCoordinator(cache, this, id, null); } else { proxy = new TXStateProxyImpl(cache, this, id, null);
@Override public void validateExecution(Function function, Set targetMembers) { InternalCache cache = GemFireCacheImpl.getInstance(); if (cache != null && cache.getTxManager().getTXState() != null) { TXStateProxyImpl tx = (TXStateProxyImpl) cache.getTxManager().getTXState(); tx.getRealDeal(null, region); tx.incOperationCount(); } }
@Test public void getKeyForIteratorReturnsKey() { RegionEntryFactory regionEntryFactory = new RegionEntryFactoryBuilder().create(false, false, false, false, false); RegionEntry regionEntry = regionEntryFactory.createEntry(region, key, null); KeyInfo stringKeyInfo = new KeyInfo(key, null, null); KeyInfo regionEntryKeyInfo = new KeyInfo(regionEntry, null, null); boolean allowTombstones = false; boolean rememberReads = true; when(region.getSharedDataView()).thenReturn(view); when(view.getEntry(stringKeyInfo, region, allowTombstones)).thenReturn(mock(NonTXEntry.class)); when(view.getKeyForIterator(stringKeyInfo, region, rememberReads, allowTombstones)) .thenCallRealMethod(); when(view.getKeyForIterator(regionEntryKeyInfo, region, rememberReads, allowTombstones)) .thenCallRealMethod(); TXStateProxyImpl tx = new TXStateProxyImpl(cache, txManager, txId, false); Object key1 = tx.getKeyForIterator(regionEntryKeyInfo, region, rememberReads, allowTombstones); assertThat(key1.equals(key)).isTrue(); Object key2 = tx.getKeyForIterator(stringKeyInfo, region, rememberReads, allowTombstones); assertThat(key2.equals(key)).isTrue(); }
/** * This is a test hook method used to find out what keys the current tx has read or written. * * @return an unmodifiable set of keys that have been read or written by the transaction on this * thread. * @throws IllegalStateException if not tx in progress * @since GemFire 5.5 */ public Set testHookTXKeys() { if (!isTX()) { throw new IllegalStateException( "tx not in progress"); } TXStateProxyImpl tx = (TXStateProxyImpl) getTXState(); if (!tx.isRealDealLocal()) { return Collections.emptySet(); } TXRegionState txr = txReadRegion(); if (txr == null) { return Collections.emptySet(); } else { return txr.getEntryKeys(); } }
public TXStateInterface getRealDeal(DistributedMember t) { assert t != null; if (this.realDeal == null) { this.target = t; if (target.equals(getCache().getDistributedSystem().getDistributedMember())) { this.realDeal = new TXState(this, false); } else { /* * txtodo: // what to do!! We don't know if this is client or server!!! */ this.realDeal = new PeerTXStateStub(this, target, onBehalfOfClientMember); } if (logger.isDebugEnabled()) { logger.debug("Built a new TXState: {} me:{}", this.realDeal, this.txMgr.getDM().getId()); } } return this.realDeal; }
@Before public void setup() { txStateProxy = mock(TXStateProxyImpl.class, RETURNS_DEEP_STUBS); exception = new CommitConflictException(""); transactionDataNodeHasDepartedException = new TransactionDataNodeHasDepartedException(""); executor = mock(SingleThreadJTAExecutor.class); when(txStateProxy.getTxMgr()).thenReturn(mock(TXManagerImpl.class)); }