Search in sources :

Example 1 with PrepareResponse

use of org.infinispan.remoting.responses.PrepareResponse in project infinispan by infinispan.

the class WriteSkewHelper method mergePrepareResponses.

public static void mergePrepareResponses(Response r, PrepareResponse aggregateResponse) {
    if (r instanceof PrepareResponse && aggregateResponse != null) {
        PrepareResponse remoteRsp = (PrepareResponse) r;
        aggregateResponse.merge(remoteRsp);
    }
}
Also used : PrepareResponse(org.infinispan.remoting.responses.PrepareResponse)

Example 2 with PrepareResponse

use of org.infinispan.remoting.responses.PrepareResponse in project infinispan by infinispan.

the class TxDistributionInterceptor method checkTxCommandResponses.

protected void checkTxCommandResponses(Map<Address, Response> responseMap, TransactionBoundaryCommand command, TxInvocationContext<LocalTransaction> context, Collection<Address> recipients, PrepareResponse prepareResponse) {
    LocalizedCacheTopology cacheTopology = checkTopologyId(command);
    for (Map.Entry<Address, Response> e : responseMap.entrySet()) {
        Address recipient = e.getKey();
        Response response = e.getValue();
        mergePrepareResponses(response, prepareResponse);
        if (response == CacheNotFoundResponse.INSTANCE) {
            // We must not register a partial commit when receiving a CacheNotFoundResponse from one of those.
            if (!cacheTopology.getMembers().contains(recipient)) {
                if (log.isTraceEnabled())
                    log.tracef("Ignoring response from node not targeted %s", recipient);
            } else {
                if (checkCacheNotFoundResponseInPartitionHandling(command, context, recipients)) {
                    if (log.isTraceEnabled())
                        log.tracef("Cache not running on node %s, or the node is missing. It will be handled by the PartitionHandlingManager", recipient);
                    return;
                } else {
                    if (log.isTraceEnabled())
                        log.tracef("Cache not running on node %s, or the node is missing", recipient);
                    throw OutdatedTopologyException.RETRY_NEXT_TOPOLOGY;
                }
            }
        } else if (response == UnsureResponse.INSTANCE) {
            if (log.isTraceEnabled())
                log.tracef("Node %s has a newer topology id", recipient);
            throw OutdatedTopologyException.RETRY_NEXT_TOPOLOGY;
        }
    }
}
Also used : CacheNotFoundResponse(org.infinispan.remoting.responses.CacheNotFoundResponse) UnsureResponse(org.infinispan.remoting.responses.UnsureResponse) PrepareResponse(org.infinispan.remoting.responses.PrepareResponse) SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) Response(org.infinispan.remoting.responses.Response) Address(org.infinispan.remoting.transport.Address) LocalizedCacheTopology(org.infinispan.distribution.LocalizedCacheTopology) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with PrepareResponse

use of org.infinispan.remoting.responses.PrepareResponse in project infinispan by infinispan.

the class TxDistributionInterceptor method prepareOnAffectedNodes.

protected CompletionStage<Object> prepareOnAffectedNodes(TxInvocationContext<?> ctx, PrepareCommand command, Collection<Address> recipients) {
    try {
        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(rpcManager.getMembers().size());
            remoteInvocation = rpcManager.invokeCommandOnAll(command, collector, rpcManager.getSyncRpcOptions());
        }
        return remoteInvocation.handle((responses, t) -> {
            transactionRemotelyPrepared(ctx);
            CompletableFutures.rethrowExceptionIfPresent(t);
            PrepareResponse prepareResponse = new PrepareResponse();
            checkTxCommandResponses(responses, command, (LocalTxInvocationContext) ctx, recipients, prepareResponse);
            for (Response r : responses.values()) mergePrepareResponses(r, prepareResponse);
            return prepareResponse;
        });
    } catch (Throwable t) {
        transactionRemotelyPrepared(ctx);
        throw t;
    }
}
Also used : CacheNotFoundResponse(org.infinispan.remoting.responses.CacheNotFoundResponse) UnsureResponse(org.infinispan.remoting.responses.UnsureResponse) PrepareResponse(org.infinispan.remoting.responses.PrepareResponse) SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) Response(org.infinispan.remoting.responses.Response) PrepareResponse(org.infinispan.remoting.responses.PrepareResponse) Map(java.util.Map) HashMap(java.util.HashMap) MapResponseCollector(org.infinispan.remoting.transport.impl.MapResponseCollector)

Example 4 with PrepareResponse

use of org.infinispan.remoting.responses.PrepareResponse in project infinispan by infinispan.

the class OptimisticTxIracLocalSiteInterceptor method afterRemoteTwoPhasePrepare.

private Object afterRemoteTwoPhasePrepare(InvocationContext ctx, PrepareCommand command, Object rv) {
    if (isTraceEnabled()) {
        getLog().tracef("[IRAC] After successful remote prepare for tx %s. Return Value: %s", command.getGlobalTransaction(), rv);
    }
    PrepareResponse rsp = PrepareResponse.asPrepareResponse(rv);
    Iterator<StreamData> iterator = streamKeysFromModifications(command.getModifications()).filter(this::isPrimaryOwner).distinct().iterator();
    Map<Integer, IracEntryVersion> maxVersionSeen = new HashMap<>();
    while (iterator.hasNext()) {
        StreamData data = iterator.next();
        IracEntryVersion versionSeen = getIracVersionFromCacheEntry(ctx.lookupEntry(data.key));
        if (versionSeen != null) {
            maxVersionSeen.merge(data.segment, versionSeen, IracEntryVersion::merge);
        } else {
            maxVersionSeen.putIfAbsent(data.segment, null);
        }
    }
    Map<Integer, IracMetadata> segmentMetadata = new HashMap<>();
    maxVersionSeen.forEach((segment, version) -> segmentMetadata.put(segment, iracVersionGenerator.generateNewMetadata(segment, version)));
    rsp.setNewIracMetadata(segmentMetadata);
    if (isTraceEnabled()) {
        getLog().tracef("[IRAC] After successful remote prepare for tx %s. New Return Value: %s", command.getGlobalTransaction(), rsp);
    }
    return rsp;
}
Also used : PrepareResponse.asPrepareResponse(org.infinispan.remoting.responses.PrepareResponse.asPrepareResponse) PrepareResponse(org.infinispan.remoting.responses.PrepareResponse) IracEntryVersion(org.infinispan.container.versioning.irac.IracEntryVersion) HashMap(java.util.HashMap) IracMetadata(org.infinispan.metadata.impl.IracMetadata)

Example 5 with PrepareResponse

use of org.infinispan.remoting.responses.PrepareResponse in project infinispan by infinispan.

the class OptimisticTxIracLocalSiteInterceptor method afterLocalTwoPhasePrepare.

private void afterLocalTwoPhasePrepare(InvocationContext ctx, PrepareCommand command, Object rv) {
    if (isTraceEnabled()) {
        getLog().tracef("[IRAC] After successful local prepare for tx %s. Return Value: %s", command.getGlobalTransaction(), rv);
    }
    PrepareResponse prepareResponse = asPrepareResponse(rv);
    Iterator<StreamData> iterator = streamKeysFromModifications(command.getModifications()).iterator();
    Map<Integer, IracMetadata> segmentMetadata = new HashMap<>();
    while (iterator.hasNext()) {
        StreamData data = iterator.next();
        IracMetadata metadata;
        if (isPrimaryOwner(data)) {
            IracEntryVersion versionSeen = getIracVersionFromCacheEntry(ctx.lookupEntry(data.key));
            metadata = segmentMetadata.computeIfAbsent(data.segment, segment -> iracVersionGenerator.generateNewMetadata(segment, versionSeen));
        } else {
            metadata = segmentMetadata.computeIfAbsent(data.segment, prepareResponse::getIracMetadata);
        }
        assert metadata != null : "[IRAC] metadata is null after successful prepare! Data=" + data;
        updateCommandMetadata(data.key, data.command, metadata);
    }
}
Also used : IracUtils.getIracVersionFromCacheEntry(org.infinispan.util.IracUtils.getIracVersionFromCacheEntry) PrepareCommand(org.infinispan.commands.tx.PrepareCommand) WriteCommand(org.infinispan.commands.write.WriteCommand) IracMetadata(org.infinispan.metadata.impl.IracMetadata) Iterator(java.util.Iterator) RollbackCommand(org.infinispan.commands.tx.RollbackCommand) HashMap(java.util.HashMap) CommitCommand(org.infinispan.commands.tx.CommitCommand) InvocationSuccessFunction(org.infinispan.interceptors.InvocationSuccessFunction) IracEntryVersion(org.infinispan.container.versioning.irac.IracEntryVersion) PrepareResponse.asPrepareResponse(org.infinispan.remoting.responses.PrepareResponse.asPrepareResponse) FlagBitSets(org.infinispan.context.impl.FlagBitSets) List(java.util.List) InvocationContext(org.infinispan.context.InvocationContext) Stream(java.util.stream.Stream) PrepareResponse(org.infinispan.remoting.responses.PrepareResponse) InvocationSuccessAction(org.infinispan.interceptors.InvocationSuccessAction) TxInvocationContext(org.infinispan.context.impl.TxInvocationContext) Map(java.util.Map) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand) RemoteTxInvocationContext(org.infinispan.context.impl.RemoteTxInvocationContext) PrepareResponse.asPrepareResponse(org.infinispan.remoting.responses.PrepareResponse.asPrepareResponse) PrepareResponse(org.infinispan.remoting.responses.PrepareResponse) IracEntryVersion(org.infinispan.container.versioning.irac.IracEntryVersion) HashMap(java.util.HashMap) IracMetadata(org.infinispan.metadata.impl.IracMetadata)

Aggregations

PrepareResponse (org.infinispan.remoting.responses.PrepareResponse)6 HashMap (java.util.HashMap)4 Map (java.util.Map)4 IracEntryVersion (org.infinispan.container.versioning.irac.IracEntryVersion)2 IracMetadata (org.infinispan.metadata.impl.IracMetadata)2 CacheNotFoundResponse (org.infinispan.remoting.responses.CacheNotFoundResponse)2 PrepareResponse.asPrepareResponse (org.infinispan.remoting.responses.PrepareResponse.asPrepareResponse)2 Response (org.infinispan.remoting.responses.Response)2 SuccessfulResponse (org.infinispan.remoting.responses.SuccessfulResponse)2 UnsureResponse (org.infinispan.remoting.responses.UnsureResponse)2 MapResponseCollector (org.infinispan.remoting.transport.impl.MapResponseCollector)2 Iterator (java.util.Iterator)1 List (java.util.List)1 Stream (java.util.stream.Stream)1 CommitCommand (org.infinispan.commands.tx.CommitCommand)1 PrepareCommand (org.infinispan.commands.tx.PrepareCommand)1 RollbackCommand (org.infinispan.commands.tx.RollbackCommand)1 PutKeyValueCommand (org.infinispan.commands.write.PutKeyValueCommand)1 WriteCommand (org.infinispan.commands.write.WriteCommand)1 InvocationContext (org.infinispan.context.InvocationContext)1