Skip to content

Commit

Permalink
Another option for polymorphic repair()
Browse files Browse the repository at this point in the history
  • Loading branch information
Miles-Garnsey committed Aug 22, 2023
1 parent e84942f commit 975be5d
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package com.datastax.mgmtapi;

import com.datastax.mgmtapi.models.RingRange;
import com.datastax.mgmtapi.rpc.Rpc;
import com.datastax.mgmtapi.rpc.RpcParam;
import com.datastax.mgmtapi.rpc.RpcRegistry;
Expand Down Expand Up @@ -734,6 +735,8 @@ public void clearSnapshots(
}
}

// This version of repair takes beginToken and endToken, which does not allow for non-contiguous ranges to be repaired under
// a single run.
@Rpc(name = "repair")
public void repair(
@RpcParam(name = "keyspaceName") String keyspace,
Expand All @@ -743,29 +746,56 @@ public void repair(
@RpcParam(name = "endToken") BigInteger endToken,
@RpcParam(name = "repairParallelism") RepairParallelism repairParallelism,
@RpcParam(name = "datacenters") Collection<String> datacenters,
@RpcParam(name = "repairThreadCount") int repairThreadCount)
throws IOException {
// At least one keyspace is required
assert(keyspace != null);
Map<String, String> options = new HashMap<>();
options.put(RepairOption.PARALLELISM_KEY, repairParallelism.getName());
options.put(RepairOption.INCREMENTAL_KEY, Boolean.toString(!full));
options.put(
RepairOption.JOB_THREADS_KEY,
Integer.toString(repairThreadCount == 0 ? 1 : repairThreadCount));
options.put(RepairOption.TRACE_KEY, Boolean.toString(Boolean.FALSE));
options.put(RepairOption.COLUMNFAMILIES_KEY, StringUtils.join(tables, ","));
if (full) {
options.put(
RepairOption.RANGES_KEY, StringUtils.join(beginToken + ":" + endToken)
);
}

}

// This version of repair() takes a list of RingRange objects instead of begin/end tokens.
@Rpc(name = "repair")
public void repair(
@RpcParam(name = "keyspaceName") String keyspace,
@RpcParam(name = "tables") List<String> tables,
@RpcParam(name = "full") Boolean full,
@RpcParam(name = "repairParallelism") RepairParallelism repairParallelism,
@RpcParam(name = "datacenters") Collection<String> datacenters,
@RpcParam(name = "associatedTokens") List<RingRange> associatedTokens,
@RpcParam(name = "repairThreadCount") int repairThreadCount)
throws IOException {
// At least one keyspace is required
if (keyspace != null) {
Map<String, String> options = new HashMap<>();
options.put(RepairOption.PARALLELISM_KEY, repairParallelism.getName());
options.put(RepairOption.INCREMENTAL_KEY, Boolean.toString(!full));
assert(keyspace != null);
Map<String, String> options = new HashMap<>();
options.put(RepairOption.PARALLELISM_KEY, repairParallelism.getName());
options.put(RepairOption.INCREMENTAL_KEY, Boolean.toString(!full));
options.put(
RepairOption.JOB_THREADS_KEY,
Integer.toString(repairThreadCount == 0 ? 1 : repairThreadCount));
options.put(RepairOption.TRACE_KEY, Boolean.toString(Boolean.FALSE));
options.put(RepairOption.COLUMNFAMILIES_KEY, StringUtils.join(tables, ","));
if (full) {
options.put(
RepairOption.JOB_THREADS_KEY,
Integer.toString(repairThreadCount == 0 ? 1 : repairThreadCount));
options.put(RepairOption.TRACE_KEY, Boolean.toString(Boolean.FALSE));
options.put(RepairOption.COLUMNFAMILIES_KEY, StringUtils.join(tables, ","));
if (full) {
options.put(
RepairOption.RANGES_KEY,
StringUtils.join(
associatedTokens
.stream()
.map(token -> token.getStart() + ":" + token.getEnd())
.collect(Collectors.toList()),
","));
}
RepairOption.RANGES_KEY,
StringUtils.join(
associatedTokens
.stream()
.map(token -> token.getStart() + ":" + token.getEnd())
.collect(Collectors.toList()),
","));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.datastax.mgmtapi.models;

import java.math.BigInteger;
import java.util.Comparator;

public final class RingRange {

public static final Comparator<RingRange> START_COMPARATOR
= (RingRange o1, RingRange o2) -> o1.start.compareTo(o2.start);

private final BigInteger start;
private final BigInteger end;

public RingRange(BigInteger start, BigInteger end) {
this.start = start;
this.end = end;
}

public RingRange(String... range) {
start = new BigInteger(range[0]);
end = new BigInteger(range[1]);
}

public BigInteger getStart() {
return start;
}

public BigInteger getEnd() {
return end;
}

}

0 comments on commit 975be5d

Please sign in to comment.