aweisberg commented on code in PR #4508:
URL: https://github.com/apache/cassandra/pull/4508#discussion_r2611475463
##########
src/java/org/apache/cassandra/tcm/transformations/AlterSchema.java:
##########
@@ -332,6 +337,64 @@ public static Transformer
maybeUpdateConsensusMigrationState(ConsensusMigrationS
return next;
}
+ /**
+ * Auto-start mutation tracking migration when keyspace replication type
changes.
+ * Detects transitions between tracked and untracked replication and
initializes
+ * migration state accordingly.
+ * Also handles removing dropped tables and keyspaces from migration state.
+ */
+ public static Transformer maybeUpdateMutationTrackingMigrationState(Epoch
nextEpoch,
+
MutationTrackingMigrationState prev,
+
Transformer next,
+
ImmutableList<KeyspaceDiff> altered,
+
Keyspaces dropped)
+ {
+ MutationTrackingMigrationState migrationState = prev;
+
+ // Handle dropped keyspaces - remove their migration state entirely
+ if (!dropped.isEmpty())
+ {
+ Set<String> droppedKeyspaceNames = dropped.stream()
+ .map(ks -> ks.name)
+ .collect(Collectors.toSet());
+ migrationState = migrationState.dropKeyspaces(nextEpoch,
droppedKeyspaceNames);
+ }
+
+ // Handle dropped tables from altered keyspaces
+ Set<TableId> droppedTableIds = altered.stream()
+ .flatMap(diff ->
diff.tables.dropped.stream().map(TableMetadata::id))
+ .collect(Collectors.toSet());
+
+ if (!droppedTableIds.isEmpty())
+ migrationState = migrationState.dropTables(droppedTableIds,
nextEpoch);
+
+ // Handle keyspace replication type changes (new migrations or
reversals)
+ for (KeyspaceDiff diff : altered)
+ {
+ ReplicationType beforeType = diff.before.params.replicationType;
+ ReplicationType afterType = diff.after.params.replicationType;
+
+ // Check if replication type changed
+ if (beforeType != afterType)
+ {
+ // Auto-start migration for this keyspace
+ logger.info("Auto-starting mutation tracking migration for
keyspace {} (replication_type={})",
+ diff.after.name, afterType);
+
+ Collection<TableId> tableIds = diff.after.tables.stream()
+ .map(table -> table.id)
+ .collect(Collectors.toList());
+
+ migrationState =
migrationState.withKeyspaceMigrating(diff.after.name, tableIds, nextEpoch);
Review Comment:
Maybe a comment or a name change to reflect the fact that it does reversal?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]