Skip to content

Commit 516f124

Browse files
committed
HBASE-28742 Fixes NPE for CompactionTool when mslab enabled
1 parent 90d323e commit 516f124

File tree

3 files changed

+93
-6
lines changed

3 files changed

+93
-6
lines changed

hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/regionserver/CompactionTool.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ public void setup(Context context) {
211211
} catch (IOException e) {
212212
throw new RuntimeException("Could not get the input FileSystem", e);
213213
}
214+
// Disable the MemStoreLAB as MemStore is not used by flow during compaction
215+
conf.setBoolean(MemStoreLAB.USEMSLAB_KEY, false);
214216
}
215217

216218
@Override
@@ -369,6 +371,8 @@ private int doMapReduce(final FileSystem fs, final Set<Path> toCompactDirs,
369371
*/
370372
private int doClient(final FileSystem fs, final Set<Path> toCompactDirs,
371373
final boolean compactOnce, final boolean major) throws IOException {
374+
// Disable the MemStoreLAB as MemStore is not used by flow during compaction
375+
getConf().setBoolean(MemStoreLAB.USEMSLAB_KEY, false);
372376
CompactionWorker worker = new CompactionWorker(fs, getConf());
373377
for (Path path : toCompactDirs) {
374378
worker.compact(path, compactOnce, major);

hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionTool.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ public class TestCompactionTool {
4646
public static final HBaseClassTestRule CLASS_RULE =
4747
HBaseClassTestRule.forClass(TestCompactionTool.class);
4848

49-
private final HBaseTestingUtility testUtil = new HBaseTestingUtility();
49+
protected final HBaseTestingUtility testUtil = new HBaseTestingUtility();
5050

51-
private HRegion region;
52-
private final static byte[] qualifier = Bytes.toBytes("qf");
53-
private Path rootDir;
54-
private final TableName tableName = TableName.valueOf(getClass().getSimpleName());
51+
protected HRegion region;
52+
protected final static byte[] qualifier = Bytes.toBytes("qf");
53+
protected Path rootDir;
54+
protected final TableName tableName = TableName.valueOf(getClass().getSimpleName());
5555

5656
@Before
5757
public void setUp() throws Exception {
@@ -90,7 +90,7 @@ public void testCompactedFilesArchived() throws Exception {
9090
assertEquals(1, regionDirFiles.length);
9191
}
9292

93-
private void putAndFlush(int key) throws Exception {
93+
protected void putAndFlush(int key) throws Exception {
9494
Put put = new Put(Bytes.toBytes(key));
9595
put.addColumn(HBaseTestingUtility.fam1, qualifier, Bytes.toBytes("val" + key));
9696
region.put(put);
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.hbase.regionserver;
19+
20+
import static org.junit.Assert.assertEquals;
21+
22+
import org.apache.hadoop.conf.Configuration;
23+
import org.apache.hadoop.fs.FileStatus;
24+
import org.apache.hadoop.fs.FileSystem;
25+
import org.apache.hadoop.fs.Path;
26+
import org.apache.hadoop.hbase.HBaseClassTestRule;
27+
import org.apache.hadoop.hbase.HBaseConfiguration;
28+
import org.apache.hadoop.hbase.HBaseTestingUtility;
29+
import org.apache.hadoop.hbase.testclassification.MediumTests;
30+
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
31+
import org.apache.hadoop.hbase.util.Bytes;
32+
import org.apache.hadoop.hbase.util.CommonFSUtils;
33+
import org.apache.hadoop.util.ToolRunner;
34+
import org.junit.Before;
35+
import org.junit.ClassRule;
36+
import org.junit.Test;
37+
import org.junit.experimental.categories.Category;
38+
39+
/**
40+
* Test the issue of HBASE-28472
41+
*/
42+
@Category({ MediumTests.class, RegionServerTests.class })
43+
public class TestCompactionToolNpeFix extends TestCompactionTool {
44+
45+
@ClassRule
46+
public static final HBaseClassTestRule CLASS_RULE =
47+
HBaseClassTestRule.forClass(TestCompactionToolNpeFix.class);
48+
49+
@Before
50+
public void setUp() throws Exception {
51+
testUtil.getConfiguration().setBoolean(MemStoreLAB.USEMSLAB_KEY, false);
52+
super.setUp();
53+
}
54+
55+
@Test
56+
public void testCompactedFilesArchivedMapRed() throws Exception {
57+
for (int i = 0; i < 10; i++) {
58+
this.putAndFlush(i);
59+
}
60+
HStore store = region.getStore(HBaseTestingUtility.fam1);
61+
assertEquals(10, store.getStorefilesCount());
62+
Path tableDir = CommonFSUtils.getTableDir(rootDir, region.getRegionInfo().getTable());
63+
FileSystem fs = store.getFileSystem();
64+
String storePath = tableDir + "/" + region.getRegionInfo().getEncodedName() + "/"
65+
+ Bytes.toString(HBaseTestingUtility.fam1);
66+
FileStatus[] regionDirFiles = fs.listStatus(new Path(storePath));
67+
assertEquals(10, regionDirFiles.length);
68+
String defaultFS = testUtil.getMiniHBaseCluster().getConfiguration().get("fs.defaultFS");
69+
testUtil.startMiniMapReduceCluster();
70+
try {
71+
Configuration config = HBaseConfiguration.create(testUtil.getConfiguration());
72+
config.setBoolean(MemStoreLAB.USEMSLAB_KEY, true);
73+
config.set("fs.defaultFS", defaultFS);
74+
int result = ToolRunner.run(config, new CompactionTool(),
75+
new String[] { "-compactOnce", "-mapred", "-major", storePath });
76+
assertEquals(0, result);
77+
regionDirFiles = fs.listStatus(new Path(storePath));
78+
assertEquals(1, regionDirFiles.length);
79+
} finally {
80+
testUtil.shutdownMiniMapReduceCluster();
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)