-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HBASE-27304 Support using IP to expose master/rs servers for some spe…
…cial scenarios (#4713) Signed-off-by: Duo Zhang <[email protected]>
- Loading branch information
1 parent
de127bd
commit cc4268a
Showing
7 changed files
with
335 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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); | ||
} | ||
} | ||
} |