dajac commented on code in PR #21350: URL: https://github.com/apache/kafka/pull/21350#discussion_r2723926151
########## coordinator-common/src/main/java/org/apache/kafka/coordinator/common/runtime/CoordinatorTimerImpl.java: ########## @@ -0,0 +1,170 @@ +/* + * 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.coordinator.common.runtime; + +import org.apache.kafka.common.errors.CoordinatorLoadInProgressException; +import org.apache.kafka.common.errors.NotCoordinatorException; +import org.apache.kafka.common.utils.LogContext; +import org.apache.kafka.server.util.timer.Timer; +import org.apache.kafka.server.util.timer.TimerTask; + +import org.slf4j.Logger; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.concurrent.RejectedExecutionException; +import java.util.concurrent.TimeUnit; + +/** + * An event-based coordinator timer that bridges Kafka's utility Timer class with the + * coordinator runtime's event-driven architecture. It converts timeout expiries into + * write operations that are scheduled through the runtime, ensuring all timeout operations + * respect the coordinator's threading model. + * + * When a timer fails with an unexpected exception, the timer is rescheduled with a backoff. + */ +public class CoordinatorTimerImpl<U> implements CoordinatorTimer<Void, U> { + private final Logger log; + private final Timer timer; + private final CoordinatorShardScheduler<U> scheduler; + private final Map<String, TimerTask> tasks = new HashMap<>(); + + public CoordinatorTimerImpl( + LogContext logContext, + Timer timer, + CoordinatorShardScheduler<U> scheduler + ) { + this.log = logContext.logger(CoordinatorTimerImpl.class); + this.timer = timer; + this.scheduler = scheduler; + } + + @Override + public void schedule( + String key, + long delay, Review Comment: I have not considered it. It will consider it separately and raise a PR if it makes sense to do it. -- 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]
