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