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.backup.impl; 019 020import java.util.ArrayList; 021import java.util.List; 022import org.apache.commons.lang3.StringUtils; 023import org.apache.hadoop.hbase.HBaseIOException; 024import org.apache.hadoop.hbase.TableName; 025import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor; 026import org.apache.yetus.audience.InterfaceAudience; 027 028@InterfaceAudience.Public 029public final class ColumnFamilyMismatchException extends HBaseIOException { 030 private final List<TableName> mismatchedTables; 031 032 private ColumnFamilyMismatchException(String msg, List<TableName> mismatchedTables) { 033 super(msg); 034 this.mismatchedTables = mismatchedTables; 035 } 036 037 public static final class ColumnFamilyMismatchExceptionBuilder { 038 private final List<TableName> mismatchedTables = new ArrayList<>(); 039 private final StringBuilder msg = new StringBuilder(); 040 041 public ColumnFamilyMismatchExceptionBuilder addMismatchedTable(TableName tableName, 042 ColumnFamilyDescriptor[] currentCfs, ColumnFamilyDescriptor[] backupCfs) { 043 this.mismatchedTables.add(tableName); 044 045 String currentCfsParsed = StringUtils.join(currentCfs, ','); 046 String backupCfsParsed = StringUtils.join(backupCfs, ','); 047 msg.append("\nMismatch in column family descriptor for table: ").append(tableName) 048 .append("\n"); 049 msg.append("Current families: ").append(currentCfsParsed).append("\n"); 050 msg.append("Backup families: ").append(backupCfsParsed); 051 052 return this; 053 } 054 055 public ColumnFamilyMismatchException build() { 056 return new ColumnFamilyMismatchException(msg.toString(), mismatchedTables); 057 } 058 } 059 060 public List<TableName> getMismatchedTables() { 061 return mismatchedTables; 062 } 063 064 public static ColumnFamilyMismatchExceptionBuilder newBuilder() { 065 return new ColumnFamilyMismatchExceptionBuilder(); 066 } 067}