lcspinter commented on a change in pull request #2989:
URL: https://github.com/apache/hive/pull/2989#discussion_r797489255



##########
File path: 
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/CompactionTxnHandler.java
##########
@@ -1584,38 +1584,17 @@ public boolean 
updateCompactionMetricsData(CompactionMetricsData data) throws Me
       try {
         dbConn = getDbConn(Connection.TRANSACTION_READ_COMMITTED);
         boolean updateRes;
-        CompactionMetricsData prevMetricsData = getCompactionMetricsData(data, 
dbConn);
-        if (prevMetricsData != null) {
-          String query = UPDATE_COMPACTION_METRICS_CACHE_QUERY;
-          if (data.getPartitionName() != null) {
-            query += " AND \"CMC_PARTITION\" = ?";
+        if (data.getMetricValue() >= data.getThreshold()) {
+          CompactionMetricsData prevMetricsData = 
getCompactionMetricsData(data, dbConn);
+          if (prevMetricsData != null) {
+            updateRes = updateCompactionMetricsData(dbConn, data, 
prevMetricsData);
           } else {
-            query += " AND \"CMC_PARTITION\" IS NULL";
-          }
-          try (PreparedStatement pstmt = dbConn.prepareStatement(query)) {
-            pstmt.setInt(1, data.getMetricValue());
-            pstmt.setInt(2, prevMetricsData.getVersion() + 1);
-            pstmt.setString(3, data.getDbName());
-            pstmt.setString(4, data.getTblName());
-            pstmt.setString(5, data.getMetricType().toString());
-            pstmt.setInt(6, prevMetricsData.getVersion());
-            if (data.getPartitionName() != null) {
-              pstmt.setString(7, data.getPartitionName());
-            }
-            updateRes = pstmt.executeUpdate() > 0;
+            updateRes = createCompactionMetricsData(dbConn, data);
           }
         } else {
-          try (PreparedStatement pstmt = 
dbConn.prepareStatement(INSERT_COMPACTION_METRICS_CACHE_QUERY)) {
-            pstmt.setString(1, data.getDbName());
-            pstmt.setString(2, data.getTblName());
-            pstmt.setString(3, data.getPartitionName());
-            pstmt.setString(4, data.getMetricType().toString());
-            pstmt.setInt(5, data.getMetricValue());
-            pstmt.setInt(6, 1);
-            updateRes = pstmt.executeUpdate() > 0;
-          }
+          updateRes = removeCompactionMetricsData(dbConn, data.getDbName(), 
data.getTblName(), data.getPartitionName(),

Review comment:
       Good point. I changed the logic to run remove in case the new metric is 
below threshold and it is already present in the cache. 




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