|
35 | 35 | import static org.mockito.Mockito.times; |
36 | 36 | import static org.mockito.Mockito.verify; |
37 | 37 | import static org.mockito.Mockito.when; |
| 38 | + |
38 | 39 | import java.io.IOException; |
39 | 40 | import java.util.ArrayList; |
40 | 41 | import java.util.Arrays; |
|
51 | 52 | import org.apache.hadoop.hbase.HColumnDescriptor; |
52 | 53 | import org.apache.hadoop.hbase.HRegionInfo; |
53 | 54 | import org.apache.hadoop.hbase.KeyValue; |
| 55 | +import org.apache.hadoop.hbase.io.TimeRange; |
54 | 56 | import org.apache.hadoop.hbase.io.hfile.HFile; |
55 | 57 | import org.apache.hadoop.hbase.regionserver.BloomType; |
56 | 58 | import org.apache.hadoop.hbase.regionserver.HStore; |
|
83 | 85 | import org.junit.runners.Parameterized.Parameter; |
84 | 86 | import org.junit.runners.Parameterized.Parameters; |
85 | 87 | import org.mockito.ArgumentMatcher; |
| 88 | + |
86 | 89 | import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableList; |
87 | 90 | import org.apache.hbase.thirdparty.com.google.common.collect.Lists; |
88 | 91 |
|
@@ -283,6 +286,35 @@ public void testNothingToCompactFromL0() throws Exception { |
283 | 286 | verifyNoCompaction(policy, si); |
284 | 287 | } |
285 | 288 |
|
| 289 | + @Test |
| 290 | + public void testCheckExpiredStripeCompaction() throws Exception { |
| 291 | + Configuration conf = HBaseConfiguration.create(); |
| 292 | + conf.setInt(StripeStoreConfig.MIN_FILES_L0_KEY, 5); |
| 293 | + conf.setInt(StripeStoreConfig.MIN_FILES_KEY, 4); |
| 294 | + |
| 295 | + ManualEnvironmentEdge edge = new ManualEnvironmentEdge(); |
| 296 | + long now = defaultTtl + 2; |
| 297 | + edge.setValue(now); |
| 298 | + EnvironmentEdgeManager.injectEdge(edge); |
| 299 | + HStoreFile expiredFile = createFile(10), notExpiredFile = createFile(10); |
| 300 | + when(expiredFile.getReader().getMaxTimestamp()).thenReturn(now - defaultTtl - 1); |
| 301 | + when(notExpiredFile.getReader().getMaxTimestamp()).thenReturn(now - defaultTtl + 1); |
| 302 | + List<HStoreFile> expired = Lists.newArrayList(expiredFile, expiredFile); |
| 303 | + List<HStoreFile> mixed = Lists.newArrayList(expiredFile, notExpiredFile); |
| 304 | + |
| 305 | + StripeCompactionPolicy policy = |
| 306 | + createPolicy(conf, defaultSplitSize, defaultSplitCount, defaultInitialCount, true); |
| 307 | + // Merge expired if there are eligible stripes. |
| 308 | + StripeCompactionPolicy.StripeInformationProvider si = |
| 309 | + createStripesWithFiles(mixed, mixed, mixed); |
| 310 | + assertFalse(policy.needsCompactions(si, al())); |
| 311 | + |
| 312 | + si = createStripesWithFiles(mixed, mixed, mixed, expired); |
| 313 | + assertFalse(policy.needsSingleStripeCompaction(si)); |
| 314 | + assertTrue(policy.hasExpiredStripes(si)); |
| 315 | + assertTrue(policy.needsCompactions(si, al())); |
| 316 | + } |
| 317 | + |
286 | 318 | @Test |
287 | 319 | public void testSplitOffStripe() throws Exception { |
288 | 320 | Configuration conf = HBaseConfiguration.create(); |
@@ -771,6 +803,7 @@ private static HStoreFile createFile(long size) throws Exception { |
771 | 803 | anyBoolean())).thenReturn(mock(StoreFileScanner.class)); |
772 | 804 | when(sf.getReader()).thenReturn(r); |
773 | 805 | when(sf.getBulkLoadTimestamp()).thenReturn(OptionalLong.empty()); |
| 806 | + when(r.getMaxTimestamp()).thenReturn(TimeRange.INITIAL_MAX_TIMESTAMP); |
774 | 807 | return sf; |
775 | 808 | } |
776 | 809 |
|
|
0 commit comments