use of org.infinispan.persistence.support.SegmentPublisherWrapper in project infinispan by infinispan.
the class SFSToSIFSStore method start.
@Override
public CompletionStage<Void> start(InitializationContext ctx) {
SFSToSIFSConfiguration sfsToSIFSConfiguration = ctx.getConfiguration();
CompletionStage<NonBlockingStore<K, V>> targetStage = createAndStartSoftIndexFileStore(ctx, sfsToSIFSConfiguration);
// If config has purge don't even bother with migration
if (sfsToSIFSConfiguration.purgeOnStartup()) {
return targetStage.thenAccept(sifsStore -> targetStore = sifsStore);
}
CompletionStage<NonBlockingStore<K, V>> nonSegmentedSFSStage = createAndStartSingleFileStore(ctx, sfsToSIFSConfiguration.dataLocation(), false);
CompletionStage<NonBlockingStore<K, V>> segmentedSFSStage = createAndStartSingleFileStore(ctx, sfsToSIFSConfiguration.dataLocation(), true);
Function<NonBlockingStore<K, V>, CompletionStage<Void>> composed = sourceStore -> targetStage.thenCompose(targetStore -> {
this.targetStore = targetStore;
int segmentCount = ctx.getCache().getCacheConfiguration().clustering().hash().numSegments();
IntSet allSegments = IntSets.immutableRangeSet(segmentCount);
Flowable<GroupedFlowable<Integer, MarshallableEntry<K, V>>> groupedFlowable = Flowable.fromPublisher(sourceStore.publishEntries(allSegments, null, true)).groupBy(ctx.getKeyPartitioner()::getSegment);
return targetStore.batch(segmentCount, Flowable.empty(), groupedFlowable.map(SegmentPublisherWrapper::wrap)).thenCompose(ignore -> sourceStore.destroy());
});
return CompletionStages.allOf(nonSegmentedSFSStage.thenCompose(composed), segmentedSFSStage.thenCompose(composed));
}
Aggregations