Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore keys with TTL #125

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<byte[]>, KeyValue<byte[]>> {
@Override
public KeyValue<byte[]> process( KeyValue<byte[]> item) throws Exception {
if ( item.getTtl() > 0L ) {
return null;
}
return item;
}
}
7 changes: 6 additions & 1 deletion plugins/riot/src/main/java/com/redis/riot/cli/Replicate.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<byte[]>, KeyValue<byte[]>> scanStep(ReplicateCommandContext context) {
Expand Down Expand Up @@ -263,6 +265,9 @@ private ItemProcessor<KeyValue<byte[]>, KeyValue<byte[]>> 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]));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class ReplicateOptions {
@Option(names = "--ttl-tolerance", description = "Max TTL difference to use for dataset verification (default: ${DEFAULT-VALUE}).", paramLabel = "<ms>")
private long ttlTolerance = KeyComparisonItemReader.DEFAULT_TTL_TOLERANCE.toMillis();

@Option(names = "--ignore-ttl-keys", description = "Ignore keys with TTL (default: false)", paramLabel = "<bool>")
private boolean ignoreKeysWithTtl = false;

@Option(names = "--show-diffs", description = "Print details of key mismatches during dataset verification. Disables progress reporting.")
private boolean showDiffs;

Expand Down Expand Up @@ -151,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();
}
Expand Down