Skip to content

Commit 0eb7657

Browse files
committed
HBASE-23081 Add an option to enable/disable rs group feature (#691)
Signed-off-by: Peter Somogyi <psomogyi@apache.org>
1 parent b274144 commit 0eb7657

13 files changed

+140
-18
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@
186186
import org.apache.hadoop.hbase.replication.master.ReplicationLogCleaner;
187187
import org.apache.hadoop.hbase.replication.master.ReplicationPeerConfigUpgrader;
188188
import org.apache.hadoop.hbase.replication.regionserver.ReplicationStatus;
189+
import org.apache.hadoop.hbase.rsgroup.RSGroupAdminEndpoint;
189190
import org.apache.hadoop.hbase.rsgroup.RSGroupBasedLoadBalancer;
190191
import org.apache.hadoop.hbase.rsgroup.RSGroupInfoManager;
191192
import org.apache.hadoop.hbase.security.AccessDeniedException;
@@ -778,6 +779,17 @@ protected void initializeZKBasedSystemTrackers()
778779
this.splitOrMergeTracker = new SplitOrMergeTracker(zooKeeper, conf, this);
779780
this.splitOrMergeTracker.start();
780781

782+
// This is for backwards compatible. We do not need the CP for rs group now but if user want to
783+
// load it, we need to enable rs group.
784+
String[] cpClasses = conf.getStrings(MasterCoprocessorHost.MASTER_COPROCESSOR_CONF_KEY);
785+
if (cpClasses != null) {
786+
for (String cpClass : cpClasses) {
787+
if (RSGroupAdminEndpoint.class.getName().equals(cpClass)) {
788+
conf.setBoolean(RSGroupInfoManager.RS_GROUP_ENABLED, true);
789+
break;
790+
}
791+
}
792+
}
781793
this.rsGroupInfoManager = RSGroupInfoManager.create(this);
782794

783795
this.replicationPeerManager = ReplicationPeerManager.create(zooKeeper, conf);
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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.rsgroup;
19+
20+
import java.io.IOException;
21+
import java.util.Arrays;
22+
import java.util.List;
23+
import java.util.Set;
24+
import java.util.SortedSet;
25+
import java.util.TreeSet;
26+
import org.apache.hadoop.hbase.DoNotRetryIOException;
27+
import org.apache.hadoop.hbase.ServerName;
28+
import org.apache.hadoop.hbase.TableName;
29+
import org.apache.hadoop.hbase.master.ServerManager;
30+
import org.apache.hadoop.hbase.net.Address;
31+
import org.apache.yetus.audience.InterfaceAudience;
32+
33+
/**
34+
* A dummy RSGroupInfoManager which only contains a default rs group.
35+
*/
36+
@InterfaceAudience.Private
37+
class DisabledRSGroupInfoManager implements RSGroupInfoManager {
38+
39+
private final ServerManager serverManager;
40+
41+
public DisabledRSGroupInfoManager(ServerManager serverManager) {
42+
this.serverManager = serverManager;
43+
}
44+
45+
@Override
46+
public void start() {
47+
}
48+
49+
@Override
50+
public void addRSGroup(RSGroupInfo rsGroupInfo) throws IOException {
51+
throw new DoNotRetryIOException("RSGroup is disabled");
52+
}
53+
54+
@Override
55+
public void removeRSGroup(String groupName) throws IOException {
56+
throw new DoNotRetryIOException("RSGroup is disabled");
57+
}
58+
59+
@Override
60+
public Set<Address> moveServers(Set<Address> servers, String srcGroup, String dstGroup)
61+
throws IOException {
62+
throw new DoNotRetryIOException("RSGroup is disabled");
63+
}
64+
65+
private SortedSet<Address> getOnlineServers() {
66+
SortedSet<Address> onlineServers = new TreeSet<Address>();
67+
serverManager.getOnlineServers().keySet().stream().map(ServerName::getAddress)
68+
.forEach(onlineServers::add);
69+
return onlineServers;
70+
}
71+
72+
@Override
73+
public RSGroupInfo getRSGroupOfServer(Address serverHostPort) throws IOException {
74+
SortedSet<Address> onlineServers = getOnlineServers();
75+
if (onlineServers.contains(serverHostPort)) {
76+
return new RSGroupInfo(RSGroupInfo.DEFAULT_GROUP, onlineServers);
77+
} else {
78+
return null;
79+
}
80+
}
81+
82+
@Override
83+
public RSGroupInfo getRSGroup(String groupName) throws IOException {
84+
if (RSGroupInfo.DEFAULT_GROUP.equals(groupName)) {
85+
return new RSGroupInfo(RSGroupInfo.DEFAULT_GROUP, getOnlineServers());
86+
} else {
87+
return null;
88+
}
89+
}
90+
91+
@Override
92+
public List<RSGroupInfo> listRSGroups() throws IOException {
93+
return Arrays.asList(new RSGroupInfo(RSGroupInfo.DEFAULT_GROUP, getOnlineServers()));
94+
}
95+
96+
@Override
97+
public boolean isOnline() {
98+
return true;
99+
}
100+
101+
@Override
102+
public void removeServers(Set<Address> servers) throws IOException {
103+
throw new DoNotRetryIOException("RSGroup is disabled");
104+
}
105+
106+
@Override
107+
public RSGroupInfo getRSGroupForTable(TableName tableName) throws IOException {
108+
return null;
109+
}
110+
}

hbase-server/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManager.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
@InterfaceAudience.Private
3333
public interface RSGroupInfoManager {
3434

35+
static final String RS_GROUP_ENABLED = "hbase.balancer.rsgroup.enabled";
36+
3537
void start();
3638

3739
/**
@@ -90,6 +92,10 @@ Set<Address> moveServers(Set<Address> servers, String srcGroup, String dstGroup)
9092
RSGroupInfo getRSGroupForTable(TableName tableName) throws IOException;
9193

9294
static RSGroupInfoManager create(MasterServices master) throws IOException {
93-
return RSGroupInfoManagerImpl.getInstance(master);
95+
if (master.getConfiguration().getBoolean(RS_GROUP_ENABLED, false)) {
96+
return RSGroupInfoManagerImpl.getInstance(master);
97+
} else {
98+
return new DisabledRSGroupInfoManager(master.getServerManager());
99+
}
94100
}
95101
}

hbase-server/src/test/java/org/apache/hadoop/hbase/TestNamespace.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ public void verifyReservedNS() throws IOException {
114114
assertEquals(2, admin.listNamespaceDescriptors().length);
115115

116116
//verify existence of system tables
117-
Set<TableName> systemTables = Sets.newHashSet(
118-
TableName.META_TABLE_NAME, TableName.valueOf("hbase:rsgroup"));
117+
Set<TableName> systemTables = Sets.newHashSet(TableName.META_TABLE_NAME);
119118
List<TableDescriptor> descs = admin.listTableDescriptorsByNamespace(
120119
Bytes.toBytes(NamespaceDescriptor.SYSTEM_NAMESPACE.getName()));
121120
assertEquals(systemTables.size(), descs.size());

hbase-server/src/test/java/org/apache/hadoop/hbase/master/AbstractTestDLS.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,14 +504,14 @@ private Table installTable(int nrs, int existingRegions) throws Exception {
504504
for (String oregion : regions)
505505
LOG.debug("Region still online: " + oregion);
506506
}
507-
assertEquals(2 + existingRegions, regions.size());
507+
assertEquals(1 + existingRegions, regions.size());
508508
LOG.debug("Enabling table\n");
509509
TEST_UTIL.getAdmin().enableTable(tableName);
510510
LOG.debug("Waiting for no more RIT\n");
511511
blockUntilNoRIT();
512512
LOG.debug("Verifying there are " + numRegions + " assigned on cluster\n");
513513
regions = HBaseTestingUtility.getAllOnlineRegions(cluster);
514-
assertEquals(numRegions + 2 + existingRegions, regions.size());
514+
assertEquals(numRegions + 1 + existingRegions, regions.size());
515515
return table;
516516
}
517517

hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClusterRestart.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class TestClusterRestart extends AbstractTestRestartCluster {
4343

4444
private static final Logger LOG = LoggerFactory.getLogger(TestClusterRestart.class);
4545

46-
private static final int NUM_REGIONS = 4;
46+
private static final int NUM_REGIONS = 3;
4747

4848
@Override
4949
protected boolean splitWALCoordinatedByZk() {

hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterMetrics.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.apache.hadoop.hbase.MiniHBaseCluster;
2626
import org.apache.hadoop.hbase.ServerName;
2727
import org.apache.hadoop.hbase.StartMiniClusterOption;
28-
import org.apache.hadoop.hbase.TableName;
2928
import org.apache.hadoop.hbase.test.MetricsAssertHelper;
3029
import org.apache.hadoop.hbase.testclassification.MasterTests;
3130
import org.apache.hadoop.hbase.testclassification.MediumTests;
@@ -91,7 +90,6 @@ public static void startCluster() throws Exception {
9190
cluster = TEST_UTIL.getHBaseCluster();
9291
LOG.info("Waiting for active/ready master");
9392
cluster.waitForActiveAndReadyMaster();
94-
TEST_UTIL.waitTableAvailable(TableName.valueOf("hbase:rsgroup"));
9593
master = cluster.getMaster();
9694
}
9795

@@ -133,7 +131,7 @@ public void testDefaultMasterMetrics() throws Exception {
133131
MetricsMasterSource masterSource = master.getMasterMetrics().getMetricsSource();
134132
boolean tablesOnMaster = LoadBalancer.isTablesOnMaster(TEST_UTIL.getConfiguration());
135133
metricsHelper.assertGauge("numRegionServers", 1 + (tablesOnMaster ? 1 : 0), masterSource);
136-
metricsHelper.assertGauge("averageLoad", 2, masterSource);
134+
metricsHelper.assertGauge("averageLoad", 1, masterSource);
137135
metricsHelper.assertGauge("numDeadRegionServers", 0, masterSource);
138136

139137
metricsHelper.assertGauge("masterStartTime", master.getMasterStartTime(), masterSource);

hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterRestartAfterDisablingTable.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void testForCheckingIfEnableAndDisableWorksFineAfterSwitch()
9292

9393
NavigableSet<String> regions = HBaseTestingUtility.getAllOnlineRegions(cluster);
9494
assertEquals("The number of regions for the table tableRestart should be 0 and only" +
95-
"the catalog table should be present.", 2, regions.size());
95+
"the catalog table should be present.", 1, regions.size());
9696

9797
List<MasterThread> masterThreads = cluster.getMasterThreads();
9898
MasterThread activeMaster = null;
@@ -120,7 +120,7 @@ public void testForCheckingIfEnableAndDisableWorksFineAfterSwitch()
120120
log("Verifying there are " + numRegions + " assigned on cluster\n");
121121
regions = HBaseTestingUtility.getAllOnlineRegions(cluster);
122122
assertEquals("The assigned regions were not onlined after master" +
123-
" switch except for the catalog table.", 6, regions.size());
123+
" switch except for the catalog table.", 5, regions.size());
124124
assertTrue("The table should be in enabled state", cluster.getMaster().getTableStateManager()
125125
.isTableState(TableName.valueOf(name.getMethodName()), TableState.State.ENABLED));
126126
ht.close();

hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRollingRestart.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public void testBasicRollingRestart() throws Exception {
121121
log("Region still online: " + oregion);
122122
}
123123
}
124-
assertEquals(2, regions.size());
124+
assertEquals(1, regions.size());
125125
log("Enabling table\n");
126126
TEST_UTIL.getAdmin().enableTable(tableName);
127127
log("Waiting for no more RIT\n");

hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionOpen.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ public void testPriorityRegionIsOpenedWithSeparateThreadPool() throws Exception
8686
final TableName tableName = TableName.valueOf(TestRegionOpen.class.getSimpleName());
8787
ThreadPoolExecutor exec = getRS().getExecutorService()
8888
.getExecutorThreadPool(ExecutorType.RS_OPEN_PRIORITY_REGION);
89-
HTU.waitTableAvailable(TableName.valueOf("hbase:rsgroup"));
9089
long completed = exec.getCompletedTaskCount();
9190

9291
HTableDescriptor htd = new HTableDescriptor(tableName);

hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionReplicasWithRestartScenarios.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ private void assertReplicaDistributed() throws Exception {
146146
checkDuplicates(onlineRegions3);
147147
assertFalse(res);
148148
int totalRegions = onlineRegions.size() + onlineRegions2.size() + onlineRegions3.size();
149-
assertEquals(62, totalRegions);
149+
assertEquals(61, totalRegions);
150150
}
151151

152152
private boolean checkDuplicates(Collection<HRegion> onlineRegions3) throws Exception {

hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerMetrics.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ private void doScan(int n, boolean caching) throws IOException {
225225

226226
@Test
227227
public void testRegionCount() throws Exception {
228-
metricsHelper.assertGauge("regionCount", TABLES_ON_MASTER ? 1 : 3, serverSource);
228+
metricsHelper.assertGauge("regionCount", TABLES_ON_MASTER ? 1 : 2, serverSource);
229229
}
230230

231231
@Test
@@ -335,7 +335,7 @@ public void testStoreCount() throws Exception {
335335
TEST_UTIL.getAdmin().flush(tableName);
336336

337337
metricsRegionServer.getRegionServerWrapper().forceRecompute();
338-
assertGauge("storeCount", TABLES_ON_MASTER ? 1 : 6);
338+
assertGauge("storeCount", TABLES_ON_MASTER ? 1 : 5);
339339
assertGauge("storeFileCount", 1);
340340
}
341341

hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsckReplication.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.apache.hadoop.hbase.HBaseClassTestRule;
2525
import org.apache.hadoop.hbase.HBaseTestingUtility;
2626
import org.apache.hadoop.hbase.ServerName;
27-
import org.apache.hadoop.hbase.TableName;
2827
import org.apache.hadoop.hbase.replication.ReplicationPeerConfig;
2928
import org.apache.hadoop.hbase.replication.ReplicationPeerStorage;
3029
import org.apache.hadoop.hbase.replication.ReplicationQueueStorage;
@@ -53,7 +52,6 @@ public class TestHBaseFsckReplication {
5352
public static void setUp() throws Exception {
5453
UTIL.getConfiguration().setBoolean("hbase.write.hbck1.lock.file", false);
5554
UTIL.startMiniCluster(1);
56-
UTIL.waitTableAvailable(TableName.valueOf("hbase:rsgroup"));
5755
}
5856

5957
@AfterClass

0 commit comments

Comments
 (0)