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



##########
File path: 
ql/src/test/org/apache/hadoop/hive/metastore/txn/TestCompactionTxnHandler.java
##########
@@ -340,6 +341,121 @@ private void addFailedCompaction(String dbName, String 
tableName, CompactionType
     txnHandler.markFailed(ci);
   }
 
+  private void addDidNotInitiateCompaction(String dbName, String tableName, 
String partitionName,
+          CompactionType type, String errorMessage) throws MetaException {
+    CompactionInfo ci = new CompactionInfo(dbName, tableName, partitionName, 
type);
+    ci.errorMessage = errorMessage;
+    ci.id = 0;
+    txnHandler.markFailed(ci);
+  }
+
+  private void addSucceededCompaction(String dbName, String tableName, String 
partitionName,
+          CompactionType type) throws Exception {
+    CompactionRequest rqst = new CompactionRequest(dbName, tableName, type);
+    rqst.setPartitionname(partitionName);
+    txnHandler.compact(rqst);
+    assertEquals(0, txnHandler.findReadyToClean(0, 0).size());
+    CompactionInfo ci = txnHandler.findNextToCompact("fred", WORKER_VERSION);
+    assertNotNull(ci);
+    txnHandler.markCompacted(ci);
+    txnHandler.markCleaned(ci);
+  }
+
+  @Test
+  public void testPurgeCompactionHistory() throws Exception {
+    MetastoreConf.setLongVar(conf, 
MetastoreConf.ConfVars.COMPACTOR_HISTORY_RETENTION_SUCCEEDED, 2);
+    MetastoreConf.setLongVar(conf, 
MetastoreConf.ConfVars.COMPACTOR_HISTORY_RETENTION_DID_NOT_INITIATE, 2);
+    MetastoreConf.setLongVar(conf, 
MetastoreConf.ConfVars.COMPACTOR_HISTORY_RETENTION_FAILED, 2);
+    txnHandler.setConf(conf);
+
+    String dbName = "default";
+    String tableName = "tpch";
+    String part1 = "(p=1)";
+    String part2 = "(p=2)";
+
+    // 3 successful compactions on p=1
+    addSucceededCompaction(dbName, tableName, part1, CompactionType.MAJOR);
+    addSucceededCompaction(dbName, tableName, part1, CompactionType.MAJOR);
+    addSucceededCompaction(dbName, tableName, part1, CompactionType.MAJOR);
+
+    // 3 failed on p=1
+    addFailedCompaction(dbName, tableName, CompactionType.MAJOR, part1, 
"message");
+    addFailedCompaction(dbName, tableName, CompactionType.MAJOR, part1, 
"message");
+    addFailedCompaction(dbName, tableName, CompactionType.MAJOR, part1, 
"message");
+    //4 failed on p=2
+    addFailedCompaction(dbName, tableName, CompactionType.MAJOR, part2, 
"message");
+    addFailedCompaction(dbName, tableName, CompactionType.MAJOR, part2, 
"message");
+    addFailedCompaction(dbName, tableName, CompactionType.MAJOR, part2, 
"message");
+    addFailedCompaction(dbName, tableName, CompactionType.MAJOR, part2, 
"message");
+
+    // 3 not initiated on p=1
+    addDidNotInitiateCompaction(dbName, tableName, part1, 
CompactionType.MAJOR, "message");
+    addDidNotInitiateCompaction(dbName, tableName, part1, 
CompactionType.MAJOR, "message");
+    addDidNotInitiateCompaction(dbName, tableName, part1, 
CompactionType.MAJOR, "message");
+
+    countCompactionsInHistory(13);
+
+    txnHandler.purgeCompactionHistory();
+
+    countCompactionsInHistory(8);

Review comment:
       should we check the status and tbl/part for the remained compactions 
here?




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