Source:
<code>protected final BasicInvocationStage handleNonTxWriteCommand(InvocationContext ctx, AbstractDataWriteCommand command) throws Throwable { if (ctx.isInTxScope()) { throw new CacheException("Attempted execution of non-transactional write command in a transactional invocation context"); } Object key = command.getKey(); CacheEntry entry = ctx.lookupEntry(key); if (entry == null) { if (isLocalModeForced(command)) { entryFactory.wrapExternalEntry(ctx, key, null, true, true); return invokeNext(ctx, command); } else { DistributionInfo info = new DistributionInfo(key, checkTopologyId(command).getWriteConsistentHash(), rpcManager.getAddress()); boolean load = shouldLoad(ctx, command, info); if (info.isPrimary()) { if (load) { CompletableFuture<?> getFuture = remoteGet(ctx, command, true); return invokeNextAsync(ctx, command, getFuture).thenCompose(this::primaryReturnHandler); } else { entryFactory.wrapExternalEntry(ctx, command, null, true, true); return invokeNext(ctx, command).thenCompose(this::primaryReturnHandler); } } else if (ctx.isOriginLocal()) { return invokeRemotely(command, info.primary()); } else { if (load) { CompletableFuture<?> getFuture = remoteGet(ctx, command, true); return invokeNextAsync(ctx, command, getFuture); } else { entryFactory.wrapExternalEntry(ctx, key, null, true, true); return invokeNext(ctx, command); } } } <START> } else if (command.hasFlag(Flag.CACHE_MODE_LOCAL)) { <END> return invokeNext(ctx, command); } else { DistributionInfo info = new DistributionInfo(key, checkTopologyId(command).getWriteConsistentHash(), rpcManager.getAddress()); if (info.isPrimary()) { return invokeNext(ctx, command).thenCompose(this::primaryReturnHandler); } else if (ctx.isOriginLocal()) { return invokeRemotely(command, info.primary()); } else { return invokeNext(ctx, command); } } }</code><technical_language>this more symmetrical entry == null branch, check for CACHE_MODE_LOCAL first</technical_language>

Target:
protected final BasicInvocationStage handleNonTxWriteCommand(InvocationContext ctx, AbstractDataWriteCommand command) throws Throwable { Object key = command.getKey(); CacheEntry entry = ctx.lookupEntry(key); if (isLocalModeForced(command)) { if (entry == null) { entryFactory.wrapExternalEntry(ctx, key, null, true); } return invokeNext(ctx, command); } if (entry == null) { DistributionInfo info = new DistributionInfo(key, checkTopologyId(command).getWriteConsistentHash(), rpcManager.getAddress()); boolean load = shouldLoad(ctx, command, info); if (info.isPrimary()) { throw new IllegalStateException("Primary owner in writeCH should always be an owner in readCH as well."); } else if (ctx.isOriginLocal()) { return invokeRemotely(command, info.primary()); } else { if (load) { CompletableFuture<?> getFuture = remoteGet(ctx, command, command.getKey(), true); return invokeNextAsync(ctx, command, getFuture); } else { entryFactory.wrapExternalEntry(ctx, key, null, true); return invokeNext(ctx, command); } } } else { DistributionInfo info = new DistributionInfo(key, checkTopologyId(command).getWriteConsistentHash(), rpcManager.getAddress()); if (info.isPrimary()) { return invokeNext(ctx, command).thenCompose(this::primaryReturnHandler); } else if (ctx.isOriginLocal()) { return invokeRemotely(command, info.primary()); } else { return invokeNext(ctx, command); } } }