cmccabe commented on code in PR #17502:
URL: https://github.com/apache/kafka/pull/17502#discussion_r1811535659


##########
metadata/src/main/java/org/apache/kafka/controller/PeriodicTaskControlManager.java:
##########
@@ -0,0 +1,229 @@
+/*
+ * 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.controller;
+
+import org.apache.kafka.common.utils.LogContext;
+import org.apache.kafka.common.utils.Time;
+
+import org.slf4j.Logger;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Supplier;
+
+import static java.util.concurrent.TimeUnit.NANOSECONDS;
+
+
+class PeriodicTaskControlManager {
+    static class Builder {
+        private LogContext logContext = null;
+        private Time time = Time.SYSTEM;
+        private QueueAccessor queueAccessor = null;
+
+        Builder setLogContext(LogContext logContext) {
+            this.logContext = logContext;
+            return this;
+        }
+
+        Builder setTime(Time time) {
+            this.time = time;
+            return this;
+        }
+
+        Builder setQueueAccessor(QueueAccessor queueAccessor) {
+            this.queueAccessor = queueAccessor;
+            return this;
+        }
+
+        PeriodicTaskControlManager build() {
+            if (logContext == null) logContext = new LogContext();
+            if (queueAccessor == null) throw new RuntimeException("You must 
set queueAccessor");
+            return new PeriodicTaskControlManager(logContext,
+                    time,
+                    queueAccessor);
+        }
+    }
+
+    interface QueueAccessor {
+        void scheduleDeferred(
+            String tag,
+            long deadlineNs,
+            Supplier<ControllerResult<Void>> op
+        );
+
+        void cancelDeferred(String tag);
+    }
+
+    class PeriodicTaskOperation implements Supplier<ControllerResult<Void>> {
+        private final PeriodicTask task;
+
+        PeriodicTaskOperation(PeriodicTask task) {
+            this.task = task;
+        }
+
+        @Override
+        public ControllerResult<Void> get() {
+            long startNs = 0;
+            if (log.isDebugEnabled() || 
task.flags().contains(PeriodicTaskFlag.VERBOSE)) {
+                startNs = time.nanoseconds();
+            }
+            ControllerResult<Boolean> result = task.op().get();

Review Comment:
   Oh, exceptions will end up in `QuorumController.handleEventException`. Which 
could do a few things: nothing, cause controller failover, or increment the 
metadata error count metric, depending on exception type. I will add more 
comments about this... and see if I can add a test case...



-- 
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: jira-unsubscr...@kafka.apache.org

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

Reply via email to