CEP-45: Incremental repair for mutation tracking#4696
CEP-45: Incremental repair for mutation tracking#4696aweisberg wants to merge 46 commits intoapache:cep-45-mutation-trackingfrom
Conversation
…dn't work in 2 minutes it won't work.
…tionTrackingIncrementalRepairTask
…ce shard for keyspace distributed_test_keyspace, but it already exists on bounce
…marking sstables repaired to effect the migration
…e it will hang, so just use IR instead
…ntirely inside migrated ranges or entirely outside, but not both
…een completed, use tryFailure instead
| catch (RuntimeException e) | ||
| { | ||
| allSucceeded = false; | ||
| error = Throwables.merge(error, e); |
There was a problem hiding this comment.
nit: Coverage tooling indicates this might not be tested.
There was a problem hiding this comment.
I'll convert timeouts to exceptions so it can be exercised.
| catch (Exception e) | ||
| { | ||
| logger.error("Error during mutation tracking repair", e); | ||
| resultPromise.tryFailure(e); |
There was a problem hiding this comment.
nit: Coverage tooling indicates this might not be tested.
There was a problem hiding this comment.
The errors are put in resultPromise and don't get surfaced by allowing them to bubble up. To make this branch fire I could let exceptions bubble up and then get handled here. Would be less exception handling in general and then it would show up as tested.
I'll do that.
| if (allRanges.isEmpty()) | ||
| { | ||
| logger.info("No common ranges to repair for keyspace {}", keyspace); | ||
| return new AsyncPromise<CoordinatedRepairResult>().setSuccess(CoordinatedRepairResult.create(List.of(), List.of())); |
There was a problem hiding this comment.
nit: Coverage tooling indicates this might not be tested.
| if (overlappingShards.isEmpty()) | ||
| { | ||
| completionFuture.setSuccess(null); | ||
| return; |
There was a problem hiding this comment.
nit: Coverage tooling indicates this might not be tested.
There was a problem hiding this comment.
Converted to a checkState
| public void onFailure(InetAddressAndPort from, RequestFailure failure) | ||
| { | ||
| fail(new RuntimeException( | ||
| String.format("Mutation tracking sync failed: participant %s returned failure %s", from, failure.reason))); |
There was a problem hiding this comment.
nit: Coverage tooling indicates this might not be tested.
There was a problem hiding this comment.
Added a test case that sends an exception through here
| Shard currentShard = getCurrentShard(state.shard.range); | ||
| if (currentShard != state.shard) | ||
| { | ||
| failWithTopologyChange(); |
There was a problem hiding this comment.
nit: Coverage tooling indicates this might not be tested.
There was a problem hiding this comment.
Topology changes aren't supported yet https://issues.apache.org/jira/browse/CASSANDRA-20386
I'll take a look and see if I can at least induce one to exercise this failure path.
It might end up being more unit test then end to end test.
There was a problem hiding this comment.
Added an end to end test. Seems like we don't error out on topology changes and more or less do it.
| * their current witnessed offsets. This establishes a happens-before relationship: the | ||
| * participant's response contains offsets captured after receiving this request, which is | ||
| * sent after the repair starts. | ||
| * |
There was a problem hiding this comment.
nit:
| * | |
| * <p> |
| inMigrationPendingRange = migrationInfo.isRangeInPendingMigration(metadata().id, | ||
| first.getToken(), | ||
| last.getToken()); | ||
| } |
There was a problem hiding this comment.
nit: Could replace the above w/
KeyspaceMigrationInfo migrationInfo = ClusterMetadata.current().mutationTrackingMigrationState.getKeyspaceInfo(metadata().keyspace);
boolean inMigrationPendingRange = migrationInfo != null && migrationInfo.isRangeInPendingMigration(metadata().id, first.getToken(), last.getToken());
| // when incremental repair streams SSTables that were written before tracking was enabled. | ||
| Preconditions.checkState(!cfstore.metadata().replicationType().isTracked() | ||
| || ClusterMetadata.current().mutationTrackingMigrationState | ||
| .getKeyspaceInfo(cfstore.metadata().keyspace) != null); |
There was a problem hiding this comment.
nit: Might be nice to have something like an isMigrating(String) on MTMS, but just a matter of taste I guess.
There was a problem hiding this comment.
I'll update it to use a helper.
| { | ||
| Preconditions.checkState(!cfstore.metadata().replicationType().isTracked()); | ||
| // Tracked tables may legitimately use this path during migration from untracked to tracked, | ||
| // when incremental repair streams SSTables that were written before tracking was enabled. |
There was a problem hiding this comment.
Does this mean that during migration to tracked, we'd expect these SSTables to have no coordinator log offsets then? Is that worth asserting?
There was a problem hiding this comment.
It shouldn't matter for imports, since the keyspace being currently tracked means we'll avoid this method.
There was a problem hiding this comment.
No we will actually hit this method during migration. The sstables might actually have offsets in them since tracked writes have already started and the incremental repair starts after.
| // flag on the mutation hasn't been set yet at this point — it's set later in | ||
| // applyMutation() — so we check the handler type instead. | ||
| if (this instanceof ReadRepairVerbHandler) | ||
| return metadata; |
There was a problem hiding this comment.
nit: I guess the other option would be something like a handlesReadRepair() method that only ReadRepairVerbHandler overrides, but it's literally called ReadRepairVerbHandler, and we probably won't have something else handle RR mutations.
In any case, I'm remembering blocking RR is going to be reworked for migration anyway, so ignore me :D
| @Nonnull Collection<String> columnFamilies) | ||
| { | ||
| Iterable<TableMetadata> tables; | ||
| if (!columnFamilies.isEmpty()) |
There was a problem hiding this comment.
nit: This is almost a case where null would be nice to indicate "all tables", in the sense that an empty collection might be more likely than null to indicate incorrect argument construction.
There was a problem hiding this comment.
That is an artifact of how RepairOption treats the empty set as "all tables". I'll update this method to use null and then fix it at the caller to convert an empty set to null.
| RepairTask task = new PreviewRepairTask(this, state.id, neighborsAndRanges.filterCommonRanges(state.keyspace, cfnames), neighborsAndRanges.shouldExcludeDeadParticipants, cfnames); | ||
| return task.perform(executor, validationScheduler) | ||
| .<Pair<CoordinatedRepairResult, Supplier<String>>>map(r -> Pair.create(r, task::successMessage)) | ||
| .addCallback((s, f) -> executor.shutdown()); |
There was a problem hiding this comment.
This block here is duplicated 3 more times below. The original code here avoided that by returning after the if/else stuff, but we could just delegate to a submitRepairTask() or something similar.
| RepairJobDesc desc = new RepairJobDesc(parentSession, TimeUUID.Generator.nextTimeUUID(), | ||
| keyspace, "Mutation Tracking Sync", List.of(range)); | ||
| MutationTrackingSyncCoordinator syncCoordinator = new MutationTrackingSyncCoordinator( | ||
| coordinator.ctx, desc, commonRange.endpoints, metadata); |
There was a problem hiding this comment.
MutationTrackingSyncCoordinator syncCoordinator =
new MutationTrackingSyncCoordinator(coordinator.ctx, desc, commonRange.endpoints, metadata);
...might be a little easier on the eyes.
| Pair<CoordinatedRepairResult, Supplier<String>> irPair = Pair.create(irResult, incrementalTask::successMessage); | ||
| mtTask.perform(executor, validationScheduler) | ||
| .addCallback( | ||
| mtResult -> result.trySuccess(irPair), |
There was a problem hiding this comment.
Do we need to handle partial failure here? (i.e. Do we just return the irPair result if the MT task partially fails?)
There was a problem hiding this comment.
A failure at any step is a failure of the entire thing since we didn't complete the entire repair. That is what this should be doing which is return failure immediately once any step fails.
| * Determines if this keyspace should use mutation tracking incremental repair. | ||
| * Returns true if: | ||
| * - Keyspace uses mutation tracking replication, OR | ||
| * - Keyspace is currently migrating (either direction) |
There was a problem hiding this comment.
nit: Not strictly true if migrating to untracked?
There was a problem hiding this comment.
I'll address that in the follow up where I am changing migration from tracked to untracked to be instant.
| for (Range<Token> range : commonRange.ranges) | ||
| { | ||
| RepairJobDesc desc = new RepairJobDesc(parentSession, TimeUUID.Generator.nextTimeUUID(), | ||
| keyspace, "Mutation Tracking Sync", List.of(range)); |
There was a problem hiding this comment.
Table name is meaningless here, right?
There was a problem hiding this comment.
Yes but I figured for debugging purposes it's clearer to not leave it empty.
|
|
||
| if (overlappingShards.isEmpty()) | ||
| { | ||
| completionFuture.setSuccess(null); |
There was a problem hiding this comment.
nit: Might be nice to have a DEBUG level log message to indicate this happened.
There was a problem hiding this comment.
Converted it a checkState
| } | ||
| // Always include the local node | ||
| liveHostIds.add(metadata.directory.peerId(ctx.broadcastAddressAndPort()).id()); | ||
| } |
There was a problem hiding this comment.
nit: If we just build the liveHostIds at construction time, could we make it final?
There was a problem hiding this comment.
Yes I'll make it a final ImmutableSet
| if (completionFuture.isDone()) | ||
| return; | ||
|
|
||
| recaptureTargets(); |
There was a problem hiding this comment.
It looks like this is called from updateReplicatedOffsets(), but does that mean we keep expanding the targets after the initial round of sync requests? (i.e. If there are ongoing writes, can this cause the whole IR to time out?)
There was a problem hiding this comment.
Yeah this shouldn't occur on offsets received. I missed this coming in from the original PR.
…o checkState since it shouldn't actually happen
…ackingIncrementalRepairTask and improve test coverage
No description provided.