Search in sources :

Example 1 with PrepareResponse.asPrepareResponse

use of org.infinispan.remoting.responses.PrepareResponse.asPrepareResponse 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)

Aggregations

HashMap (java.util.HashMap)1 IracEntryVersion (org.infinispan.container.versioning.irac.IracEntryVersion)1 IracMetadata (org.infinispan.metadata.impl.IracMetadata)1 PrepareResponse (org.infinispan.remoting.responses.PrepareResponse)1 PrepareResponse.asPrepareResponse (org.infinispan.remoting.responses.PrepareResponse.asPrepareResponse)1