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

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

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



##########
File path: 
ql/src/test/org/apache/hadoop/hive/ql/txn/compactor/TestDeltaFilesMetrics.java
##########
@@ -39,199 +45,396 @@
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
 import java.lang.management.ManagementFactory;
-import java.util.EnumMap;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
-import java.util.Queue;
 import java.util.concurrent.TimeUnit;
 
-import static 
org.apache.hadoop.hive.ql.txn.compactor.metrics.DeltaFilesMetricReporter.DeltaFilesMetricType.NUM_DELTAS;
-import static 
org.apache.hadoop.hive.ql.txn.compactor.metrics.DeltaFilesMetricReporter.DeltaFilesMetricType.NUM_OBSOLETE_DELTAS;
-import static 
org.apache.hadoop.hive.ql.txn.compactor.metrics.DeltaFilesMetricReporter.DeltaFilesMetricType.NUM_SMALL_DELTAS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
 public class TestDeltaFilesMetrics extends CompactorTest  {
 
   private void setUpHiveConf() {
-    HiveConf.setBoolVar(conf, HiveConf.ConfVars.HIVE_SERVER2_METRICS_ENABLED, 
true);
-    HiveConf.setIntVar(conf, 
HiveConf.ConfVars.HIVE_TXN_ACID_METRICS_MAX_CACHE_SIZE, 2);
-    HiveConf.setTimeVar(conf, 
HiveConf.ConfVars.HIVE_TXN_ACID_METRICS_CACHE_DURATION, 7200, TimeUnit.SECONDS);
-    HiveConf.setIntVar(conf, 
HiveConf.ConfVars.HIVE_TXN_ACID_METRICS_OBSOLETE_DELTA_NUM_THRESHOLD, 100);
-    HiveConf.setIntVar(conf, 
HiveConf.ConfVars.HIVE_TXN_ACID_METRICS_DELTA_NUM_THRESHOLD, 100);
-    HiveConf.setTimeVar(conf, 
HiveConf.ConfVars.HIVE_TXN_ACID_METRICS_REPORTING_INTERVAL, 1, 
TimeUnit.SECONDS);
+    MetastoreConf.setLongVar(conf, 
MetastoreConf.ConfVars.METASTORE_DELTAMETRICS_DELTA_NUM_THRESHOLD, 1);
+    MetastoreConf.setLongVar(conf, 
MetastoreConf.ConfVars.METASTORE_DELTAMETRICS_OBSOLETE_DELTA_NUM_THRESHOLD, 1);
+    MetastoreConf.setTimeVar(conf, 
MetastoreConf.ConfVars.METASTORE_DELTAMETRICS_REPORTING_INTERVAL, 1,
+        TimeUnit.SECONDS);
+    MetastoreConf.setDoubleVar(conf, 
MetastoreConf.ConfVars.METASTORE_DELTAMETRICS_DELTA_PCT_THRESHOLD, 0.15f);
+    MetastoreConf.setBoolVar(conf, MetastoreConf.ConfVars.METRICS_ENABLED, 
true);
+    MetastoreConf.setBoolVar(conf, 
MetastoreConf.ConfVars.METASTORE_ACIDMETRICS_EXT_ON, true);
+    MetastoreConf.setBoolVar(conf, 
MetastoreConf.ConfVars.COMPACTOR_INITIATOR_ON, true);
   }
 
-  private void initAndCollectFirstMetrics() throws Exception {
-    MetricsFactory.close();
-    MetricsFactory.init(conf);
+  @After
+  public void tearDown() throws Exception {
+    DeltaFilesMetricReporter.close();
+  }
 
-    DeltaFilesMetricReporter.init(conf);
 
-    TezCounters tezCounters = new TezCounters();
-    tezCounters.findCounter(NUM_OBSOLETE_DELTAS + "", 
"default.acid/p=1").setValue(200);
-    tezCounters.findCounter(NUM_OBSOLETE_DELTAS + "", 
"default.acid/p=2").setValue(100);
-    tezCounters.findCounter(NUM_OBSOLETE_DELTAS + "", 
"default.acid/p=3").setValue(150);
-    tezCounters.findCounter(NUM_OBSOLETE_DELTAS + "", 
"default.acid_v2").setValue(250);
+  static void verifyMetricsMatch(Map<String, String> expected, Map<String, 
String> actual) {
+    Assert.assertTrue("Actual metrics " + actual + " don't match expected: " + 
expected,
+        equivalent(expected, actual));
+  }
 
-    tezCounters.findCounter(NUM_DELTAS + "", "default.acid/p=1").setValue(150);
-    tezCounters.findCounter(NUM_DELTAS + "", "default.acid/p=2").setValue(100);
-    tezCounters.findCounter(NUM_DELTAS + "", "default.acid/p=3").setValue(250);
-    tezCounters.findCounter(NUM_DELTAS + "", "default.acid_v2").setValue(200);
+  private static boolean equivalent(Map<String, String> lhs, Map<String, 
String> rhs) {
+    return lhs.size() == rhs.size() && Maps.difference(lhs, rhs).areEqual();
+  }
 
-    tezCounters.findCounter(NUM_SMALL_DELTAS + "", 
"default.acid/p=1").setValue(250);
-    tezCounters.findCounter(NUM_SMALL_DELTAS + "", 
"default.acid/p=2").setValue(200);
-    tezCounters.findCounter(NUM_SMALL_DELTAS + "", 
"default.acid/p=3").setValue(150);
-    tezCounters.findCounter(NUM_SMALL_DELTAS + "", 
"default.acid_v2").setValue(100);
+  static Map<String, String> gaugeToMap(String metric) throws Exception {
+    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+    ObjectName oname = new 
ObjectName(DeltaFilesMetricReporter.OBJECT_NAME_PREFIX + metric);
+    MBeanInfo mbeanInfo = mbs.getMBeanInfo(oname);
 
-    DeltaFilesMetricReporter.getInstance().submit(tezCounters, null);
-    Thread.sleep(1000);
+    Map<String, String> result = new HashMap<>();
+    for (MBeanAttributeInfo attr : mbeanInfo.getAttributes()) {
+      result.put(attr.getName(), String.valueOf(mbs.getAttribute(oname, 
attr.getName())));
+    }
+    return result;
   }
 
-  @After
-  public void tearDown() {
-    DeltaFilesMetricReporter.close();
+  @Override
+  boolean useHive130DeltaDirName() {
+    return false;
   }
 
   @Test
-  public void testDeltaFilesMetric() throws Exception {
+  public void testDeltaFileMetricPartitionedTable() throws Exception {
     setUpHiveConf();
-    initAndCollectFirstMetrics();
+    String dbName = "default";
+    String tblName = "dp";
+    String partName = "ds=part1";
 
+    Table t = newTable(dbName, tblName, true);
+    List<LockComponent> components = new ArrayList<>();
+
+    Partition p = newPartition(t, "part1");
+    addBaseFile(t, p, 20L, 20);
+    addDeltaFile(t, p, 21L, 22L, 2);
+    addDeltaFile(t, p, 23L, 24L, 20);
+
+    components.add(createLockComponent(dbName, tblName, partName));
+
+    burnThroughTransactions(dbName, tblName, 23);
+    long txnid = openTxn();
+
+    LockRequest req = new LockRequest(components, "me", "localhost");
+    req.setTxnid(txnid);
+    LockResponse res = txnHandler.lock(req);
+    Assert.assertEquals(LockState.ACQUIRED, res.getState());
+
+    long writeid = allocateWriteId(dbName, tblName, txnid);
+    Assert.assertEquals(24, writeid);
+    txnHandler.commitTxn(new CommitTxnRequest(txnid));
+
+    startInitiator();
+
+    TimeUnit.SECONDS.sleep(1);

Review comment:
       Done.




-- 
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: 712177)
    Time Spent: 5h 20m  (was: 5h 10m)

> 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: 5h 20m
>  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