Search in sources :

Example 1 with RemoveExpiredCommand

use of org.infinispan.commands.write.RemoveExpiredCommand in project infinispan by infinispan.

the class SingleKeyBackupWriteCommand method createWriteCommand.

@Override
WriteCommand createWriteCommand() {
    DataWriteCommand command;
    switch(operation) {
        case REMOVE:
            command = new RemoveCommand(key, null, segmentId, getFlags(), getCommandInvocationId());
            break;
        case WRITE:
            command = EnumUtil.containsAny(getFlags(), FlagBitSets.IRAC_UPDATE) ? new IracPutKeyValueCommand(key, segmentId, getCommandInvocationId(), valueOrFunction, metadata, internalMetadata) : new PutKeyValueCommand(key, valueOrFunction, false, metadata, segmentId, getFlags(), getCommandInvocationId());
            break;
        case COMPUTE:
            command = new ComputeCommand(key, (BiFunction) valueOrFunction, false, segmentId, getFlags(), getCommandInvocationId(), metadata);
            break;
        case REPLACE:
            command = new ReplaceCommand(key, null, valueOrFunction, metadata, segmentId, getFlags(), getCommandInvocationId());
            break;
        case REMOVE_EXPIRED:
            // Doesn't matter if it is max idle or not - important thing is that it raises expired event
            command = new RemoveExpiredCommand(key, valueOrFunction, null, false, segmentId, getFlags(), getCommandInvocationId());
            break;
        case COMPUTE_IF_PRESENT:
            command = new ComputeCommand(key, (BiFunction) valueOrFunction, true, segmentId, getFlags(), getCommandInvocationId(), metadata);
            break;
        case COMPUTE_IF_ABSENT:
            command = new ComputeIfAbsentCommand(key, (Function) valueOrFunction, segmentId, getFlags(), getCommandInvocationId(), metadata);
            break;
        default:
            throw new IllegalStateException("Unknown operation " + operation);
    }
    command.setInternalMetadata(internalMetadata);
    return command;
}
Also used : RemoveCommand(org.infinispan.commands.write.RemoveCommand) ComputeCommand(org.infinispan.commands.write.ComputeCommand) BiFunction(java.util.function.BiFunction) Function(java.util.function.Function) DataWriteCommand(org.infinispan.commands.write.DataWriteCommand) BiFunction(java.util.function.BiFunction) ReplaceCommand(org.infinispan.commands.write.ReplaceCommand) RemoveExpiredCommand(org.infinispan.commands.write.RemoveExpiredCommand) ComputeIfAbsentCommand(org.infinispan.commands.write.ComputeIfAbsentCommand) IracPutKeyValueCommand(org.infinispan.commands.write.IracPutKeyValueCommand) IracPutKeyValueCommand(org.infinispan.commands.write.IracPutKeyValueCommand) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand)

Example 2 with RemoveExpiredCommand

use of org.infinispan.commands.write.RemoveExpiredCommand in project infinispan by infinispan.

the class AbstractIracLocalSiteInterceptor method visitNonTxKey.

/**
 * Visits the {@link WriteCommand} before executing it.
 * <p>
 * The primary owner generates a new {@link IracMetadata} and stores it in the {@link WriteCommand}.
 */
protected void visitNonTxKey(InvocationContext ctx, Object key, WriteCommand command) {
    int segment = getSegment(command, key);
    if (getOwnership(segment) != Ownership.PRIMARY) {
        return;
    }
    Optional<IracMetadata> entryMetadata = IracUtils.findIracMetadataFromCacheEntry(ctx.lookupEntry(key));
    IracMetadata metadata;
    // RemoveExpired should lose to any other conflicting write
    if (command instanceof RemoveExpiredCommand) {
        metadata = entryMetadata.orElseGet(() -> iracVersionGenerator.generateMetadataWithCurrentVersion(segment));
    } else {
        IracEntryVersion versionSeen = entryMetadata.map(IracMetadata::getVersion).orElse(null);
        metadata = iracVersionGenerator.generateNewMetadata(segment, versionSeen);
    }
    updateCommandMetadata(key, command, metadata);
    if (log.isTraceEnabled()) {
        log.tracef("[IRAC] New metadata for key '%s' is %s. Command=%s", key, metadata, command);
    }
}
Also used : IracEntryVersion(org.infinispan.container.versioning.irac.IracEntryVersion) IracUtils.setIracMetadata(org.infinispan.util.IracUtils.setIracMetadata) IracMetadata(org.infinispan.metadata.impl.IracMetadata) RemoveExpiredCommand(org.infinispan.commands.write.RemoveExpiredCommand)

Example 3 with RemoveExpiredCommand

use of org.infinispan.commands.write.RemoveExpiredCommand in project infinispan by infinispan.

the class NotifyHelper method entryCommitted.

public static CompletionStage<Void> entryCommitted(CacheNotifier notifier, FunctionalNotifier functionalNotifier, boolean created, boolean removed, boolean expired, CacheEntry entry, InvocationContext ctx, FlagAffectedCommand command, Object previousValue, Metadata previousMetadata, EvictionManager evictionManager) {
    // We only notify if there is no state transfer flag
    if (FlagBitSets.extractStateTransferFlag(ctx, command) != null) {
        return CompletableFutures.completedNull();
    }
    CompletionStage<Void> stage;
    boolean isWriteOnly = (command instanceof WriteCommand) && ((WriteCommand) command).isWriteOnly();
    if (removed) {
        if (command instanceof RemoveExpiredCommand) {
            // It is possible this command was generated from a store and the value is not in memory, thus we have
            // to fall back to the command value and metadata if not present
            Object expiredValue = previousValue != null ? previousValue : ((RemoveExpiredCommand) command).getValue();
            Metadata expiredMetadata = entry.getMetadata() != null ? entry.getMetadata() : ((RemoveExpiredCommand) command).getMetadata();
            stage = notifier.notifyCacheEntryExpired(entry.getKey(), expiredValue, expiredMetadata, ctx);
        } else if (command instanceof EvictCommand) {
            stage = evictionManager.onEntryEviction(Collections.singletonMap(entry.getKey(), entry), command);
        } else if (command instanceof RemoveCommand) {
            stage = notifier.notifyCacheEntryRemoved(entry.getKey(), previousValue, entry.getMetadata(), false, ctx, command);
        } else if (command instanceof InvalidateCommand) {
            stage = notifier.notifyCacheEntryInvalidated(entry.getKey(), previousValue, entry.getMetadata(), false, ctx, command);
        } else {
            if (expired) {
                stage = notifier.notifyCacheEntryExpired(entry.getKey(), previousValue, previousMetadata, ctx);
            } else {
                stage = notifier.notifyCacheEntryRemoved(entry.getKey(), previousValue, previousMetadata, false, ctx, command);
            }
            // send remove event when the command is read-write.
            if (!isWriteOnly)
                functionalNotifier.notifyOnRemove(EntryViews.readOnly(entry.getKey(), previousValue, previousMetadata));
            functionalNotifier.notifyOnWriteRemove(entry.getKey());
        }
    } else {
        // Notify entry event after container has been updated
        if (created) {
            stage = notifier.notifyCacheEntryCreated(entry.getKey(), entry.getValue(), entry.getMetadata(), false, ctx, command);
            // when the command is read-write.
            if (!isWriteOnly)
                functionalNotifier.notifyOnCreate(entry);
            functionalNotifier.notifyOnWrite(entry);
        } else {
            stage = notifier.notifyCacheEntryModified(entry.getKey(), entry.getValue(), entry.getMetadata(), previousValue, previousMetadata, false, ctx, command);
            // command is read-write.
            if (!isWriteOnly)
                functionalNotifier.notifyOnModify(entry, previousValue, previousMetadata);
            functionalNotifier.notifyOnWrite(entry);
        }
    }
    return stage;
}
Also used : WriteCommand(org.infinispan.commands.write.WriteCommand) RemoveCommand(org.infinispan.commands.write.RemoveCommand) Metadata(org.infinispan.metadata.Metadata) RemoveExpiredCommand(org.infinispan.commands.write.RemoveExpiredCommand) EvictCommand(org.infinispan.commands.write.EvictCommand) InvalidateCommand(org.infinispan.commands.write.InvalidateCommand)

Aggregations

RemoveExpiredCommand (org.infinispan.commands.write.RemoveExpiredCommand)3 RemoveCommand (org.infinispan.commands.write.RemoveCommand)2 BiFunction (java.util.function.BiFunction)1 Function (java.util.function.Function)1 ComputeCommand (org.infinispan.commands.write.ComputeCommand)1 ComputeIfAbsentCommand (org.infinispan.commands.write.ComputeIfAbsentCommand)1 DataWriteCommand (org.infinispan.commands.write.DataWriteCommand)1 EvictCommand (org.infinispan.commands.write.EvictCommand)1 InvalidateCommand (org.infinispan.commands.write.InvalidateCommand)1 IracPutKeyValueCommand (org.infinispan.commands.write.IracPutKeyValueCommand)1 PutKeyValueCommand (org.infinispan.commands.write.PutKeyValueCommand)1 ReplaceCommand (org.infinispan.commands.write.ReplaceCommand)1 WriteCommand (org.infinispan.commands.write.WriteCommand)1 IracEntryVersion (org.infinispan.container.versioning.irac.IracEntryVersion)1 Metadata (org.infinispan.metadata.Metadata)1 IracMetadata (org.infinispan.metadata.impl.IracMetadata)1 IracUtils.setIracMetadata (org.infinispan.util.IracUtils.setIracMetadata)1