-
Notifications
You must be signed in to change notification settings - Fork 4.8k
HIVE-28755: Statistics Management Task #6438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| /* | ||
| * 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.List; | ||
| import java.util.concurrent.TimeUnit; | ||
|
Comment on lines
+21
to
+22
|
||
| import java.util.concurrent.locks.Lock; | ||
| import java.util.concurrent.locks.ReentrantLock; | ||
|
|
||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.hive.metastore.api.DeleteColumnStatisticsRequest; | ||
| import org.apache.hadoop.hive.metastore.conf.MetastoreConf; | ||
| 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 is primarily responsible for auto deletion of table column stats based on a certain frequency | ||
|
Check warning on line 37 in standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/StatisticsManagementTask.java
|
||
| * | ||
| * If some table or partition column statistics are older than the configured retention interval | ||
| * (MetastoreConf.ConfVars.STATISTICS_RETENTION_PERIOD), they are deleted when this metastore task runs periodically. | ||
| */ | ||
| public class StatisticsManagementTask extends ObjectStore implements MetastoreTaskThread { | ||
| private static final Logger LOG = LoggerFactory.getLogger(StatisticsManagementTask.class); | ||
|
|
||
| // The 2 configs for users to set in the conf | ||
| // this is an optional table property, if this property does not exist for a table, then it is not excluded | ||
| public static final String STATISTICS_AUTO_DELETION_EXCLUDE_TBLPROPERTY = "statistics.auto.deletion.exclude"; | ||
|
Check warning on line 47 in standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/StatisticsManagementTask.java
|
||
|
|
||
| private static final Lock lock = new ReentrantLock(); | ||
|
|
||
| private Configuration conf; | ||
|
|
||
| @Override | ||
| public long runFrequency(TimeUnit unit) { | ||
| return MetastoreConf.getTimeVar(conf, MetastoreConf.ConfVars.STATISTICS_MANAGEMENT_TASK_FREQUENCY, unit); | ||
| } | ||
|
|
||
| @Override | ||
| public void setConf(Configuration configuration) { | ||
| // we modify conf in setupConf(), so we make a copy | ||
| this.conf = new Configuration(configuration); | ||
| super.setConf(configuration); | ||
| } | ||
|
Check warning on line 63 in standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/StatisticsManagementTask.java
|
||
|
|
||
| @Override | ||
|
Check warning on line 65 in standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/StatisticsManagementTask.java
|
||
| public Configuration getConf() { | ||
| return conf; | ||
|
Check warning on line 67 in standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/StatisticsManagementTask.java
|
||
| } | ||
|
|
||
| // what needs to be included in this run() method: | ||
| // get the "lastAnalyzed" information from TAB_COL_STATS and find all the tables need to be deleted | ||
| // delete all column stats | ||
| @Override | ||
| public void run() { | ||
| LOG.debug("Auto statistics deletion started. Cleaning up table/partition column statistics over the retention period."); | ||
| long retentionMillis = MetastoreConf.getTimeVar(conf, MetastoreConf.ConfVars.STATISTICS_RETENTION_PERIOD, TimeUnit.MILLISECONDS); | ||
| if (retentionMillis <= 0 || !MetastoreConf.getBoolVar(conf, MetastoreConf.ConfVars.STATISTICS_AUTO_DELETION)) { | ||
| LOG.info("Statistics auto deletion is set to off currently."); | ||
|
Check warning on line 78 in standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/StatisticsManagementTask.java
|
||
| return; | ||
|
Check warning on line 79 in standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/StatisticsManagementTask.java
|
||
| } | ||
|
Check warning on line 80 in standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/StatisticsManagementTask.java
|
||
| if (!lock.tryLock()) { | ||
| return; | ||
|
Check warning on line 82 in standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/StatisticsManagementTask.java
|
||
| } | ||
| try { | ||
| long now = System.currentTimeMillis(); | ||
| long lastAnalyzedThreshold = (now - retentionMillis) / 1000; | ||
|
|
||
| String filter = "lastAnalyzed < threshold"; | ||
| String paramStr = "long threshold"; | ||
|
|
||
| PersistenceManager pm = getPersistenceManager(); | ||
| boolean committed = false; | ||
| openTransaction(); // open JDO transaction | ||
| try { | ||
| Query q = null; | ||
|
Check warning on line 95 in standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/StatisticsManagementTask.java
|
||
| try { | ||
| q = pm.newQuery(MTableColumnStatistics.class); | ||
|
Check warning on line 97 in standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/StatisticsManagementTask.java
|
||
| q.setFilter(filter); | ||
|
Check warning on line 98 in standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/StatisticsManagementTask.java
|
||
| q.declareParameters(paramStr); | ||
| q.setResult( | ||
| "table.database.name, " + | ||
| "table.tableName, " + | ||
| "partitionName, " + | ||
| "table.parameters.get(\"" + STATISTICS_AUTO_DELETION_EXCLUDE_TBLPROPERTY + "\")" | ||
| ); | ||
|
Comment on lines
+100
to
+105
|
||
| @SuppressWarnings("unchecked") | ||
| List<Object[]> rows = (List<Object[]>) q.execute(lastAnalyzedThreshold); | ||
|
|
||
| try (IMetaStoreClient msc = new HiveMetaStoreClient(conf)) { | ||
|
Check warning on line 109 in standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/StatisticsManagementTask.java
|
||
| for (Object[] row : rows) { | ||
| String dbName = (String) row[0]; | ||
| String tblName = (String) row[1]; | ||
| String partName = (String) row[2]; | ||
| String excludeVal = (String) row[3]; | ||
|
|
||
| if (excludeVal != null) { | ||
| LOG.info("Skipping auto deletion of stats for table {}.{} due to STATISTICS_AUTO_DELETION_EXCLUDE_TBLPROPERTY property being set on the table.", dbName, tblName); | ||
|
Check warning on line 117 in standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/StatisticsManagementTask.java
|
||
| continue; | ||
| } | ||
| DeleteColumnStatisticsRequest request = new DeleteColumnStatisticsRequest(dbName, tblName); | ||
|
Check warning on line 120 in standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/StatisticsManagementTask.java
|
||
| request.setEngine("hive"); | ||
| request.setTableLevel(partName == null); | ||
| msc.deleteColumnStatistics(request); | ||
| } | ||
|
Check warning on line 124 in standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/StatisticsManagementTask.java
|
||
| } | ||
| } finally { | ||
| if (q != null) { | ||
|
Check warning on line 127 in standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/StatisticsManagementTask.java
|
||
| q.closeAll(); | ||
| } | ||
|
DanielZhu58 marked this conversation as resolved.
|
||
| } | ||
|
Check warning on line 130 in standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/StatisticsManagementTask.java
|
||
| committed = commitTransaction(); | ||
| } finally { | ||
|
Check warning on line 132 in standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/StatisticsManagementTask.java
|
||
| if (!committed) { | ||
| rollbackTransaction(); | ||
| } | ||
| } | ||
| } catch (Exception e) { | ||
| LOG.error("Error during statistics auto deletion", e); | ||
| } finally { | ||
| lock.unlock(); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding
org.apache.hadoop.hive.metastore.StatisticsManagementTasktoMETASTORE_TASK_THREADS_ALWAYSmeans it will start in all deployments. Given the new configs currently default to enabling deletion, this can change runtime behavior unexpectedly after upgrade; ensure this is gated behind an explicit opt-in (or keep it out of the always-start list until explicitly configured).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Acknowledged. Set to false by default.