[ 
https://issues.apache.org/jira/browse/HIVE-24974?focusedWorklogId=587306&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-587306
 ]

ASF GitHub Bot logged work on HIVE-24974:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 22/Apr/21 15:28
            Start Date: 22/Apr/21 15:28
    Worklog Time Spent: 10m 
      Work Description: deniskuzZ commented on a change in pull request #2148:
URL: https://github.com/apache/hive/pull/2148#discussion_r618506403



##########
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:
       fixed

##########
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:
       fixed

##########
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:
       fixed




-- 
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:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 587306)
    Time Spent: 1h 50m  (was: 1h 40m)

> Create new metrics about the number of delta files in the ACID table
> --------------------------------------------------------------------
>
>                 Key: HIVE-24974
>                 URL: https://issues.apache.org/jira/browse/HIVE-24974
>             Project: Hive
>          Issue Type: Sub-task
>            Reporter: Denys Kuzmenko
>            Assignee: Denys Kuzmenko
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 1h 50m
>  Remaining Estimate: 0h
>
> 2 metrics should be collected by each table/partition that exceeds some limit.
>  * Number of used deltas
>  * Number of obsolete deltas
> Both of them should be collected in AcidUtils.getAcidstate call, and only be 
> published if they reached a configurable threshold (to not pollute metrics) 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to