klcopp commented on a change in pull request #2148:
URL: https://github.com/apache/hive/pull/2148#discussion_r616843875



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezTask.java
##########
@@ -254,6 +255,10 @@ public int execute() {
         try {
           Set<StatusGetOpts> statusGetOpts = 
EnumSet.of(StatusGetOpts.GET_COUNTERS);
           TezCounters dagCounters = 
dagClient.getDAGStatus(statusGetOpts).getDAGCounters();
+
+          if (HiveConf.getBoolVar(conf, 
HiveConf.ConfVars.HIVE_SERVER2_METRICS_ENABLED)) {

Review comment:
       Maybe a feature flag for these specific metrics would be a good idea. 
What do you think?

##########
File path: common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
##########
@@ -3002,6 +3002,26 @@ private static void 
populateLlapDaemonVarsSet(Set<String> llapDaemonVarsSetLocal
     HIVE_TXN_READONLY_ENABLED("hive.txn.readonly.enabled", false,
       "Enables read-only transaction classification and related 
optimizations"),
 
+    // Configs having to do with DeltaFilesMetricReporter, which collects 
lists of most recently active tables
+    // with the most number of active/obsolete deltas.
+    
HIVE_TXN_ACID_METRICS_MAX_CACHE_SIZE("hive.txn.acid.metrics.max.cache.size", 
100,
+        "Size of the ACID metrics cache. Only topN metrics would remain in the 
cache if exceeded."),
+    
HIVE_TXN_ACID_METRICS_CACHE_DURATION("hive.txn.acid.metrics.cache.duration", 
"7200s",
+        new TimeValidator(TimeUnit.SECONDS),
+        "Maximum lifetime in seconds for an entry in the ACID metrics cache."),
+    
HIVE_TXN_ACID_METRICS_REPORTING_INTERVAL("hive.txn.acid.metrics.reporting.interval",
 "30s",
+        new TimeValidator(TimeUnit.SECONDS),
+        "Reporting period for ACID metrics in seconds."),
+    
HIVE_TXN_ACID_METRICS_DELTA_NUM_THRESHOLD("hive.txn.acid.metrics.delta.num.threshold",
 100,
+        "The minimum number of active delta files a table/partition must be 
included in the ACID metrics report."),
+    
HIVE_TXN_ACID_METRICS_OBSOLETE_DELTA_NUM_THRESHOLD("hive.txn.acid.metrics.obsolete.delta.num.threshold",
 100,
+        "The minimum number of obsolete delta files a table/partition must be 
included in the ACID metrics report."),
+    
HIVE_TXN_ACID_METRICS_DELTA_CHECK_THRESHOLD("hive.txn.acid.metrics.delta.check.threshold",
 "300s",
+        new TimeValidator(TimeUnit.SECONDS),
+        "Deltas not older than this value will not be included in the ACID 
metrics report."),

Review comment:
       Should be: Deltas older than this value will not be included in the ACID 
metrics report

##########
File path: common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
##########
@@ -3002,6 +3002,26 @@ private static void 
populateLlapDaemonVarsSet(Set<String> llapDaemonVarsSetLocal
     HIVE_TXN_READONLY_ENABLED("hive.txn.readonly.enabled", false,
       "Enables read-only transaction classification and related 
optimizations"),
 
+    // Configs having to do with DeltaFilesMetricReporter, which collects 
lists of most recently active tables
+    // with the most number of active/obsolete deltas.
+    
HIVE_TXN_ACID_METRICS_MAX_CACHE_SIZE("hive.txn.acid.metrics.max.cache.size", 
100,
+        "Size of the ACID metrics cache. Only topN metrics would remain in the 
cache if exceeded."),
+    
HIVE_TXN_ACID_METRICS_CACHE_DURATION("hive.txn.acid.metrics.cache.duration", 
"7200s",
+        new TimeValidator(TimeUnit.SECONDS),
+        "Maximum lifetime in seconds for an entry in the ACID metrics cache."),
+    
HIVE_TXN_ACID_METRICS_REPORTING_INTERVAL("hive.txn.acid.metrics.reporting.interval",
 "30s",
+        new TimeValidator(TimeUnit.SECONDS),
+        "Reporting period for ACID metrics in seconds."),
+    
HIVE_TXN_ACID_METRICS_DELTA_NUM_THRESHOLD("hive.txn.acid.metrics.delta.num.threshold",
 100,
+        "The minimum number of active delta files a table/partition must be 
included in the ACID metrics report."),
+    
HIVE_TXN_ACID_METRICS_OBSOLETE_DELTA_NUM_THRESHOLD("hive.txn.acid.metrics.obsolete.delta.num.threshold",
 100,
+        "The minimum number of obsolete delta files a table/partition must be 
included in the ACID metrics report."),

Review comment:
       ...a table/partition must be ...
   should be: ...a table/partition must have to be ...

##########
File path: 
ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/metrics/DeltaFilesMetricReporter.java
##########
@@ -0,0 +1,296 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.txn.compactor.metrics;
+
+import com.google.common.base.Joiner;
+import com.google.common.base.Splitter;
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+
+import com.google.common.cache.RemovalNotification;
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hive.common.metrics.common.Metrics;
+import org.apache.hadoop.hive.common.metrics.common.MetricsFactory;
+import org.apache.hadoop.hive.common.metrics.common.MetricsVariable;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.ql.io.AcidDirectory;
+import org.apache.hadoop.hive.ql.io.AcidUtils;
+
+import org.apache.hadoop.hive.shims.HadoopShims;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hive.common.util.Ref;
+import org.apache.tez.common.counters.TezCounters;
+import org.jetbrains.annotations.NotNull;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.Comparator;
+
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.Executors;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.PriorityBlockingQueue;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Stream;
+
+import static 
org.apache.hadoop.hive.metastore.metrics.MetricsConstants.COMPACTION_NUM_DELTAS;
+import static 
org.apache.hadoop.hive.metastore.metrics.MetricsConstants.COMPACTION_NUM_OBSOLETE_DELTAS;
+import static 
org.apache.hadoop.hive.metastore.metrics.MetricsConstants.COMPACTION_NUM_SMALL_DELTAS;
+
+/**
+ * Collects and publishes ACID compaction related metrics.
+ */
+public class DeltaFilesMetricReporter {
+
+  private static final Logger LOG = LoggerFactory.getLogger(AcidUtils.class);
+
+  public static final String NUM_OBSOLETE_DELTAS = 
"HIVE_ACID_NUM_OBSOLETE_DELTAS";
+  public static final String NUM_DELTAS = "HIVE_ACID_NUM_DELTAS";
+  public static final String NUM_SMALL_DELTAS = "HIVE_ACID_NUM_SMALL_DELTAS";
+
+  private int deltasThreshold;
+  private int obsoleteDeltasThreshold;
+
+  private int maxCacheSize;
+
+  private Cache<String, Integer> deltaCache, smallDeltaCache;
+  private Cache<String, Integer> obsoleteDeltaCache;
+
+  private BlockingQueue<Pair<String, Integer>> deltaTopN, smallDeltaTopN;
+  private BlockingQueue<Pair<String, Integer>> obsoleteDeltaTopN;
+
+  private ScheduledExecutorService executorService;
+
+  private static class InstanceHolder {
+    public static DeltaFilesMetricReporter instance = new 
DeltaFilesMetricReporter();
+  }
+
+  private DeltaFilesMetricReporter() {
+  }
+
+  public static DeltaFilesMetricReporter getInstance() {
+    return InstanceHolder.instance;
+  }
+
+  public static synchronized void init(HiveConf conf){
+    getInstance().configure(conf);
+  }
+
+  public void submit(TezCounters counters) {
+    updateMetrics(NUM_OBSOLETE_DELTAS,
+        obsoleteDeltaCache, obsoleteDeltaTopN, obsoleteDeltasThreshold, 
counters);
+    updateMetrics(NUM_DELTAS,
+        deltaCache, deltaTopN, deltasThreshold, counters);
+    updateMetrics(NUM_SMALL_DELTAS,
+        smallDeltaCache, smallDeltaTopN, deltasThreshold, counters);
+  }
+
+  public static Pair<Integer, Integer> getNumDeltas(AcidDirectory dir, long 
checkThresholdInSec,

Review comment:
       style-related: it's a little weird that getNumDeltas returns 
Pair<Integer, Integer> and getNumObsoleteDeltas returns int, and they're only 
ever called together. What do you think about merging these 2 functions into 1?
   
   If you don't like that then at least, getNumDeltas needs a javadoc comment 
describing what it returns.

##########
File path: 
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/metrics/MetricsConstants.java
##########
@@ -33,6 +33,10 @@
   public static final String OLDEST_ABORTED_TXN_ID = "oldest_aborted_txn_id";
   public static final String OLDEST_ABORTED_TXN_AGE = 
"oldest_aborted_txn_age_in_sec";
 
+  public static final String COMPACTION_NUM_OBSOLETE_DELTAS = 
COMPACTION_STATUS_PREFIX + "obsolete_deltas";
+  public static final String COMPACTION_NUM_DELTAS = COMPACTION_STATUS_PREFIX 
+ "deltas";

Review comment:
       suggestion:  active_deltas instead of deltas
   is more clear

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/io/orc/OrcInputFormat.java
##########
@@ -1781,6 +1787,14 @@ private long computeProjectionSize(List<OrcProto.Type> 
fileTypes,
         " reader schema " + (readerSchema == null ? "NULL" : 
readerSchema.toString()) +
         " ACID scan property " + isAcidTableScan);
     }
+    boolean metricsEnabled = HiveConf.getBoolVar(conf, 
HiveConf.ConfVars.HIVE_SERVER2_METRICS_ENABLED);
+    long checkThresholdInSec = HiveConf.getTimeVar(conf,
+        HiveConf.ConfVars.HIVE_TXN_ACID_METRICS_DELTA_CHECK_THRESHOLD, 
TimeUnit.SECONDS);
+    float deltaPctThreshold = HiveConf.getFloatVar(conf, 
HiveConf.ConfVars.HIVE_TXN_ACID_METRICS_DELTA_PCT_THRESHOLD);
+
+    Map<String, Map<String, Integer>> deltas = new HashMap<>();
+    Stream.of(NUM_OBSOLETE_DELTAS, NUM_DELTAS, NUM_SMALL_DELTAS).forEach(

Review comment:
       Should this only be executed if metrics are enabled?

##########
File path: common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
##########
@@ -3002,6 +3002,26 @@ private static void 
populateLlapDaemonVarsSet(Set<String> llapDaemonVarsSetLocal
     HIVE_TXN_READONLY_ENABLED("hive.txn.readonly.enabled", false,
       "Enables read-only transaction classification and related 
optimizations"),
 
+    // Configs having to do with DeltaFilesMetricReporter, which collects 
lists of most recently active tables
+    // with the most number of active/obsolete deltas.
+    
HIVE_TXN_ACID_METRICS_MAX_CACHE_SIZE("hive.txn.acid.metrics.max.cache.size", 
100,
+        "Size of the ACID metrics cache. Only topN metrics would remain in the 
cache if exceeded."),
+    
HIVE_TXN_ACID_METRICS_CACHE_DURATION("hive.txn.acid.metrics.cache.duration", 
"7200s",
+        new TimeValidator(TimeUnit.SECONDS),
+        "Maximum lifetime in seconds for an entry in the ACID metrics cache."),
+    
HIVE_TXN_ACID_METRICS_REPORTING_INTERVAL("hive.txn.acid.metrics.reporting.interval",
 "30s",
+        new TimeValidator(TimeUnit.SECONDS),
+        "Reporting period for ACID metrics in seconds."),
+    
HIVE_TXN_ACID_METRICS_DELTA_NUM_THRESHOLD("hive.txn.acid.metrics.delta.num.threshold",
 100,
+        "The minimum number of active delta files a table/partition must be 
included in the ACID metrics report."),

Review comment:
       ...a table/partition must be ...
   should be: ...a table/partition must have to be ...

##########
File path: common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
##########
@@ -3002,6 +3002,26 @@ private static void 
populateLlapDaemonVarsSet(Set<String> llapDaemonVarsSetLocal
     HIVE_TXN_READONLY_ENABLED("hive.txn.readonly.enabled", false,
       "Enables read-only transaction classification and related 
optimizations"),
 
+    // Configs having to do with DeltaFilesMetricReporter, which collects 
lists of most recently active tables
+    // with the most number of active/obsolete deltas.
+    
HIVE_TXN_ACID_METRICS_MAX_CACHE_SIZE("hive.txn.acid.metrics.max.cache.size", 
100,
+        "Size of the ACID metrics cache. Only topN metrics would remain in the 
cache if exceeded."),
+    
HIVE_TXN_ACID_METRICS_CACHE_DURATION("hive.txn.acid.metrics.cache.duration", 
"7200s",
+        new TimeValidator(TimeUnit.SECONDS),
+        "Maximum lifetime in seconds for an entry in the ACID metrics cache."),
+    
HIVE_TXN_ACID_METRICS_REPORTING_INTERVAL("hive.txn.acid.metrics.reporting.interval",
 "30s",
+        new TimeValidator(TimeUnit.SECONDS),
+        "Reporting period for ACID metrics in seconds."),
+    
HIVE_TXN_ACID_METRICS_DELTA_NUM_THRESHOLD("hive.txn.acid.metrics.delta.num.threshold",
 100,
+        "The minimum number of active delta files a table/partition must be 
included in the ACID metrics report."),
+    
HIVE_TXN_ACID_METRICS_OBSOLETE_DELTA_NUM_THRESHOLD("hive.txn.acid.metrics.obsolete.delta.num.threshold",
 100,
+        "The minimum number of obsolete delta files a table/partition must be 
included in the ACID metrics report."),
+    
HIVE_TXN_ACID_METRICS_DELTA_CHECK_THRESHOLD("hive.txn.acid.metrics.delta.check.threshold",
 "300s",
+        new TimeValidator(TimeUnit.SECONDS),
+        "Deltas not older than this value will not be included in the ACID 
metrics report."),
+    
HIVE_TXN_ACID_METRICS_DELTA_PCT_THRESHOLD("hive.txn.acid.metrics.delta.pct.threshold",
 0.01f,
+        "Percentage (fractional) size of the delta files relative to the base. 
Default 0.01 = 1%.)"),

Review comment:
       What do you think about:
   Percentage (fractional) size of the delta files relative to the base 
directory. Deltas smaller than this threshold count as small deltas. Default 
0.01 = 1%.




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

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