Search in sources :

Example 1 with MetadataImmortalCacheValue

use of org.infinispan.container.entries.metadata.MetadataImmortalCacheValue in project infinispan by infinispan.

the class ScatteredDistributionInterceptor method handleWriteManyOnPrimary.

private Object handleWriteManyOnPrimary(InvocationContext ctx, WriteCommand cmd, Object rv) {
    int numKeys = cmd.getAffectedKeys().size();
    InternalCacheValue[] values = new InternalCacheValue[numKeys];
    // keys are always iterated in order
    int i = 0;
    AggregateCompletionStage<Void> aggregateCompletionStage = CompletionStages.aggregateCompletionStage();
    for (Object key : cmd.getAffectedKeys()) {
        RepeatableReadEntry entry = (RepeatableReadEntry) ctx.lookupEntry(key);
        EntryVersion nextVersion = svm.incrementVersion(keyPartitioner.getSegment(key));
        entry.setMetadata(addVersion(entry.getMetadata(), nextVersion));
        if (cmd.loadType() == DONT_LOAD) {
            aggregateCompletionStage.dependsOn(commitSingleEntryIfNewer(entry, ctx, cmd));
        } else {
            aggregateCompletionStage.dependsOn(commitSingleEntryIfNoChange(entry, ctx, cmd));
        }
        values[i++] = new MetadataImmortalCacheValue(entry.getValue(), entry.getMetadata());
    }
    CompletionStage<Void> aggregatedStage = aggregateCompletionStage.freeze();
    Object returnValue;
    if (cmd.loadType() == DONT_LOAD) {
        // Disable ignoring return value in response
        cmd.setFlagsBitSet(cmd.getFlagsBitSet() & ~FlagBitSets.IGNORE_RETURN_VALUES);
        returnValue = values;
    } else {
        returnValue = new Object[] { values, ((List) rv).toArray() };
    }
    return asyncValue(aggregatedStage).thenApply(ctx, cmd, ((rCtx, rCommand, rv1) -> manyWriteResponse(rCtx, cmd, returnValue)));
}
Also used : MetadataImmortalCacheValue(org.infinispan.container.entries.metadata.MetadataImmortalCacheValue) WriteCommand(org.infinispan.commands.write.WriteCommand) Arrays(java.util.Arrays) GetCacheEntryCommand(org.infinispan.commands.read.GetCacheEntryCommand) CacheNotFoundResponse(org.infinispan.remoting.responses.CacheNotFoundResponse) LogFactory(org.infinispan.util.logging.LogFactory) RemoteMetadata(org.infinispan.container.entries.RemoteMetadata) ClusteredGetAllCommand(org.infinispan.commands.remote.ClusteredGetAllCommand) Map(java.util.Map) RemoveCommand(org.infinispan.commands.write.RemoveCommand) ConsistentHash(org.infinispan.distribution.ch.ConsistentHash) EmbeddedMetadata(org.infinispan.metadata.EmbeddedMetadata) ReadWriteManyEntriesCommand(org.infinispan.commands.functional.ReadWriteManyEntriesCommand) UnsuccessfulResponse(org.infinispan.remoting.responses.UnsuccessfulResponse) Set(java.util.Set) GroupManager(org.infinispan.distribution.group.impl.GroupManager) CacheTopology(org.infinispan.topology.CacheTopology) ResponseCollector(org.infinispan.remoting.transport.ResponseCollector) DONT_LOAD(org.infinispan.commands.VisitableCommand.LoadType.DONT_LOAD) CompletionStage(java.util.concurrent.CompletionStage) Stream(java.util.stream.Stream) SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) InternalCacheValue(org.infinispan.container.entries.InternalCacheValue) AbstractVisitor(org.infinispan.commands.AbstractVisitor) ArrayCollector(org.infinispan.commons.util.ArrayCollector) InternalCacheEntry(org.infinispan.container.entries.InternalCacheEntry) CacheEntryRemoved(org.infinispan.notifications.cachelistener.annotation.CacheEntryRemoved) PersistenceManager(org.infinispan.persistence.manager.PersistenceManager) ComputeCommand(org.infinispan.commands.write.ComputeCommand) MetadataAwareCommand(org.infinispan.commands.MetadataAwareCommand) EvictionManager(org.infinispan.eviction.EvictionManager) ReadOnlyKeyCommand(org.infinispan.commands.functional.ReadOnlyKeyCommand) ArrayList(java.util.ArrayList) WriteOnlyManyEntriesCommand(org.infinispan.commands.functional.WriteOnlyManyEntriesCommand) Start(org.infinispan.factories.annotations.Start) MapResponseCollector(org.infinispan.remoting.transport.impl.MapResponseCollector) PassthroughSingleResponseCollector(org.infinispan.remoting.transport.impl.PassthroughSingleResponseCollector) SingleResponseCollector(org.infinispan.remoting.transport.impl.SingleResponseCollector) DataWriteCommand(org.infinispan.commands.write.DataWriteCommand) FunctionalNotifier(org.infinispan.functional.impl.FunctionalNotifier) ValueMatcher(org.infinispan.commands.write.ValueMatcher) ClearCommand(org.infinispan.commands.write.ClearCommand) Address(org.infinispan.remoting.transport.Address) ExceptionResponse(org.infinispan.remoting.responses.ExceptionResponse) CacheEntry(org.infinispan.container.entries.CacheEntry) NotifyHelper(org.infinispan.notifications.cachelistener.NotifyHelper) WriteOnlyKeyValueCommand(org.infinispan.commands.functional.WriteOnlyKeyValueCommand) ValidResponse(org.infinispan.remoting.responses.ValidResponse) CacheNotifier(org.infinispan.notifications.cachelistener.CacheNotifier) Inject(org.infinispan.factories.annotations.Inject) ReadWriteKeyCommand(org.infinispan.commands.functional.ReadWriteKeyCommand) ReadWriteManyCommand(org.infinispan.commands.functional.ReadWriteManyCommand) NullCacheEntry(org.infinispan.container.entries.NullCacheEntry) AggregateCompletionStage(org.infinispan.util.concurrent.AggregateCompletionStage) ReplaceCommand(org.infinispan.commands.write.ReplaceCommand) EntryVersion(org.infinispan.container.versioning.EntryVersion) UnsureResponse(org.infinispan.remoting.responses.UnsureResponse) MultiTargetCollector(org.infinispan.util.concurrent.CommandAckCollector.MultiTargetCollector) GetKeysInGroupCommand(org.infinispan.commands.remote.GetKeysInGroupCommand) ActivationManager(org.infinispan.eviction.impl.ActivationManager) RepeatableReadEntry(org.infinispan.container.entries.RepeatableReadEntry) InvocationContext(org.infinispan.context.InvocationContext) CompletableFutures(org.infinispan.util.concurrent.CompletableFutures) OutdatedTopologyException(org.infinispan.statetransfer.OutdatedTopologyException) RpcOptions(org.infinispan.remoting.rpc.RpcOptions) Predicate(java.util.function.Predicate) Collection(java.util.Collection) ReadWriteKeyValueCommand(org.infinispan.commands.functional.ReadWriteKeyValueCommand) MetadataImmortalCacheEntry(org.infinispan.container.entries.metadata.MetadataImmortalCacheEntry) DataOperationOrderer(org.infinispan.util.concurrent.DataOperationOrderer) InequalVersionComparisonResult(org.infinispan.container.versioning.InequalVersionComparisonResult) InvocationSuccessFunction(org.infinispan.interceptors.InvocationSuccessFunction) List(java.util.List) SingletonMapResponseCollector(org.infinispan.remoting.transport.impl.SingletonMapResponseCollector) InvocationFinallyAction(org.infinispan.interceptors.InvocationFinallyAction) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand) FlagAffectedCommand(org.infinispan.commands.FlagAffectedCommand) TopologyAffectedCommand(org.infinispan.commands.TopologyAffectedCommand) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Metadata(org.infinispan.metadata.Metadata) CompletionStages(org.infinispan.util.concurrent.CompletionStages) GetAllCommand(org.infinispan.commands.read.GetAllCommand) Function(java.util.function.Function) AllOwnersLostException(org.infinispan.statetransfer.AllOwnersLostException) FlagBitSets(org.infinispan.context.impl.FlagBitSets) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) ClusteredGetCommand(org.infinispan.commands.remote.ClusteredGetCommand) IracPutKeyValueCommand(org.infinispan.commands.write.IracPutKeyValueCommand) Log(org.infinispan.util.logging.Log) AbstractDataCommand(org.infinispan.commands.read.AbstractDataCommand) SegmentSpecificCommand(org.infinispan.commands.SegmentSpecificCommand) MetadataImmortalCacheValue(org.infinispan.container.entries.metadata.MetadataImmortalCacheValue) ResponseCollectors(org.infinispan.remoting.transport.ResponseCollectors) Response(org.infinispan.remoting.responses.Response) ClusteringInterceptor(org.infinispan.interceptors.impl.ClusteringInterceptor) GetKeyValueCommand(org.infinispan.commands.read.GetKeyValueCommand) CacheException(org.infinispan.commons.CacheException) Iterator(java.util.Iterator) EvictCommand(org.infinispan.commands.write.EvictCommand) WriteOnlyManyCommand(org.infinispan.commands.functional.WriteOnlyManyCommand) PutMapCommand(org.infinispan.commands.write.PutMapCommand) ReadOnlyManyCommand(org.infinispan.commands.functional.ReadOnlyManyCommand) ComputeIfAbsentCommand(org.infinispan.commands.write.ComputeIfAbsentCommand) LocalizedCacheTopology(org.infinispan.distribution.LocalizedCacheTopology) Configuration(org.infinispan.configuration.cache.Configuration) DistributionInfo(org.infinispan.distribution.DistributionInfo) Operation(org.infinispan.util.concurrent.DataOperationOrderer.Operation) WriteOnlyKeyCommand(org.infinispan.commands.functional.WriteOnlyKeyCommand) VisitableCommand(org.infinispan.commands.VisitableCommand) DeliverOrder(org.infinispan.remoting.inboundhandler.DeliverOrder) Collections(java.util.Collections) TimeService(org.infinispan.commons.time.TimeService) ScatteredVersionManager(org.infinispan.scattered.ScatteredVersionManager) EntryVersion(org.infinispan.container.versioning.EntryVersion) RepeatableReadEntry(org.infinispan.container.entries.RepeatableReadEntry) InternalCacheValue(org.infinispan.container.entries.InternalCacheValue)

Example 2 with MetadataImmortalCacheValue

use of org.infinispan.container.entries.metadata.MetadataImmortalCacheValue in project infinispan by infinispan.

the class InternalEntryFactoryImpl method createValue.

@Override
public InternalCacheValue createValue(CacheEntry cacheEntry) {
    Metadata metadata = cacheEntry.getMetadata();
    long lifespan = cacheEntry.getLifespan();
    long maxIdle = cacheEntry.getMaxIdle();
    if (!isStoreMetadata(metadata, null)) {
        if (lifespan < 0 && maxIdle < 0)
            return new ImmortalCacheValue(cacheEntry.getValue());
        if (lifespan > -1 && maxIdle < 0)
            return new MortalCacheValue(cacheEntry.getValue(), cacheEntry.getCreated(), lifespan);
        if (lifespan < 0 && maxIdle > -1)
            return new TransientCacheValue(cacheEntry.getValue(), maxIdle, cacheEntry.getLastUsed());
        return new TransientMortalCacheValue(cacheEntry.getValue(), cacheEntry.getCreated(), lifespan, maxIdle, cacheEntry.getLastUsed());
    } else {
        if (lifespan < 0 && maxIdle < 0)
            return new MetadataImmortalCacheValue(cacheEntry.getValue(), cacheEntry.getMetadata());
        if (lifespan > -1 && maxIdle < 0)
            return new MetadataMortalCacheValue(cacheEntry.getValue(), cacheEntry.getMetadata(), cacheEntry.getCreated());
        if (lifespan < 0 && maxIdle > -1)
            return new MetadataTransientCacheValue(cacheEntry.getValue(), cacheEntry.getMetadata(), cacheEntry.getLastUsed());
        return new MetadataTransientMortalCacheValue(cacheEntry.getValue(), cacheEntry.getMetadata(), cacheEntry.getCreated(), cacheEntry.getLastUsed());
    }
}
Also used : MetadataImmortalCacheValue(org.infinispan.container.entries.metadata.MetadataImmortalCacheValue) MetadataMortalCacheValue(org.infinispan.container.entries.metadata.MetadataMortalCacheValue) TransientMortalCacheValue(org.infinispan.container.entries.TransientMortalCacheValue) MetadataTransientMortalCacheValue(org.infinispan.container.entries.metadata.MetadataTransientMortalCacheValue) MetadataTransientMortalCacheValue(org.infinispan.container.entries.metadata.MetadataTransientMortalCacheValue) MetadataTransientCacheValue(org.infinispan.container.entries.metadata.MetadataTransientCacheValue) TransientCacheValue(org.infinispan.container.entries.TransientCacheValue) Metadata(org.infinispan.metadata.Metadata) PrivateMetadata(org.infinispan.metadata.impl.PrivateMetadata) EmbeddedMetadata(org.infinispan.metadata.EmbeddedMetadata) TransientMortalCacheValue(org.infinispan.container.entries.TransientMortalCacheValue) MetadataTransientMortalCacheValue(org.infinispan.container.entries.metadata.MetadataTransientMortalCacheValue) MetadataMortalCacheValue(org.infinispan.container.entries.metadata.MetadataMortalCacheValue) MortalCacheValue(org.infinispan.container.entries.MortalCacheValue) MetadataTransientCacheValue(org.infinispan.container.entries.metadata.MetadataTransientCacheValue) MetadataImmortalCacheValue(org.infinispan.container.entries.metadata.MetadataImmortalCacheValue) ImmortalCacheValue(org.infinispan.container.entries.ImmortalCacheValue)

Example 3 with MetadataImmortalCacheValue

use of org.infinispan.container.entries.metadata.MetadataImmortalCacheValue in project infinispan by infinispan.

the class MetadataImmortalCacheValueExternalizer method readObject.

@Override
public MetadataImmortalCacheValue readObject(ObjectInput input) throws IOException, ClassNotFoundException {
    Object value = input.readObject();
    Metadata metadata = (Metadata) input.readObject();
    return new MetadataImmortalCacheValue(value, metadata);
}
Also used : MetadataImmortalCacheValue(org.infinispan.container.entries.metadata.MetadataImmortalCacheValue) Metadata(org.infinispan.metadata.Metadata)

Aggregations

MetadataImmortalCacheValue (org.infinispan.container.entries.metadata.MetadataImmortalCacheValue)3 Metadata (org.infinispan.metadata.Metadata)3 EmbeddedMetadata (org.infinispan.metadata.EmbeddedMetadata)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionStage (java.util.concurrent.CompletionStage)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Stream (java.util.stream.Stream)1 AbstractVisitor (org.infinispan.commands.AbstractVisitor)1 FlagAffectedCommand (org.infinispan.commands.FlagAffectedCommand)1 MetadataAwareCommand (org.infinispan.commands.MetadataAwareCommand)1