View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  package org.apache.hadoop.hbase.master.normalizer;
20  
21  import org.apache.commons.logging.Log;
22  import org.apache.commons.logging.LogFactory;
23  import org.apache.hadoop.hbase.HRegionInfo;
24  import org.apache.hadoop.hbase.classification.InterfaceAudience;
25  import org.apache.hadoop.hbase.client.Admin;
26  
27  import java.io.IOException;
28  import java.util.Arrays;
29  
30  /**
31   * Normalization plan to split region.
32   */
33  @InterfaceAudience.Private
34  public class SplitNormalizationPlan implements NormalizationPlan {
35    private static final Log LOG = LogFactory.getLog(SplitNormalizationPlan.class.getName());
36  
37    private HRegionInfo regionInfo;
38    private byte[] splitPoint;
39  
40    public SplitNormalizationPlan(HRegionInfo regionInfo, byte[] splitPoint) {
41      this.regionInfo = regionInfo;
42      this.splitPoint = splitPoint;
43    }
44  
45    @Override
46    public PlanType getType() {
47      return PlanType.SPLIT;
48    }
49  
50    public HRegionInfo getRegionInfo() {
51      return regionInfo;
52    }
53  
54    public void setRegionInfo(HRegionInfo regionInfo) {
55      this.regionInfo = regionInfo;
56    }
57  
58    public byte[] getSplitPoint() {
59      return splitPoint;
60    }
61  
62    public void setSplitPoint(byte[] splitPoint) {
63      this.splitPoint = splitPoint;
64    }
65  
66    @Override
67    public String toString() {
68      return "SplitNormalizationPlan{" +
69        "regionInfo=" + regionInfo +
70        ", splitPoint=" + Arrays.toString(splitPoint) +
71        '}';
72    }
73  
74    /**
75     * {@inheritDoc}
76     */
77    @Override
78    public void execute(Admin admin) {
79      LOG.info("Executing splitting normalization plan: " + this);
80      try {
81        admin.splitRegion(regionInfo.getRegionName());
82      } catch (IOException ex) {
83        LOG.error("Error during region split: ", ex);
84      }
85    }
86  }