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  
29  /**
30   * Normalization plan to merge regions (smallest region in the table with its smallest neighbor).
31   */
32  @InterfaceAudience.Private
33  public class MergeNormalizationPlan implements NormalizationPlan {
34    private static final Log LOG = LogFactory.getLog(MergeNormalizationPlan.class.getName());
35  
36    private final HRegionInfo firstRegion;
37    private final HRegionInfo secondRegion;
38  
39    public MergeNormalizationPlan(HRegionInfo firstRegion, HRegionInfo secondRegion) {
40      this.firstRegion = firstRegion;
41      this.secondRegion = secondRegion;
42    }
43  
44    HRegionInfo getFirstRegion() {
45      return firstRegion;
46    }
47  
48    HRegionInfo getSecondRegion() {
49      return secondRegion;
50    }
51  
52    @Override
53    public String toString() {
54      return "MergeNormalizationPlan{" +
55        "firstRegion=" + firstRegion +
56        ", secondRegion=" + secondRegion +
57        '}';
58    }
59  
60    /**
61     * {@inheritDoc}
62     */
63    @Override
64    public void execute(Admin admin) {
65      LOG.info("Executing merging normalization plan: " + this);
66      try {
67        admin.mergeRegions(firstRegion.getEncodedNameAsBytes(),
68          secondRegion.getEncodedNameAsBytes(), true);
69      } catch (IOException ex) {
70        LOG.error("Error during region merge: ", ex);
71      }
72    }
73  }