|
17 | 17 | */ |
18 | 18 | package org.apache.hadoop.hbase.regionserver; |
19 | 19 |
|
20 | | -import static org.junit.jupiter.api.Assertions.assertEquals; |
21 | | - |
22 | | -import java.io.IOException; |
23 | | -import java.util.ArrayList; |
24 | | -import java.util.stream.Stream; |
25 | | -import org.apache.hadoop.conf.Configuration; |
26 | | -import org.apache.hadoop.hbase.CacheEvictionStats; |
27 | | -import org.apache.hadoop.hbase.Cell; |
28 | | -import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate; |
29 | | -import org.apache.hadoop.hbase.HBaseTestingUtil; |
30 | | -import org.apache.hadoop.hbase.HConstants; |
31 | | -import org.apache.hadoop.hbase.SingleProcessHBaseCluster; |
32 | 20 | import org.apache.hadoop.hbase.TableName; |
33 | | -import org.apache.hadoop.hbase.client.Admin; |
34 | | -import org.apache.hadoop.hbase.client.AsyncAdmin; |
35 | | -import org.apache.hadoop.hbase.client.AsyncConnection; |
36 | | -import org.apache.hadoop.hbase.client.ConnectionFactory; |
37 | | -import org.apache.hadoop.hbase.client.Scan; |
38 | | -import org.apache.hadoop.hbase.client.Table; |
39 | | -import org.apache.hadoop.hbase.io.hfile.BlockCache; |
40 | 21 | import org.apache.hadoop.hbase.testclassification.LargeTests; |
41 | | -import org.apache.hadoop.hbase.util.Bytes; |
42 | | -import org.junit.jupiter.api.AfterEach; |
43 | | -import org.junit.jupiter.api.BeforeEach; |
| 22 | +import org.junit.jupiter.api.AfterAll; |
| 23 | +import org.junit.jupiter.api.BeforeAll; |
44 | 24 | import org.junit.jupiter.api.Tag; |
45 | | -import org.junit.jupiter.api.TestTemplate; |
46 | | -import org.junit.jupiter.params.provider.Arguments; |
47 | | -import org.slf4j.Logger; |
48 | | -import org.slf4j.LoggerFactory; |
49 | 25 |
|
50 | 26 | @Tag(LargeTests.TAG) |
51 | | -@HBaseParameterizedTestTemplate(name = "{index}: {0}") |
52 | | -public class TestClearRegionBlockCache { |
53 | | - |
54 | | - private static final Logger LOG = LoggerFactory.getLogger(TestClearRegionBlockCache.class); |
55 | | - private static final TableName TABLE_NAME = TableName.valueOf("testClearRegionBlockCache"); |
56 | | - private static final byte[] FAMILY = Bytes.toBytes("family"); |
57 | | - private static final byte[][] SPLIT_KEY = new byte[][] { Bytes.toBytes("5") }; |
58 | | - private static final int NUM_RS = 2; |
59 | | - |
60 | | - private final HBaseTestingUtil HTU = new HBaseTestingUtil(); |
61 | | - |
62 | | - private Configuration CONF = HTU.getConfiguration(); |
63 | | - private Table table; |
64 | | - private HRegionServer rs1, rs2; |
65 | | - private SingleProcessHBaseCluster cluster; |
66 | | - |
67 | | - private final String cacheType; |
68 | | - |
69 | | - public TestClearRegionBlockCache(String cacheType) { |
70 | | - this.cacheType = cacheType; |
71 | | - } |
72 | | - |
73 | | - public static Stream<Arguments> parameters() { |
74 | | - return Stream.of(Arguments.of("lru"), Arguments.of("bucket")); |
75 | | - } |
76 | | - |
77 | | - @BeforeEach |
78 | | - public void setup() throws Exception { |
79 | | - if (cacheType.equals("bucket")) { |
80 | | - CONF.set(HConstants.BUCKET_CACHE_IOENGINE_KEY, "offheap"); |
81 | | - CONF.setInt(HConstants.BUCKET_CACHE_SIZE_KEY, 30); |
82 | | - } |
83 | | - |
84 | | - cluster = HTU.startMiniCluster(NUM_RS); |
85 | | - rs1 = cluster.getRegionServer(0); |
86 | | - rs2 = cluster.getRegionServer(1); |
87 | | - |
88 | | - // Create table |
89 | | - table = HTU.createTable(TABLE_NAME, FAMILY, SPLIT_KEY); |
90 | | - |
91 | | - HTU.loadNumericRows(table, FAMILY, 1, 10); |
92 | | - HTU.flush(TABLE_NAME); |
93 | | - } |
94 | | - |
95 | | - @AfterEach |
96 | | - public void teardown() throws Exception { |
97 | | - HTU.shutdownMiniCluster(); |
98 | | - } |
| 27 | +public class TestClearRegionBlockCache extends ClearRegionBlockCacheTestBase { |
99 | 28 |
|
100 | | - @TestTemplate |
101 | | - public void testClearBlockCache() throws Exception { |
102 | | - BlockCache blockCache1 = rs1.getBlockCache().get(); |
103 | | - BlockCache blockCache2 = rs2.getBlockCache().get(); |
104 | | - |
105 | | - long initialBlockCount1 = blockCache1.getBlockCount(); |
106 | | - long initialBlockCount2 = blockCache2.getBlockCount(); |
107 | | - |
108 | | - // scan will cause blocks to be added in BlockCache |
109 | | - scanAllRegionsForRS(rs1); |
110 | | - assertEquals(blockCache1.getBlockCount() - initialBlockCount1, |
111 | | - HTU.getNumHFilesForRS(rs1, TABLE_NAME, FAMILY)); |
112 | | - clearRegionBlockCache(rs1); |
113 | | - |
114 | | - scanAllRegionsForRS(rs2); |
115 | | - assertEquals(blockCache2.getBlockCount() - initialBlockCount2, |
116 | | - HTU.getNumHFilesForRS(rs2, TABLE_NAME, FAMILY)); |
117 | | - clearRegionBlockCache(rs2); |
118 | | - |
119 | | - assertEquals(initialBlockCount1, blockCache1.getBlockCount(), "" + blockCache1.getBlockCount()); |
120 | | - assertEquals(initialBlockCount2, blockCache2.getBlockCount(), "" + blockCache2.getBlockCount()); |
121 | | - } |
122 | | - |
123 | | - @TestTemplate |
124 | | - public void testClearBlockCacheFromAdmin() throws Exception { |
125 | | - Admin admin = HTU.getAdmin(); |
126 | | - |
127 | | - BlockCache blockCache1 = rs1.getBlockCache().get(); |
128 | | - BlockCache blockCache2 = rs2.getBlockCache().get(); |
129 | | - long initialBlockCount1 = blockCache1.getBlockCount(); |
130 | | - long initialBlockCount2 = blockCache2.getBlockCount(); |
131 | | - |
132 | | - // scan will cause blocks to be added in BlockCache |
133 | | - scanAllRegionsForRS(rs1); |
134 | | - assertEquals(blockCache1.getBlockCount() - initialBlockCount1, |
135 | | - HTU.getNumHFilesForRS(rs1, TABLE_NAME, FAMILY)); |
136 | | - scanAllRegionsForRS(rs2); |
137 | | - assertEquals(blockCache2.getBlockCount() - initialBlockCount2, |
138 | | - HTU.getNumHFilesForRS(rs2, TABLE_NAME, FAMILY)); |
139 | | - |
140 | | - CacheEvictionStats stats = admin.clearBlockCache(TABLE_NAME); |
141 | | - assertEquals(stats.getEvictedBlocks(), HTU.getNumHFilesForRS(rs1, TABLE_NAME, FAMILY) |
142 | | - + HTU.getNumHFilesForRS(rs2, TABLE_NAME, FAMILY)); |
143 | | - assertEquals(initialBlockCount1, blockCache1.getBlockCount()); |
144 | | - assertEquals(initialBlockCount2, blockCache2.getBlockCount()); |
145 | | - } |
146 | | - |
147 | | - @TestTemplate |
148 | | - public void testClearBlockCacheFromAsyncAdmin() throws Exception { |
149 | | - try (AsyncConnection conn = |
150 | | - ConnectionFactory.createAsyncConnection(HTU.getConfiguration()).get()) { |
151 | | - AsyncAdmin admin = conn.getAdmin(); |
152 | | - |
153 | | - BlockCache blockCache1 = rs1.getBlockCache().get(); |
154 | | - BlockCache blockCache2 = rs2.getBlockCache().get(); |
155 | | - long initialBlockCount1 = blockCache1.getBlockCount(); |
156 | | - long initialBlockCount2 = blockCache2.getBlockCount(); |
157 | | - |
158 | | - // scan will cause blocks to be added in BlockCache |
159 | | - scanAllRegionsForRS(rs1); |
160 | | - assertEquals(blockCache1.getBlockCount() - initialBlockCount1, |
161 | | - HTU.getNumHFilesForRS(rs1, TABLE_NAME, FAMILY)); |
162 | | - scanAllRegionsForRS(rs2); |
163 | | - assertEquals(blockCache2.getBlockCount() - initialBlockCount2, |
164 | | - HTU.getNumHFilesForRS(rs2, TABLE_NAME, FAMILY)); |
165 | | - |
166 | | - CacheEvictionStats stats = admin.clearBlockCache(TABLE_NAME).get(); |
167 | | - assertEquals(stats.getEvictedBlocks(), HTU.getNumHFilesForRS(rs1, TABLE_NAME, FAMILY) |
168 | | - + HTU.getNumHFilesForRS(rs2, TABLE_NAME, FAMILY)); |
169 | | - assertEquals(initialBlockCount1, blockCache1.getBlockCount()); |
170 | | - assertEquals(initialBlockCount2, blockCache2.getBlockCount()); |
171 | | - } |
172 | | - } |
| 29 | + private static final TableName TABLE_NAME = |
| 30 | + TableName.valueOf("testClearRegionBlockCacheWithLruBlockCache"); |
173 | 31 |
|
174 | | - private void scanAllRegionsForRS(HRegionServer rs) throws IOException { |
175 | | - for (Region region : rs.getRegions(TABLE_NAME)) { |
176 | | - RegionScanner scanner = region.getScanner(new Scan()); |
177 | | - while (scanner.next(new ArrayList<Cell>())) |
178 | | - ; |
179 | | - } |
| 32 | + @BeforeAll |
| 33 | + public static void setUp() throws Exception { |
| 34 | + setUpCluster(TABLE_NAME); |
180 | 35 | } |
181 | 36 |
|
182 | | - private void clearRegionBlockCache(HRegionServer rs) { |
183 | | - for (Region region : rs.getRegions(TABLE_NAME)) { |
184 | | - rs.clearRegionBlockCache(region); |
185 | | - } |
| 37 | + @AfterAll |
| 38 | + public static void tearDown() throws Exception { |
| 39 | + tearDownCluster(); |
186 | 40 | } |
187 | 41 | } |
0 commit comments