deniskuzZ commented on a change in pull request #2184:
URL: https://github.com/apache/hive/pull/2184#discussion_r616544766



##########
File path: 
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/metrics/AcidMetricService.java
##########
@@ -108,19 +112,56 @@ private void updateDBMetrics() throws MetaException {
   @VisibleForTesting
   public static void updateMetricsFromShowCompact(ShowCompactResponse 
showCompactResponse) {
     Map<String, ShowCompactResponseElement> lastElements = new HashMap<>();
+    Map<String, Long> lastUnsuccessfulMajor = new HashMap<>();
+    Map<String, Long> lastUnsuccessfulMinor = new HashMap<>();
     long oldestEnqueueTime = Long.MAX_VALUE;
 
-    // Get the last compaction for each db/table/partition
-    for(ShowCompactResponseElement element : 
showCompactResponse.getCompacts()) {
+    // sort compactions by ID. This is not done in TxnHandler.
+    List<ShowCompactResponseElement> compactions = 
showCompactResponse.getCompacts().stream()
+            .sorted((o1, o2) -> (int) (o1.getId() - 
o2.getId())).collect(Collectors.toList());
+    for (ShowCompactResponseElement element : compactions) {
       String key = element.getDbname() + "/" + element.getTablename() +
           (element.getPartitionname() != null ? "/" + 
element.getPartitionname() : "");
+
+      // Get the last compaction for each db/table/partition
       // 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));
       if (TxnStore.INITIATED_RESPONSE.equals(element.getState()) && 
oldestEnqueueTime > element.getEnqueueTime()) {
         oldestEnqueueTime = element.getEnqueueTime();
       }
+
+      // Count incomplete compactions
+      CompactionType type = element.getType();
+      lastUnsuccessfulMajor.compute(key, (k, old) -> {
+        // Add newest unsuccessful compaction to the map
+        if (wasUnsuccessful(element) && type == MAJOR) {

Review comment:
       Could it be simplified ?
   ```
   if (type == MAJOR){
       if (wasUnsuccessful(element)) return element.getId();
       if (wasSuccessful(element)) return null;
   }
   ```




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