From c625ab4f07316696cf6bb9c625fe44fa4bff68e6 Mon Sep 17 00:00:00 2001 From: Sanjeet Nishad Date: Tue, 15 Dec 2020 18:15:42 +0530 Subject: [PATCH] HBASE-25301 NPE while running balance_rsgroup if any split region is present. --- .../hbase/rsgroup/RSGroupInfoManagerImpl.java | 6 ++++ .../hbase/rsgroup/TestRSGroupsAdmin1.java | 35 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManagerImpl.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManagerImpl.java index 038e4dfc0e0..0222d562ed4 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManagerImpl.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManagerImpl.java @@ -1130,6 +1130,12 @@ final class RSGroupInfoManagerImpl implements RSGroupInfoManager { if (region.isSplitParent()) { continue; } + + // isSplitParent() and isSplit() is not always reliable. So for those scenarios, better to + // have a check here. + if(null == server) { + continue; + } result.computeIfAbsent(tn, k -> new HashMap<>()) .computeIfAbsent(server, k -> new ArrayList<>()).add(region); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroupsAdmin1.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroupsAdmin1.java index 87cb76e20a6..4897be85492 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroupsAdmin1.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroupsAdmin1.java @@ -37,6 +37,7 @@ import org.apache.hadoop.hbase.TableNotFoundException; import org.apache.hadoop.hbase.Waiter; import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor; import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; +import org.apache.hadoop.hbase.client.RegionInfo; import org.apache.hadoop.hbase.client.TableDescriptor; import org.apache.hadoop.hbase.client.TableDescriptorBuilder; import org.apache.hadoop.hbase.constraint.ConstraintException; @@ -621,4 +622,38 @@ public class TestRSGroupsAdmin1 extends TestRSGroupsBase { TEST_UTIL.deleteTable(tableName); ADMIN.deleteNamespace(ns); } + + @Test + public void testHBASE25301() throws IOException, InterruptedException { + String pgroup = "pgroup"; + ADMIN.addRSGroup(pgroup); + + ServerName serverName0 = TEST_UTIL.getMiniHBaseCluster().getRegionServer(0).getServerName(); + ServerName serverName1 = TEST_UTIL.getMiniHBaseCluster().getRegionServer(1).getServerName(); + ADMIN.moveServersToRSGroup(Sets.newHashSet(serverName0.getAddress(), serverName1.getAddress()), + pgroup); + + TableName table1 = TableName.valueOf("table1"); + TableName table2 = TableName.valueOf("table2"); + TEST_UTIL.createTable(table1, "cf"); + TEST_UTIL.createTable(table2, "cf"); + + ADMIN.setRSGroup(Sets.newHashSet(table1, table2), pgroup); + + List regionInfoList = ADMIN.getRegions(table1); + regionInfoList.addAll(ADMIN.getRegions(table2)); + for (RegionInfo regionInfo : regionInfoList) { + ADMIN.move(regionInfo.getEncodedNameAsBytes(), serverName0); + } + + ADMIN.split(table2, "50".getBytes()); + // Waiting briefly so that daughter regions are created but parent is not cleaned yet. + Thread.sleep(2000); + ADMIN.balancerSwitch(true, true); + try { + ADMIN.balanceRSGroup(pgroup); + } catch (IOException e) { + fail("Exception not expected. " + e); + } + } }