|
18 | 18 | package org.apache.hadoop.hbase.regionserver.compactions;
|
19 | 19 |
|
20 | 20 | import static org.apache.hadoop.hbase.regionserver.StripeStoreConfig.MAX_FILES_KEY;
|
| 21 | +import static org.apache.hadoop.hbase.regionserver.StripeStoreConfig.MIN_FILES_KEY; |
21 | 22 | import static org.apache.hadoop.hbase.regionserver.StripeStoreFileManager.OPEN_KEY;
|
22 | 23 | import static org.apache.hadoop.hbase.regionserver.compactions.CompactionConfiguration.HBASE_HSTORE_COMPACTION_MAX_SIZE_KEY;
|
23 | 24 | import static org.junit.Assert.assertEquals;
|
|
39 | 40 | import static org.mockito.Mockito.times;
|
40 | 41 | import static org.mockito.Mockito.verify;
|
41 | 42 | import static org.mockito.Mockito.when;
|
| 43 | + |
42 | 44 | import java.io.IOException;
|
43 | 45 | import java.util.ArrayList;
|
44 | 46 | import java.util.Arrays;
|
45 | 47 | import java.util.Collection;
|
46 | 48 | import java.util.Iterator;
|
47 | 49 | import java.util.List;
|
48 | 50 | import java.util.OptionalLong;
|
| 51 | + |
49 | 52 | import org.apache.hadoop.conf.Configuration;
|
50 | 53 | import org.apache.hadoop.fs.Path;
|
51 | 54 | import org.apache.hadoop.hbase.Cell;
|
|
88 | 91 | import org.junit.runners.Parameterized.Parameter;
|
89 | 92 | import org.junit.runners.Parameterized.Parameters;
|
90 | 93 | import org.mockito.ArgumentMatcher;
|
| 94 | + |
91 | 95 | import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableList;
|
92 | 96 | import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
|
93 | 97 |
|
@@ -536,6 +540,44 @@ public void testSingleStripeDropDeletes() throws Exception {
|
536 | 540 | true);
|
537 | 541 | }
|
538 | 542 |
|
| 543 | + @Test |
| 544 | + public void testCheckExpiredL0Compaction() throws Exception { |
| 545 | + Configuration conf = HBaseConfiguration.create(); |
| 546 | + int minL0 = 100; |
| 547 | + conf.setInt(StripeStoreConfig.MIN_FILES_L0_KEY, minL0); |
| 548 | + conf.setInt(MIN_FILES_KEY, 4); |
| 549 | + |
| 550 | + ManualEnvironmentEdge edge = new ManualEnvironmentEdge(); |
| 551 | + long now = defaultTtl + 2; |
| 552 | + edge.setValue(now); |
| 553 | + EnvironmentEdgeManager.injectEdge(edge); |
| 554 | + HStoreFile expiredFile = createFile(10), notExpiredFile = createFile(10); |
| 555 | + when(expiredFile.getReader().getMaxTimestamp()).thenReturn(now - defaultTtl - 1); |
| 556 | + when(notExpiredFile.getReader().getMaxTimestamp()).thenReturn(now - defaultTtl + 1); |
| 557 | + List<HStoreFile> expired = Lists.newArrayList(expiredFile, expiredFile); |
| 558 | + List<HStoreFile> mixed = Lists.newArrayList(expiredFile, notExpiredFile); |
| 559 | + |
| 560 | + StripeCompactionPolicy policy = |
| 561 | + createPolicy(conf, defaultSplitSize, defaultSplitCount, defaultInitialCount, true); |
| 562 | + // Merge expired if there are eligible stripes. |
| 563 | + StripeCompactionPolicy.StripeInformationProvider si = |
| 564 | + createStripesWithFiles(null, new ArrayList<>(), mixed); |
| 565 | + assertFalse(policy.needsCompactions(si, al())); |
| 566 | + |
| 567 | + List<HStoreFile> largeMixed = new ArrayList<>(); |
| 568 | + for (int i = 0; i < minL0 - 1; i++) { |
| 569 | + largeMixed.add(i % 2 == 0 ? notExpiredFile : expiredFile); |
| 570 | + } |
| 571 | + si = createStripesWithFiles(null, new ArrayList<>(), largeMixed); |
| 572 | + assertFalse(policy.needsCompactions(si, al())); |
| 573 | + |
| 574 | + si = createStripesWithFiles(null, new ArrayList<>(), expired); |
| 575 | + assertFalse(policy.needsSingleStripeCompaction(si)); |
| 576 | + assertFalse(policy.hasExpiredStripes(si)); |
| 577 | + assertTrue(policy.allL0FilesExpired(si)); |
| 578 | + assertTrue(policy.needsCompactions(si, al())); |
| 579 | + } |
| 580 | + |
539 | 581 | /********* HELPER METHODS ************/
|
540 | 582 | private static StripeCompactionPolicy createPolicy(
|
541 | 583 | Configuration conf) throws Exception {
|
|
0 commit comments