public void removeHostedTXState(Set<TXId> txIds) { for (TXId txId : txIds) { removeHostedTXState(txId); } }
@Override public void run() { txMgr.removeHostedTXState(txid); } });
/** timer task for expiring the given TXStates */ public void expireDisconnectedClientTransactions(Set<TXId> txIds, boolean distribute) { // increase the client transaction timeout setting to avoid a late in-flight client operation // preventing the expiration of the client transaction. long timeout = (long) (TimeUnit.SECONDS.toMillis(getTransactionTimeToLive()) * 1.1); if (timeout <= 0) { removeHostedTXState(txIds); } synchronized (this.hostedTXStates) { Iterator<Map.Entry<TXId, TXStateProxy>> iterator = this.hostedTXStates.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<TXId, TXStateProxy> entry = iterator.next(); if (txIds.contains(entry.getKey())) { scheduleToRemoveClientTransaction(entry.getKey(), timeout); } } } if (distribute) { expireClientTransactionsOnRemoteServer(txIds); } }
@Override public void run() { txMgr.removeHostedTXState(txid); // replace with new TXState txMgr.getOrSetHostedTXState(txid, msg); } });
/** * expire the transaction states for the given client. * If the timeout is non-positive we expire the states immediately */ void scheduleToRemoveClientTransaction(TXId txId, long timeout) { if (timeout <= 0) { removeHostedTXState(txId); } else { if (scheduledToBeRemovedTx != null) { scheduledToBeRemovedTx.add(txId); } SystemTimerTask task = new SystemTimerTask() { @Override public void run2() { scheduleToRemoveExpiredClientTransaction(txId); if (scheduledToBeRemovedTx != null) { scheduledToBeRemovedTx.remove(txId); } } }; getCache().getCCPTimer().schedule(task, timeout); } }
@Test public void clientTransactionIsRemovedIfWithNoTimeout() { spyTxMgr.scheduleToRemoveClientTransaction(txid, 0); verify(spyTxMgr, times(1)).removeHostedTXState(eq(txid)); }
@Override protected boolean operateOnTx(TXId txId, ClusterDistributionManager dm) { InternalCache cache = dm.getCache(); if (cache == null) { throw new CacheClosedException( "A cache has not yet been created."); } TXManagerImpl txMgr = cache.getTXMgr(); if (logger.isDebugEnabled()) { logger.debug("TX: Rolling back :{}", txId); } try { if (!txMgr.isHostedTxRecentlyCompleted(txId)) { txMgr.rollback(); } } finally { txMgr.removeHostedTXState(txId); } return true; }
txMgr.removeHostedTXState(txId);
@Test public void clientTransactionsToBeExpiredAreRemovedAndNotDistributedIfWithNoTimeout() { doReturn(1).when(spyTxMgr).getTransactionTimeToLive(); TXId txId1 = mock(TXId.class); TXId txId2 = mock(TXId.class); TXId txId3 = mock(TXId.class); tx1 = spyTxMgr.getOrSetHostedTXState(txId1, msg); tx2 = spyTxMgr.getOrSetHostedTXState(txId2, msg); Set<TXId> txIds = spy(new HashSet<>()); txIds.add(txId1); doReturn(0).when(spyTxMgr).getTransactionTimeToLive(); when(txIds.iterator()).thenAnswer(new Answer<Iterator<TXId>>() { @Override public Iterator<TXId> answer(InvocationOnMock invocation) throws Throwable { return Arrays.asList(txId1, txId3).iterator(); } }); assertEquals(2, spyTxMgr.getHostedTXStates().size()); spyTxMgr.expireDisconnectedClientTransactions(txIds, false); verify(spyTxMgr, never()).expireClientTransactionsOnRemoteServer(eq(txIds)); verify(spyTxMgr, times(1)).removeHostedTXState(eq(txIds)); verify(spyTxMgr, times(1)).removeHostedTXState(eq(txId1)); verify(spyTxMgr, times(1)).removeHostedTXState(eq(txId3)); assertEquals(tx2, spyTxMgr.getHostedTXStates().get(txId2)); assertEquals(1, spyTxMgr.getHostedTXStates().size()); }
logger.debug("TX: found a recently rolled back tx: {}", txId); sendRollbackReply(clientMessage, serverConnection); txMgr.removeHostedTXState(txId); return; TXStateProxy proxy = txMgr.removeHostedTXState(txId); if (logger.isDebugEnabled()) { logger.debug("TX: removed tx state proxy {}", proxy);
@Override public void run() { when(msg.getTXOriginatorClient()).thenReturn(mock(InternalDistributedMember.class)); TXStateProxy tx; try { tx = txMgr.masqueradeAs(commitMsg); } catch (InterruptedException e) { e.printStackTrace(); throw new RuntimeException(e); } tx.setCommitOnBehalfOfRemoteStub(true); try { tx.commit(); } finally { txMgr.unmasquerade(tx); } txMgr.removeHostedTXState(txid); txMgr.saveTXCommitMessageForClientFailover(txid, txCommitMsg); } });
txMgr.removeHostedTXState(txId);
txMgr.removeHostedTXState(txId);
sendException(clientMessage, serverConnection, txMgr.getExceptionForToken(commitMsg, txId)); txMgr.removeHostedTXState(txId); return;
} finally { if (txId != null) { txMgr.removeHostedTXState(txId);
@Override protected boolean operateOnTx(TXId txId, ClusterDistributionManager dm) throws RemoteOperationException { TXManagerImpl txMgr = dm.getCache().getTXMgr(); if (logger.isDebugEnabled()) { logger.debug("JTA: Calling afterCompletion for :{}", txId); } TXCommitMessage commitMessage = txMgr.getRecentlyCompletedMessage(txId); if (commitMessage != null) { TXCommitMessage message = commitMessage == TXCommitMessage.ROLLBACK_MSG ? null : commitMessage; TXRemoteCommitReplyMessage.send(getSender(), getProcessorId(), message, getReplySender(dm)); return false; } TXStateProxy txState = txMgr.getTXState(); txState.setCommitOnBehalfOfRemoteStub(true); txState.afterCompletion(status); commitMessage = txState.getCommitMessage(); TXRemoteCommitReplyMessage.send(getSender(), getProcessorId(), commitMessage, getReplySender(dm)); txMgr.removeHostedTXState(txId); return false; }
mgr.removeHostedTXState(txId);
writeReply(clientMessage, serverConnection); serverConnection.setAsTrue(RESPONDED); mgr.removeHostedTXState(txId); return; "Could not find transaction host for " + txId), false, serverConnection); serverConnection.setAsTrue(RESPONDED); mgr.removeHostedTXState(txId); return;
try { writeCommitResponse(clientMessage, serverConnection, cmsg); txMgr.removeHostedTXState(txProxy.getTxId()); } catch (IOException e) {
@Override public void run() { tx1 = txMgr.getHostedTXState(txid); assertNull(tx1); tx1 = txMgr.getOrSetHostedTXState(txid, msg); assertNotNull(tx1); assertTrue(txMgr.getLock(tx1, txid)); latch.countDown(); await() .until(() -> tx1.getLock().hasQueuedThreads()); txMgr.removeHostedTXState(txid); tx2 = txMgr.getOrSetHostedTXState(txid, msg); assertNotNull(tx2); assertTrue(txMgr.getLock(tx2, txid)); tx2.getLock().unlock(); tx1.getLock().unlock(); } });