-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-27304 Support using IP to expose master/rs servers for some special scenarios #4713
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
349c790
HBASE-27304 Support using IP to expose master/rs servers for some spe…
2005hithlj 8bfdee7
HBASE-27304 Support using IP to expose master/rs servers for some spe…
2005hithlj a4cec48
HBASE-27304 Support using IP to expose master/rs servers for some spe…
2005hithlj 0e15a1e
HBASE-27304 Support using IP to expose master/rs servers for some spe…
2005hithlj 6d02ab7
HBASE-27304 Support using IP to expose master/rs servers for some spe…
2005hithlj 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
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
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
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
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
76 changes: 76 additions & 0 deletions
76
hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterUseIp.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,76 @@ | ||
| /* | ||
| * 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.master; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
|
|
||
| import java.net.InetAddress; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.hbase.HBaseClassTestRule; | ||
| import org.apache.hadoop.hbase.HBaseConfiguration; | ||
| import org.apache.hadoop.hbase.HBaseTestingUtil; | ||
| import org.apache.hadoop.hbase.HConstants; | ||
| import org.apache.hadoop.hbase.SingleProcessHBaseCluster; | ||
| import org.apache.hadoop.hbase.StartTestingClusterOption; | ||
| import org.apache.hadoop.hbase.testclassification.MasterTests; | ||
| import org.apache.hadoop.hbase.testclassification.MediumTests; | ||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.ClassRule; | ||
| import org.junit.Test; | ||
| import org.junit.experimental.categories.Category; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| @Category({ MasterTests.class, MediumTests.class }) | ||
| public class TestMasterUseIp { | ||
| @ClassRule | ||
| public static final HBaseClassTestRule CLASS_RULE = | ||
| HBaseClassTestRule.forClass(TestMasterUseIp.class); | ||
|
|
||
| private static final Logger LOG = LoggerFactory.getLogger(TestMasterUseIp.class); | ||
|
|
||
| private HBaseTestingUtil TEST_UTIL; | ||
| private SingleProcessHBaseCluster CLUSTER; | ||
|
|
||
| private static final int NUM_MASTERS = 1; | ||
| private static final int NUM_RS = 1; | ||
|
|
||
| @Before | ||
| public void setup() throws Exception { | ||
| Configuration conf = HBaseConfiguration.create(); | ||
| conf.setBoolean(HConstants.HBASE_SERVER_USEIP_ENABLED_KEY, true); | ||
| TEST_UTIL = new HBaseTestingUtil(conf); | ||
| StartTestingClusterOption option = StartTestingClusterOption.builder().numMasters(NUM_MASTERS) | ||
| .numRegionServers(NUM_RS).numDataNodes(NUM_RS).build(); | ||
| CLUSTER = TEST_UTIL.startMiniCluster(option); | ||
| } | ||
|
|
||
| @After | ||
| public void teardown() throws Exception { | ||
| TEST_UTIL.shutdownMiniCluster(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testMasterUseIp() throws Exception { | ||
| String hostname = CLUSTER.getMaster(0).getServerName().getHostname(); | ||
| String ip = InetAddress.getByName(hostname).getHostAddress(); | ||
| LOG.info("hostname= " + hostname + " ,ip=" + ip); | ||
| assertEquals(ip, hostname); | ||
| } | ||
| } |
76 changes: 76 additions & 0 deletions
76
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerUseIp.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,76 @@ | ||
| /* | ||
| * 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.regionserver; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
|
|
||
| import java.net.InetAddress; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.hbase.HBaseClassTestRule; | ||
| import org.apache.hadoop.hbase.HBaseConfiguration; | ||
| import org.apache.hadoop.hbase.HBaseTestingUtil; | ||
| import org.apache.hadoop.hbase.HConstants; | ||
| import org.apache.hadoop.hbase.SingleProcessHBaseCluster; | ||
| import org.apache.hadoop.hbase.StartTestingClusterOption; | ||
| import org.apache.hadoop.hbase.testclassification.MediumTests; | ||
| import org.apache.hadoop.hbase.testclassification.RegionServerTests; | ||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.ClassRule; | ||
| import org.junit.Test; | ||
| import org.junit.experimental.categories.Category; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| @Category({ RegionServerTests.class, MediumTests.class }) | ||
| public class TestRegionServerUseIp { | ||
| @ClassRule | ||
| public static final HBaseClassTestRule CLASS_RULE = | ||
| HBaseClassTestRule.forClass(TestRegionServerUseIp.class); | ||
|
|
||
| private static final Logger LOG = LoggerFactory.getLogger(TestRegionServerUseIp.class); | ||
|
|
||
| private HBaseTestingUtil TEST_UTIL; | ||
| private SingleProcessHBaseCluster CLUSTER; | ||
|
|
||
| private static final int NUM_MASTERS = 1; | ||
| private static final int NUM_RS = 1; | ||
|
|
||
| @Before | ||
| public void setup() throws Exception { | ||
| Configuration conf = HBaseConfiguration.create(); | ||
| conf.setBoolean(HConstants.HBASE_SERVER_USEIP_ENABLED_KEY, true); | ||
| TEST_UTIL = new HBaseTestingUtil(conf); | ||
| StartTestingClusterOption option = StartTestingClusterOption.builder().numMasters(NUM_MASTERS) | ||
| .numRegionServers(NUM_RS).numDataNodes(NUM_RS).build(); | ||
| CLUSTER = TEST_UTIL.startMiniCluster(option); | ||
| } | ||
|
|
||
| @After | ||
| public void teardown() throws Exception { | ||
| TEST_UTIL.shutdownMiniCluster(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testRegionServerUseIp() throws Exception { | ||
| String hostname = CLUSTER.getRegionServer(0).getServerName().getHostname(); | ||
| String ip = InetAddress.getByName(hostname).getHostAddress(); | ||
| LOG.info("hostname= " + hostname + " ,ip=" + ip); | ||
| assertEquals(ip, hostname); | ||
| } | ||
| } |
139 changes: 139 additions & 0 deletions
139
hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestRegionMoverUseIp.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,139 @@ | ||
| /* | ||
| * 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.util; | ||
|
|
||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.IntStream; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.hbase.HBaseClassTestRule; | ||
| import org.apache.hadoop.hbase.HBaseConfiguration; | ||
| import org.apache.hadoop.hbase.HBaseTestingUtil; | ||
| import org.apache.hadoop.hbase.HConstants; | ||
| import org.apache.hadoop.hbase.ServerName; | ||
| import org.apache.hadoop.hbase.SingleProcessHBaseCluster; | ||
| import org.apache.hadoop.hbase.TableName; | ||
| import org.apache.hadoop.hbase.client.Admin; | ||
| import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; | ||
| import org.apache.hadoop.hbase.client.Put; | ||
| import org.apache.hadoop.hbase.client.Table; | ||
| import org.apache.hadoop.hbase.client.TableDescriptor; | ||
| import org.apache.hadoop.hbase.client.TableDescriptorBuilder; | ||
| import org.apache.hadoop.hbase.regionserver.HRegionServer; | ||
| import org.apache.hadoop.hbase.testclassification.LargeTests; | ||
| import org.apache.hadoop.hbase.testclassification.MiscTests; | ||
| import org.junit.AfterClass; | ||
| import org.junit.Assert; | ||
| import org.junit.Before; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.ClassRule; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.junit.experimental.categories.Category; | ||
| import org.junit.rules.TestName; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| @Category({ MiscTests.class, LargeTests.class }) | ||
| public class TestRegionMoverUseIp { | ||
|
|
||
| @ClassRule | ||
| public static final HBaseClassTestRule CLASS_RULE = | ||
| HBaseClassTestRule.forClass(TestRegionMoverUseIp.class); | ||
| private static final Logger LOG = LoggerFactory.getLogger(TestRegionMoverUseIp.class); | ||
|
|
||
| @Rule | ||
| public TestName name = new TestName(); | ||
|
|
||
| private static HBaseTestingUtil TEST_UTIL; | ||
| private static ServerName rs0; | ||
| private static ServerName rs1; | ||
| private static ServerName rs2; | ||
|
|
||
| @BeforeClass | ||
| public static void setUpBeforeClass() throws Exception { | ||
| Configuration conf = HBaseConfiguration.create(); | ||
| conf.setBoolean(HConstants.HBASE_SERVER_USEIP_ENABLED_KEY, true); | ||
| TEST_UTIL = new HBaseTestingUtil(conf); | ||
| TEST_UTIL.startMiniCluster(3); | ||
|
|
||
| SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); | ||
| rs0 = cluster.getRegionServer(0).getServerName(); | ||
| rs1 = cluster.getRegionServer(1).getServerName(); | ||
| rs2 = cluster.getRegionServer(2).getServerName(); | ||
| LOG.info("rs0 hostname=" + rs0.getHostname()); | ||
| LOG.info("rs1 hostname=" + rs1.getHostname()); | ||
| LOG.info("rs2 hostname=" + rs2.getHostname()); | ||
| TEST_UTIL.getAdmin().balancerSwitch(false, true); | ||
| } | ||
|
|
||
| @AfterClass | ||
| public static void tearDownAfterClass() throws Exception { | ||
| TEST_UTIL.shutdownMiniCluster(); | ||
| } | ||
|
|
||
| @Before | ||
| public void setUp() throws Exception { | ||
| final TableName tableName = TableName.valueOf(name.getMethodName()); | ||
| TableDescriptor tableDesc = TableDescriptorBuilder.newBuilder(tableName) | ||
| .setColumnFamily(ColumnFamilyDescriptorBuilder.of("fam1")).build(); | ||
| int startKey = 0; | ||
| int endKey = 80000; | ||
| TEST_UTIL.getAdmin().createTable(tableDesc, Bytes.toBytes(startKey), Bytes.toBytes(endKey), 9); | ||
| } | ||
|
|
||
| @Test | ||
| public void testRegionUnloadUesIp() throws Exception { | ||
| final TableName tableName = TableName.valueOf(name.getMethodName()); | ||
| SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); | ||
| Admin admin = TEST_UTIL.getAdmin(); | ||
| Table table = TEST_UTIL.getConnection().getTable(tableName); | ||
| List<Put> puts = IntStream.range(10, 50000).mapToObj(i -> new Put(Bytes.toBytes(i)) | ||
| .addColumn(Bytes.toBytes("fam1"), Bytes.toBytes("q1"), Bytes.toBytes("val_" + i))) | ||
| .collect(Collectors.toList()); | ||
| table.put(puts); | ||
| admin.flush(tableName); | ||
| admin.compact(tableName); | ||
| Thread.sleep(3000); | ||
| HRegionServer hRegionServer0 = cluster.getRegionServer(0); | ||
| HRegionServer hRegionServer1 = cluster.getRegionServer(1); | ||
| HRegionServer hRegionServer2 = cluster.getRegionServer(2); | ||
| int numRegions0 = hRegionServer0.getNumberOfOnlineRegions(); | ||
| int numRegions1 = hRegionServer1.getNumberOfOnlineRegions(); | ||
| int numRegions2 = hRegionServer2.getNumberOfOnlineRegions(); | ||
|
|
||
| Assert.assertTrue(numRegions0 >= 3); | ||
| Assert.assertTrue(numRegions1 >= 3); | ||
| Assert.assertTrue(numRegions2 >= 3); | ||
| int totalRegions = numRegions0 + numRegions1 + numRegions2; | ||
|
|
||
| // source RS: rs0 | ||
| String sourceRSName = rs0.getAddress().toString(); | ||
| RegionMover.RegionMoverBuilder rmBuilder = | ||
| new RegionMover.RegionMoverBuilder(sourceRSName, TEST_UTIL.getConfiguration()).ack(true) | ||
| .maxthreads(8); | ||
| try (RegionMover regionMover = rmBuilder.build()) { | ||
| regionMover.unload(); | ||
| int newNumRegions0 = hRegionServer0.getNumberOfOnlineRegions(); | ||
| int newNumRegions1 = hRegionServer1.getNumberOfOnlineRegions(); | ||
| int newNumRegions2 = hRegionServer2.getNumberOfOnlineRegions(); | ||
| Assert.assertEquals(0, newNumRegions0); | ||
| Assert.assertEquals(totalRegions, newNumRegions1 + newNumRegions2); | ||
| } | ||
| } | ||
| } |
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.
This is a tool? Can we get the hostname/ip by accessing the hbase cluster, instead of relying on the configuration? What if the configuration mismatches?
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.
@Apache9 sir.
Thanks for your review.
There may be configuration mismatch. I have modified and submitted the code.
Could you take a look? Thanks.