-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-24286: HMaster won't become healthy after after cloning or crea… #2114
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
taklwu
wants to merge
1
commit into
apache:master
Choose a base branch
from
taklwu:HBASE-24286-master
base: master
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.
+208
−4
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
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
185 changes: 185 additions & 0 deletions
185
hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRecreateCluster.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,185 @@ | ||
| /** | ||
| * 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 static org.junit.Assert.assertFalse; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| import java.io.IOException; | ||
| import java.time.Duration; | ||
| import java.util.List; | ||
| import org.apache.hadoop.fs.Path; | ||
| import org.apache.hadoop.hbase.Cell; | ||
| import org.apache.hadoop.hbase.HBaseClassTestRule; | ||
| import org.apache.hadoop.hbase.HBaseTestingUtility; | ||
| import org.apache.hadoop.hbase.HConstants; | ||
| import org.apache.hadoop.hbase.MiniHBaseCluster; | ||
| import org.apache.hadoop.hbase.StartMiniClusterOption; | ||
| import org.apache.hadoop.hbase.TableName; | ||
| import org.apache.hadoop.hbase.client.Get; | ||
| import org.apache.hadoop.hbase.client.Put; | ||
| import org.apache.hadoop.hbase.client.RegionInfo; | ||
| import org.apache.hadoop.hbase.client.Result; | ||
| import org.apache.hadoop.hbase.client.Table; | ||
| import org.apache.hadoop.hbase.procedure2.store.wal.WALProcedureStore; | ||
| import org.apache.hadoop.hbase.regionserver.HRegionServer; | ||
| import org.apache.hadoop.hbase.testclassification.LargeTests; | ||
| import org.apache.hadoop.hbase.util.Bytes; | ||
| import org.apache.hadoop.hbase.zookeeper.ZooKeeperHelper; | ||
| import org.apache.zookeeper.ZKUtil; | ||
| import org.apache.zookeeper.ZooKeeper; | ||
| import org.junit.ClassRule; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.junit.experimental.categories.Category; | ||
| import org.junit.rules.TestName; | ||
|
|
||
| /** | ||
| * Test reuse data directory when cluster failover with a set of new region servers with | ||
| * different hostnames. For any hbase system table and user table can be assigned normally after | ||
| * cluster restart | ||
| */ | ||
| @Category({ LargeTests.class }) | ||
| public class TestRecreateCluster { | ||
| @ClassRule | ||
| public static final HBaseClassTestRule CLASS_RULE = | ||
| HBaseClassTestRule.forClass(TestRecreateCluster.class); | ||
|
|
||
| @Rule | ||
| public TestName name = new TestName(); | ||
|
|
||
| private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); | ||
| private static final int NUM_RS = 3; | ||
| private static final long LIVE_REGION_SERVER_TIMEOUT_MS = Duration.ofMinutes(3).toMillis(); | ||
|
|
||
| @Test | ||
| public void testRecreateCluster_UserTableDisabled() throws Exception { | ||
| TEST_UTIL.startMiniCluster(NUM_RS); | ||
| try { | ||
| TableName tableName = TableName.valueOf("t1"); | ||
| prepareDataBeforeRecreate(TEST_UTIL, tableName); | ||
| TEST_UTIL.getAdmin().disableTable(tableName); | ||
| TEST_UTIL.waitTableDisabled(tableName.getName()); | ||
| restartCluster(); | ||
| TEST_UTIL.getAdmin().enableTable(tableName); | ||
| validateDataAfterRecreate(TEST_UTIL, tableName); | ||
| } finally { | ||
| TEST_UTIL.shutdownMiniCluster(); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testRecreateCluster_UserTableEnabled() throws Exception { | ||
| TEST_UTIL.startMiniCluster(NUM_RS); | ||
| try { | ||
| TableName tableName = TableName.valueOf("t1"); | ||
| prepareDataBeforeRecreate(TEST_UTIL, tableName); | ||
| restartCluster(); | ||
| validateDataAfterRecreate(TEST_UTIL, tableName); | ||
| } finally { | ||
| TEST_UTIL.shutdownMiniCluster(); | ||
| } | ||
| } | ||
|
|
||
| private void restartCluster() throws Exception { | ||
| // flush cache so that everything is on disk | ||
| TEST_UTIL.getMiniHBaseCluster().flushcache(); | ||
|
|
||
| // delete all wal data | ||
| Path walRootPath = TEST_UTIL.getMiniHBaseCluster().getMaster().getWALRootDir(); | ||
| TEST_UTIL.shutdownMiniHBaseCluster(); | ||
| TEST_UTIL.getDFSCluster().getFileSystem().delete( | ||
| new Path(walRootPath.toString(), HConstants.HREGION_LOGDIR_NAME), true); | ||
| TEST_UTIL.getDFSCluster().getFileSystem().delete( | ||
| new Path(walRootPath.toString(), WALProcedureStore.MASTER_PROCEDURE_LOGDIR), true); | ||
| TEST_UTIL.getDFSCluster().getFileSystem().delete( | ||
| new Path(walRootPath.toString(), HConstants.HREGION_OLDLOGDIR_NAME), true); | ||
|
|
||
| // delete all zk data | ||
| ZooKeeper zk = ZooKeeperHelper | ||
| .getConnectedZooKeeper(TEST_UTIL.getZooKeeperWatcher().getQuorum(), 10000); | ||
| ZKUtil.deleteRecursive(zk, TEST_UTIL.getZooKeeperWatcher().getZNodePaths().baseZNode); | ||
| TEST_UTIL.shutdownMiniZKCluster(); | ||
|
|
||
| // restart zk and hbase | ||
| TEST_UTIL.startMiniZKCluster(); | ||
| StartMiniClusterOption option = StartMiniClusterOption.builder() | ||
| .numRegionServers(NUM_RS).build(); | ||
| TEST_UTIL.startMiniHBaseCluster(option); | ||
| } | ||
|
|
||
| private void prepareDataBeforeRecreate( | ||
| HBaseTestingUtility testUtil, TableName tableName) throws Exception { | ||
| Table table = testUtil.createTable(tableName, "f"); | ||
| Put put = new Put(Bytes.toBytes("r1")); | ||
| put.addColumn(Bytes.toBytes("f"), Bytes.toBytes("c"), Bytes.toBytes("v")); | ||
| table.put(put); | ||
|
|
||
| ensureTableNotColocatedWithSystemTable(tableName, TableName.NAMESPACE_TABLE_NAME); | ||
| } | ||
|
|
||
| private void ensureTableNotColocatedWithSystemTable(TableName userTable, TableName systemTable) | ||
| throws IOException, InterruptedException { | ||
| MiniHBaseCluster hbaseCluster = TEST_UTIL.getHBaseCluster(); | ||
| assertTrue("Please start more than 1 regionserver", | ||
| hbaseCluster.getRegionServerThreads().size() > 1); | ||
|
|
||
| int userTableServerNum = getServerNumForTableWithOnlyOneRegion(userTable); | ||
| int systemTableServerNum = getServerNumForTableWithOnlyOneRegion(systemTable); | ||
|
|
||
| if (userTableServerNum != systemTableServerNum) { | ||
| // no-ops if user table and system are already on a different host | ||
| return; | ||
| } | ||
|
|
||
| int destServerNum = (systemTableServerNum + 1) % NUM_RS; | ||
| assertTrue(systemTableServerNum != destServerNum); | ||
|
|
||
| HRegionServer systemTableServer = hbaseCluster.getRegionServer(systemTableServerNum); | ||
| HRegionServer destServer = hbaseCluster.getRegionServer(destServerNum); | ||
| assertTrue(!systemTableServer.equals(destServer)); | ||
| // make sure the dest server is live before moving region | ||
| hbaseCluster.waitForRegionServerToStart(destServer.getServerName().getHostname(), | ||
| destServer.getServerName().getPort(), LIVE_REGION_SERVER_TIMEOUT_MS); | ||
| // move region of userTable to a different regionserver not co-located with system table | ||
| TEST_UTIL.moveRegionAndWait(TEST_UTIL.getAdmin().getRegions(userTable).get(0), | ||
| destServer.getServerName()); | ||
| } | ||
|
|
||
| private int getServerNumForTableWithOnlyOneRegion(TableName tableName) throws IOException { | ||
| List<RegionInfo> tableRegionInfos = TEST_UTIL.getAdmin().getRegions(tableName); | ||
| assertEquals(1, tableRegionInfos.size()); | ||
| return TEST_UTIL.getHBaseCluster() | ||
| .getServerWith(tableRegionInfos.get(0).getRegionName()); | ||
| } | ||
|
|
||
| private void validateDataAfterRecreate( | ||
| HBaseTestingUtility testUtil, TableName tableName) throws Exception { | ||
| Table t1 = testUtil.getConnection().getTable(tableName); | ||
| Get get = new Get(Bytes.toBytes("r1")); | ||
| get.addColumn(Bytes.toBytes("f"), Bytes.toBytes("c")); | ||
| Result result = t1.get(get); | ||
| assertTrue(result.advance()); | ||
| Cell cell = result.current(); | ||
| assertEquals("v", Bytes.toString(cell.getValueArray(), | ||
| cell.getValueOffset(), cell.getValueLength())); | ||
| assertFalse(result.advance()); | ||
| } | ||
|
|
||
| } |
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.
I guess not an issue for master (which doesn't have the separate namespace table), but elsewhere do we still have
hbase.master.namespace.init.timeoutsetting an upper-bound on how long we wait for hbase:namespace to get assigned? Thinking that, waiting for CatalogJanitor to run, will be a pretty "slow" solution (up to 5min wait), and we may have a master crash if the ns init timeout is 5 mins as well as the catalog janitor's interval.