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.migrate; 019 020import static org.junit.Assert.assertEquals; 021 022import java.io.IOException; 023import org.apache.commons.lang3.StringUtils; 024import org.apache.hadoop.conf.Configuration; 025import org.apache.hadoop.hbase.HBaseClassTestRule; 026import org.apache.hadoop.hbase.HBaseConfiguration; 027import org.apache.hadoop.hbase.HBaseTestingUtility; 028import org.apache.hadoop.hbase.HColumnDescriptor; 029import org.apache.hadoop.hbase.HTableDescriptor; 030import org.apache.hadoop.hbase.TableDescriptors; 031import org.apache.hadoop.hbase.TableName; 032import org.apache.hadoop.hbase.client.TableDescriptor; 033import org.apache.hadoop.hbase.client.TableDescriptorBuilder; 034import org.apache.hadoop.hbase.regionserver.storefiletracker.StoreFileTrackerFactory; 035import org.apache.hadoop.hbase.testclassification.MasterTests; 036import org.apache.hadoop.hbase.testclassification.MediumTests; 037import org.apache.hadoop.hbase.util.Bytes; 038import org.junit.After; 039import org.junit.Assert; 040import org.junit.Before; 041import org.junit.ClassRule; 042import org.junit.Test; 043import org.junit.experimental.categories.Category; 044 045@Category({ MediumTests.class, MasterTests.class }) 046public class TestInitializeStoreFileTracker { 047 @ClassRule 048 public static final HBaseClassTestRule CLASS_RULE = 049 HBaseClassTestRule.forClass(TestInitializeStoreFileTracker.class); 050 private final static String[] tables = new String[] { "t1", "t2", "t3", "t4", "t5", "t6" }; 051 private final static String famStr = "f1"; 052 private final static byte[] fam = Bytes.toBytes(famStr); 053 054 private HBaseTestingUtility HTU; 055 private Configuration conf; 056 private HTableDescriptor tableDescriptor; 057 058 @Before 059 public void setUp() throws Exception { 060 conf = HBaseConfiguration.create(); 061 // Speed up the launch of RollingUpgradeChore 062 conf.setInt(RollingUpgradeChore.ROLLING_UPGRADE_CHORE_PERIOD_SECONDS_KEY, 1); 063 conf.setLong(RollingUpgradeChore.ROLLING_UPGRADE_CHORE_DELAY_SECONDS_KEY, 1); 064 // Set the default implementation to file instead of default, to confirm we will not set SFT to 065 // file 066 conf.set(StoreFileTrackerFactory.TRACKER_IMPL, StoreFileTrackerFactory.Trackers.FILE.name()); 067 HTU = new HBaseTestingUtility(conf); 068 HTU.startMiniCluster(); 069 } 070 071 @After 072 public void tearDown() throws Exception { 073 HTU.shutdownMiniCluster(); 074 } 075 076 @Test 077 public void testMigrateStoreFileTracker() throws IOException, InterruptedException { 078 // create tables to test 079 for (int i = 0; i < tables.length; i++) { 080 tableDescriptor = HTU.createTableDescriptor(tables[i]); 081 tableDescriptor.addFamily(new HColumnDescriptor(fam)); 082 HTU.createTable(tableDescriptor, null); 083 } 084 TableDescriptors tableDescriptors = HTU.getMiniHBaseCluster().getMaster().getTableDescriptors(); 085 for (int i = 0; i < tables.length; i++) { 086 TableDescriptor tdAfterCreated = tableDescriptors.get(TableName.valueOf(tables[i])); 087 // make sure that TRACKER_IMPL was set by default after tables have been created. 088 Assert.assertNotNull(tdAfterCreated.getValue(StoreFileTrackerFactory.TRACKER_IMPL)); 089 // Remove StoreFileTracker impl from tableDescriptor 090 TableDescriptor tdRemovedSFT = TableDescriptorBuilder.newBuilder(tdAfterCreated) 091 .removeValue(StoreFileTrackerFactory.TRACKER_IMPL).build(); 092 tableDescriptors.update(tdRemovedSFT); 093 } 094 HTU.getMiniHBaseCluster().stopMaster(0).join(); 095 HTU.getMiniHBaseCluster().startMaster(); 096 HTU.getMiniHBaseCluster().waitForActiveAndReadyMaster(30000); 097 // wait until all tables have been migrated 098 TableDescriptors tds = HTU.getMiniHBaseCluster().getMaster().getTableDescriptors(); 099 HTU.waitFor(30000, () -> { 100 try { 101 for (int i = 0; i < tables.length; i++) { 102 TableDescriptor td = tds.get(TableName.valueOf(tables[i])); 103 if (StringUtils.isEmpty(td.getValue(StoreFileTrackerFactory.TRACKER_IMPL))) { 104 return false; 105 } 106 } 107 return true; 108 } catch (IOException e) { 109 return false; 110 } 111 }); 112 for (String table : tables) { 113 TableDescriptor td = tds.get(TableName.valueOf(table)); 114 assertEquals(StoreFileTrackerFactory.Trackers.DEFAULT.name(), 115 td.getValue(StoreFileTrackerFactory.TRACKER_IMPL)); 116 } 117 } 118}