maedhroz commented on code in PR #4696:
URL: https://github.com/apache/cassandra/pull/4696#discussion_r3029189759


##########
src/java/org/apache/cassandra/service/replication/migration/KeyspaceMigrationInfo.java:
##########
@@ -246,6 +270,107 @@ public boolean shouldUseTrackedForWrites(boolean 
isTracked, TableId tableId, Tok
         return isTracked || isTokenInPendingRange(tableId, token);
     }
 
+    /**
+     * Asserts that the given ranges are either entirely inside or entirely 
outside the pending
+     * migration set for each specified table. During migration, reads for 
pending ranges continue
+     * to use the untracked read path with blocking read repair, so it is safe 
to exclude mutation
+     * tracking streaming for those ranges. However, partial overlap is not 
supported — repair must
+     * operate on ranges that are fully migrated or fully pending.
+     *
+     * @param ranges the normalized ranges to check
+     * @param tables the tables to check against
+     * @throws IllegalStateException if ranges partially overlap with pending 
ranges for any table
+     */
+    public void assertRangesNotMixedMigration(@Nonnull NormalizedRanges<Token> 
ranges,
+                                              @Nonnull Iterable<TableMetadata> 
tables)
+    {
+        for (TableMetadata table : tables)
+        {
+            NormalizedRanges<Token> pendingRanges = 
getPendingRangesForTable(table.id);
+            if (pendingRanges.isEmpty())
+                continue;
+
+            NormalizedRanges<Token> overlap = 
pendingRanges.intersection(ranges);
+            if (overlap.isEmpty())
+                continue;
+
+            // Some ranges overlap with pending — verify ALL ranges are 
pending for this table
+            NormalizedRanges<Token> outside = ranges.subtract(pendingRanges);
+            if (!outside.isEmpty())
+                throw new IllegalStateException(String.format(
+                    "Ranges for keyspace %s partially overlap with migration 
pending ranges for table %s. " +
+                    "Ranges must be entirely inside or entirely outside the 
pending set.",
+                    keyspace, table.name));
+        }
+    }
+
+    /**
+     * Convenience overload that resolves column family names to table 
metadata before checking.
+     * If columnFamilies is empty, all tables in the keyspace are checked.
+     *
+     * @param ranges the normalized ranges to check
+     * @param ksm the keyspace metadata for resolving table names
+     * @param columnFamilies specific table names to check, or empty for all 
tables
+     * @throws IllegalStateException if ranges partially overlap with pending 
ranges for any table
+     */
+    public void assertRangesNotMixedMigration(@Nonnull NormalizedRanges<Token> 
ranges,
+                                              @Nonnull KeyspaceMetadata ksm,
+                                              @Nonnull Collection<String> 
columnFamilies)
+    {
+        Iterable<TableMetadata> tables;
+        if (!columnFamilies.isEmpty())

Review 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.



-- 
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]

Reply via email to