deniskuzZ commented on code in PR #3645:
URL: https://github.com/apache/hive/pull/3645#discussion_r991911089


##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/metrics/CompactionMetricData.java:
##########
@@ -67,34 +70,53 @@ static CompactionMetricData 
of(List<ShowCompactResponseElement> compacts) {
 
   private void init() {
     final Map<String, ShowCompactResponseElement> lastElements = new 
HashMap<>();
-    poolCount = new HashMap<>();
+    initiatedPoolCount = new HashMap<>();
+    workingPoolCount = new HashMap<>();
+    oldestEnqueueTimePerPool = new HashMap<>();
+    oldestWorkingTimePerPool = new HashMap<>();
 
     oldestEnqueueTime = OLDEST_TIME_NO_VALUE;
     oldestWorkingTime = OLDEST_TIME_NO_VALUE;
     oldestCleaningTime = OLDEST_TIME_NO_VALUE;
+
+    long currentTime = System.currentTimeMillis();
     for (ShowCompactResponseElement element : compacts) {
       final String key = element.getDbname() + "/" + element.getTablename() +
           (element.getPartitionname() != null ? "/" + 
element.getPartitionname() : "");
 
       // If new key, add the element, if there is an existing one, change to 
the element if the element.id is greater than old.id
       lastElements.compute(key, (k, old) -> (old == null) ? element : 
(element.getId() > old.getId() ? element : old));
 
-      // find the oldest elements with initiated and working states
       String state = element.getState();
-      if (TxnStore.INITIATED_RESPONSE.equals(state) && (oldestEnqueueTime > 
element.getEnqueueTime())) {
-        oldestEnqueueTime = element.getEnqueueTime();
-        poolCount.compute(element.getPoolName(), (k, old) -> (old == null) ? 1 
: old + 1);
+      if (TxnStore.INITIATED_RESPONSE.equals(state)) {
+        final int enqueueSeconds = (int) ((currentTime - 
element.getEnqueueTime()) / 1000);
+        oldestWorkingTimePerPool.compute(element.getPoolName(), (k, old) -> 
(old == null) ? enqueueSeconds : Math.max(enqueueSeconds, old));
+
+        initiatedPoolCount.compute(element.getPoolName(), (k, old) -> (old == 
null) ? 1 : old + 1);
+        // find the oldest element
+        if (oldestEnqueueTime > element.getEnqueueTime()) {
+          oldestEnqueueTime = element.getEnqueueTime();
+        }
       }
 
       if (element.isSetStart()) {
-        if (TxnStore.WORKING_RESPONSE.equals(state) && (oldestWorkingTime > 
element.getStart())) {
-          oldestWorkingTime = element.getStart();
+        if (TxnStore.WORKING_RESPONSE.equals(state)) {
+          final int startSeconds = (int) ((currentTime - element.getStart()) / 
1000);
+          oldestEnqueueTimePerPool.compute(element.getPoolName(), (k, old) -> 
(old == null) ? startSeconds : Math.max(startSeconds, old));
+
+          workingPoolCount.compute(element.getPoolName(), (k, old) -> (old == 
null) ? 1 : old + 1);
+          // find the oldest element
+          if (oldestWorkingTime > element.getStart()) {
+            oldestWorkingTime = element.getStart();
+          }
         }
       }
 
       if (element.isSetCleanerStart()) {
-        if (TxnStore.CLEANING_RESPONSE.equals(state) && (oldestCleaningTime > 
element.getCleanerStart())) {
-          oldestCleaningTime = element.getCleanerStart();
+        if (TxnStore.CLEANING_RESPONSE.equals(state)) {

Review Comment:
   why is this change?



-- 
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: [email protected]

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