Search in sources :

Example 31 with DataConversion

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

the class PersistenceManagerImpl method preload.

@Override
public CompletionStage<Void> preload() {
    long stamp = acquireReadLock();
    NonBlockingStore<Object, Object> nonBlockingStore = getStoreLocked(status -> status.config.preload());
    if (nonBlockingStore == null) {
        releaseReadLock(stamp);
        return CompletableFutures.completedNull();
    }
    Publisher<MarshallableEntry<Object, Object>> publisher = nonBlockingStore.publishEntries(IntSets.immutableRangeSet(segmentCount), null, true);
    long start = timeService.time();
    final long maxEntries = getMaxEntries();
    final long flags = getFlagsForStateInsertion();
    AdvancedCache<?, ?> tmpCache = this.cache.wired().withStorageMediaType();
    DataConversion keyDataConversion = tmpCache.getKeyDataConversion();
    DataConversion valueDataConversion = tmpCache.getValueDataConversion();
    return Flowable.fromPublisher(publisher).doFinally(() -> releaseReadLock(stamp)).take(maxEntries).concatMapSingle(me -> preloadEntry(flags, me, keyDataConversion, valueDataConversion)).count().toCompletionStage().thenAccept(insertAmount -> {
        this.preloaded = insertAmount < maxEntries;
        log.debugf("Preloaded %d keys in %s", insertAmount, Util.prettyPrintTime(timeService.timeDuration(start, MILLISECONDS)));
    });
}
Also used : DataConversion(org.infinispan.encoding.DataConversion) WriteCommand(org.infinispan.commands.write.WriteCommand) ComponentName(org.infinispan.factories.annotations.ComponentName) LogFactory(org.infinispan.util.logging.LogFactory) InvocationHelper(org.infinispan.cache.impl.InvocationHelper) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) KnownComponentNames(org.infinispan.factories.KnownComponentNames) StoreUnavailableException(org.infinispan.persistence.spi.StoreUnavailableException) Scopes(org.infinispan.factories.scopes.Scopes) AdvancedCache(org.infinispan.AdvancedCache) TxInvocationContext(org.infinispan.context.impl.TxInvocationContext) InitializationContextImpl(org.infinispan.persistence.InitializationContextImpl) Transaction(javax.transaction.Transaction) MethodHandles(java.lang.invoke.MethodHandles) ByRef(org.infinispan.commons.util.ByRef) Set(java.util.Set) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) IntSet(org.infinispan.commons.util.IntSet) CompletionStage(java.util.concurrent.CompletionStage) ComposedSegmentedLoadWriteStore(org.infinispan.persistence.support.ComposedSegmentedLoadWriteStore) DelegatingNonBlockingStore(org.infinispan.persistence.support.DelegatingNonBlockingStore) InternalCacheValue(org.infinispan.container.entries.InternalCacheValue) DataConversion(org.infinispan.encoding.DataConversion) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) Single(io.reactivex.rxjava3.core.Single) TransactionalStoreInterceptor(org.infinispan.interceptors.impl.TransactionalStoreInterceptor) NonBlockingStoreAdapter(org.infinispan.persistence.support.NonBlockingStoreAdapter) EnumUtil(org.infinispan.commons.util.EnumUtil) InternalExpirationManager(org.infinispan.expiration.impl.InternalExpirationManager) CacheLoaderInterceptor(org.infinispan.interceptors.impl.CacheLoaderInterceptor) Start(org.infinispan.factories.annotations.Start) ArrayList(java.util.ArrayList) Maybe(io.reactivex.rxjava3.core.Maybe) StoreConfiguration(org.infinispan.configuration.cache.StoreConfiguration) MarshallableEntry(org.infinispan.persistence.spi.MarshallableEntry) DataWriteCommand(org.infinispan.commands.write.DataWriteCommand) AsyncInterceptor(org.infinispan.interceptors.AsyncInterceptor) InternalEntryFactory(org.infinispan.container.impl.InternalEntryFactory) Properties(java.util.Properties) Executor(java.util.concurrent.Executor) Publisher(org.reactivestreams.Publisher) InvalidTransactionException(javax.transaction.InvalidTransactionException) IOException(java.io.IOException) CacheNotifier(org.infinispan.notifications.cachelistener.CacheNotifier) Inject(org.infinispan.factories.annotations.Inject) MVCCEntry(org.infinispan.container.entries.MVCCEntry) InvalidateCommand(org.infinispan.commands.write.InvalidateCommand) Function(io.reactivex.rxjava3.functions.Function) PersistenceMarshaller(org.infinispan.marshall.persistence.PersistenceMarshaller) SystemException(javax.transaction.SystemException) StampedLock(java.util.concurrent.locks.StampedLock) DistributionManager(org.infinispan.distribution.DistributionManager) AggregateCompletionStage(org.infinispan.util.concurrent.AggregateCompletionStage) IntSets(org.infinispan.commons.util.IntSets) MarshallableEntryFactory(org.infinispan.persistence.spi.MarshallableEntryFactory) Stop(org.infinispan.factories.annotations.Stop) InvocationContext(org.infinispan.context.InvocationContext) ComponentRef(org.infinispan.factories.impl.ComponentRef) SingleSegmentPublisher(org.infinispan.persistence.support.SingleSegmentPublisher) CompletableFutures(org.infinispan.util.concurrent.CompletableFutures) Lifecycle(org.infinispan.commons.api.Lifecycle) Scope(org.infinispan.factories.scopes.Scope) ByteBufferFactory(org.infinispan.commons.io.ByteBufferFactory) PERSISTENCE(org.infinispan.util.logging.Log.PERSISTENCE) CommandsFactory(org.infinispan.commands.CommandsFactory) AsyncNonBlockingStore(org.infinispan.persistence.async.AsyncNonBlockingStore) Predicate(java.util.function.Predicate) Collection(java.util.Collection) AbstractCacheTransaction(org.infinispan.transaction.impl.AbstractCacheTransaction) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand) GuardedBy(net.jcip.annotations.GuardedBy) SegmentPublisherWrapper(org.infinispan.persistence.support.SegmentPublisherWrapper) PersistenceException(org.infinispan.persistence.spi.PersistenceException) LocalOnlyCacheLoader(org.infinispan.persistence.spi.LocalOnlyCacheLoader) CompletionStages(org.infinispan.util.concurrent.CompletionStages) CompletableFuture(java.util.concurrent.CompletableFuture) AbstractSegmentedStoreConfiguration(org.infinispan.configuration.cache.AbstractSegmentedStoreConfiguration) FlagBitSets(org.infinispan.context.impl.FlagBitSets) InternalMetadataImpl(org.infinispan.metadata.impl.InternalMetadataImpl) HashSet(java.util.HashSet) Characteristic(org.infinispan.persistence.spi.NonBlockingStore.Characteristic) BiPredicate(java.util.function.BiPredicate) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) Log(org.infinispan.util.logging.Log) CacheWriterInterceptor(org.infinispan.interceptors.impl.CacheWriterInterceptor) Flowable(io.reactivex.rxjava3.core.Flowable) Iterator(java.util.Iterator) NonBlockingStore(org.infinispan.persistence.spi.NonBlockingStore) Util(org.infinispan.commons.util.Util) NonBlockingManager(org.infinispan.util.concurrent.NonBlockingManager) Completable(io.reactivex.rxjava3.core.Completable) PutMapCommand(org.infinispan.commands.write.PutMapCommand) NotSupportedException(javax.transaction.NotSupportedException) PersistenceUtil(org.infinispan.persistence.internal.PersistenceUtil) Configuration(org.infinispan.configuration.cache.Configuration) BlockingManager(org.infinispan.util.concurrent.BlockingManager) TransactionManager(javax.transaction.TransactionManager) TimeService(org.infinispan.commons.time.TimeService) InputStream(java.io.InputStream) MarshallableEntry(org.infinispan.persistence.spi.MarshallableEntry)

Example 32 with DataConversion

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

the class Mutations method readFrom.

static <K, V, T> Mutation<K, V, ?> readFrom(ObjectInput input) throws IOException, ClassNotFoundException {
    DataConversion keyDataConversion = DataConversion.readFrom(input);
    DataConversion valueDataConversion = DataConversion.readFrom(input);
    switch(input.readByte()) {
        case ReadWrite.TYPE:
            return new ReadWrite<>(keyDataConversion, valueDataConversion, (Function<EntryView.ReadWriteEntryView<K, V>, T>) input.readObject());
        case ReadWriteWithValue.TYPE:
            return new ReadWriteWithValue<>(keyDataConversion, valueDataConversion, input.readObject(), (BiFunction<V, EntryView.ReadWriteEntryView<K, V>, T>) input.readObject());
        case Write.TYPE:
            return new Write<>(keyDataConversion, valueDataConversion, (Consumer<EntryView.WriteEntryView<K, V>>) input.readObject());
        case WriteWithValue.TYPE:
            return new WriteWithValue<>(keyDataConversion, valueDataConversion, input.readObject(), (BiConsumer<T, EntryView.WriteEntryView<K, V>>) input.readObject());
        default:
            throw new IllegalStateException("Unknown type of mutation, broken input?");
    }
}
Also used : DataConversion(org.infinispan.encoding.DataConversion)

Example 33 with DataConversion

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

the class InternalCacheFactory method buildEncodingCache.

private AdvancedCache<K, V> buildEncodingCache(AdvancedCache<K, V> wrappedCache) {
    DataConversion keyDataConversion = newKeyDataConversion();
    DataConversion valueDataConversion = newValueDataConversion();
    return new EncoderCache<>(wrappedCache, null, null, keyDataConversion, valueDataConversion);
}
Also used : DataConversion.newKeyDataConversion(org.infinispan.encoding.DataConversion.newKeyDataConversion) DataConversion(org.infinispan.encoding.DataConversion) DataConversion.newValueDataConversion(org.infinispan.encoding.DataConversion.newValueDataConversion) EncoderCache(org.infinispan.cache.impl.EncoderCache)

Example 34 with DataConversion

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

the class EncoderCache method withKeyEncoding.

@Override
public AdvancedCache<K, V> withKeyEncoding(Class<? extends Encoder> encoderClass) {
    checkSubclass(encoderClass, Encoder.class);
    DataConversion newKeyDataConversion = keyDataConversion.withEncoding(encoderClass);
    EncoderCache<K, V> encoderCache = new EncoderCache<>(cache, entryFactory, componentRegistry, newKeyDataConversion, valueDataConversion);
    encoderCache.lookupEncoderWrapper();
    return encoderCache;
}
Also used : DataConversion(org.infinispan.encoding.DataConversion)

Example 35 with DataConversion

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

the class CallInterceptor method visitWriteOnlyKeyValueCommand.

@Override
public Object visitWriteOnlyKeyValueCommand(InvocationContext ctx, WriteOnlyKeyValueCommand command) throws Throwable {
    MVCCEntry e = (MVCCEntry) ctx.lookupEntry(command.getKey());
    // Could be that the key is not local
    if (e == null)
        return null;
    DataConversion valueDataConversion = command.getValueDataConversion();
    Object decodedArgument = valueDataConversion.fromStorage(command.getArgument());
    boolean exists = e.getValue() != null;
    command.getBiConsumer().accept(decodedArgument, EntryViews.writeOnly(e, valueDataConversion));
    // The effective result of retried command is not safe; we'll go to backup anyway
    if (!e.isChanged() && !command.hasAnyFlag(FlagBitSets.COMMAND_RETRY)) {
        command.fail();
    }
    updateStoreFlags(command, e);
    return Param.StatisticsMode.isSkip(command.getParams()) ? null : StatsEnvelope.create(null, e, exists, false);
}
Also used : DataConversion(org.infinispan.encoding.DataConversion) MVCCEntry(org.infinispan.container.entries.MVCCEntry)

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