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    public HRegionInfo getRegionInfo() {
46      return regionInfo;
47    }
48  
49    public void setRegionInfo(HRegionInfo regionInfo) {
50      this.regionInfo = regionInfo;
51    }
52  
53    public byte[] getSplitPoint() {
54      return splitPoint;
55    }
56  
57    public void setSplitPoint(byte[] splitPoint) {
58      this.splitPoint = splitPoint;
59    }
60  
61    @Override
62    public String toString() {
63      return "SplitNormalizationPlan{" +
64        "regionInfo=" + regionInfo +
65        ", splitPoint=" + Arrays.toString(splitPoint) +
66        '}';
67    }
68  
69    /**
70     * {@inheritDoc}
71     */
72    @Override
73    public void execute(Admin admin) {
74      LOG.info("Executing splitting normalization plan: " + this);
75      try {
76        admin.splitRegion(regionInfo.getRegionName());
77      } catch (IOException ex) {
78        LOG.error("Error during region split: ", ex);
79      }
80    }
81  }