1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.regionserver;
20
21 import java.io.IOException;
22
23 import com.google.common.collect.ImmutableList;
24 import org.apache.commons.lang.RandomStringUtils;
25 import org.apache.hadoop.hbase.HBaseTestingUtility;
26 import org.apache.hadoop.hbase.HColumnDescriptor;
27 import org.apache.hadoop.hbase.client.Get;
28 import org.apache.hadoop.hbase.client.Put;
29 import org.apache.hadoop.hbase.filter.TimestampsFilter;
30 import org.apache.hadoop.hbase.testclassification.LargeTests;
31 import org.apache.hadoop.hbase.testclassification.RegionServerTests;
32 import org.apache.hadoop.hbase.util.Bytes;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.junit.experimental.categories.Category;
36
37 import static org.junit.Assert.assertTrue;
38
39 @Category({RegionServerTests.class, LargeTests.class})
40 public class TestTimestampFilterSeekHint {
41
42 private final static HBaseTestingUtility TEST_UTIL = HBaseTestingUtility.createLocalHTU();
43 private final static String RK = "myRK";
44 private final static byte[] RK_BYTES = Bytes.toBytes(RK);
45
46 private final static String FAMILY = "D";
47 private final static byte[] FAMILY_BYTES = Bytes.toBytes(FAMILY);
48
49 private final static String QUAL = "0";
50 private final static byte[] QUAL_BYTES = Bytes.toBytes(QUAL);
51
52 public static final int MAX_VERSIONS = 50000;
53 private HRegion region;
54 private int regionCount = 0;
55
56 @Test
57 public void testGetSeek() throws IOException {
58 StoreFileScanner.instrument();
59 prepareRegion();
60
61 Get g = new Get(RK_BYTES);
62 final TimestampsFilter timestampsFilter = new TimestampsFilter(ImmutableList.of(5L), true);
63 g.setFilter(timestampsFilter);
64 final long initialSeekCount = StoreFileScanner.getSeekCount();
65 region.get(g);
66 final long finalSeekCount = StoreFileScanner.getSeekCount();
67
68
69
70
71
72 assertTrue(finalSeekCount >= initialSeekCount + 3 );
73 }
74
75 @Test
76 public void testGetDoesntSeekWithNoHint() throws IOException {
77 StoreFileScanner.instrument();
78 prepareRegion();
79
80 Get g = new Get(RK_BYTES);
81 g.setFilter(new TimestampsFilter(ImmutableList.of(5L)));
82 final long initialSeekCount = StoreFileScanner.getSeekCount();
83 region.get(g);
84 final long finalSeekCount = StoreFileScanner.getSeekCount();
85
86 assertTrue(finalSeekCount >= initialSeekCount );
87 assertTrue(finalSeekCount < initialSeekCount + 3);
88 }
89
90 @Before
91 public void prepareRegion() throws IOException {
92 region =
93 TEST_UTIL.createTestRegion("TestTimestampFilterSeekHint" + regionCount++,
94 new HColumnDescriptor(FAMILY)
95 .setBlocksize(1024)
96 .setMaxVersions(MAX_VERSIONS)
97 );
98
99 for (long i = 0; i <MAX_VERSIONS - 2; i++) {
100 Put p = new Put(RK_BYTES, i);
101 p.add(FAMILY_BYTES, QUAL_BYTES, Bytes.toBytes(RandomStringUtils.randomAlphabetic(255)));
102 region.put(p);
103 }
104 region.flushcache();
105 }
106 }