architjainjain commented on code in PR #6501:
URL: https://github.com/apache/hive/pull/6501#discussion_r3713593744


##########
ql/src/java/org/apache/hadoop/hive/ql/exec/tez/monitoring/yarnqueue/YarnQueueMetricsCollector.java:
##########
@@ -0,0 +1,204 @@
+/*
+ * 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 org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.yarn.api.records.QueueInfo;
+import org.apache.hadoop.yarn.client.api.YarnClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Collects YARN queue resource metrics using a shared cache to reduce 
ResourceManager load.
+ * Coordinates with other collectors via QueueMetricsCache to prevent 
duplicate RM calls.
+ *
+ * Executor pool management (sizing, lifecycle, JMX) is fully delegated to
+ * {@link QueueMetricsRefreshPool}. This class focuses solely on 
per-query/per-queue
+ * metrics logic: session registration, refresh scheduling, and cache 
coordination.
+ */
+public class YarnQueueMetricsCollector implements QueueMetricsCollector {
+  private static final Logger LOG = 
LoggerFactory.getLogger(YarnQueueMetricsCollector.class);
+
+  private final YarnClient yarnClient;
+  private final String queueName;
+  private final long refreshIntervalMs;
+  private final String queryId;
+
+
+  /**
+   * Creates a collector for the given queue and query. Non-blocking: metrics 
are
+   * fetched asynchronously; the first progress update may show no metrics, 
subsequent
+   * updates will once the first fetch completes (within one 
refreshIntervalMs).
+   *
+   * @param yarnClient        Live YarnClient from the Tez session
+   * @param queueName         YARN queue this query runs on
+   * @param refreshIntervalMs How often to poll YARN RM (ms)
+   * @param queryId           DAG name for logging
+   * @param hiveConf          Unused (kept for API compatibility)
+   */
+  public YarnQueueMetricsCollector(YarnClient yarnClient, String queueName, 
long refreshIntervalMs, String queryId,
+      HiveConf hiveConf) {
+    if (yarnClient == null) {
+      throw new IllegalArgumentException("YarnClient cannot be null");
+    }
+    if (queueName == null) {
+      throw new IllegalArgumentException("Queue name cannot be null");
+    }
+    if (refreshIntervalMs <= 0) {
+      throw new IllegalArgumentException("refreshIntervalMs must be > 0, got: 
" + refreshIntervalMs);
+    }
+
+    this.yarnClient = yarnClient;
+    this.queueName = queueName;
+    this.refreshIntervalMs = refreshIntervalMs;
+    this.queryId = queryId;
+
+
+    // Register session and start background refresh scheduling.
+    initializeSession();
+
+    LOG.info("Started queue metrics collector for queue: {}, refresh interval: 
{}ms, query: {}", queueName,
+        refreshIntervalMs, queryId);
+  }
+
+
+  /**
+   * Startup sequence: get or create the cache entry for {@code queueName},
+   * register this session's interval, then schedule the refresh task if 
needed.
+   * Concurrent safety: {@link QueueMetricsCache#putPlaceholder} uses
+   * {@code putIfAbsent} — two threads seeing null both get back the same 
entry.
+   */
+  private void initializeSession() {
+    QueueMetricsCache cache = QueueMetricsCache.getInstance();
+    QueueMetricsState state = cache.get(queueName);
+    if (state == null) {
+      state = cache.putPlaceholder(queueName, refreshIntervalMs);
+    }

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]

Reply via email to