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 static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertTrue;
23
24 import java.io.IOException;
25 import java.util.List;
26
27 import org.apache.hadoop.conf.Configuration;
28 import org.apache.hadoop.fs.FileSystem;
29 import org.apache.hadoop.fs.Path;
30 import org.apache.hadoop.hbase.HBaseTestingUtility;
31 import org.apache.hadoop.hbase.KeyValue;
32 import org.apache.hadoop.hbase.Tag;
33 import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
34 import org.apache.hadoop.hbase.io.hfile.CacheConfig;
35 import org.apache.hadoop.hbase.io.hfile.HFileContext;
36 import org.apache.hadoop.hbase.io.hfile.HFileContextBuilder;
37 import org.apache.hadoop.hbase.testclassification.SmallTests;
38 import org.apache.hadoop.hbase.util.Bytes;
39 import org.junit.BeforeClass;
40 import org.junit.Test;
41 import org.junit.experimental.categories.Category;
42
43 @Category(SmallTests.class)
44 public class TestStoreFileScannerWithTagCompression {
45
46 private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
47 private static Configuration conf = TEST_UTIL.getConfiguration();
48 private static CacheConfig cacheConf = new CacheConfig(TEST_UTIL.getConfiguration());
49 private static String ROOT_DIR = TEST_UTIL.getDataTestDir(
50 "TestStoreFileScannerWithTagCompression").toString();
51 private static FileSystem fs = null;
52
53 @BeforeClass
54 public static void setUp() throws IOException {
55 conf.setInt("hfile.format.version", 3);
56 fs = FileSystem.get(conf);
57 }
58
59 @Test
60 public void testReseek() throws Exception {
61
62 Path f = new Path(ROOT_DIR, "testReseek");
63 HFileContext meta = new HFileContextBuilder().withBlockSize(8 * 1024).withIncludesTags(true)
64 .withCompressTags(true).withDataBlockEncoding(DataBlockEncoding.PREFIX).build();
65
66 StoreFile.Writer writer = new StoreFile.WriterBuilder(conf, cacheConf, fs).withFilePath(f)
67 .withFileContext(meta).build();
68
69 writeStoreFile(writer);
70 writer.close();
71
72 StoreFile.Reader reader = new StoreFile.Reader(fs, f, cacheConf, conf);
73 StoreFileScanner s = reader.getStoreFileScanner(false, false);
74 try {
75
76 KeyValue k = KeyValue.createFirstOnRow(Bytes.toBytes("k2"));
77 s.reseek(k);
78 KeyValue kv = s.next();
79 kv = s.next();
80 kv = s.next();
81 byte[] key5 = Bytes.toBytes("k5");
82 assertTrue(Bytes.equals(key5, 0, key5.length, kv.getRowArray(), kv.getRowOffset(),
83 kv.getRowLength()));
84 List<Tag> tags = kv.getTags();
85 assertEquals(1, tags.size());
86 assertEquals("tag3", Bytes.toString(tags.get(0).getValue()));
87 } finally {
88 s.close();
89 }
90 }
91
92 private void writeStoreFile(final StoreFile.Writer writer) throws IOException {
93 byte[] fam = Bytes.toBytes("f");
94 byte[] qualifier = Bytes.toBytes("q");
95 long now = System.currentTimeMillis();
96 byte[] b = Bytes.toBytes("k1");
97 Tag t1 = new Tag((byte) 1, "tag1");
98 Tag t2 = new Tag((byte) 2, "tag2");
99 Tag t3 = new Tag((byte) 3, "tag3");
100 try {
101 writer.append(new KeyValue(b, fam, qualifier, now, b, new Tag[] { t1 }));
102 b = Bytes.toBytes("k3");
103 writer.append(new KeyValue(b, fam, qualifier, now, b, new Tag[] { t2, t1 }));
104 b = Bytes.toBytes("k4");
105 writer.append(new KeyValue(b, fam, qualifier, now, b, new Tag[] { t3 }));
106 b = Bytes.toBytes("k5");
107 writer.append(new KeyValue(b, fam, qualifier, now, b, new Tag[] { t3 }));
108 } finally {
109 writer.close();
110 }
111 }
112 }