[ https://issues.apache.org/jira/browse/HIVE-25916?focusedWorklogId=719291&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-719291 ]
ASF GitHub Bot logged work on HIVE-25916: ----------------------------------------- Author: ASF GitHub Bot Created on: 02/Feb/22 10:59 Start Date: 02/Feb/22 10:59 Worklog Time Spent: 10m Work Description: 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 719291) Time Spent: 0.5h (was: 20m) > Optimise updateCompactionMetricsData > ------------------------------------ > > Key: HIVE-25916 > URL: https://issues.apache.org/jira/browse/HIVE-25916 > Project: Hive > Issue Type: Improvement > Reporter: László Pintér > Assignee: László Pintér > Priority: Major > Labels: pull-request-available > Time Spent: 0.5h > Remaining Estimate: 0h > > TxnStore#updateCompactionMetricsData can be optimised to use the same DB > connection during create/update/delete if the delta metric threshold > evaluation is moved inside this method. -- This message was sent by Atlassian Jira (v8.20.1#820001)