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;
}
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);
}
}
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;
}
Aggregations