From 76277638359da6b48ca1310aedd8ca15cafc6f4c Mon Sep 17 00:00:00 2001 From: William Burns Date: Wed, 3 Oct 2018 16:55:05 -0400 Subject: [PATCH] rework_comments --- .../java/org/infinispan/cache/impl/CacheImpl.java | 7 +++---- .../org/infinispan/commands/CommandsFactory.java | 6 ++++-- .../infinispan/commands/CommandsFactoryImpl.java | 13 +++++++------ .../triangle/SingleKeyBackupWriteCommand.java | 6 ++++-- .../commands/write/RemoveExpiredCommand.java | 10 ++-------- .../infinispan/container/impl/EntryFactoryImpl.java | 4 ++-- .../distribution/BaseDistributionInterceptor.java | 3 ++- .../locking/NonTransactionalLockingInterceptor.java | 6 ------ .../util/mocks/ControlledCommandFactory.java | 9 +++++---- 9 files changed, 29 insertions(+), 35 deletions(-) diff --git a/core/src/main/java/org/infinispan/cache/impl/CacheImpl.java b/core/src/main/java/org/infinispan/cache/impl/CacheImpl.java index 24d371323971..1e56ad74331d 100644 --- a/core/src/main/java/org/infinispan/cache/impl/CacheImpl.java +++ b/core/src/main/java/org/infinispan/cache/impl/CacheImpl.java @@ -689,8 +689,7 @@ public CompletableFuture removeLifespanExpired(K key, V value, Long lifesp final CompletableFuture 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 completableFuture = performRemoveExpiredCommand(command); @@ -703,8 +702,8 @@ public CompletableFuture removeMaxIdleExpired(K key, V value) { } final CompletableFuture 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); } diff --git a/core/src/main/java/org/infinispan/commands/CommandsFactory.java b/core/src/main/java/org/infinispan/commands/CommandsFactory.java index d8f1ab47b4fe..118b8d410d11 100644 --- a/core/src/main/java/org/infinispan/commands/CommandsFactory.java +++ b/core/src/main/java/org/infinispan/commands/CommandsFactory.java @@ -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. diff --git a/core/src/main/java/org/infinispan/commands/CommandsFactoryImpl.java b/core/src/main/java/org/infinispan/commands/CommandsFactoryImpl.java index 3441b66e3a26..e50ce10a44eb 100644 --- a/core/src/main/java/org/infinispan/commands/CommandsFactoryImpl.java +++ b/core/src/main/java/org/infinispan/commands/CommandsFactoryImpl.java @@ -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 diff --git a/core/src/main/java/org/infinispan/commands/triangle/SingleKeyBackupWriteCommand.java b/core/src/main/java/org/infinispan/commands/triangle/SingleKeyBackupWriteCommand.java index 1e73f62168e7..7716ed5b573c 100644 --- a/core/src/main/java/org/infinispan/commands/triangle/SingleKeyBackupWriteCommand.java +++ b/core/src/main/java/org/infinispan/commands/triangle/SingleKeyBackupWriteCommand.java @@ -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; @@ -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; @@ -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); diff --git a/core/src/main/java/org/infinispan/commands/write/RemoveExpiredCommand.java b/core/src/main/java/org/infinispan/commands/write/RemoveExpiredCommand.java index 48ed24708c69..0299f1072e2d 100644 --- a/core/src/main/java/org/infinispan/commands/write/RemoveExpiredCommand.java +++ b/core/src/main/java/org/infinispan/commands/write/RemoveExpiredCommand.java @@ -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; @@ -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 diff --git a/core/src/main/java/org/infinispan/container/impl/EntryFactoryImpl.java b/core/src/main/java/org/infinispan/container/impl/EntryFactoryImpl.java index db275afa1fb8..b015560e871f 100644 --- a/core/src/main/java/org/infinispan/container/impl/EntryFactoryImpl.java +++ b/core/src/main/java/org/infinispan/container/impl/EntryFactoryImpl.java @@ -211,7 +211,7 @@ 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) { @@ -219,7 +219,7 @@ private CacheEntry getFromContainerForWrite(Object key, int segment, boolean isO } 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; diff --git a/core/src/main/java/org/infinispan/interceptors/distribution/BaseDistributionInterceptor.java b/core/src/main/java/org/infinispan/interceptors/distribution/BaseDistributionInterceptor.java index 1cc02203f079..2cbaf82ee6f3 100644 --- a/core/src/main/java/org/infinispan/interceptors/distribution/BaseDistributionInterceptor.java +++ b/core/src/main/java/org/infinispan/interceptors/distribution/BaseDistributionInterceptor.java @@ -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; diff --git a/core/src/main/java/org/infinispan/interceptors/locking/NonTransactionalLockingInterceptor.java b/core/src/main/java/org/infinispan/interceptors/locking/NonTransactionalLockingInterceptor.java index 4e95dc28cdb8..3317a4db0e83 100644 --- a/core/src/main/java/org/infinispan/interceptors/locking/NonTransactionalLockingInterceptor.java +++ b/core/src/main/java/org/infinispan/interceptors/locking/NonTransactionalLockingInterceptor.java @@ -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; @@ -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); diff --git a/core/src/test/java/org/infinispan/util/mocks/ControlledCommandFactory.java b/core/src/test/java/org/infinispan/util/mocks/ControlledCommandFactory.java index 5e7a43f1ad8a..8348ab5cc411 100644 --- a/core/src/test/java/org/infinispan/util/mocks/ControlledCommandFactory.java +++ b/core/src/test/java/org/infinispan/util/mocks/ControlledCommandFactory.java @@ -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