From b3f28b6130729266342b2c90015c7f0f7b7f6161 Mon Sep 17 00:00:00 2001 From: raghu nandan Date: Sat, 5 Aug 2023 23:15:42 +0530 Subject: [PATCH 1/2] Ignore keys with TTL --- .../core/processor/IgnoreKeysWithTTLProcessor.java | 14 ++++++++++++++ .../main/java/com/redis/riot/cli/Replicate.java | 7 ++++++- .../redis/riot/cli/common/ReplicateOptions.java | 11 +++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 core/riot-core/src/main/java/com/redis/riot/core/processor/IgnoreKeysWithTTLProcessor.java diff --git a/core/riot-core/src/main/java/com/redis/riot/core/processor/IgnoreKeysWithTTLProcessor.java b/core/riot-core/src/main/java/com/redis/riot/core/processor/IgnoreKeysWithTTLProcessor.java new file mode 100644 index 000000000..a167d72eb --- /dev/null +++ b/core/riot-core/src/main/java/com/redis/riot/core/processor/IgnoreKeysWithTTLProcessor.java @@ -0,0 +1,14 @@ +package com.redis.riot.core.processor; + +import com.redis.spring.batch.common.KeyValue; +import org.springframework.batch.item.ItemProcessor; + +public class IgnoreKeysWithTTLProcessor implements ItemProcessor, KeyValue> { + @Override + public KeyValue process( KeyValue item) throws Exception { + if ( item.getTtl() > 0L ) { + return null; + } + return item; + } +} diff --git a/plugins/riot/src/main/java/com/redis/riot/cli/Replicate.java b/plugins/riot/src/main/java/com/redis/riot/cli/Replicate.java index 06ee4d07b..1b85150fe 100644 --- a/plugins/riot/src/main/java/com/redis/riot/cli/Replicate.java +++ b/plugins/riot/src/main/java/com/redis/riot/cli/Replicate.java @@ -7,6 +7,7 @@ import java.util.concurrent.BlockingQueue; import java.util.logging.Logger; +import com.redis.riot.core.processor.IgnoreKeysWithTTLProcessor; import org.springframework.batch.core.Job; import org.springframework.batch.core.job.builder.FlowBuilder; import org.springframework.batch.core.job.builder.JobFlowBuilder; @@ -167,7 +168,8 @@ private Job liveJob(ReplicateCommandContext context) { private boolean shouldCompare() { return !replicateOptions.isNoVerify() && !writerOptions.isDryRun() - && !replicateOptions.getKeyProcessor().isPresent(); + && !replicateOptions.getKeyProcessor().isPresent() + && !replicateOptions.isIgnoreKeysWithTtl(); } private SimpleStepBuilder, KeyValue> scanStep(ReplicateCommandContext context) { @@ -263,6 +265,9 @@ private ItemProcessor, KeyValue> processor(ReplicateCom Expression expression = parser.parseExpression(p); processors.add(new KeyValueProcessor(expression, evaluationContext)); }); + if (replicateOptions.isIgnoreKeysWithTtl()) { + processors.add(new IgnoreKeysWithTTLProcessor()); + } return CompositeItemStreamItemProcessor.delegates(processors.toArray(new ItemProcessor[0])); } diff --git a/plugins/riot/src/main/java/com/redis/riot/cli/common/ReplicateOptions.java b/plugins/riot/src/main/java/com/redis/riot/cli/common/ReplicateOptions.java index fae3f16c2..92214a14c 100644 --- a/plugins/riot/src/main/java/com/redis/riot/cli/common/ReplicateOptions.java +++ b/plugins/riot/src/main/java/com/redis/riot/cli/common/ReplicateOptions.java @@ -36,6 +36,17 @@ public class ReplicateOptions { @Option(names = "--ttl-tolerance", description = "Max TTL difference to use for dataset verification (default: ${DEFAULT-VALUE}).", paramLabel = "") private long ttlTolerance = KeyComparisonItemReader.DEFAULT_TTL_TOLERANCE.toMillis(); + public boolean isIgnoreKeysWithTtl() { + return ignoreKeysWithTtl; + } + + public void setIgnoreKeysWithTtl(boolean ignoreKeysWithTtl) { + this.ignoreKeysWithTtl = ignoreKeysWithTtl; + } + + @Option(names = "--ignore-ttl-keys", description = "Ignore keys with TTL (default: false)", paramLabel = "") + private boolean ignoreKeysWithTtl = false; + @Option(names = "--show-diffs", description = "Print details of key mismatches during dataset verification. Disables progress reporting.") private boolean showDiffs; From 875e42037bbadeaece67c4b77cd2847a7abe4b69 Mon Sep 17 00:00:00 2001 From: raghu nandan Date: Mon, 7 Aug 2023 09:50:02 +0530 Subject: [PATCH 2/2] Formatting --- .../redis/riot/cli/common/ReplicateOptions.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/plugins/riot/src/main/java/com/redis/riot/cli/common/ReplicateOptions.java b/plugins/riot/src/main/java/com/redis/riot/cli/common/ReplicateOptions.java index 92214a14c..127e14119 100644 --- a/plugins/riot/src/main/java/com/redis/riot/cli/common/ReplicateOptions.java +++ b/plugins/riot/src/main/java/com/redis/riot/cli/common/ReplicateOptions.java @@ -36,14 +36,6 @@ public class ReplicateOptions { @Option(names = "--ttl-tolerance", description = "Max TTL difference to use for dataset verification (default: ${DEFAULT-VALUE}).", paramLabel = "") private long ttlTolerance = KeyComparisonItemReader.DEFAULT_TTL_TOLERANCE.toMillis(); - public boolean isIgnoreKeysWithTtl() { - return ignoreKeysWithTtl; - } - - public void setIgnoreKeysWithTtl(boolean ignoreKeysWithTtl) { - this.ignoreKeysWithTtl = ignoreKeysWithTtl; - } - @Option(names = "--ignore-ttl-keys", description = "Ignore keys with TTL (default: false)", paramLabel = "") private boolean ignoreKeysWithTtl = false; @@ -162,6 +154,15 @@ public void setShowDiffs(boolean showDiffs) { this.showDiffs = showDiffs; } + + public boolean isIgnoreKeysWithTtl() { + return ignoreKeysWithTtl; + } + + public void setIgnoreKeysWithTtl(boolean ignoreKeysWithTtl) { + this.ignoreKeysWithTtl = ignoreKeysWithTtl; + } + public PoolOptions targetPoolOptions() { return PoolOptions.builder().maxTotal(targetPoolMaxTotal).build(); }