DanielZhu58 commented on code in PR #6438:
URL: https://github.com/apache/hive/pull/6438#discussion_r3232404682


##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/StatisticsManagementTask.java:
##########
@@ -0,0 +1,278 @@
+/*
+ * 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.metastore;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
+import org.apache.hadoop.hive.metastore.model.MPartitionColumnStatistics;
+import org.apache.hadoop.hive.metastore.model.MTableColumnStatistics;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+
+/**
+ * Statistics management task responsible for periodic auto-deletion of table 
and partition column
+ * statistics based on a configured retention interval.
+ *
+ * <p>When {@code metastore.column.statistics.auto.deletion} is enabled, this 
task scans
+ * {@code TAB_COL_STATS} and {@code PART_COL_STATS} for rows whose {@code 
lastAnalyzed} timestamp
+ * is older than {@code metastore.column.statistics.retention.period}, and 
deletes them.
+ * Individual tables may opt out by setting the table property
+ * {@value #STATISTICS_AUTO_DELETION_EXCLUDE_TBLPROPERTY} to {@code "true"}.
+ */
+public class StatisticsManagementTask extends ObjectStore implements 
MetastoreTaskThread {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(StatisticsManagementTask.class);
+
+  /**
+   * Table property key that, when set to {@code "true"} on a table, excludes 
it from automatic
+   * statistics deletion regardless of the global retention setting.
+   */
+  public static final String STATISTICS_AUTO_DELETION_EXCLUDE_TBLPROPERTY =
+      "statistics.auto.deletion.exclude";
+
+  /** Separator used when building composite map keys; chosen to be safe in 
HMS identifiers. */
+  private static final String KEY_SEP = "\0";
+
+  private static final Lock LOCK = new ReentrantLock();

Review Comment:
   Acknowledged. I will keep this for now. 
   The HMS task scheduler is indeed single-threaded. We can keep the lock as a 
defensive measure — the overhead of tryLock is negligible, and it guards 
against duplicate runs if the scheduler ever becomes multi-threaded or if run() 
is invoked directly in tests or tooling.



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