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.master.region;
019
020import static org.junit.jupiter.api.Assertions.assertEquals;
021
022import java.io.IOException;
023import org.apache.hadoop.hbase.HBaseTestingUtil;
024import org.apache.hadoop.hbase.HConstants;
025import org.apache.hadoop.hbase.TableName;
026import org.apache.hadoop.hbase.client.TableDescriptor;
027import org.apache.hadoop.hbase.regionserver.storefiletracker.StoreFileTrackerFactory;
028import org.apache.hadoop.hbase.testclassification.MasterTests;
029import org.apache.hadoop.hbase.testclassification.MediumTests;
030import org.apache.hadoop.hbase.util.Bytes;
031import org.junit.jupiter.api.AfterAll;
032import org.junit.jupiter.api.BeforeAll;
033import org.junit.jupiter.api.Tag;
034import org.junit.jupiter.api.Test;
035
036/**
037 * Make sure we do not loss data after changing SFT implementation
038 */
039@Tag(MasterTests.TAG)
040@Tag(MediumTests.TAG)
041public class TestChangeSFTForMasterRegion {
042
043  private static final HBaseTestingUtil UTIL = new HBaseTestingUtil();
044
045  private static TableName NAME = TableName.valueOf("test");
046
047  private static byte[] FAMILY = Bytes.toBytes("family");
048
049  @BeforeAll
050  public static void setUp() throws Exception {
051    UTIL.getConfiguration().set(MasterRegionFactory.TRACKER_IMPL,
052      StoreFileTrackerFactory.Trackers.DEFAULT.name());
053    // use zk connection registry, as we will shutdown the only master instance which will likely to
054    // lead to dead loop
055    UTIL.getConfiguration().set(HConstants.CLIENT_CONNECTION_REGISTRY_IMPL_CONF_KEY,
056      HConstants.ZK_CONNECTION_REGISTRY_CLASS);
057    UTIL.startMiniCluster(1);
058    UTIL.createTable(NAME, FAMILY).close();
059  }
060
061  @AfterAll
062  public static void tearDown() throws IOException {
063    UTIL.shutdownMiniCluster();
064  }
065
066  @Test
067  public void test() throws Exception {
068    // shutdown master
069    UTIL.getMiniHBaseCluster().stopMaster(0).join();
070    UTIL.getMiniHBaseCluster().getConf().set(MasterRegionFactory.TRACKER_IMPL,
071      StoreFileTrackerFactory.Trackers.FILE.name());
072    UTIL.getMiniHBaseCluster().startMaster();
073    // make sure that the table still exists
074    UTIL.waitTableAvailable(NAME);
075    // confirm that we have changed the SFT to FILE
076    TableDescriptor td =
077      UTIL.getMiniHBaseCluster().getMaster().getMasterRegion().region.getTableDescriptor();
078    assertEquals(StoreFileTrackerFactory.Trackers.FILE.name(),
079      td.getValue(StoreFileTrackerFactory.TRACKER_IMPL));
080  }
081}