001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.client;
019
020import static org.junit.jupiter.api.Assertions.assertEquals;
021
022import org.apache.hadoop.hbase.HConstants;
023import org.apache.hadoop.hbase.TableDescriptors;
024import org.apache.hadoop.hbase.TableName;
025import org.apache.hadoop.hbase.master.HMaster;
026import org.apache.hadoop.hbase.testclassification.MediumTests;
027import org.apache.hadoop.hbase.testclassification.MiscTests;
028import org.junit.jupiter.api.BeforeAll;
029import org.junit.jupiter.api.Tag;
030import org.junit.jupiter.api.Test;
031
032/**
033 * Make sure we will honor the {@link HConstants#META_REPLICAS_NUM}.And also test upgrading.
034 */
035@Tag(MiscTests.TAG)
036@Tag(MediumTests.TAG)
037public class TestIncreaseMetaReplicaThroughConfig extends MetaWithReplicasTestBase {
038
039  @BeforeAll
040  public static void setUp() throws Exception {
041    startCluster();
042  }
043
044  @Test
045  public void testUpgradeAndIncreaseReplicaCount() throws Exception {
046    HMaster oldMaster = TEST_UTIL.getMiniHBaseCluster().getMaster();
047    TableDescriptors oldTds = oldMaster.getTableDescriptors();
048    TableDescriptor oldMetaTd = oldTds.get(TableName.META_TABLE_NAME);
049    assertEquals(3, oldMetaTd.getRegionReplication());
050    // force update the replica count to 1 and then kill the master, to simulate that hen upgrading,
051    // we have no region replication in meta table descriptor but we actually have meta region
052    // replicas
053    oldTds.update(TableDescriptorBuilder.newBuilder(oldMetaTd).setRegionReplication(1).build());
054    oldMaster.stop("Restarting");
055    TEST_UTIL.waitFor(30000, () -> oldMaster.isStopped());
056
057    // increase replica count to 5 through Configuration
058    TEST_UTIL.getMiniHBaseCluster().getConfiguration().setInt(HConstants.META_REPLICAS_NUM, 5);
059    TEST_UTIL.getMiniHBaseCluster().startMaster();
060    TEST_UTIL.waitFor(30000,
061      () -> TEST_UTIL.getZooKeeperWatcher().getMetaReplicaNodes().size() == 5);
062  }
063}