mumrah commented on a change in pull request #9732:
URL: https://github.com/apache/kafka/pull/9732#discussion_r541216977



##########
File path: 
core/src/main/scala/kafka/server/BrokerToControllerChannelManager.scala
##########
@@ -135,7 +117,16 @@ class BrokerToControllerChannelManagerImpl(metadataCache: 
kafka.server.MetadataC
       brokerToControllerListenerName, time, threadName)
   }
 
-  override def sendRequest(request: AbstractRequest.Builder[_ <: 
AbstractRequest],
+  /**
+   * Send request to the controller.
+   *
+   * @param request         The request to be sent.
+   * @param callback        Request completion callback.
+   * @param retryDeadlineMs The retry deadline which will only be checked 
after receiving a response.
+   *                        This means that in the worst case, the total 
timeout would be twice of
+   *                        the configured timeout.
+   */
+  def sendRequest(request: AbstractRequest.Builder[_ <: AbstractRequest],
                            callback: ControllerRequestCompletionHandler,

Review comment:
       nit: indent misaligned 

##########
File path: 
raft/src/main/java/org/apache/kafka/raft/internals/BlockingMessageQueue.java
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.kafka.raft.internals;
+
+import org.apache.kafka.common.errors.InterruptException;
+import org.apache.kafka.raft.RaftMessage;
+import org.apache.kafka.raft.RaftMessageQueue;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class BlockingMessageQueue implements RaftMessageQueue {
+    private final BlockingQueue<RaftEvent> queue = new LinkedBlockingQueue<>();
+    private final AtomicInteger size = new AtomicInteger(0);
+
+    @Override
+    public RaftMessage poll(long timeoutMs) {
+        try {
+            RaftEvent event = queue.poll(timeoutMs, TimeUnit.MILLISECONDS);
+            if (event instanceof MessageReceived) {
+                size.decrementAndGet();
+                return ((MessageReceived) event).message;
+            } else {
+                return null;
+            }
+        } catch (InterruptedException e) {
+            throw new InterruptException(e);
+        }
+
+    }
+
+    @Override
+    public void offer(RaftMessage message) {
+        queue.add(new MessageReceived(message));
+        size.incrementAndGet();
+    }
+
+    @Override
+    public boolean isEmpty() {
+        return size.get() == 0;
+    }
+
+    @Override
+    public void wakeup() {
+        queue.add(Wakeup.INSTANCE);
+    }
+
+    public interface RaftEvent {

Review comment:
       Could you use a sentinel RaftMessage object here instead? Might simplify 
this class a bit. Not a big deal either way

##########
File path: raft/src/main/java/org/apache/kafka/raft/RaftMessageQueue.java
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.kafka.raft;
+
+/**
+ * This class is used to serialize inbound requests or responses to outbound 
requests.
+ * It basically just allows us to wrap a blocking queue so that we can have a 
mocked
+ * implementation which does not depend on system time.
+ *
+ * See {@link org.apache.kafka.raft.internals.BlockingMessageQueue}.
+ */
+public interface RaftMessageQueue {
+
+    /**
+     * Block for the arrival of a new message.
+     *
+     * @param timeoutMs timeout in milliseconds to wait for a new event
+     * @return the event or null if the timeout was reached

Review comment:
       nit: should add something like "timeout was reached or #wakeup() was 
called"




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

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


Reply via email to