Search in sources :

Example 1 with CacheTransaction

use of org.infinispan.transaction.xa.CacheTransaction in project infinispan by infinispan.

the class StateConsumerImpl method applyTransactions.

private void applyTransactions(Address sender, Collection<TransactionInfo> transactions, int topologyId) {
    log.debugf("Applying %d transactions for cache %s transferred from node %s", transactions.size(), cacheName, sender);
    if (isTransactional) {
        for (TransactionInfo transactionInfo : transactions) {
            GlobalTransaction gtx = transactionInfo.getGlobalTransaction();
            if (rpcManager.getAddress().equals(gtx.getAddress())) {
                // it is a transaction originated in this node. can happen with partition handling
                continue;
            }
            // Mark the global transaction as remote. Only used for logging, hashCode/equals ignore it.
            gtx.setRemote(true);
            CacheTransaction tx = transactionTable.getLocalTransaction(gtx);
            if (tx == null) {
                tx = transactionTable.getRemoteTransaction(gtx);
                if (tx == null) {
                    try {
                        // just in case, set the previous topology id to make the current topology id check for pending locks.
                        tx = transactionTable.getOrCreateRemoteTransaction(gtx, transactionInfo.getModifications(), topologyId - 1);
                        // Force this node to replay the given transaction data by making it think it is 1 behind
                        ((RemoteTransaction) tx).setLookedUpEntriesTopology(topologyId - 1);
                    } catch (Throwable t) {
                        if (log.isTraceEnabled())
                            log.tracef(t, "Failed to create remote transaction %s", gtx);
                    }
                }
            }
            if (tx != null) {
                transactionInfo.getLockedKeys().forEach(tx::addBackupLockForKey);
            }
        }
    }
}
Also used : RemoteTransaction(org.infinispan.transaction.impl.RemoteTransaction) GlobalTransaction(org.infinispan.transaction.xa.GlobalTransaction) CacheTransaction(org.infinispan.transaction.xa.CacheTransaction)

Example 2 with CacheTransaction

use of org.infinispan.transaction.xa.CacheTransaction in project infinispan by infinispan.

the class StateProviderImpl method collectTransactionsToTransfer.

private void collectTransactionsToTransfer(Address destination, List<TransactionInfo> transactionsToTransfer, Collection<? extends CacheTransaction> transactions, IntSet segments, CacheTopology cacheTopology) {
    int topologyId = cacheTopology.getTopologyId();
    Set<Address> members = new HashSet<>(cacheTopology.getMembers());
    // no need to filter out state transfer generated transactions because there should not be any such transactions running for any of the requested segments
    for (CacheTransaction tx : transactions) {
        final GlobalTransaction gtx = tx.getGlobalTransaction();
        // Also skip transactions that originates after state transfer starts.
        if (tx.getTopologyId() == topologyId || (transactionOriginatorChecker.isOriginatorMissing(gtx, members))) {
            if (log.isTraceEnabled())
                log.tracef("Skipping transaction %s as it was started in the current topology or by a leaver", tx);
            continue;
        }
        // transfer only locked keys that belong to requested segments
        Set<Object> filteredLockedKeys = new HashSet<>();
        // avoids the warning about synchronizing in a local variable.
        // and allows us to change the CacheTransaction internals without having to worry about it
        Consumer<Object> lockFilter = key -> {
            if (segments.contains(keyPartitioner.getSegment(key))) {
                filteredLockedKeys.add(key);
            }
        };
        tx.forEachLock(lockFilter);
        tx.forEachBackupLock(lockFilter);
        if (filteredLockedKeys.isEmpty()) {
            if (log.isTraceEnabled())
                log.tracef("Skipping transaction %s because the state requestor %s doesn't own any key", tx, destination);
            continue;
        }
        if (log.isTraceEnabled())
            log.tracef("Sending transaction %s to new owner %s", tx, destination);
        List<WriteCommand> txModifications = tx.getModifications();
        WriteCommand[] modifications = null;
        if (!txModifications.isEmpty()) {
            modifications = txModifications.toArray(new WriteCommand[0]);
        }
        // affected nodes set, so that the it receives the commit/rollback command. See ISPN-3389.
        if (tx instanceof LocalTransaction) {
            LocalTransaction localTx = (LocalTransaction) tx;
            localTx.locksAcquired(Collections.singleton(destination));
            if (log.isTraceEnabled())
                log.tracef("Adding affected node %s to transferred transaction %s (keys %s)", destination, gtx, filteredLockedKeys);
        }
        transactionsToTransfer.add(new TransactionInfo(gtx, tx.getTopologyId(), modifications, filteredLockedKeys));
    }
}
Also used : WriteCommand(org.infinispan.commands.write.WriteCommand) IntSets(org.infinispan.commons.util.IntSets) ComponentName(org.infinispan.factories.annotations.ComponentName) LogFactory(org.infinispan.util.logging.LogFactory) KnownComponentNames(org.infinispan.factories.KnownComponentNames) Stop(org.infinispan.factories.annotations.Stop) Scopes(org.infinispan.factories.scopes.Scopes) CompletableFutures(org.infinispan.util.concurrent.CompletableFutures) Map(java.util.Map) Scope(org.infinispan.factories.scopes.Scope) TransactionOriginatorChecker(org.infinispan.transaction.impl.TransactionOriginatorChecker) CommandsFactory(org.infinispan.commands.CommandsFactory) ConsistentHash(org.infinispan.distribution.ch.ConsistentHash) Collection(java.util.Collection) Set(java.util.Set) CacheTopology(org.infinispan.topology.CacheTopology) IntSet(org.infinispan.commons.util.IntSet) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) LocalTransaction(org.infinispan.transaction.impl.LocalTransaction) CLUSTER(org.infinispan.util.logging.Log.CLUSTER) CacheTransaction(org.infinispan.transaction.xa.CacheTransaction) ClusterCacheNotifier(org.infinispan.notifications.cachelistener.cluster.ClusterCacheNotifier) InternalCacheEntry(org.infinispan.container.entries.InternalCacheEntry) PersistenceManager(org.infinispan.persistence.manager.PersistenceManager) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) Start(org.infinispan.factories.annotations.Start) HashSet(java.util.HashSet) Configurations(org.infinispan.configuration.cache.Configurations) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) Log(org.infinispan.util.logging.Log) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) MarshallableEntry(org.infinispan.persistence.spi.MarshallableEntry) Address(org.infinispan.remoting.transport.Address) InternalEntryFactory(org.infinispan.container.impl.InternalEntryFactory) Flowable(io.reactivex.rxjava3.core.Flowable) Iterator(java.util.Iterator) InternalDataContainer(org.infinispan.container.impl.InternalDataContainer) ClusterListenerReplicateCallable(org.infinispan.notifications.cachelistener.cluster.ClusterListenerReplicateCallable) Publisher(org.reactivestreams.Publisher) RpcManager(org.infinispan.remoting.rpc.RpcManager) Inject(org.infinispan.factories.annotations.Inject) Consumer(java.util.function.Consumer) GlobalTransaction(org.infinispan.transaction.xa.GlobalTransaction) Configuration(org.infinispan.configuration.cache.Configuration) Collections(java.util.Collections) TransactionTable(org.infinispan.transaction.impl.TransactionTable) DistributionManager(org.infinispan.distribution.DistributionManager) WriteCommand(org.infinispan.commands.write.WriteCommand) Address(org.infinispan.remoting.transport.Address) LocalTransaction(org.infinispan.transaction.impl.LocalTransaction) GlobalTransaction(org.infinispan.transaction.xa.GlobalTransaction) CacheTransaction(org.infinispan.transaction.xa.CacheTransaction) HashSet(java.util.HashSet)

Example 3 with CacheTransaction

use of org.infinispan.transaction.xa.CacheTransaction in project infinispan by infinispan.

the class DefaultPendingLockManager method getTopologyId.

private int getTopologyId(TxInvocationContext<?> context) {
    final CacheTransaction tx = context.getCacheTransaction();
    boolean isFromStateTransfer = context.isOriginLocal() && ((LocalTransaction) tx).isFromStateTransfer();
    // if the transaction is from state transfer it should not wait for the backup locks of other transactions
    if (!isFromStateTransfer) {
        final int topologyId = distributionManager.getCacheTopology().getTopologyId();
        if (topologyId != TransactionTable.CACHE_STOPPED_TOPOLOGY_ID) {
            if (transactionTable.getMinTopologyId() < topologyId) {
                return topologyId;
            }
        }
    }
    return NO_PENDING_CHECK;
}
Also used : CacheTransaction(org.infinispan.transaction.xa.CacheTransaction)

Example 4 with CacheTransaction

use of org.infinispan.transaction.xa.CacheTransaction in project infinispan by infinispan.

the class VersionedDistributionInterceptor method prepareOnAffectedNodes.

@Override
protected CompletionStage<Object> prepareOnAffectedNodes(TxInvocationContext<?> ctx, PrepareCommand command, Collection<Address> recipients) {
    CompletionStage<Map<Address, Response>> remoteInvocation;
    if (recipients != null) {
        MapResponseCollector collector = MapResponseCollector.ignoreLeavers(recipients.size());
        remoteInvocation = rpcManager.invokeCommand(recipients, command, collector, rpcManager.getSyncRpcOptions());
    } else {
        MapResponseCollector collector = MapResponseCollector.ignoreLeavers();
        remoteInvocation = rpcManager.invokeCommandOnAll(command, collector, rpcManager.getSyncRpcOptions());
    }
    return remoteInvocation.handle((responses, t) -> {
        transactionRemotelyPrepared(ctx);
        CompletableFutures.rethrowExceptionIfPresent(t);
        PrepareResponse prepareResponse = new PrepareResponse();
        checkTxCommandResponses(responses, command, (TxInvocationContext<LocalTransaction>) ctx, recipients, prepareResponse);
        // Now store newly generated versions from lock owners for use during the commit phase.
        CacheTransaction ct = ctx.getCacheTransaction();
        ct.setUpdatedEntryVersions(prepareResponse.mergeEntryVersions(ct.getUpdatedEntryVersions()));
        return prepareResponse;
    });
}
Also used : PrepareResponse(org.infinispan.remoting.responses.PrepareResponse) LocalTransaction(org.infinispan.transaction.impl.LocalTransaction) AbstractCacheTransaction(org.infinispan.transaction.impl.AbstractCacheTransaction) CacheTransaction(org.infinispan.transaction.xa.CacheTransaction) Map(java.util.Map) MapResponseCollector(org.infinispan.remoting.transport.impl.MapResponseCollector)

Aggregations

CacheTransaction (org.infinispan.transaction.xa.CacheTransaction)4 Map (java.util.Map)2 GlobalTransaction (org.infinispan.transaction.xa.GlobalTransaction)2 Flowable (io.reactivex.rxjava3.core.Flowable)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionStage (java.util.concurrent.CompletionStage)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 Consumer (java.util.function.Consumer)1 CommandsFactory (org.infinispan.commands.CommandsFactory)1 WriteCommand (org.infinispan.commands.write.WriteCommand)1 IntSet (org.infinispan.commons.util.IntSet)1 IntSets (org.infinispan.commons.util.IntSets)1