architjainjain commented on code in PR #6501: URL: https://github.com/apache/hive/pull/6501#discussion_r3712800243
########## ql/src/java/org/apache/hadoop/hive/ql/exec/tez/monitoring/yarnqueue/QueueMetricsCache.java: ########## @@ -0,0 +1,144 @@ +/* + * 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.hadoop.hive.ql.exec.tez.monitoring.yarnqueue; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.concurrent.TimeUnit; + +/** + * JVM-wide cache mapping queue names to their {@link QueueMetricsState}. + * Responsible only for entry lifecycle: get, put, placeholder creation, and expiry. + * All per-queue logic lives in {@link QueueMetricsState}. + * <p> + * Entries expire after {@value #CACHE_EXPIRE_AFTER_ACCESS_MINUTES} minutes of inactivity + * (no reads or writes). While a queue has active sessions, both the background refresh task + * (via put) and TezProgressMonitor (via get) continuously reset the access timer — the entry + * lives as long as the queue is in use. Once all sessions finish and the refresh task is + * cancelled, no more reads or writes occur and the entry auto-expires after 60 minutes. + * This provides a natural grace period for brief query gaps on the same queue. + */ +public final class QueueMetricsCache { + private static final Logger LOG = LoggerFactory.getLogger(QueueMetricsCache.class); + + private static final QueueMetricsCache INSTANCE = new QueueMetricsCache(); + + // Entries auto-expire after 60 minutes of no reads or writes. + // Active queues: reset continuously by get() (TezProgressMonitor polling) and put() (RM refresh). + // Idle queues: task cancelled + job done → no reads or writes → expires after 60 minutes. + // 60 minutes safely exceeds any realistic refresh interval or progress polling interval. + private static final long CACHE_EXPIRE_AFTER_ACCESS_MINUTES = 60; Review Comment: done -- 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]
