Skip to content

Commit

Permalink
Simplify the creation of repair runs and their segments.
Browse files Browse the repository at this point in the history
 Repair runs and their segments are one unit of work in concept and the persistence layer should be designed accordingly.
 Previous they were separated because the concern of sequence generation for IDs were exposed in the code. This is now encapsulated within storage implementations.
 This work allows the CassandraStorage to implement segments as clustering keys within the repair_run table.

ref:
 - #94
 - #101
  • Loading branch information
michaelsembwever authored and adejanovski committed Jun 23, 2017
1 parent 2ef929c commit ce09d54
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/spotify/reaper/core/RepairSegment.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public enum State {

public static class Builder {


public final RingRange tokenRange;
private final UUID repairUnitId;
private UUID runId;
Expand All @@ -116,8 +117,7 @@ public static class Builder {
private DateTime startTime;
private DateTime endTime;

public Builder(UUID runId, RingRange tokenRange, UUID repairUnitId) {
this.runId = runId;
public Builder(RingRange tokenRange, UUID repairUnitId) {
this.repairUnitId = repairUnitId;
this.tokenRange = tokenRange;
this.failCount = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,9 @@ private RepairSegment createRepairSegmentFromRow(Row segmentRow){
}
private RepairSegment createRepairSegmentFromRow(Row segmentRow, UUID segmentId){
return new RepairSegment.Builder(
segmentRow.getUUID("run_id"),
new RingRange(new BigInteger(segmentRow.getVarint("start_token") +""), new BigInteger(segmentRow.getVarint("end_token")+"")),
segmentRow.getUUID("repair_unit_id"))
.withRunId(segmentRow.getUUID("run_id"))
.coordinatorHost(segmentRow.getString("coordinator_host"))
.endTime(new DateTime(segmentRow.getTimestamp("segment_end_time")))
.failCount(segmentRow.getInt("fail_count"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ public class RepairSegmentMapper implements ResultSetMapper<RepairSegment> {
public RepairSegment map(int index, ResultSet r, StatementContext ctx) throws SQLException {
RingRange range = new RingRange(r.getBigDecimal("start_token").toBigInteger(),
r.getBigDecimal("end_token").toBigInteger());
RepairSegment.Builder repairSegmentBuilder =
new RepairSegment.Builder(fromSequenceId(r.getLong("run_id")), range, fromSequenceId(r.getLong("repair_unit_id")));
return repairSegmentBuilder
.state(RepairSegment.State.values()[r.getInt("state")])
.coordinatorHost(r.getString("coordinator_host"))
.startTime(RepairRunMapper.getDateTimeOrNull(r, "start_time"))
.endTime(RepairRunMapper.getDateTimeOrNull(r, "end_time"))
.failCount(r.getInt("fail_count"))
.build(fromSequenceId(r.getLong("id")));
return
new RepairSegment.Builder(range, fromSequenceId(r.getLong("repair_unit_id")))
.withRunId(fromSequenceId(r.getLong("run_id")))
.state(RepairSegment.State.values()[r.getInt("state")])
.coordinatorHost(r.getString("coordinator_host"))
.startTime(RepairRunMapper.getDateTimeOrNull(r, "start_time"))
.endTime(RepairRunMapper.getDateTimeOrNull(r, "end_time"))
.failCount(r.getInt("fail_count"))
.build(fromSequenceId(r.getLong("id")));
}

private static UUID fromSequenceId(long insertedId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public void successTest() throws InterruptedException, ReaperException, Executio
RepairRun run = storage.addRepairRun(
new RepairRun.Builder("reaper", cf.getId(), DateTime.now(), 0.5, 1, RepairParallelism.PARALLEL),
Collections.singleton(new RepairSegment.Builder(new RingRange(BigInteger.ONE, BigInteger.ZERO), cf.getId())));

final UUID runId = run.getId();
final UUID segmentId = storage.getNextFreeSegment(run.getId()).get().getId();

Expand Down

0 comments on commit ce09d54

Please sign in to comment.