difin commented on code in PR #6507:
URL: https://github.com/apache/hive/pull/6507#discussion_r3430179078


##########
packaging/src/kubernetes/src/java/org/apache/hive/kubernetes/operator/autoscaling/HiveClusterAutoscaler.java:
##########
@@ -0,0 +1,356 @@
+/*
+ * 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.hive.kubernetes.operator.autoscaling;
+
+import java.time.Duration;
+import java.time.Instant;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import io.fabric8.kubernetes.client.KubernetesClient;
+import org.apache.hive.kubernetes.operator.model.HiveCluster;
+import org.apache.hive.kubernetes.operator.model.HiveClusterSpec;
+import org.apache.hive.kubernetes.operator.model.spec.AutoscalingSpec;
+import org.apache.hive.kubernetes.operator.model.status.AutoscalingStatus;
+import org.apache.hive.kubernetes.operator.util.ConfigUtils;
+import org.apache.hive.kubernetes.operator.util.Labels;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Main autoscaling orchestrator. Evaluates all enabled components and
+ * returns a map of component → desired replica count for those that need 
changing.
+ * <p>
+ * Maintains per-cluster, per-component state (stabilization windows).
+ */
+public class HiveClusterAutoscaler {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(HiveClusterAutoscaler.class);
+
+  /** Result of evaluating all components. */
+  public record AutoscalingEvaluation(
+      Map<String, Integer> patches,
+      Map<String, AutoscalingStatus> statuses) {}
+
+  // Shared replica store: the autoscaler writes its desired replicas here so 
that
+  // dependent resources can read them (avoids informer cache lag reverting 
patches).
+  // Key: "namespace/clusterName/component" → desired replicas
+  private static final ConcurrentHashMap<String, Integer> MANAGED_REPLICAS =
+      new ConcurrentHashMap<>();
+
+  /**
+   * Returns the autoscaler-managed replica count for a component, or null if 
the
+   * autoscaler hasn't made a decision yet (e.g., first reconcile before 
evaluation runs).
+   */
+  public static Integer getManagedReplicas(String namespace, String 
clusterName, String component) {
+    return MANAGED_REPLICAS.get(namespace + "/" + clusterName + "/" + 
component);
+  }
+
+  /**
+   * Sets the managed replica count for a component. Used by suspend/wake logic
+   * to override what the autoscaler would normally compute.
+   */
+  public static void setManagedReplicas(String namespace, String clusterName,
+      String component, int replicas) {
+    MANAGED_REPLICAS.put(namespace + "/" + clusterName + "/" + component, 
replicas);

Review Comment:
   `namespace + "/" + clusterName + "/" + component` appears also on line 64, 
should we have a method to avoid duplication?



-- 
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