Skip to content

Commit

Permalink
HBASE-25682 Add a new command to update the configuration of all RSs …
Browse files Browse the repository at this point in the history
…in a RSGroup for branch-2 (#3106)

* HBASE-25682 Add a new command to update the configuration of all RSs in a RSGroup

Signed-off-by: Pankaj Kumar<[email protected]>
  • Loading branch information
ZhaoBQ authored May 21, 2021
1 parent d78c164 commit cd06870
Show file tree
Hide file tree
Showing 11 changed files with 356 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public boolean containsServer(Address hostPort) {
/**
* Get list of servers.
*/
public Set<Address> getServers() {
public SortedSet<Address> getServers() {
return servers;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,12 @@ void moveServersAndTables(Set<Address> servers, Set<TableName> tables,
* @throws IOException if a remote or network exception occurs
*/
void updateRSGroupConfig(String groupName, Map<String, String> configuration) throws IOException;

/**
* Update the configuration and trigger an online config change
* on all the regionservers in the RSGroup.
* @param groupName the group name
* @throws IOException if a remote or network exception occurs
*/
void updateConfiguration(String groupName) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.hadoop.hbase.ClusterMetrics;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.TableNotFoundException;
import org.apache.hadoop.hbase.client.Admin;
Expand Down Expand Up @@ -269,4 +273,19 @@ public void updateRSGroupConfig(String groupName, Map<String, String> configurat
throw ProtobufUtil.handleRemoteException(e);
}
}

@Override
public void updateConfiguration(String groupName) throws IOException {
RSGroupInfo rsGroupInfo = getRSGroupInfo(groupName);
if (rsGroupInfo == null) {
throw new IllegalArgumentException("RSGroup does not exist: " + groupName);
}
ClusterMetrics status =
admin.getClusterMetrics(EnumSet.of(ClusterMetrics.Option.SERVERS_NAME));
List<ServerName> groupServers = status.getServersName().stream().filter(
s -> rsGroupInfo.containsServer(s.getAddress())).collect(Collectors.toList());
for (ServerName server : groupServers) {
admin.updateConfiguration(server);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,15 @@ public void updateRSGroupConfig(String groupName, Map<String, String> configurat
}
}

/**
* Because the {@link RSGroupAdminClient#updateConfiguration(String)} calls
* {@link org.apache.hadoop.hbase.client.Admin#updateConfiguration(ServerName)} method, the
* implementation of this method on the Server side is empty.
*/
@Override
public void updateConfiguration(String groupName) throws IOException {
}

private Map<String, RegionState> rsGroupGetRegionsInTransition(String groupName)
throws IOException {
Map<String, RegionState> rit = Maps.newTreeMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.Waiter;
import org.apache.hadoop.hbase.client.AbstractTestUpdateConfiguration;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.RegionInfo;
import org.apache.hadoop.hbase.client.TableDescriptor;
Expand All @@ -62,7 +63,7 @@
import org.apache.hbase.thirdparty.com.google.common.collect.Maps;
import org.apache.hbase.thirdparty.com.google.common.collect.Sets;

public abstract class TestRSGroupsBase {
public abstract class TestRSGroupsBase extends AbstractTestUpdateConfiguration {
protected static final Logger LOG = LoggerFactory.getLogger(TestRSGroupsBase.class);

//shared
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hbase.rsgroup;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import java.util.stream.Collectors;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.JVMClusterUtil;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Category(MediumTests.class)
public class TestUpdateRSGroupConfiguration extends TestRSGroupsBase {
protected static final Logger LOG = LoggerFactory.getLogger(TestUpdateRSGroupConfiguration.class);

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestUpdateRSGroupConfiguration.class);
private static final String TEST_GROUP = "test";
private static final String TEST2_GROUP = "test2";

@BeforeClass
public static void setUp() throws Exception {
setUpConfigurationFiles(TEST_UTIL);
setUpTestBeforeClass();
addResourceToRegionServerConfiguration(TEST_UTIL);
}

@AfterClass
public static void tearDown() throws Exception {
tearDownAfterClass();
}

@Before
public void beforeMethod() throws Exception {
setUpBeforeMethod();
}

@After
public void afterMethod() throws Exception {
tearDownAfterMethod();
}

@Test
public void testOnlineConfigChangeInRSGroup() throws Exception {
addGroup(TEST_GROUP, 1);
rsGroupAdmin.updateConfiguration(TEST_GROUP);
}

@Test
public void testNonexistentRSGroup() throws Exception {
try {
rsGroupAdmin.updateConfiguration(TEST2_GROUP);
fail("Group does not exist: test2");
} catch (IllegalArgumentException iae) {
// expected
}
}

@Test
public void testCustomOnlineConfigChangeInRSGroup() throws Exception {
// Check the default configuration of the RegionServers
TEST_UTIL.getMiniHBaseCluster().getRegionServerThreads().forEach(thread -> {
Configuration conf = thread.getRegionServer().getConfiguration();
assertEquals(0, conf.getInt("hbase.custom.config", 0));
});

replaceHBaseSiteXML();
RSGroupInfo testRSGroup = addGroup(TEST_GROUP, 1);
RSGroupInfo test2RSGroup = addGroup(TEST2_GROUP, 1);
rsGroupAdmin.updateConfiguration(TEST_GROUP);

// Check the configuration of the RegionServer in test rsgroup, should be update
Configuration regionServerConfiguration =
TEST_UTIL.getMiniHBaseCluster().getLiveRegionServerThreads().stream()
.map(JVMClusterUtil.RegionServerThread::getRegionServer)
.filter(regionServer ->
(regionServer.getServerName().getAddress().equals(testRSGroup.getServers().first())))
.collect(Collectors.toList()).get(0).getConfiguration();
int custom = regionServerConfiguration.getInt("hbase.custom.config", 0);
assertEquals(1000, custom);

// Check the configuration of the RegionServer in test2 rsgroup, should not be update
regionServerConfiguration =
TEST_UTIL.getMiniHBaseCluster().getLiveRegionServerThreads().stream()
.map(JVMClusterUtil.RegionServerThread::getRegionServer)
.filter(regionServer ->
(regionServer.getServerName().getAddress().equals(test2RSGroup.getServers().first())))
.collect(Collectors.toList()).get(0).getConfiguration();
custom = regionServerConfiguration.getInt("hbase.custom.config", 0);
assertEquals(0, custom);

restoreHBaseSiteXML();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ public void updateRSGroupConfig(String groupName, Map<String, String> configurat
verify();
}

@Override
public void updateConfiguration(String groupName) throws IOException {
wrapped.updateConfiguration(groupName);
}

public void verify() throws IOException {
Map<String, RSGroupInfo> groupMap = Maps.newHashMap();
Set<RSGroupInfo> zList = Sets.newHashSet();
Expand Down
146 changes: 146 additions & 0 deletions hbase-rsgroup/src/test/resources/override-hbase-site.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
/**
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->
<configuration>
<property>
<name>hbase.custom.config</name>
<value>1000</value>
</property>
<property>
<name>hbase.regionserver.msginterval</name>
<value>1000</value>
<description>Interval between messages from the RegionServer to HMaster
in milliseconds. Default is 15. Set this value low if you want unit
tests to be responsive.
</description>
</property>
<property>
<name>hbase.defaults.for.version.skip</name>
<value>true</value>
</property>
<property>
<name>hbase.server.thread.wakefrequency</name>
<value>1000</value>
<description>Time to sleep in between searches for work (in milliseconds).
Used as sleep interval by service threads such as hbase:meta scanner and log roller.
</description>
</property>
<property>
<name>hbase.master.event.waiting.time</name>
<value>50</value>
<description>Time to sleep between checks to see if a table event took place.
</description>
</property>
<property>
<name>hbase.regionserver.handler.count</name>
<value>5</value>
</property>
<property>
<name>hbase.master.info.port</name>
<value>-1</value>
<description>The port for the hbase master web UI
Set to -1 if you do not want the info server to run.
</description>
</property>
<property>
<name>hbase.master.port</name>
<value>0</value>
<description>Always have masters and regionservers come up on port '0' so we don't clash over
default ports.
</description>
</property>
<property>
<name>hbase.regionserver.port</name>
<value>0</value>
<description>Always have masters and regionservers come up on port '0' so we don't clash over
default ports.
</description>
</property>
<property>
<name>hbase.ipc.client.fallback-to-simple-auth-allowed</name>
<value>true</value>
</property>

<property>
<name>hbase.regionserver.info.port</name>
<value>-1</value>
<description>The port for the hbase regionserver web UI
Set to -1 if you do not want the info server to run.
</description>
</property>
<property>
<name>hbase.regionserver.info.port.auto</name>
<value>true</value>
<description>Info server auto port bind. Enables automatic port
search if hbase.regionserver.info.port is already in use.
Enabled for testing to run multiple tests on one machine.
</description>
</property>
<property>
<name>hbase.regionserver.safemode</name>
<value>false</value>
<description>
Turn on/off safe mode in region server. Always on for production, always off
for tests.
</description>
</property>
<property>
<name>hbase.hregion.max.filesize</name>
<value>67108864</value>
<description>
Maximum desired file size for an HRegion. If filesize exceeds
value + (value / 2), the HRegion is split in two. Default: 256M.

Keep the maximum filesize small so we split more often in tests.
</description>
</property>
<property>
<name>hadoop.log.dir</name>
<value>${user.dir}/../logs</value>
</property>
<property>
<name>hbase.zookeeper.property.clientPort</name>
<value>21818</value>
<description>Property from ZooKeeper's config zoo.cfg.
The port at which the clients will connect.
</description>
</property>
<property>
<name>hbase.defaults.for.version.skip</name>
<value>true</value>
<description>
Set to true to skip the 'hbase.defaults.for.version'.
Setting this to true can be useful in contexts other than
the other side of a maven generation; i.e. running in an
ide. You'll want to set this boolean to true to avoid
seeing the RuntimeException complaint: "hbase-default.xml file
seems to be for and old version of HBase (@@@VERSION@@@), this
version is X.X.X-SNAPSHOT"
</description>
</property>
<property>
<name>hbase.table.sanity.checks</name>
<value>false</value>
<description>Skip sanity checks in tests
</description>
</property>
</configuration>
6 changes: 6 additions & 0 deletions hbase-shell/src/main/ruby/hbase/rsgroup_admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,5 +220,11 @@ def alter_rsgroup_config(rsgroup_name, *args)
end
@admin.updateRSGroupConfig(rsgroup_name, configuration)
end

#----------------------------------------------------------------------------------------------
# Updates the configuration of all the regionservers in the rsgroup.
def update_rsgroup_config(groupName)
@admin.updateConfiguration(groupName)
end
end
end
1 change: 1 addition & 0 deletions hbase-shell/src/main/ruby/shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ def self.exception_handler(hide_traceback)
commands: %w[
update_config
update_all_config
update_rsgroup_config
]
)

Expand Down
Loading

0 comments on commit cd06870

Please sign in to comment.