public void cleanupTimedOutTransactions() { if (trace) log.tracef( "About to cleanup remote transactions older than %d ms", configuration.transaction().completedTxTimeout()); long beginning = timeService.time(); long cutoffCreationTime = beginning - TimeUnit.MILLISECONDS.toNanos(configuration.transaction().completedTxTimeout()); List<GlobalTransaction> toKill = new ArrayList<>(); // Check remote transactions. for (Map.Entry<GlobalTransaction, RemoteTransaction> e : remoteTransactions.entrySet()) { GlobalTransaction gtx = e.getKey(); RemoteTransaction remoteTx = e.getValue(); if (remoteTx != null) { if (trace) log.tracef("Checking transaction %s", gtx); // Check the time. if (remoteTx.getCreationTime() - cutoffCreationTime < 0) { long duration = timeService.timeDuration( remoteTx.getCreationTime(), beginning, TimeUnit.MILLISECONDS); log.remoteTransactionTimeout(gtx, duration); toKill.add(gtx); } } } // Rollback the orphaned transactions and release any held locks. for (GlobalTransaction gtx : toKill) { killTransaction(gtx); } }
private RemoteTransaction getOrCreateRemoteTransaction( GlobalTransaction globalTx, WriteCommand[] modifications, int topologyId) { RemoteTransaction remoteTransaction = remoteTransactions.get(globalTx); if (remoteTransaction != null) return remoteTransaction; remoteTransaction = modifications == null ? txFactory.newRemoteTransaction(globalTx, topologyId) : txFactory.newRemoteTransaction(modifications, globalTx, topologyId); RemoteTransaction existing = remoteTransactions.putIfAbsent(globalTx, remoteTransaction); if (existing != null) { if (trace) log.tracef("Remote transaction already registered: %s", existing); return existing; } else { if (trace) log.tracef("Created and registered remote transaction %s", remoteTransaction); if (remoteTransaction.getTopologyId() < minTxTopologyId) { if (trace) log.tracef( "Changing minimum topology ID from %d to %d", minTxTopologyId, remoteTransaction.getTopologyId()); minTxTopologyId = remoteTransaction.getTopologyId(); } return remoteTransaction; } }
public Set<Object> getLockedKeysForRemoteTransaction(GlobalTransaction gtx) { RemoteTransaction transaction = remoteTransactions.get(gtx); if (transaction == null) return InfinispanCollections.emptySet(); return transaction.getLockedKeys(); }