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

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

                Author: ASF GitHub Bot
            Created on: 18/Jan/22 15:56
            Start Date: 18/Jan/22 15:56
    Worklog Time Spent: 10m 
      Work Description: lcspinter commented on a change in pull request #2916:
URL: https://github.com/apache/hive/pull/2916#discussion_r786900655



##########
File path: 
ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/metrics/DeltaFilesMetricReporter.java
##########
@@ -512,7 +284,177 @@ private void shutdown() {
     }
   }
 
-  public static class DeltaFilesMetadata implements Serializable {
-    public String dbName, tableName, partitionName;
+  public static void updateMetricsFromInitiator(AcidDirectory dir, String 
dbName, String tableName, String partitionName,
+      Configuration conf, TxnStore txnHandler) {
+    LOG.debug("Updating delta file metrics from initiator");
+    double deltaPctThreshold = MetastoreConf.getDoubleVar(conf, 
MetastoreConf.ConfVars.METASTORE_DELTAMETRICS_DELTA_PCT_THRESHOLD);
+    int deltasThreshold = MetastoreConf.getIntVar(conf, 
MetastoreConf.ConfVars.METASTORE_DELTAMETRICS_DELTA_NUM_THRESHOLD);
+    int obsoleteDeltasThreshold = MetastoreConf.getIntVar(conf,
+        
MetastoreConf.ConfVars.METASTORE_DELTAMETRICS_OBSOLETE_DELTA_NUM_THRESHOLD);
+    try {
+      // We have an AcidDir from the initiator, therefore we can use that to 
calculate active,small, obsolete delta
+      // count
+      long baseSize = getBaseSize(dir);
+
+      int numDeltas = dir.getCurrentDirectories().size();
+      int numSmallDeltas = 0;
+
+      for (AcidUtils.ParsedDelta delta : dir.getCurrentDirectories()) {
+        long deltaSize = getDirSize(delta, dir.getFs());
+        if (baseSize != 0 && deltaSize / (float) baseSize < deltaPctThreshold) 
{
+          numSmallDeltas++;
+        }
+      }
+
+      int numObsoleteDeltas = dir.getObsolete().size();
+
+      if (numDeltas > deltasThreshold) {
+        updateMetrics(dbName, tableName, partitionName, 
CompactionMetricsData.MetricType.NUM_DELTAS, numDeltas,
+            txnHandler);
+      }
+
+      if (numSmallDeltas > deltasThreshold) {
+        updateMetrics(dbName, tableName, partitionName, 
CompactionMetricsData.MetricType.NUM_SMALL_DELTAS,
+            numSmallDeltas, txnHandler);
+      }
+
+      if (numObsoleteDeltas > obsoleteDeltasThreshold) {
+        updateMetrics(dbName, tableName, partitionName, 
CompactionMetricsData.MetricType.NUM_OBSOLETE_DELTAS,
+            numObsoleteDeltas, txnHandler);
+      }
+
+      LOG.debug("Finished updating delta file metrics from initiator.\n 
deltaPctThreshold = {}, deltasThreshold = {}, "
+          + "obsoleteDeltasThreshold = {}, numDeltas = {}, numSmallDeltas = 
{},  numObsoleteDeltas = {}",
+          deltaPctThreshold, deltasThreshold, obsoleteDeltasThreshold, 
numDeltas, numSmallDeltas, numObsoleteDeltas);
+
+    } catch (Throwable t) {
+      LOG.warn("Unknown throwable caught while updating delta metrics. Metrics 
will not be updated.", t);
+    }
+  }
+
+  public static void updateMetricsFromWorker(AcidDirectory directory, String 
dbName, String tableName, String partitionName,
+      CompactionType type, Configuration conf, IMetaStoreClient client) {
+    LOG.debug("Updating delta file metrics from worker");
+    int deltasThreshold = MetastoreConf.getIntVar(conf, 
MetastoreConf.ConfVars.METASTORE_DELTAMETRICS_DELTA_NUM_THRESHOLD);
+    int obsoleteDeltasThreshold = MetastoreConf.getIntVar(conf,
+        
MetastoreConf.ConfVars.METASTORE_DELTAMETRICS_OBSOLETE_DELTA_NUM_THRESHOLD);
+    try {
+      // we have an instance of the AcidDirectory before the compaction worker 
was started
+      // from this we can get how many delta directories existed
+      // the previously active delta directories are now moved to obsolete
+      int numObsoleteDeltas = directory.getCurrentDirectories().size();
+      if (numObsoleteDeltas > obsoleteDeltasThreshold) {
+        updateMetrics(dbName, tableName, partitionName, 
CompactionMetricsMetricType.NUM_OBSOLETE_DELTAS,
+            numObsoleteDeltas, client);
+      }
+
+      // We don't know the size of the newly create delta directories, that 
would require a fresh AcidDirectory
+      // Clear the small delta num counter from the cache for this key
+      client.removeCompactionMetricsData(dbName, tableName, partitionName, 
CompactionMetricsMetricType.NUM_SMALL_DELTAS);
+
+      // The new number of active delta dirs are either 0, 1 or 2.
+      // If we ran MAJOR compaction, no new delta is created, just base dir
+      // If we ran MINOR compaction, we can have 1 or 2 new delta dirs, 
depending on whether we had deltas or
+      // delete deltas.
+      if (type == CompactionType.MAJOR) {
+        client.removeCompactionMetricsData(dbName, tableName, partitionName, 
CompactionMetricsMetricType.NUM_DELTAS);
+      } else {
+        int numNewDeltas = 0;
+        // check whether we had deltas
+        if (directory.getDeleteDeltas().size() > 0) {
+          numNewDeltas++;
+        }
+
+        // if the size of the current dirs is bigger than the size of delete 
deltas, it means we have active deltas
+        if (directory.getCurrentDirectories().size() > 
directory.getDeleteDeltas().size()) {
+          numNewDeltas++;
+        }
+
+        // recalculate the delta count
+        CompactionMetricsDataStruct prevDelta =
+            client.getCompactionMetricsData(dbName, tableName, partitionName, 
CompactionMetricsMetricType.NUM_DELTAS)
+                .getData();
+        int deltaNum = numNewDeltas;
+        if (prevDelta != null) {
+          deltaNum += prevDelta.getMetricvalue() - 
directory.getCurrentDirectories().size();

Review comment:
       That is true, but in that case shouldn't we clean up the active delta 
metrics, if that falls behind the threshold? 




-- 
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: gitbox-unsubscr...@hive.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

    Worklog Id:     (was: 710602)
    Time Spent: 2.5h  (was: 2h 20m)

> Reimplement delta file metric collection
> ----------------------------------------
>
>                 Key: HIVE-25842
>                 URL: https://issues.apache.org/jira/browse/HIVE-25842
>             Project: Hive
>          Issue Type: Improvement
>            Reporter: László Pintér
>            Assignee: László Pintér
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 2.5h
>  Remaining Estimate: 0h
>
> FUNCTIONALITY: Metrics are collected only when a Tez query runs a table 
> (select * and select count( * ) don't update the metrics)
> Metrics aren't updated after compaction or cleaning after compaction, so 
> users will probably see "issues" with compaction (like many active or 
> obsolete or small deltas) that don't exist.
> RISK: Metrics are collected during queries – we tried to put a try-catch 
> around each method in DeltaFilesMetricsReporter but of course this isn't 
> foolproof. This is a HUGE performance and functionality liability. Tests 
> caught some issues, but our tests aren't perfect.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to