-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-30323 [RSGroup] Forward-port HBASE-22658 to branch-2 #8547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Umeshkumar9414
wants to merge
1
commit into
apache:branch-2
Choose a base branch
from
Umeshkumar9414:HBASE-30323
base: branch-2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
239 changes: 239 additions & 0 deletions
239
...group/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRegionMoverWithRSGroupEnable.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,239 @@ | ||
| /* | ||
| * 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.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collection; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import org.apache.hadoop.fs.Path; | ||
| import org.apache.hadoop.hbase.HBaseTestingUtility; | ||
| import org.apache.hadoop.hbase.HConstants; | ||
| import org.apache.hadoop.hbase.ServerName; | ||
| import org.apache.hadoop.hbase.TableName; | ||
| import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; | ||
| import org.apache.hadoop.hbase.client.TableDescriptor; | ||
| import org.apache.hadoop.hbase.client.TableDescriptorBuilder; | ||
| import org.apache.hadoop.hbase.coprocessor.CoprocessorHost; | ||
| import org.apache.hadoop.hbase.master.ServerManager; | ||
| import org.apache.hadoop.hbase.net.Address; | ||
| import org.apache.hadoop.hbase.regionserver.HRegion; | ||
| import org.apache.hadoop.hbase.regionserver.HRegionServer; | ||
| import org.apache.hadoop.hbase.testclassification.MediumTests; | ||
| import org.apache.hadoop.hbase.testclassification.MiscTests; | ||
| import org.apache.hadoop.hbase.util.Bytes; | ||
| import org.apache.hadoop.hbase.util.JVMClusterUtil; | ||
| import org.apache.hadoop.hbase.util.RegionMover; | ||
| import org.apache.hadoop.hbase.util.RegionMover.RegionMoverBuilder; | ||
| import org.junit.jupiter.api.AfterAll; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Tag; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** | ||
| * Tests that RegionMover.unloadRegions() respects RSGroup membership in branch-2: regions | ||
| * decommissioned from a server in a non-default RSGroup must land only on other servers in the same | ||
| * group, not on servers in unrelated groups. | ||
| */ | ||
| @Tag(MiscTests.TAG) | ||
| @Tag(MediumTests.TAG) | ||
| public class TestRegionMoverWithRSGroupEnable { | ||
|
|
||
| private static final Logger LOG = LoggerFactory.getLogger(TestRegionMoverWithRSGroupEnable.class); | ||
|
|
||
| private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); | ||
| private static final String TEST_RSGROUP = "test"; | ||
| private static final TableName TABLE_NAME = TableName.valueOf("testRegionMoverWithRSGroupEnable"); | ||
|
|
||
| @BeforeAll | ||
| public static void setUpBeforeClass() throws Exception { | ||
| TEST_UTIL.getConfiguration().set(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, | ||
| RSGroupBasedLoadBalancer.class.getName()); | ||
| TEST_UTIL.getConfiguration().set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, | ||
| RSGroupAdminEndpoint.class.getName()); | ||
| TEST_UTIL.getConfiguration().setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, 5); | ||
| TEST_UTIL.startMiniCluster(5); | ||
| } | ||
|
|
||
| @AfterAll | ||
| public static void tearDownAfterClass() throws Exception { | ||
| TEST_UTIL.shutdownMiniCluster(); | ||
| } | ||
|
|
||
| // Addresses of the two servers placed in TEST_RSGROUP each test. | ||
| private final List<Address> rsservers = new ArrayList<>(2); | ||
| // Addresses of the servers that remain in the default group (excludes meta RS). | ||
| private final List<ServerName> defaultGroupServers = new ArrayList<>(); | ||
| private RSGroupAdminClient rsGroupAdmin; | ||
|
|
||
| @BeforeEach | ||
| public void setUp() throws Exception { | ||
| rsGroupAdmin = new RSGroupAdminClient(TEST_UTIL.getConnection()); | ||
| if (rsGroupAdmin.getRSGroupInfo(TEST_RSGROUP) == null) { | ||
| rsGroupAdmin.addRSGroup(TEST_RSGROUP); | ||
| } | ||
| Collection<ServerName> allServers = TEST_UTIL.getAdmin().getRegionServers(); | ||
|
|
||
| // Exclude the RS that hosts hbase:meta to keep the test stable. | ||
| ServerName rsContainMeta = TEST_UTIL.getMiniHBaseCluster().getRegionServerThreads().stream() | ||
| .map(JVMClusterUtil.RegionServerThread::getRegionServer) | ||
| .filter(rs -> !rs.getRegions(TableName.META_TABLE_NAME).isEmpty()).findFirst().get() | ||
| .getServerName(); | ||
| LOG.info("{} contains hbase:meta, keeping in default group", rsContainMeta); | ||
|
|
||
| // Move any leftover servers back to default before setting up fresh assignments. | ||
| RSGroupInfo existingGroup = rsGroupAdmin.getRSGroupInfo(TEST_RSGROUP); | ||
| if (existingGroup != null && !existingGroup.getServers().isEmpty()) { | ||
| rsGroupAdmin.moveServers(new HashSet<>(existingGroup.getServers()), | ||
| RSGroupInfo.DEFAULT_GROUP); | ||
| } | ||
|
|
||
| List<ServerName> modifiable = new ArrayList<>(allServers); | ||
| modifiable.remove(rsContainMeta); | ||
| int i = 0; | ||
| for (ServerName server : modifiable) { | ||
| if (i == 2) break; | ||
| rsservers.add(Address.fromParts(server.getHostname(), server.getPort())); | ||
| i++; | ||
| } | ||
| rsGroupAdmin.moveServers(new HashSet<>(rsservers), TEST_RSGROUP); | ||
| LOG.info("Servers moved to {} group: {}", TEST_RSGROUP, rsservers); | ||
|
|
||
| assertEquals(3, rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP).getServers().size()); | ||
| assertEquals(2, rsGroupAdmin.getRSGroupInfo(TEST_RSGROUP).getServers().size()); | ||
|
|
||
| // Record the three default-group servers (used for isolation assertions). | ||
| for (ServerName sn : allServers) { | ||
| Address addr = sn.getAddress(); | ||
| if (!rsservers.contains(addr)) { | ||
| defaultGroupServers.add(sn); | ||
| } | ||
| } | ||
|
|
||
| if (TEST_UTIL.getAdmin().tableExists(TABLE_NAME)) { | ||
| TEST_UTIL.deleteTable(TABLE_NAME); | ||
| } | ||
| TableDescriptor tableDesc = TableDescriptorBuilder.newBuilder(TABLE_NAME) | ||
| .setColumnFamily(ColumnFamilyDescriptorBuilder.of("f")).build(); | ||
| TEST_UTIL.getAdmin().createTable(tableDesc, Bytes.toBytes("a"), Bytes.toBytes("z"), 9); | ||
| rsGroupAdmin.moveTables(new HashSet<>(Arrays.asList(TABLE_NAME)), TEST_RSGROUP); | ||
| TEST_UTIL.waitTableAvailable(TABLE_NAME); | ||
| } | ||
|
|
||
| @AfterEach | ||
| public void tearDown() throws Exception { | ||
| if (TEST_UTIL.getAdmin().tableExists(TABLE_NAME)) { | ||
| TEST_UTIL.deleteTable(TABLE_NAME); | ||
| } | ||
| if (!rsservers.isEmpty()) { | ||
| rsGroupAdmin.moveServers(new HashSet<>(rsservers), RSGroupInfo.DEFAULT_GROUP); | ||
| } | ||
| if (rsGroupAdmin.getRSGroupInfo(TEST_RSGROUP) != null) { | ||
| rsGroupAdmin.removeRSGroup(TEST_RSGROUP); | ||
| } | ||
| rsservers.clear(); | ||
| defaultGroupServers.clear(); | ||
| } | ||
|
|
||
| /** | ||
| * Unloading a server in a non-default RSGroup must move all regions to the remaining server in | ||
| * that group — and must not move any region to a server in the default group. | ||
| */ | ||
| @Test | ||
| public void testUnloadRegionsRespectsRSGroup() throws Exception { | ||
| Address decommission = rsservers.get(0); | ||
| Address online = rsservers.get(1); | ||
| String filename = new Path(TEST_UTIL.getDataTestDir(), "testRSGroupUnload").toString(); | ||
|
|
||
| RegionMoverBuilder builder = | ||
| new RegionMoverBuilder(decommission.toString(), TEST_UTIL.getConfiguration()); | ||
| try (RegionMover rm = builder.filename(filename).ack(true).build()) { | ||
| LOG.info("Unloading {}", decommission.getHostname()); | ||
| rm.unload(); | ||
| } | ||
|
|
||
| HRegionServer onlineRS = TEST_UTIL.getMiniHBaseCluster().getRegionServerThreads().stream() | ||
| .map(JVMClusterUtil.RegionServerThread::getRegionServer) | ||
| .filter(rs -> rs.getServerName().getAddress().equals(online)).findFirst().get(); | ||
|
|
||
| // Positive assertion: all 9 regions landed on the one remaining test-group server. | ||
| assertEquals(9, onlineRS.getNumberOfOnlineRegions(), | ||
| "All 9 regions must be on the single remaining server in the test RSGroup"); | ||
|
|
||
| // Isolation assertion: no default-group server received any of the table's regions. | ||
| for (ServerName defaultSN : defaultGroupServers) { | ||
| HRegionServer defaultRS = TEST_UTIL.getMiniHBaseCluster().getRegionServerThreads().stream() | ||
| .map(JVMClusterUtil.RegionServerThread::getRegionServer) | ||
| .filter(rs -> rs.getServerName().equals(defaultSN)).findFirst().orElse(null); | ||
| if (defaultRS == null) continue; | ||
| List<HRegion> tableRegions = defaultRS.getRegions(TABLE_NAME); | ||
| assertTrue(tableRegions.isEmpty(), "Default-group server " + defaultSN | ||
| + " must not hold any regions of " + TABLE_NAME + " but had: " + tableRegions); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Unloading a server that is in the default RSGroup must still succeed end-to-end when RSGroups | ||
| * are enabled. The server's regions should be spread across all available servers (not filtered). | ||
| */ | ||
| @Test | ||
| public void testUnloadDefaultGroupServerWithRSGroupEnabled() throws Exception { | ||
| ServerName defaultSN = defaultGroupServers.get(0); | ||
| Address decommission = defaultSN.getAddress(); | ||
| String filename = new Path(TEST_UTIL.getDataTestDir(), "testDefaultGroupUnload").toString(); | ||
|
|
||
| // Create a table in the default group; the balancer will distribute its 6 regions naturally | ||
| // across the 3 default-group servers, so defaultSN will hold at least some. | ||
| TableName defaultTable = TableName.valueOf("testDefaultGroupTable"); | ||
| if (TEST_UTIL.getAdmin().tableExists(defaultTable)) { | ||
| TEST_UTIL.deleteTable(defaultTable); | ||
| } | ||
| try { | ||
| TableDescriptor td = TableDescriptorBuilder.newBuilder(defaultTable) | ||
| .setColumnFamily(ColumnFamilyDescriptorBuilder.of("f")).build(); | ||
| TEST_UTIL.getAdmin().createTable(td, Bytes.toBytes("a"), Bytes.toBytes("z"), 6); | ||
| TEST_UTIL.waitTableAvailable(defaultTable); | ||
|
|
||
| RegionMoverBuilder builder = | ||
| new RegionMoverBuilder(decommission.toString(), TEST_UTIL.getConfiguration()); | ||
| try (RegionMover rm = builder.filename(filename).ack(true).build()) { | ||
| LOG.info("Unloading default-group server {}", decommission.getHostname()); | ||
| rm.unload(); | ||
| } | ||
|
|
||
| // After unload, the decommissioned server must hold no regions of the default table. | ||
| HRegionServer decommRS = TEST_UTIL.getMiniHBaseCluster().getRegionServerThreads().stream() | ||
| .map(JVMClusterUtil.RegionServerThread::getRegionServer) | ||
| .filter(rs -> rs.getServerName().equals(defaultSN)).findFirst().get(); | ||
| assertEquals(0, decommRS.getRegions(defaultTable).size(), | ||
| "Decommissioned default-group server must hold no regions after unload"); | ||
| } finally { | ||
| if (TEST_UTIL.getAdmin().tableExists(defaultTable)) { | ||
| TEST_UTIL.deleteTable(defaultTable); | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also please add assertion that default group regions don't land on
testRS group servers?