Search in sources :

Example 1 with OutboundTransferTask

use of org.infinispan.statetransfer.OutboundTransferTask in project infinispan by infinispan.

the class ScatteredStateProviderImpl method startKeysTransfer.

@Override
public void startKeysTransfer(IntSet segments, Address origin) {
    CacheTopology cacheTopology = distributionManager.getCacheTopology();
    OutboundTransferTask outboundTransferTask = new OutboundTransferTask(origin, segments, cacheTopology.getCurrentCH().getNumSegments(), chunkSize, cacheTopology.getTopologyId(), keyPartitioner, chunks -> {
    }, rpcManager, commandsFactory, timeout, cacheName, true, false);
    addTransfer(outboundTransferTask);
    outboundTransferTask.execute(Flowable.concat(publishDataContainerKeys(segments), publishStoreKeys(segments))).whenComplete((ignored, throwable) -> {
        if (throwable != null) {
            logError(outboundTransferTask, throwable);
        }
        onTaskCompletion(outboundTransferTask);
    });
}
Also used : CacheTopology(org.infinispan.topology.CacheTopology) OutboundTransferTask(org.infinispan.statetransfer.OutboundTransferTask)

Example 2 with OutboundTransferTask

use of org.infinispan.statetransfer.OutboundTransferTask in project infinispan by infinispan.

the class ScatteredStateProviderImpl method replicateAndInvalidate.

// This method handles creating the backup copy and invalidation on other nodes for segments
// that this node keeps from previous topology.
private CompletableFuture<Void> replicateAndInvalidate(CacheTopology cacheTopology) {
    Address nextMember = getNextMember(cacheTopology);
    if (nextMember != null) {
        HashSet<Address> otherMembers = new HashSet<>(cacheTopology.getActualMembers());
        Address localAddress = rpcManager.getAddress();
        otherMembers.remove(localAddress);
        otherMembers.remove(nextMember);
        if (!cacheTopology.getCurrentCH().getMembers().contains(localAddress)) {
            log.trace("Local address is not a member of currentCH, returning");
            return CompletableFutures.completedNull();
        }
        IntSet oldSegments = IntSets.from(cacheTopology.getCurrentCH().getSegmentsForOwner(localAddress));
        oldSegments.retainAll(cacheTopology.getPendingCH().getSegmentsForOwner(localAddress));
        log.trace("Segments to replicate and invalidate: " + oldSegments);
        if (oldSegments.isEmpty()) {
            return CompletableFutures.completedNull();
        }
        // We pretend to do one extra invalidation at the beginning that finishes after we sent all chunks
        AtomicInteger outboundInvalidations = new AtomicInteger(1);
        CompletableFuture<Void> invalidationFuture = new CompletableFuture<>();
        OutboundTransferTask outboundTransferTask = new OutboundTransferTask(nextMember, oldSegments, cacheTopology.getCurrentCH().getNumSegments(), chunkSize, cacheTopology.getTopologyId(), keyPartitioner, chunks -> invalidateChunks(chunks, otherMembers, outboundInvalidations, invalidationFuture, cacheTopology), rpcManager, commandsFactory, timeout, cacheName, true, true);
        outboundTransferTask.execute(Flowable.concat(publishDataContainerEntries(oldSegments), publishStoreEntries(oldSegments))).whenComplete((ignored, throwable) -> {
            if (throwable != null) {
                logError(outboundTransferTask, throwable);
            }
            if (outboundInvalidations.decrementAndGet() == 0) {
                invalidationFuture.complete(null);
            }
        });
        return invalidationFuture;
    } else {
        return CompletableFutures.completedNull();
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Address(org.infinispan.remoting.transport.Address) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IntSet(org.infinispan.commons.util.IntSet) OutboundTransferTask(org.infinispan.statetransfer.OutboundTransferTask) HashSet(java.util.HashSet)

Aggregations

OutboundTransferTask (org.infinispan.statetransfer.OutboundTransferTask)2 HashSet (java.util.HashSet)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 IntSet (org.infinispan.commons.util.IntSet)1 Address (org.infinispan.remoting.transport.Address)1 CacheTopology (org.infinispan.topology.CacheTopology)1