Search in sources :

Example 1 with MetadataValue

use of org.infinispan.client.hotrod.MetadataValue in project infinispan by infinispan.

the class NearCacheService method calculateBloomBits.

public byte[] calculateBloomBits() {
    if (bloomFilterBits <= 0) {
        return null;
    }
    BloomFilter<byte[]> bloomFilter = MurmurHash3BloomFilter.createFilter(bloomFilterBits);
    for (Map.Entry<K, MetadataValue<V>> entry : cache) {
        bloomFilter.addToFilter(remote.keyToBytes(entry.getKey()));
    }
    IntSet intSet = bloomFilter.getIntSet();
    return intSet.toBitSet();
}
Also used : MetadataValue(org.infinispan.client.hotrod.MetadataValue) IntSet(org.infinispan.commons.util.IntSet) Map(java.util.Map)

Example 2 with MetadataValue

use of org.infinispan.client.hotrod.MetadataValue in project wildfly by wildfly.

the class SessionManagerNearCacheFactory method onRemoval.

@Override
public void onRemoval(Object key, Object value, RemovalCause cause) {
    // Cascade invalidation to dependent entries
    if ((cause == RemovalCause.SIZE) && (key instanceof SessionCreationMetaDataKey)) {
        String id = ((SessionCreationMetaDataKey) key).getId();
        Cache<K, MetadataValue<V>> cache = this.cache.get();
        List<Object> keys = new LinkedList<>();
        keys.add(new SessionAccessMetaDataKey(id));
        switch(this.strategy) {
            case COARSE:
                {
                    keys.add(new SessionAttributesKey(id));
                    break;
                }
            case FINE:
                {
                    SessionAttributeNamesKey namesKey = new SessionAttributeNamesKey(id);
                    keys.add(namesKey);
                    MetadataValue<V> namesValue = cache.getIfPresent(namesKey);
                    if (namesValue != null) {
                        @SuppressWarnings("unchecked") Map<String, UUID> names = (Map<String, UUID>) namesValue.getValue();
                        for (UUID attributeId : names.values()) {
                            keys.add(new SessionAttributeKey(id, attributeId));
                        }
                    }
                    break;
                }
        }
        cache.invalidateAll(keys);
    }
}
Also used : MetadataValue(org.infinispan.client.hotrod.MetadataValue) SessionAttributeNamesKey(org.wildfly.clustering.web.hotrod.session.fine.SessionAttributeNamesKey) SessionAttributesKey(org.wildfly.clustering.web.hotrod.session.coarse.SessionAttributesKey) LinkedList(java.util.LinkedList) SessionAttributeKey(org.wildfly.clustering.web.hotrod.session.fine.SessionAttributeKey) UUID(java.util.UUID) Map(java.util.Map)

Example 3 with MetadataValue

use of org.infinispan.client.hotrod.MetadataValue 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)

Example 4 with MetadataValue

use of org.infinispan.client.hotrod.MetadataValue in project infinispan by infinispan.

the class RemoteStore method publishEntries.

@Override
public Publisher<MarshallableEntry<K, V>> publishEntries(IntSet segments, Predicate<? super K> filter, boolean includeValues) {
    // We assume our segments don't map to the remote node when segmentation is disabled
    IntSet segmentsToUse = configuration.segmented() ? segments : null;
    if (configuration.rawValues()) {
        Flowable<Map.Entry<Object, MetadataValue<Object>>> entryFlowable = Flowable.fromPublisher(remoteCache.publishEntriesWithMetadata(segmentsToUse, 512));
        if (filter != null) {
            entryFlowable = entryFlowable.filter(e -> filter.test(wrap(e.getKey())));
        }
        return entryFlowable.map(e -> {
            MetadataValue<Object> value = e.getValue();
            Metadata metadata = new EmbeddedMetadata.Builder().version(new NumericVersion(value.getVersion())).lifespan(value.getLifespan(), TimeUnit.SECONDS).maxIdle(value.getMaxIdle(), TimeUnit.SECONDS).build();
            long created = value.getCreated();
            long lastUsed = value.getLastUsed();
            Object realValue = value.getValue();
            return entryFactory.create(wrap(e.getKey()), wrap(realValue), metadata, null, created, lastUsed);
        });
    } else {
        Flowable<Map.Entry<Object, Object>> entryFlowable = Flowable.fromPublisher(remoteCache.publishEntries(null, null, segmentsToUse, 512));
        if (filter != null) {
            entryFlowable = entryFlowable.filter(e -> filter.test(wrap(e.getKey())));
        }
        // Technically we will send the metadata and value to the user, no matter what.
        return entryFlowable.map(e -> e.getValue() == null ? null : entryFactory.create(wrap(e.getKey()), (MarshalledValue) e.getValue()));
    }
}
Also used : MarshalledValue(org.infinispan.persistence.spi.MarshalledValue) LogFactory(org.infinispan.util.logging.LogFactory) MarshallableEntryFactory(org.infinispan.persistence.spi.MarshallableEntryFactory) RemoteCache(org.infinispan.client.hotrod.RemoteCache) WrappedByteArray(org.infinispan.commons.marshall.WrappedByteArray) CompletableFutures(org.infinispan.util.concurrent.CompletableFutures) DataFormat(org.infinispan.client.hotrod.DataFormat) RemoteServerConfiguration(org.infinispan.persistence.remote.configuration.RemoteServerConfiguration) Map(java.util.Map) ServerStatistics(org.infinispan.client.hotrod.ServerStatistics) ConfiguredBy(org.infinispan.commons.configuration.ConfiguredBy) IdentityMarshaller(org.infinispan.commons.marshall.IdentityMarshaller) EnumSet(java.util.EnumSet) Predicate(java.util.function.Predicate) EmbeddedMetadata(org.infinispan.metadata.EmbeddedMetadata) Set(java.util.Set) Log(org.infinispan.persistence.remote.logging.Log) Collectors(java.util.stream.Collectors) SslConfiguration(org.infinispan.persistence.remote.configuration.SslConfiguration) IntSet(org.infinispan.commons.util.IntSet) List(java.util.List) Codec27(org.infinispan.client.hotrod.impl.protocol.Codec27) CompletionStage(java.util.concurrent.CompletionStage) NumericVersion(org.infinispan.container.versioning.NumericVersion) InitializationContext(org.infinispan.persistence.spi.InitializationContext) RemoteStoreConfiguration(org.infinispan.persistence.remote.configuration.RemoteStoreConfiguration) InternalRemoteCache(org.infinispan.client.hotrod.impl.InternalRemoteCache) HotRodURI(org.infinispan.client.hotrod.impl.HotRodURI) Metadata(org.infinispan.metadata.Metadata) Function(java.util.function.Function) EnumUtil(org.infinispan.commons.util.EnumUtil) RemoteCacheManager(org.infinispan.client.hotrod.RemoteCacheManager) FlagBitSets(org.infinispan.context.impl.FlagBitSets) MediaType(org.infinispan.commons.dataconversion.MediaType) MarshallableEntry(org.infinispan.persistence.spi.MarshallableEntry) MetadataValue(org.infinispan.client.hotrod.MetadataValue) StorageConfigurationManager(org.infinispan.encoding.impl.StorageConfigurationManager) InternalEntryFactory(org.infinispan.container.impl.InternalEntryFactory) Properties(java.util.Properties) Flowable(io.reactivex.rxjava3.core.Flowable) NonBlockingStore(org.infinispan.persistence.spi.NonBlockingStore) Publisher(org.reactivestreams.Publisher) ConfigurationBuilder(org.infinispan.client.hotrod.configuration.ConfigurationBuilder) Util(org.infinispan.commons.util.Util) Completable(io.reactivex.rxjava3.core.Completable) AuthenticationConfiguration(org.infinispan.persistence.remote.configuration.AuthenticationConfiguration) ConnectionPoolConfiguration(org.infinispan.persistence.remote.configuration.ConnectionPoolConfiguration) TimeUnit(java.util.concurrent.TimeUnit) ProtocolVersion(org.infinispan.client.hotrod.ProtocolVersion) Configuration(org.infinispan.configuration.cache.Configuration) ExhaustedAction(org.infinispan.client.hotrod.configuration.ExhaustedAction) BlockingManager(org.infinispan.util.concurrent.BlockingManager) Marshaller(org.infinispan.commons.marshall.Marshaller) ClusteringConfiguration(org.infinispan.configuration.cache.ClusteringConfiguration) NumericVersion(org.infinispan.container.versioning.NumericVersion) MarshallableEntry(org.infinispan.persistence.spi.MarshallableEntry) IntSet(org.infinispan.commons.util.IntSet) ConfigurationBuilder(org.infinispan.client.hotrod.configuration.ConfigurationBuilder) EmbeddedMetadata(org.infinispan.metadata.EmbeddedMetadata) Metadata(org.infinispan.metadata.Metadata)

Aggregations

MetadataValue (org.infinispan.client.hotrod.MetadataValue)4 Map (java.util.Map)3 Set (java.util.Set)2 TimeUnit (java.util.concurrent.TimeUnit)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 RemoteCache (org.infinispan.client.hotrod.RemoteCache)2 EnumUtil (org.infinispan.commons.util.EnumUtil)2 Util (org.infinispan.commons.util.Util)2 NumericVersion (org.infinispan.container.versioning.NumericVersion)2 EmbeddedMetadata (org.infinispan.metadata.EmbeddedMetadata)2 Metadata (org.infinispan.metadata.Metadata)2 Log (org.infinispan.persistence.remote.logging.Log)2 LogFactory (org.infinispan.util.logging.LogFactory)2 Completable (io.reactivex.rxjava3.core.Completable)1 Flowable (io.reactivex.rxjava3.core.Flowable)1 IOException (java.io.IOException)1 ObjectInput (java.io.ObjectInput)1 ObjectOutput (java.io.ObjectOutput)1 BitSet (java.util.BitSet)1