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 java.io.IOException; 021import org.apache.hadoop.conf.Configuration; 022import org.apache.hadoop.hbase.HBaseIOException; 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.master.procedure.MasterProcedureEnv; 029import org.apache.hadoop.hbase.procedure2.ProcedureStateSerializer; 030import org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException; 031import org.apache.hadoop.hbase.regionserver.StoreUtils; 032import org.apache.hadoop.hbase.util.Bytes; 033import org.apache.yetus.audience.InterfaceAudience; 034 035import org.apache.hbase.thirdparty.com.google.protobuf.ByteString; 036 037import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.ModifyColumnFamilyStoreFileTrackerStateData; 038 039@InterfaceAudience.Private 040public class ModifyColumnFamilyStoreFileTrackerProcedure extends ModifyStoreFileTrackerProcedure { 041 042 private byte[] family; 043 044 public ModifyColumnFamilyStoreFileTrackerProcedure() { 045 } 046 047 public ModifyColumnFamilyStoreFileTrackerProcedure(MasterProcedureEnv env, TableName tableName, 048 byte[] family, String dstSFT) throws HBaseIOException { 049 super(env, tableName, dstSFT); 050 this.family = family; 051 } 052 053 @Override 054 protected void preCheck(TableDescriptor current) throws IOException { 055 if (!current.hasColumnFamily(family)) { 056 throw new NoSuchColumnFamilyException( 057 Bytes.toStringBinary(family) + " does not exist for table " + current.getTableName()); 058 } 059 } 060 061 @Override 062 protected Configuration createConf(Configuration conf, TableDescriptor current) { 063 ColumnFamilyDescriptor cfd = current.getColumnFamily(family); 064 return StoreUtils.createStoreConfiguration(conf, current, cfd); 065 } 066 067 @Override 068 protected TableDescriptor createRestoreTableDescriptor(TableDescriptor current, 069 String restoreSFT) { 070 ColumnFamilyDescriptor cfd = 071 ColumnFamilyDescriptorBuilder.newBuilder(current.getColumnFamily(family)) 072 .setConfiguration(StoreFileTrackerFactory.TRACKER_IMPL, restoreSFT).build(); 073 return TableDescriptorBuilder.newBuilder(current).modifyColumnFamily(cfd).build(); 074 } 075 076 @Override 077 protected TableDescriptor createMigrationTableDescriptor(Configuration conf, 078 TableDescriptor current) { 079 ColumnFamilyDescriptorBuilder builder = 080 ColumnFamilyDescriptorBuilder.newBuilder(current.getColumnFamily(family)); 081 migrate(conf, builder::setConfiguration); 082 return TableDescriptorBuilder.newBuilder(current).modifyColumnFamily(builder.build()).build(); 083 } 084 085 @Override 086 protected TableDescriptor createFinishTableDescriptor(TableDescriptor current) { 087 ColumnFamilyDescriptorBuilder builder = 088 ColumnFamilyDescriptorBuilder.newBuilder(current.getColumnFamily(family)); 089 finish(builder::setConfiguration, builder::removeConfiguration); 090 return TableDescriptorBuilder.newBuilder(current).modifyColumnFamily(builder.build()).build(); 091 } 092 093 @Override 094 protected void serializeStateData(ProcedureStateSerializer serializer) throws IOException { 095 super.serializeStateData(serializer); 096 serializer.serialize(ModifyColumnFamilyStoreFileTrackerStateData.newBuilder() 097 .setFamily(ByteString.copyFrom(family)).build()); 098 } 099 100 @Override 101 protected void deserializeStateData(ProcedureStateSerializer serializer) throws IOException { 102 super.deserializeStateData(serializer); 103 ModifyColumnFamilyStoreFileTrackerStateData data = 104 serializer.deserialize(ModifyColumnFamilyStoreFileTrackerStateData.class); 105 this.family = data.getFamily().toByteArray(); 106 } 107}