Skip to content

Commit

Permalink
Cassandra performance: Replace sequence ids with time-based UUIDs
Browse files Browse the repository at this point in the history
ref:
 - #99
 - #94
  • Loading branch information
michaelsembwever committed May 11, 2017
1 parent 2d8779c commit 9ac3b74
Show file tree
Hide file tree
Showing 32 changed files with 402 additions and 366 deletions.
17 changes: 9 additions & 8 deletions src/main/java/com/spotify/reaper/core/RepairRun.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
package com.spotify.reaper.core;

import java.util.Objects;
import java.util.UUID;

import org.apache.cassandra.repair.RepairParallelism;
import org.joda.time.DateTime;
import org.joda.time.DateTimeComparator;

public class RepairRun implements Comparable<RepairRun> {

private final long id;
private final UUID id;

// IDEA: maybe we want to have start and stop token for parallel runners on same repair run?
//private final long startToken;
Expand All @@ -30,7 +31,7 @@ public class RepairRun implements Comparable<RepairRun> {
private final String cause;
private final String owner;
private final String clusterName;
private final long repairUnitId;
private final UUID repairUnitId;
private final RunState runState;
private final DateTime creationTime;
private final DateTime startTime;
Expand All @@ -41,7 +42,7 @@ public class RepairRun implements Comparable<RepairRun> {
private final int segmentCount;
private final RepairParallelism repairParallelism;

private RepairRun(Builder builder, long id) {
private RepairRun(Builder builder, UUID id) {
this.id = id;
this.clusterName = builder.clusterName;
this.repairUnitId = builder.repairUnitId;
Expand All @@ -58,11 +59,11 @@ private RepairRun(Builder builder, long id) {
this.repairParallelism = builder.repairParallelism;
}

public long getId() {
public UUID getId() {
return id;
}

public long getRepairUnitId() {
public UUID getRepairUnitId() {
return repairUnitId;
}

Expand Down Expand Up @@ -174,7 +175,7 @@ public boolean isTerminated() {
public static class Builder {

public final String clusterName;
public final long repairUnitId;
public final UUID repairUnitId;
private RunState runState;
private DateTime creationTime;
private double intensity;
Expand All @@ -188,7 +189,7 @@ public static class Builder {
private int segmentCount;
private RepairParallelism repairParallelism;

public Builder(String clusterName, long repairUnitId, DateTime creationTime,
public Builder(String clusterName, UUID repairUnitId, DateTime creationTime,
double intensity, int segmentCount, RepairParallelism repairParallelism) {
this.clusterName = clusterName;
this.repairUnitId = repairUnitId;
Expand Down Expand Up @@ -270,7 +271,7 @@ public Builder repairParallelism(RepairParallelism repairParallelism) {
return this;
}

public RepairRun build(long id) {
public RepairRun build(UUID id) {
return new RepairRun(this, id);
}
}
Expand Down
27 changes: 14 additions & 13 deletions src/main/java/com/spotify/reaper/core/RepairSchedule.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,28 @@
import com.google.common.collect.ImmutableList;
import com.spotify.reaper.core.RepairSegment.State;
import com.spotify.reaper.storage.postgresql.LongCollectionSQLType;
import java.util.UUID;

import org.apache.cassandra.repair.RepairParallelism;
import org.joda.time.DateTime;

public class RepairSchedule {

private final long id;
private final UUID id;

private final long repairUnitId;
private final UUID repairUnitId;
private final State state;
private final int daysBetween;
private final DateTime nextActivation;
private final ImmutableList<Long> runHistory;
private final ImmutableList<UUID> runHistory;
private final int segmentCount;
private final RepairParallelism repairParallelism;
private final double intensity;
private final DateTime creationTime;
private final String owner;
private final DateTime pauseTime;

private RepairSchedule(Builder builder, long id) {
private RepairSchedule(Builder builder, UUID id) {
this.id = id;
this.repairUnitId = builder.repairUnitId;
this.state = builder.state;
Expand All @@ -51,11 +52,11 @@ private RepairSchedule(Builder builder, long id) {
this.pauseTime = builder.pauseTime;
}

public long getId() {
public UUID getId() {
return id;
}

public long getRepairUnitId() {
public UUID getRepairUnitId() {
return repairUnitId;
}

Expand All @@ -75,7 +76,7 @@ public DateTime getNextActivation() {
return nextActivation;
}

public ImmutableList<Long> getRunHistory() {
public ImmutableList<UUID> getRunHistory() {
return runHistory;
}

Expand Down Expand Up @@ -123,20 +124,20 @@ public enum State {

public static class Builder {

public final long repairUnitId;
public final UUID repairUnitId;
private State state;
private int daysBetween;
private DateTime nextActivation;
private ImmutableList<Long> runHistory;
private ImmutableList<UUID> runHistory;
private int segmentCount;
private RepairParallelism repairParallelism;
private double intensity;
private DateTime creationTime;
private String owner;
private DateTime pauseTime;

public Builder(long repairUnitId, State state, int daysBetween, DateTime nextActivation,
ImmutableList<Long> runHistory, int segmentCount,
public Builder(UUID repairUnitId, State state, int daysBetween, DateTime nextActivation,
ImmutableList<UUID> runHistory, int segmentCount,
RepairParallelism repairParallelism,
double intensity, DateTime creationTime) {
this.repairUnitId = repairUnitId;
Expand Down Expand Up @@ -181,7 +182,7 @@ public Builder nextActivation(DateTime nextActivation) {
return this;
}

public Builder runHistory(ImmutableList<Long> runHistory) {
public Builder runHistory(ImmutableList<UUID> runHistory) {
this.runHistory = runHistory;
return this;
}
Expand Down Expand Up @@ -216,7 +217,7 @@ public Builder pauseTime(DateTime pauseTime) {
return this;
}

public RepairSchedule build(long id) {
public RepairSchedule build(UUID id) {
return new RepairSchedule(this, id);
}
}
Expand Down
23 changes: 12 additions & 11 deletions src/main/java/com/spotify/reaper/core/RepairSegment.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
import org.joda.time.DateTime;

import java.math.BigInteger;
import java.util.UUID;

public class RepairSegment {

private final long id;
private final long runId;
private final long repairUnitId;
private final UUID id;
private final UUID runId;
private final UUID repairUnitId;
private final RingRange tokenRange;
private final int failCount;
private final State state;
Expand All @@ -32,7 +33,7 @@ public class RepairSegment {
private final DateTime startTime;
private final DateTime endTime;

private RepairSegment(Builder builder, long id) {
private RepairSegment(Builder builder, UUID id) {
this.id = id;
this.runId = builder.runId;
this.repairUnitId = builder.repairUnitId;
Expand All @@ -45,15 +46,15 @@ private RepairSegment(Builder builder, long id) {
this.endTime = builder.endTime;
}

public long getId() {
public UUID getId() {
return id;
}

public long getRunId() {
public UUID getRunId() {
return runId;
}

public long getRepairUnitId() {
public UUID getRepairUnitId() {
return repairUnitId;
}

Expand Down Expand Up @@ -105,17 +106,17 @@ public enum State {

public static class Builder {

public final long runId;
public final UUID runId;
public final RingRange tokenRange;
private final long repairUnitId;
private final UUID repairUnitId;
private int failCount;
private State state;
private String coordinatorHost;
private Integer repairCommandId;
private DateTime startTime;
private DateTime endTime;

public Builder(long runId, RingRange tokenRange, long repairUnitId) {
public Builder(UUID runId, RingRange tokenRange, UUID repairUnitId) {
this.runId = runId;
this.repairUnitId = repairUnitId;
this.tokenRange = tokenRange;
Expand Down Expand Up @@ -165,7 +166,7 @@ public Builder endTime(DateTime endTime) {
return this;
}

public RepairSegment build(long id) {
public RepairSegment build(UUID id) {
return new RepairSegment(this, id);
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/com/spotify/reaper/core/RepairUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,25 @@
package com.spotify.reaper.core;

import java.util.Set;
import java.util.UUID;

public class RepairUnit {

private final long id;
private final UUID id;
private final String clusterName;
private final String keyspaceName;
private final Set<String> columnFamilies;
private final Boolean incrementalRepair;

private RepairUnit(Builder builder, long id) {
private RepairUnit(Builder builder, UUID id) {
this.id = id;
this.clusterName = builder.clusterName;
this.keyspaceName = builder.keyspaceName;
this.columnFamilies = builder.columnFamilies;
this.incrementalRepair = builder.incrementalRepair;
}

public long getId() {
public UUID getId() {
return id;
}

Expand Down Expand Up @@ -76,7 +77,7 @@ private Builder(RepairUnit original) {
incrementalRepair = original.incrementalRepair;
}

public RepairUnit build(long id) {
public RepairUnit build(UUID id) {
return new RepairUnit(this, id);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/spotify/reaper/resources/CommonTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.spotify.reaper.core.RepairUnit;
import com.spotify.reaper.service.RingRange;
import com.spotify.reaper.service.SegmentGenerator;
import java.util.UUID;

public class CommonTools {

Expand Down Expand Up @@ -257,7 +258,7 @@ public static RepairSchedule storeNewRepairSchedule(
throws ReaperException {
RepairSchedule.Builder scheduleBuilder =
new RepairSchedule.Builder(repairUnit.getId(), RepairSchedule.State.ACTIVE, daysBetween,
nextActivation, ImmutableList.<Long>of(), segments,
nextActivation, ImmutableList.<UUID>of(), segments,
repairParallelism, intensity,
DateTime.now());
scheduleBuilder.owner(owner);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import com.spotify.reaper.core.RepairSegment;
import com.spotify.reaper.core.RepairUnit;
import com.spotify.reaper.resources.view.RepairRunStatus;
import java.util.UUID;

@Path("/repair_run")
@Produces(MediaType.APPLICATION_JSON)
Expand Down Expand Up @@ -253,7 +254,7 @@ public static Response checkRequestForAddRepair(
@Path("/{id}")
public Response modifyRunState(
@Context UriInfo uriInfo,
@PathParam("id") Long repairRunId,
@PathParam("id") UUID repairRunId,
@QueryParam("state") Optional<String> state) throws ReaperException {

LOG.info("modify repair run state called with: id = {}, state = {}", repairRunId, state);
Expand Down Expand Up @@ -373,7 +374,7 @@ private Response abortRun(RepairRun repairRun, RepairUnit repairUnit, int segmen
*/
@GET
@Path("/{id}")
public Response getRepairRun(@PathParam("id") Long repairRunId) {
public Response getRepairRun(@PathParam("id") UUID repairRunId) {
LOG.debug("get repair_run called with: id = {}", repairRunId);
Optional<RepairRun> repairRun = context.storage.getRepairRun(repairRunId);
if (repairRun.isPresent()) {
Expand Down Expand Up @@ -497,7 +498,7 @@ public Set splitStateParam(Optional<String> state) {
*/
@DELETE
@Path("/{id}")
public Response deleteRepairRun(@PathParam("id") Long runId,
public Response deleteRepairRun(@PathParam("id") UUID runId,
@QueryParam("owner") Optional<String> owner) {
LOG.info("delete repair run called with runId: {}, and owner: {}", runId, owner);
if (!owner.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import com.spotify.reaper.core.RepairUnit;
import com.spotify.reaper.resources.view.RepairScheduleStatus;
import com.spotify.reaper.service.SchedulingManager;
import java.util.UUID;

@Path("/repair_schedule")
@Produces(MediaType.APPLICATION_JSON)
Expand Down Expand Up @@ -212,7 +213,7 @@ public Response addRepairSchedule(
@Path("/{id}")
public Response modifyState(
@Context UriInfo uriInfo,
@PathParam("id") Long repairScheduleId,
@PathParam("id") UUID repairScheduleId,
@QueryParam("state") Optional<String> state) {

LOG.info("modify repair schedule state called with: id = {}, state = {}",
Expand Down Expand Up @@ -290,7 +291,7 @@ private Response resumeSchedule(RepairSchedule repairSchedule, RepairUnit repair
*/
@GET
@Path("/{id}")
public Response getRepairSchedule(@PathParam("id") Long repairScheduleId) {
public Response getRepairSchedule(@PathParam("id") UUID repairScheduleId) {
LOG.debug("get repair_schedule called with: id = {}", repairScheduleId);
Optional<RepairSchedule> repairSchedule = context.storage.getRepairSchedule(repairScheduleId);
if (repairSchedule.isPresent()) {
Expand Down Expand Up @@ -399,7 +400,7 @@ private Collection<RepairSchedule> getScheduleList(Optional<String> clusterName,
*/
@DELETE
@Path("/{id}")
public Response deleteRepairSchedule(@PathParam("id") Long repairScheduleId,
public Response deleteRepairSchedule(@PathParam("id") UUID repairScheduleId,
@QueryParam("owner") Optional<String> owner) {
LOG.info("delete repair schedule called with repairScheduleId: {}, and owner: {}",
repairScheduleId, owner);
Expand Down
Loading

0 comments on commit 9ac3b74

Please sign in to comment.