jmckenzie-dev commented on code in PR #4030:
URL: https://github.com/apache/cassandra/pull/4030#discussion_r2025505584


##########
src/java/org/apache/cassandra/locator/ReplicaPlan.java:
##########
@@ -355,9 +357,20 @@ private ForWrite copy(ConsistencyLevel 
newConsistencyLevel, EndpointsForToken ne
             return res;
         }
 
-        ForWrite withConsistencyLevel(ConsistencyLevel newConsistencylevel) { 
return copy(newConsistencylevel, contacts()); }
+        @VisibleForTesting
+        public ForWrite withConsistencyLevel(ConsistencyLevel 
newConsistencylevel) { return copy(newConsistencylevel, contacts()); }
         public ForWrite withContacts(EndpointsForToken newContact) { return 
copy(consistencyLevel, newContact); }
 
+        /**
+         * This raises an {@link IllegalArgumentException} if the state has 
changed; syntactic sugar around
+         * {@link #stillAppliesTo(ClusterMetadata)} making the calling 
convention a bit more ergonomic for the base case
+         * of "return true or raise an exception"
+         */
+        public void checkStillAppliesTo(ClusterMetadata newMetadata)
+        {
+            stillAppliesTo(newMetadata);
+        }

Review Comment:
   So this came in with TCM and I'm not sure the provenance, but we have:
   `public boolean stillAppliesTo(...)` which is overridden in some child 
classes to actually return false in cases where it doesn't apply vs. the base 
that throws, and then we have usage of the method that takes the form:
   ```java
   if (stillAppliesTo(thing)) // looks like vestigial noop
      return;
   } // end of method
   ```
   at the tail end of a method to throw if things have shifted.
   
   My real beef here was that we had a method signature that _looked_ like a 
noop from the outside because the semantics of the base version of the call are 
basically "return true or throw". I was going for a lightweight wrapper to 
shift the verb from "hey, I expect to get a boolean back", to "hey, void 
return. You either work or you barf."
   
   In theory I could go deeper on the surgery to get the ReplicaPlan hierarchy 
away from overloading the usage patterns of this base method but... meh. 
Figured this semantic sugar verb wrapper would be enough to make me stop being 
sad.



-- 
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: pr-unsubscr...@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org
For additional commands, e-mail: pr-h...@cassandra.apache.org

Reply via email to