Search in sources :

Example 41 with DataConversion

use of org.infinispan.encoding.DataConversion in project infinispan by infinispan.

the class MigrationTask method migrateEntriesWithMetadata.

private void migrateEntriesWithMetadata(RemoteCache<Object, Object> sourceCache, AtomicInteger counter, ExecutorService executorService, Cache<Object, Object> cache) {
    AdvancedCache<Object, Object> destinationCache = cache.getAdvancedCache();
    DataConversion keyDataConversion = destinationCache.getKeyDataConversion();
    DataConversion valueDataConversion = destinationCache.getValueDataConversion();
    try (CloseableIterator<Entry<Object, MetadataValue<Object>>> iterator = sourceCache.retrieveEntriesWithMetadata(segments, readBatch)) {
        CompletableFuture<?>[] completableFutures = StreamSupport.stream(spliteratorUnknownSize(iterator, 0), false).map(entry -> {
            Object key = entry.getKey();
            MetadataValue<Object> metadataValue = entry.getValue();
            int lifespan = metadataValue.getLifespan();
            int maxIdle = metadataValue.getMaxIdle();
            long version = metadataValue.getVersion();
            Metadata metadata = new EmbeddedMetadata.Builder().version(new NumericVersion(version)).lifespan(lifespan, TimeUnit.SECONDS).maxIdle(maxIdle, TimeUnit.SECONDS).build();
            if (!deletedKeys.contains(ByteArrayWrapper.INSTANCE.wrap(key))) {
                return CompletableFuture.supplyAsync(() -> {
                    int currentCount = counter.incrementAndGet();
                    if (log.isDebugEnabled() && currentCount % 100 == 0)
                        log.debugf(">>    Migrated %s entries\n", currentCount);
                    return writeToDestinationCache(entry, metadata, keyDataConversion, valueDataConversion);
                }, executorService);
            }
            return CompletableFuture.completedFuture(null);
        }).toArray(CompletableFuture[]::new);
        CompletableFuture.allOf(completableFutures).join();
    }
}
Also used : Spliterators.spliteratorUnknownSize(java.util.Spliterators.spliteratorUnknownSize) RemoteStore(org.infinispan.persistence.remote.RemoteStore) DefaultThreadFactory(org.infinispan.factories.threads.DefaultThreadFactory) LogFactory(org.infinispan.util.logging.LogFactory) UnsignedNumeric(org.infinispan.commons.io.UnsignedNumeric) ObjectOutput(java.io.ObjectOutput) BiFunction(java.util.function.BiFunction) InvocationHelper(org.infinispan.cache.impl.InvocationHelper) Cache(org.infinispan.Cache) RemoteCache(org.infinispan.client.hotrod.RemoteCache) CloseableIterator(org.infinispan.commons.util.CloseableIterator) InvocationContext(org.infinispan.context.InvocationContext) AdvancedCache(org.infinispan.AdvancedCache) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExternalizerIds(org.infinispan.persistence.remote.ExternalizerIds) CacheEntryRemovedEvent(org.infinispan.notifications.cachelistener.event.CacheEntryRemovedEvent) ByteArrayWrapper(org.infinispan.commons.dataconversion.ByteArrayWrapper) CommandsFactory(org.infinispan.commands.CommandsFactory) Listener(org.infinispan.notifications.Listener) EmbeddedMetadata(org.infinispan.metadata.EmbeddedMetadata) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Log(org.infinispan.persistence.remote.logging.Log) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) Flag(org.infinispan.context.Flag) NumericVersion(org.infinispan.container.versioning.NumericVersion) Entry(java.util.Map.Entry) AbstractExternalizer(org.infinispan.commons.marshall.AbstractExternalizer) DataConversion(org.infinispan.encoding.DataConversion) ObjectInput(java.io.ObjectInput) CacheEntryRemoved(org.infinispan.notifications.cachelistener.annotation.CacheEntryRemoved) PersistenceManager(org.infinispan.persistence.manager.PersistenceManager) ComputeCommand(org.infinispan.commands.write.ComputeCommand) CompletableFuture(java.util.concurrent.CompletableFuture) ComponentRegistry(org.infinispan.factories.ComponentRegistry) Metadata(org.infinispan.metadata.Metadata) Function(java.util.function.Function) EnumUtil(org.infinispan.commons.util.EnumUtil) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) StreamSupport(java.util.stream.StreamSupport) MetadataValue(org.infinispan.client.hotrod.MetadataValue) ExecutorService(java.util.concurrent.ExecutorService) Iterator(java.util.Iterator) Util(org.infinispan.commons.util.Util) IOException(java.io.IOException) TimeUnit(java.util.concurrent.TimeUnit) BitSet(java.util.BitSet) BlockingThreadFactory(org.infinispan.factories.threads.BlockingThreadFactory) Collections(java.util.Collections) MetadataValue(org.infinispan.client.hotrod.MetadataValue) EmbeddedMetadata(org.infinispan.metadata.EmbeddedMetadata) Metadata(org.infinispan.metadata.Metadata) DataConversion(org.infinispan.encoding.DataConversion) NumericVersion(org.infinispan.container.versioning.NumericVersion) Entry(java.util.Map.Entry) CompletableFuture(java.util.concurrent.CompletableFuture) EmbeddedMetadata(org.infinispan.metadata.EmbeddedMetadata)

Aggregations

DataConversion (org.infinispan.encoding.DataConversion)41 MVCCEntry (org.infinispan.container.entries.MVCCEntry)9 KeyPartitioner (org.infinispan.distribution.ch.KeyPartitioner)9 ArrayList (java.util.ArrayList)8 AdvancedCache (org.infinispan.AdvancedCache)8 Util (org.infinispan.commons.util.Util)8 EnumUtil (org.infinispan.commons.util.EnumUtil)7 InvocationContext (org.infinispan.context.InvocationContext)7 Completable (io.reactivex.rxjava3.core.Completable)6 Flowable (io.reactivex.rxjava3.core.Flowable)6 Set (java.util.Set)6 CompletionStage (java.util.concurrent.CompletionStage)6 Function (java.util.function.Function)6 Transaction (javax.transaction.Transaction)6 TransactionManager (javax.transaction.TransactionManager)6 MediaType (org.infinispan.commons.dataconversion.MediaType)6 TimeService (org.infinispan.commons.time.TimeService)6 Configuration (org.infinispan.configuration.cache.Configuration)6 CacheEntry (org.infinispan.container.entries.CacheEntry)6 FlagBitSets (org.infinispan.context.impl.FlagBitSets)6