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.regionserver.storefiletracker; 019 020import static org.junit.jupiter.api.Assertions.assertThrows; 021 022import org.apache.hadoop.conf.Configuration; 023import org.apache.hadoop.hbase.TableName; 024import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor; 025import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; 026import org.apache.hadoop.hbase.client.TableDescriptor; 027import org.apache.hadoop.hbase.client.TableDescriptorBuilder; 028import org.apache.hadoop.hbase.snapshot.RestoreSnapshotException; 029import org.apache.hadoop.hbase.testclassification.RegionServerTests; 030import org.apache.hadoop.hbase.testclassification.SmallTests; 031import org.apache.hadoop.hbase.util.Bytes; 032import org.junit.jupiter.api.Tag; 033import org.junit.jupiter.api.Test; 034 035@Tag(RegionServerTests.TAG) 036@Tag(SmallTests.TAG) 037public class TestStoreFileTrackerValidationUtils { 038 039 @Test 040 public void testCheckSFTCompatibility() throws Exception { 041 // checking default value change on different configuration levels 042 Configuration conf = new Configuration(); 043 conf.set(StoreFileTrackerFactory.TRACKER_IMPL, "DEFAULT"); 044 045 // creating a TD with only TableDescriptor level config 046 TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(TableName.valueOf("TableX")); 047 builder.setValue(StoreFileTrackerFactory.TRACKER_IMPL, "FILE"); 048 ColumnFamilyDescriptor cf = ColumnFamilyDescriptorBuilder.of("cf"); 049 builder.setColumnFamily(cf); 050 TableDescriptor td = builder.build(); 051 052 // creating a TD with matching ColumnFamilyDescriptor level setting 053 TableDescriptorBuilder snapBuilder = 054 TableDescriptorBuilder.newBuilder(TableName.valueOf("TableY")); 055 snapBuilder.setValue(StoreFileTrackerFactory.TRACKER_IMPL, "FILE"); 056 ColumnFamilyDescriptorBuilder snapCFBuilder = 057 ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("cf")); 058 snapCFBuilder.setValue(StoreFileTrackerFactory.TRACKER_IMPL, "FILE"); 059 snapBuilder.setColumnFamily(snapCFBuilder.build()); 060 TableDescriptor snapTd = snapBuilder.build(); 061 062 // adding a cf config that matches the td config is fine even when it does not match the default 063 StoreFileTrackerValidationUtils.validatePreRestoreSnapshot(td, snapTd, conf); 064 // removing cf level config is fine when it matches the td config 065 StoreFileTrackerValidationUtils.validatePreRestoreSnapshot(snapTd, td, conf); 066 067 TableDescriptorBuilder defaultBuilder = 068 TableDescriptorBuilder.newBuilder(TableName.valueOf("TableY")); 069 defaultBuilder.setValue(StoreFileTrackerFactory.TRACKER_IMPL, "FILE"); 070 ColumnFamilyDescriptorBuilder defaultCFBuilder = 071 ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("cf")); 072 defaultCFBuilder.setValue(StoreFileTrackerFactory.TRACKER_IMPL, "DEFAULT"); 073 defaultBuilder.setColumnFamily(defaultCFBuilder.build()); 074 TableDescriptor defaultTd = defaultBuilder.build(); 075 076 assertThrows(RestoreSnapshotException.class, () -> { 077 StoreFileTrackerValidationUtils.validatePreRestoreSnapshot(td, defaultTd, conf); 078 }); 079 assertThrows(RestoreSnapshotException.class, () -> { 080 StoreFileTrackerValidationUtils.validatePreRestoreSnapshot(snapTd, defaultTd, conf); 081 }); 082 } 083}