HBASE-20742 Always create WAL directory for region server
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/c08eff67 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/c08eff67 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/c08eff67 Branch: refs/heads/HBASE-19064 Commit: c08eff67afd8ac696c45a383077d4a42fed85ba2 Parents: 9101fc2 Author: zhangduo <zhang...@apache.org> Authored: Fri Jun 15 22:44:44 2018 +0800 Committer: zhangduo <zhang...@apache.org> Committed: Wed Jun 20 14:21:23 2018 +0800 ---------------------------------------------------------------------- .../hbase/regionserver/HRegionServer.java | 5 + .../TestRegionServerCrashDisableWAL.java | 106 +++++++++++++++++++ 2 files changed, 111 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/c08eff67/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java index db7052e..1ca76ed 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java @@ -1813,6 +1813,11 @@ public class HRegionServer extends HasThread implements throw new RegionServerRunningException( "Region server has already created directory at " + this.serverName.toString()); } + // Always create wal directory as now we need this when master restarts to find out the live + // region servers. + if (!this.walFs.mkdirs(logDir)) { + throw new IOException("Can not create wal directory " + logDir); + } // Instantiate replication if replication enabled. Pass it the log directories. createNewReplicationInstance(conf, this, this.walFs, logDir, oldLogDir, factory.getWALProvider()); http://git-wip-us.apache.org/repos/asf/hbase/blob/c08eff67/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerCrashDisableWAL.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerCrashDisableWAL.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerCrashDisableWAL.java new file mode 100644 index 0000000..c4571ac --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerCrashDisableWAL.java @@ -0,0 +1,106 @@ +/** + * 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.io.IOException; +import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseTestingUtility; +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.Table; +import org.apache.hadoop.hbase.master.HMaster; +import org.apache.hadoop.hbase.master.ServerManager; +import org.apache.hadoop.hbase.testclassification.MediumTests; +import org.apache.hadoop.hbase.testclassification.RegionServerTests; +import org.apache.hadoop.hbase.util.Bytes; +import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +/** + * Testcase for HBASE-20742 + */ +@Category({ RegionServerTests.class, MediumTests.class }) +public class TestRegionServerCrashDisableWAL { + + @ClassRule + public static final HBaseClassTestRule CLASS_RULE = + HBaseClassTestRule.forClass(TestRegionServerCrashDisableWAL.class); + + private static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); + + private static TableName TABLE_NAME = TableName.valueOf("test"); + + private static byte[] CF = Bytes.toBytes("cf"); + + private static byte[] CQ = Bytes.toBytes("cq"); + + @BeforeClass + public static void setUp() throws Exception { + UTIL.getConfiguration().setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, 1); + UTIL.getConfiguration().setBoolean("hbase.regionserver.hlog.enabled", false); + UTIL.startMiniCluster(2); + UTIL.createTable(TABLE_NAME, CF); + UTIL.waitTableAvailable(TABLE_NAME); + HRegionServer rs = UTIL.getRSForFirstRegionInTable(TABLE_NAME); + if (!rs.getRegions(TableName.META_TABLE_NAME).isEmpty()) { + HRegionServer rs1 = UTIL.getOtherRegionServer(rs); + UTIL.moveRegionAndWait( + UTIL.getMiniHBaseCluster().getRegions(TABLE_NAME).get(0).getRegionInfo(), + rs1.getServerName()); + } + UTIL.getAdmin().balancerSwitch(false, true); + } + + @AfterClass + public static void tearDown() throws Exception { + UTIL.shutdownMiniCluster(); + } + + @Test + public void test() throws InterruptedException, IOException { + HMaster master = UTIL.getMiniHBaseCluster().stopMaster(0).getMaster(); + // Shutdown master before shutting down rs + UTIL.waitFor(30000, () -> !master.isAlive()); + RegionServerThread thread = null; + for (RegionServerThread t : UTIL.getMiniHBaseCluster().getRegionServerThreads()) { + if (!t.getRegionServer().getRegions(TABLE_NAME).isEmpty()) { + thread = t; + break; + } + } + // shutdown rs + thread.getRegionServer().abort("For testing"); + thread.join(); + // restart master + UTIL.getMiniHBaseCluster().startMaster(); + // make sure that we can schedule a SCP for the crashed server which WAL is disabled and bring + // the region online. + try (Table table = + UTIL.getConnection().getTableBuilder(TABLE_NAME, null).setOperationTimeout(30000).build()) { + table.put(new Put(Bytes.toBytes(1)).addColumn(CF, CQ, Bytes.toBytes(1))); + assertEquals(1, Bytes.toInt(table.get(new Get(Bytes.toBytes(1))).getValue(CF, CQ))); + } + } +}