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