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



##########
File path: 
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/CompactionTxnHandler.java
##########
@@ -891,29 +903,42 @@ public void purgeCompactionHistory() throws MetaException 
{
     ResultSet rs = null;
     List<Long> deleteSet = new ArrayList<>();
     RetentionCounters rc = null;
+    long timeoutThreshold = System.currentTimeMillis() -
+            MetastoreConf.getTimeVar(conf, 
ConfVars.COMPACTOR_HISTORY_RETENTION_TIMEOUT, TimeUnit.MILLISECONDS);
     try {
       try {
         dbConn = getDbConn(Connection.TRANSACTION_READ_COMMITTED);
         stmt = dbConn.createStatement();
         /* cc_id is monotonically increasing so for any entity sorts in order 
of compaction history,
         thus this query groups by entity and withing group sorts most recent 
first */
-        rs = stmt.executeQuery("SELECT \"CC_ID\", \"CC_DATABASE\", 
\"CC_TABLE\", \"CC_PARTITION\", \"CC_STATE\" "
-            + "FROM \"COMPLETED_COMPACTIONS\" ORDER BY \"CC_DATABASE\", 
\"CC_TABLE\", \"CC_PARTITION\", \"CC_ID\" DESC");
+        rs = stmt.executeQuery("SELECT \"CC_ID\", \"CC_DATABASE\", 
\"CC_TABLE\", \"CC_PARTITION\", "
+            + "\"CC_STATE\" , \"CC_START\", \"CC_TYPE\" "
+            + "FROM \"COMPLETED_COMPACTIONS\" ORDER BY \"CC_DATABASE\", 
\"CC_TABLE\", \"CC_PARTITION\"," +
+                "\"CC_ID\" DESC");
         String lastCompactedEntity = null;
         /* In each group, walk from most recent and count occurrences of each 
state type.  Once you
         * have counted enough (for each state) to satisfy retention policy, 
delete all other
-        * instances of this status. */
+        * instances of this status.
+        * Also, "not initiated" and "failed" compactions are cleaned up if 
they are older than
+        * metastore.compactor.history.retention.timeout and there is a newer 
"succeeded"
+        * compaction on the table and either (1) the "succeeded" compaction is 
major or (2) it is minor
+        * and the "not initiated" or "failed" compaction is also minor –– so a 
minor succeeded compaction
+        * will not cause the deletion of a major "not initiated" or "failed" 
compaction.
+        */
         while(rs.next()) {
           CompactionInfo ci = new CompactionInfo(
               rs.getLong(1), rs.getString(2), rs.getString(3),
               rs.getString(4), rs.getString(5).charAt(0));
+          ci.start = rs.getLong(6);
+          ci.type = 
TxnHandler.dbCompactionType2ThriftType(rs.getString(7).charAt(0));
           if(!ci.getFullPartitionName().equals(lastCompactedEntity)) {
             lastCompactedEntity = ci.getFullPartitionName();
-            rc = new RetentionCounters(MetastoreConf.getIntVar(conf, 
ConfVars.COMPACTOR_HISTORY_RETENTION_DID_NOT_INITIATE),
-              getFailedCompactionRetention(),
-              MetastoreConf.getIntVar(conf, 
ConfVars.COMPACTOR_HISTORY_RETENTION_SUCCEEDED));
+            rc = new RetentionCounters(
+                MetastoreConf.getIntVar(conf, 
ConfVars.COMPACTOR_HISTORY_RETENTION_DID_NOT_INITIATE),

Review comment:
       Could you please extract conf value access out of the while loop.




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