kfaraz commented on code in PR #16719:
URL: https://github.com/apache/druid/pull/16719#discussion_r1674396492


##########
server/src/main/java/org/apache/druid/server/coordinator/duty/RoundRobinIterator.java:
##########
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.server.coordinator.duty;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.apache.druid.error.InvalidInput;
+
+import javax.annotation.concurrent.NotThreadSafe;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Set;
+import java.util.concurrent.ThreadLocalRandom;
+
+/**
+ * A round-robin iterator that is backed by an ordered list of candidates 
containing no duplicates. The iterator
+ * iterates endlessly over all the candidates. The caller must explicitly 
terminate it.
+ * The iterator has the following properties:
+ * <ul>
+ *   <li> Starts with an initial random cursor position in an ordered list of 
candidates. </li>
+ *   <li> Invoking {@code next()} on {@link #getIterator()} is guaranteed to 
result in a deterministic order
+ *   unless the set of candidates change when {@link #updateCandidates(Set)} 
is called. When the candidates change,
+ *   the cursor is reset to a random position in the new list of ordered 
candidates. </li>
+ *   <li> Guarantees that no duplicate candidates are returned in two 
consecutive {@code next()} iterations. </li>
+ * </ul>
+ *
+ * <p>
+ * This class is not thread-safe and must be used from a single thread.
+ */
+@NotThreadSafe
+public class RoundRobinIterator

Review Comment:
   Oh, that should be fine. There are enough UTs and sims in place to ensure 
that everything continues to work as expected. You need not test it out 
separately.
   
   If you still don't feel comfortable touching `RoundRobinServerSelector`, you 
may leave it for now. I can take a look at it later.
   
   But we should still use the `CircularList` in this PR as discussed above 
instead of the current approach (given that you agree with the `CircularList` 
design).



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