/** * Completes the transaction in the cache when the originator no longer belongs to the cache topology. */ private CompletableFuture<Void> completeWithRemoteCommand(AdvancedCache<?, ?> cache, RpcManager rpcManager, TxState state) throws Throwable { CommandsFactory commandsFactory = cache.getComponentRegistry().getCommandsFactory(); CacheRpcCommand command = buildRemoteCommand(cache.getCacheConfiguration(), commandsFactory, state); CompletableFuture<Void> remote = rpcManager .invokeCommandOnAll(command, validOnly(), rpcManager.getSyncRpcOptions()) .handle(handler()) .toCompletableFuture(); commandsFactory.initializeReplicableCommand(command, false); CompletableFuture<Void> local = command.invokeAsync().handle(handler()); return CompletableFuture.allOf(remote, local); }
/** * Commits a remote 1PC transaction that is already in MARK_COMMIT state */ public int onePhaseCommitRemoteTransaction(GlobalTransaction gtx, List<WriteCommand> modifications) { RpcManager rpcManager = cache.getRpcManager(); CommandsFactory factory = cache.getComponentRegistry().getCommandsFactory(); try { //only pessimistic tx are committed in 1PC and it doesn't use versions. PrepareCommand command = factory.buildPrepareCommand(gtx, modifications, true); CompletionStage<Void> cs = rpcManager.invokeCommandOnAll(command, validOnly(), rpcManager.getSyncRpcOptions()); factory.initializeReplicableCommand(command, false); command.invokeAsync().join(); cs.toCompletableFuture().join(); forgetTransaction(gtx, rpcManager, factory); return loggingCompleted(true) == Status.OK ? XAResource.XA_OK : XAException.XAER_RMERR; } catch (Throwable throwable) { //transaction should commit but we still can have exceptions (timeouts or similar) return XAException.XAER_RMERR; } }
/** * Rollbacks a transaction that is remove in all the cluster members. */ public final void rollbackRemoteTransaction(GlobalTransaction gtx) { RpcManager rpcManager = cache.getRpcManager(); CommandsFactory factory = cache.getComponentRegistry().getCommandsFactory(); try { RollbackCommand rollbackCommand = factory.buildRollbackCommand(gtx); rollbackCommand.setTopologyId(rpcManager.getTopologyId()); CompletionStage<Void> cs = rpcManager .invokeCommandOnAll(rollbackCommand, validOnly(), rpcManager.getSyncRpcOptions()); factory.initializeReplicableCommand(rollbackCommand, false); rollbackCommand.invokeAsync().join(); cs.toCompletableFuture().join(); } catch (Throwable throwable) { throw Util.rewrapAsCacheException(throwable); } finally { forgetTransaction(gtx, rpcManager, factory); } }
private void rollbackRemote(ComponentRegistry cr, CacheXid cacheXid, TxState state) { RollbackCommand rpcCommand = cr.getCommandsFactory().buildRollbackCommand(state.getGlobalTransaction()); RpcManager rpcManager = cr.getComponent(RpcManager.class); rpcCommand.setTopologyId(rpcManager.getTopologyId()); rpcManager.invokeCommandOnAll(rpcCommand, VoidResponseCollector.validOnly(), rpcManager.getSyncRpcOptions()) .thenRun(() -> { //ignore exception so the rollback can be retried. //if a node doesn't find the remote transaction, it returns null. TxFunction function = new SetCompletedTransactionFunction(false); rwMap.eval(cacheXid, function); }); }
public static ControlledCommandFactory registerControlledCommandFactory(Cache cache, Class<? extends ReplicableCommand> toBlock) { ComponentRegistry componentRegistry = cache.getAdvancedCache().getComponentRegistry(); final ControlledCommandFactory ccf = new ControlledCommandFactory(componentRegistry.getCommandsFactory(), toBlock); TestingUtil.replaceComponent(cache, CommandsFactory.class, ccf, true); //hack: re-add the component registry to the GlobalComponentRegistry's "namedComponents" (CHM) in order to correctly publish it for // when it will be read by the InboundInvocationHandlder. InboundInvocationHandlder reads the value from the GlobalComponentRegistry.namedComponents before using it componentRegistry.getGlobalComponentRegistry().registerNamedComponentRegistry(componentRegistry, EmbeddedCacheManager.DEFAULT_CACHE_NAME); return ccf; }
TransactionBoundaryCommand rpcCommand; if (cr.getComponent(Configuration.class).transaction().lockingMode() == LockingMode.PESSIMISTIC) { rpcCommand = cr.getCommandsFactory() .buildPrepareCommand(state.getGlobalTransaction(), state.getModifications(), true); } else { rpcCommand = cr.getCommandsFactory().buildCommitCommand(state.getGlobalTransaction());