|
18 | 18 |
|
19 | 19 | package org.apache.hadoop.hive.ql.txn.compactor; |
20 | 20 |
|
| 21 | +import org.apache.hadoop.fs.Path; |
| 22 | +import org.apache.hadoop.hive.metastore.api.CompactionRequest; |
| 23 | +import org.apache.hadoop.hive.metastore.api.CompactionType; |
| 24 | +import org.apache.hadoop.hive.metastore.api.ShowCompactRequest; |
| 25 | +import org.apache.hadoop.hive.metastore.api.ShowCompactResponse; |
| 26 | +import org.apache.hadoop.hive.metastore.api.Table; |
| 27 | +import org.apache.hadoop.hive.metastore.conf.MetastoreConf; |
| 28 | +import org.apache.hadoop.hive.metastore.txn.TxnStore; |
| 29 | +import org.junit.jupiter.api.BeforeEach; |
| 30 | +import org.junit.jupiter.api.Test; |
| 31 | + |
| 32 | +import java.util.List; |
| 33 | + |
| 34 | +import static org.apache.hadoop.hive.ql.io.AcidUtils.addVisibilitySuffix; |
| 35 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 36 | + |
21 | 37 | public class TestCleanerWithMinHistoryWriteId extends TestCleaner { |
| 38 | + |
| 39 | + @Override |
| 40 | + @BeforeEach |
| 41 | + public void setup() throws Exception { |
| 42 | + super.setup(); |
| 43 | + MetastoreConf.setLongVar(conf, MetastoreConf.ConfVars.HIVE_COMPACTOR_CLEANER_MAX_RETRY_ATTEMPTS, 0); |
| 44 | + } |
| 45 | + |
22 | 46 | @Override |
23 | 47 | protected boolean useMinHistoryWriteId() { |
24 | 48 | return true; |
25 | 49 | } |
| 50 | + |
| 51 | + @Test |
| 52 | + public void cleanupAfterAbortedAndRetriedMajorCompaction() throws Exception { |
| 53 | + Table t = prepareTestTable(); |
| 54 | + CompactionRequest rqst = new CompactionRequest("default", "camtc", CompactionType.MAJOR); |
| 55 | + long compactTxn = compactInTxn(rqst, false); |
| 56 | + addBaseFile(t, null, 25L, 25, compactTxn); |
| 57 | + |
| 58 | + txnHandler.revokeTimedoutWorkers(1L); |
| 59 | + compactTxn = compactInTxn(rqst); |
| 60 | + addBaseFile(t, null, 25L, 25, compactTxn); |
| 61 | + |
| 62 | + startCleaner(); |
| 63 | + |
| 64 | + // Check there are no compactions requests left. |
| 65 | + ShowCompactResponse rsp = txnHandler.showCompact(new ShowCompactRequest()); |
| 66 | + assertEquals(1, rsp.getCompactsSize()); |
| 67 | + assertEquals(TxnStore.SUCCEEDED_RESPONSE, rsp.getCompacts().getFirst().getState()); |
| 68 | + |
| 69 | + // Check that the files are removed |
| 70 | + List<Path> paths = getDirectories(conf, t, null); |
| 71 | + assertEquals(1, paths.size()); |
| 72 | + assertEquals(addVisibilitySuffix("base_25", 27), paths.getFirst().getName()); |
| 73 | + } |
| 74 | + |
| 75 | + @Test |
| 76 | + public void cleanupAfterKilledAndRetriedMajorCompaction() throws Exception { |
| 77 | + Table t = prepareTestTable(); |
| 78 | + CompactionRequest rqst = new CompactionRequest("default", "camtc", CompactionType.MAJOR); |
| 79 | + long compactTxn = compactInTxn(rqst, null); |
| 80 | + addBaseFile(t, null, 25L, 25, compactTxn); |
| 81 | + |
| 82 | + txnHandler.revokeTimedoutWorkers(1L); |
| 83 | + compactTxn = compactInTxn(rqst); |
| 84 | + addBaseFile(t, null, 25L, 25, compactTxn); |
| 85 | + |
| 86 | + startCleaner(); |
| 87 | + |
| 88 | + // Check there are no compactions requests left. |
| 89 | + ShowCompactResponse rsp = txnHandler.showCompact(new ShowCompactRequest()); |
| 90 | + assertEquals(1, rsp.getCompactsSize()); |
| 91 | + assertEquals(TxnStore.FAILED_RESPONSE, rsp.getCompacts().getFirst().getState()); |
| 92 | + assertEquals("txnid:26 is open and <= hwm: 27", rsp.getCompacts().getFirst().getErrorMessage()); |
| 93 | + |
| 94 | + // Check that the files are not removed |
| 95 | + List<Path> paths = getDirectories(conf, t, null); |
| 96 | + assertEquals(6, paths.size()); |
| 97 | + } |
| 98 | + |
| 99 | + private Table prepareTestTable() throws Exception { |
| 100 | + Table t = newTable("default", "camtc", false); |
| 101 | + |
| 102 | + addBaseFile(t, null, 20L, 20); |
| 103 | + addDeltaFile(t, null, 21L, 22L, 2); |
| 104 | + addDeltaFile(t, null, 23L, 24L, 2); |
| 105 | + addDeltaFile(t, null, 25L, 25, 2); |
| 106 | + |
| 107 | + burnThroughTransactions("default", "camtc", 25); |
| 108 | + return t; |
| 109 | + } |
| 110 | + |
26 | 111 | } |
0 commit comments