RongtongJin commented on code in PR #9549: URL: https://github.com/apache/rocketmq/pull/9549#discussion_r2331865725
########## proxy/src/main/java/org/apache/rocketmq/proxy/service/route/RouteCacheRefresher.java: ########## @@ -0,0 +1,122 @@ +/* + * 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.rocketmq.proxy.service.route; + +import org.apache.rocketmq.common.constant.LoggerName; +import org.apache.rocketmq.logging.org.slf4j.Logger; +import org.apache.rocketmq.logging.org.slf4j.LoggerFactory; +import org.apache.rocketmq.common.ThreadFactoryImpl; + +import com.github.benmanes.caffeine.cache.LoadingCache; +import org.apache.rocketmq.common.utils.ThreadUtils; + +import java.util.ArrayList; +import java.util.List; +import java.util.Queue; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +public class RouteCacheRefresher { + private static final Logger log = LoggerFactory.getLogger(LoggerName.PROXY_LOGGER_NAME); + + private final LoadingCache<String, MessageQueueView> topicCache; + private final ThreadPoolExecutor executor; + + private final ConcurrentMap<String, Long> dirtyTopics = new ConcurrentHashMap<>(); + private final Queue<String> pendingTopics = new ConcurrentLinkedQueue<>(); + private final ScheduledExecutorService scheduler; + + public RouteCacheRefresher(LoadingCache<String, MessageQueueView> topicCache, + ThreadPoolExecutor executor) { + this.topicCache = topicCache; + this.executor = executor; + + this.scheduler = ThreadUtils.newSingleThreadScheduledExecutor( + new ThreadFactoryImpl("RouteCacheScheduler_") + ); + } + + public void start() { + scheduler.scheduleWithFixedDelay(this::processDirtyTopics, 50, 200, TimeUnit.MILLISECONDS); + } + + public void markCacheDirty(String topic, long timeStamp) { + long currentTime = System.currentTimeMillis(); + if (currentTime - timeStamp > TimeUnit.MINUTES.toMillis(1)) { + return; + } + + dirtyTopics.put(topic, currentTime); + pendingTopics.offer(topic); + } + + public void markCompleted(String topic) { + dirtyTopics.remove(topic); + } + + public void markRetry(String topic) { + pendingTopics.offer(topic); + } Review Comment: 可以暂时去掉所有retry的逻辑,当前路由反向更新更多是一个辅助的功能,如果没有成功,可以fallback到基础的定时更新,没有必要重试,反而可能会有问题加大服务端压力 -- 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: commits-unsubscr...@rocketmq.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org