Skip to content

Commit

Permalink
rework_comments
Browse files Browse the repository at this point in the history
  • Loading branch information
wburns committed Oct 3, 2018
1 parent 7364824 commit 7627763
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 35 deletions.
7 changes: 3 additions & 4 deletions core/src/main/java/org/infinispan/cache/impl/CacheImpl.java
Expand Up @@ -689,8 +689,7 @@ public CompletableFuture<Void> removeLifespanExpired(K key, V value, Long lifesp

final CompletableFuture<Void> removeLifespanExpired(K key, V value, Long lifespan, long explicitFlags) {
RemoveExpiredCommand command = commandsFactory.buildRemoveExpiredCommand(key, value, keyPartitioner.getSegment(key),
lifespan);
command.setFlagsBitSet(explicitFlags);
lifespan, explicitFlags | FlagBitSets.SKIP_CACHE_LOAD);
// Remove expired returns a boolean - just ignore it, the caller just needs to know that the expired
// entry is removed when this completes
CompletableFuture<Boolean> completableFuture = performRemoveExpiredCommand(command);
Expand All @@ -703,8 +702,8 @@ public CompletableFuture<Boolean> removeMaxIdleExpired(K key, V value) {
}

final CompletableFuture<Boolean> removeMaxIdleExpired(K key, V value, long explicitFlags) {
RemoveExpiredCommand command = commandsFactory.buildRemoveExpiredCommand(key, value, keyPartitioner.getSegment(key));
command.setFlagsBitSet(explicitFlags);
RemoveExpiredCommand command = commandsFactory.buildRemoveExpiredCommand(key, value, keyPartitioner.getSegment(key),
explicitFlags | FlagBitSets.SKIP_CACHE_LOAD);
return performRemoveExpiredCommand(command);
}

Expand Down
Expand Up @@ -161,18 +161,20 @@ public interface CommandsFactory {
* @param value the value of the entry when it was expired
* @param segment the segment of the given key
* @param lifespan the lifespan that expired from the command
* @param flagsBitSet Command flags provided by cache
* @return a RemovedExpiredCommand
*/
RemoveExpiredCommand buildRemoveExpiredCommand(Object key, Object value, int segment, Long lifespan);
RemoveExpiredCommand buildRemoveExpiredCommand(Object key, Object value, int segment, Long lifespan, long flagsBitSet);

/**
* Builds an expired remove command that is used to remove only a specific entry when it expires via maxIdle
* @param key the key of the expired entry
* @param value the value of the entry when it was expired
* @param segment the segment of the given key
* @param flagsBitSet Command flags provided by cache
* @return a RemovedExpiredCommand
*/
RemoveExpiredCommand buildRemoveExpiredCommand(Object key, Object value, int segment);
RemoveExpiredCommand buildRemoveExpiredCommand(Object key, Object value, int segment, long flagsBitSet);

/**
* Builds a retrieve max idle command that is used to get the last access time for a given key.
Expand Down
Expand Up @@ -251,15 +251,16 @@ public InvalidateCommand buildInvalidateFromL1Command(Address origin, long flags
}

@Override
public RemoveExpiredCommand buildRemoveExpiredCommand(Object key, Object value, int segment, Long lifespan) {
return new RemoveExpiredCommand(key, value, lifespan, false, notifier, segment, generateUUID(transactional),
versionGenerator.nonExistingVersion(), timeService);
public RemoveExpiredCommand buildRemoveExpiredCommand(Object key, Object value, int segment, Long lifespan,
long flagsBitSet) {
return new RemoveExpiredCommand(key, value, lifespan, false, notifier, segment, flagsBitSet,
generateUUID(transactional), versionGenerator.nonExistingVersion(), timeService);
}

@Override
public RemoveExpiredCommand buildRemoveExpiredCommand(Object key, Object value, int segment) {
return new RemoveExpiredCommand(key, value, null, true, notifier, segment, generateUUID(transactional),
versionGenerator.nonExistingVersion(), timeService);
public RemoveExpiredCommand buildRemoveExpiredCommand(Object key, Object value, int segment, long flagsBitSet) {
return new RemoveExpiredCommand(key, value, null, true, notifier, segment, flagsBitSet,
generateUUID(transactional), versionGenerator.nonExistingVersion(), timeService);
}

@Override
Expand Down
Expand Up @@ -120,6 +120,7 @@ public void writeTo(ObjectOutput output) throws IOException {
case REPLACE:
case WRITE:
output.writeObject(metadata);
// falls through
case REMOVE_EXPIRED:
output.writeObject(valueOrFunction);
break;
Expand All @@ -141,6 +142,7 @@ public void readFrom(ObjectInput input) throws IOException, ClassNotFoundExcepti
case REPLACE:
case WRITE:
metadata = (Metadata) input.readObject();
// falls through
case REMOVE_EXPIRED:
valueOrFunction = input.readObject();
break;
Expand Down Expand Up @@ -171,8 +173,8 @@ WriteCommand createWriteCommand() {
getCommandInvocationId());
case REMOVE_EXPIRED:
// Doesn't matter if it is max idle or not - important thing is that it raises expired event
return new RemoveExpiredCommand(key, valueOrFunction, null, false, cacheNotifier, segmentId, getCommandInvocationId(),
versionGenerator.nonExistingVersion(), componentRegistry.getTimeService());
return new RemoveExpiredCommand(key, valueOrFunction, null, false, cacheNotifier, segmentId, getFlags(),
getCommandInvocationId(), versionGenerator.nonExistingVersion(), componentRegistry.getTimeService());
case COMPUTE_IF_PRESENT:
return new ComputeCommand(key, (BiFunction) valueOrFunction, true, segmentId, getFlags(), getCommandInvocationId(),
metadata, cacheNotifier, componentRegistry);
Expand Down
Expand Up @@ -48,10 +48,10 @@ public RemoveExpiredCommand() {
}

public RemoveExpiredCommand(Object key, Object value, Long lifespan, boolean maxIdle, CacheNotifier notifier, int segment,
CommandInvocationId commandInvocationId, IncrementableEntryVersion nonExistentVersion,
long flagBitSet, CommandInvocationId commandInvocationId, IncrementableEntryVersion nonExistentVersion,
TimeService timeService) {
//valueEquivalence can be null because this command never compares values.
super(key, value, notifier, segment, EnumUtil.EMPTY_BIT_SET, commandInvocationId);
super(key, value, notifier, segment, flagBitSet, commandInvocationId);
this.lifespan = lifespan;
this.maxIdle = maxIdle;
this.valueMatcher = ValueMatcher.MATCH_EXPECTED_OR_NULL;
Expand Down Expand Up @@ -194,12 +194,6 @@ public int hashCode() {
return Objects.hash(super.hashCode(), lifespan, maxIdle);
}

@Override
public long getFlagsBitSet() {
// Override the flags to always include skip cache load
return flags | FlagBitSets.SKIP_CACHE_LOAD;
}

/**
* Whether this remove expired was fired because of max idle
* @return if this command is max idle based expiration
Expand Down
Expand Up @@ -211,15 +211,15 @@ private boolean isPrimaryOwner(boolean isOwner, int segment) {

private CacheEntry getFromContainerForWrite(Object key, int segment, boolean isOwner) {
if (isOwner) {
final InternalCacheEntry ice = innerGetFromContainer(key, segment, false, isPrimaryOwner(isOwner, segment));
final InternalCacheEntry ice = innerGetFromContainer(key, segment, false, isPrimaryOwner(true, segment));
if (trace)
log.tracef("Retrieved from container %s", ice);
if (ice == null) {
return NullCacheEntry.getInstance();
}
return ice;
} else if (isL1Enabled) {
final InternalCacheEntry ice = innerGetFromContainer(key, segment, false, isPrimaryOwner(isOwner, segment));
final InternalCacheEntry ice = innerGetFromContainer(key, segment, false, false);
if (trace)
log.tracef("Retrieved from container %s", ice);
if (ice == null || !ice.isL1Entry()) return null;
Expand Down
Expand Up @@ -1034,7 +1034,8 @@ public Object visitRemoveExpiredCommand(InvocationContext ctx, RemoveExpiredComm
if (!ctx.isOriginLocal()) {
// Have to build a new command since the command id points to the originating node - causes
// issues with triangle since it needs to know the originating node to respond to
realRemoveCommand = cf.buildRemoveExpiredCommand(key, command.getValue(), segment);
realRemoveCommand = cf.buildRemoveExpiredCommand(key, command.getValue(), segment,
command.getFlagsBitSet());
realRemoveCommand.setTopologyId(cacheTopology.getTopologyId());
} else {
realRemoveCommand = command;
Expand Down
Expand Up @@ -7,7 +7,6 @@
import org.infinispan.commands.DataCommand;
import org.infinispan.commands.FlagAffectedCommand;
import org.infinispan.commands.write.DataWriteCommand;
import org.infinispan.commands.write.RemoveExpiredCommand;
import org.infinispan.commands.write.WriteCommand;
import org.infinispan.context.InvocationContext;
import org.infinispan.util.concurrent.locks.KeyAwareLockPromise;
Expand Down Expand Up @@ -41,11 +40,6 @@ protected Object visitDataWriteCommand(InvocationContext ctx, DataWriteCommand c
return visitNonTxDataWriteCommand(ctx, command);
}

@Override
public Object visitRemoveExpiredCommand(InvocationContext ctx, RemoveExpiredCommand command) throws Throwable {
return super.visitRemoveExpiredCommand(ctx, command);
}

@Override
protected Object handleReadManyCommand(InvocationContext ctx, FlagAffectedCommand command, Collection<?> keys) {
assertNonTransactional(ctx);
Expand Down
Expand Up @@ -196,13 +196,14 @@ public InvalidateCommand buildInvalidateFromL1Command(Address origin, long flags
}

@Override
public RemoveExpiredCommand buildRemoveExpiredCommand(Object key, Object value, int segment, Long lifespan) {
return actual.buildRemoveExpiredCommand(key, value, segment, lifespan);
public RemoveExpiredCommand buildRemoveExpiredCommand(Object key, Object value, int segment, Long lifespan,
long flagsBitSet) {
return actual.buildRemoveExpiredCommand(key, value, segment, lifespan, flagsBitSet);
}

@Override
public RemoveExpiredCommand buildRemoveExpiredCommand(Object key, Object value, int segment) {
return actual.buildRemoveExpiredCommand(key, value, segment);
public RemoveExpiredCommand buildRemoveExpiredCommand(Object key, Object value, int segment, long flagsBitSet) {
return actual.buildRemoveExpiredCommand(key, value, segment, flagsBitSet);
}

@Override
Expand Down

0 comments on commit 7627763

Please sign in to comment.