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.util.hbck;
019
020import java.io.IOException;
021import java.util.Collection;
022import org.apache.hadoop.hbase.util.HbckRegionInfo;
023import org.apache.hadoop.hbase.util.HbckTableInfo;
024import org.apache.yetus.audience.InterfaceAudience;
025
026/**
027 * This interface provides callbacks for handling particular table integrity invariant violations.
028 * This could probably be boiled down to handling holes and handling overlaps but currently
029 * preserves the older more specific error condition codes.
030 */
031@InterfaceAudience.Private
032public interface TableIntegrityErrorHandler {
033
034  HbckTableInfo getTableInfo();
035
036  /**
037   * Set the TableInfo used by all HRegionInfos fabricated by other callbacks
038   */
039  void setTableInfo(HbckTableInfo ti);
040
041  /**
042   * Callback for handling case where a Table has a first region that does not have an empty start
043   * key.
044   * @param hi An HbckRegionInfo of the second region in a table. This should have a non-empty
045   *           startkey, and can be used to fabricate a first region that has an empty start key.
046   */
047  void handleRegionStartKeyNotEmpty(HbckRegionInfo hi) throws IOException;
048
049  /**
050   * Callback for handling case where a Table has a last region that does not have an empty end key.
051   * @param curEndKey The end key of the current last region. There should be a new region with
052   *                  start key as this and an empty end key.
053   */
054  void handleRegionEndKeyNotEmpty(byte[] curEndKey) throws IOException;
055
056  /**
057   * Callback for handling a region that has the same start and end key.
058   * @param hi An HbckRegionInfo for a degenerate key.
059   */
060  void handleDegenerateRegion(HbckRegionInfo hi) throws IOException;
061
062  /**
063   * Callback for handling two regions that have the same start key. This is a specific case of a
064   * region overlap.
065   * @param hi1 one of the overlapping HbckRegionInfo
066   * @param hi2 the other overlapping HbckRegionInfo
067   */
068  void handleDuplicateStartKeys(HbckRegionInfo hi1, HbckRegionInfo hi2) throws IOException;
069
070  /**
071   * Callback for handling two regions that have the same regionID a specific case of a split
072   * @param hi1 one of the overlapping HbckRegionInfo
073   * @param hi2 the other overlapping HbckRegionInfo
074   */
075  void handleSplit(HbckRegionInfo hi1, HbckRegionInfo hi2) throws IOException;
076
077  /**
078   * Callback for handling two reigons that overlap in some arbitrary way. This is a specific case
079   * of region overlap, and called for each possible pair. If two regions have the same start key,
080   * the handleDuplicateStartKeys method is called.
081   * @param hi1 one of the overlapping HbckRegionInfo
082   * @param hi2 the other overlapping HbckRegionInfo
083   */
084  void handleOverlapInRegionChain(HbckRegionInfo hi1, HbckRegionInfo hi2) throws IOException;
085
086  /**
087   * Callback for handling a region hole between two keys.
088   * @param holeStartKey key at the beginning of the region hole
089   * @param holeEndKey   key at the end of the region hole
090   */
091  void handleHoleInRegionChain(byte[] holeStartKey, byte[] holeEndKey) throws IOException;
092
093  /**
094   * Callback for handling an group of regions that overlap.
095   * @param overlap Collection of overlapping regions.
096   */
097  void handleOverlapGroup(Collection<HbckRegionInfo> overlap) throws IOException;
098}