001/**
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements.  See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership.  The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License.  You may obtain a copy of the License at
010 *
011 *     http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 */
019package org.apache.hadoop.hbase.master.normalizer;
020
021import java.util.List;
022
023import org.apache.hadoop.hbase.HBaseIOException;
024import org.apache.hadoop.hbase.TableName;
025import org.apache.hadoop.hbase.client.RegionInfo;
026import org.apache.hadoop.hbase.master.MasterRpcServices;
027import org.apache.hadoop.hbase.master.MasterServices;
028import org.apache.hadoop.hbase.master.normalizer.NormalizationPlan.PlanType;
029import org.apache.yetus.audience.InterfaceAudience;
030
031/**
032 * Performs "normalization" of regions on the cluster, making sure that suboptimal
033 * choice of split keys doesn't leave cluster in a situation when some regions are
034 * substantially larger than others for considerable amount of time.
035 *
036 * Users who want to use this feature could either use default {@link SimpleRegionNormalizer}
037 * or plug in their own implementation. Please note that overly aggressive normalization rules
038 * (attempting to make all regions perfectly equal in size) could potentially lead to
039 * "split/merge storms".
040 */
041@InterfaceAudience.Private
042public interface RegionNormalizer {
043  /**
044   * Set the master service. Must be called before first call to
045   * {@link #computePlanForTable(TableName)}.
046   * @param masterServices master services to use
047   */
048  void setMasterServices(MasterServices masterServices);
049
050  /**
051   * Set the master RPC service. Must be called before first call to
052   * {@link #computePlanForTable(TableName)}.
053   * @param masterRpcServices master RPC services to use
054   */
055  void setMasterRpcServices(MasterRpcServices masterRpcServices);
056
057  /**
058   * Computes next optimal normalization plan.
059   * @param table table to normalize
060   * @return normalization actions to perform. Null if no action to take
061   */
062  List<NormalizationPlan> computePlanForTable(TableName table)
063      throws HBaseIOException;
064
065  /**
066   * Notification for the case where plan couldn't be executed due to constraint violation, such as
067   * namespace quota
068   * @param hri the region which is involved in the plan
069   * @param type type of plan
070   */
071  void planSkipped(RegionInfo hri, PlanType type);
072
073  /**
074   * @param type type of plan for which skipped count is to be returned
075   * @return the count of plans of specified type which were skipped
076   */
077  long getSkippedCount(NormalizationPlan.PlanType type);
078}