View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.regionserver;
19  
20  import org.apache.hadoop.conf.Configurable;
21  import org.apache.hadoop.conf.Configuration;
22  import org.apache.hadoop.hbase.HBaseInterfaceAudience;
23  import org.apache.hadoop.hbase.classification.InterfaceAudience;
24  import org.apache.hadoop.hbase.classification.InterfaceStability;
25  import org.apache.hadoop.hbase.util.ReflectionUtils;
26  
27  /**
28   * A factory for creating RegionMergeTransactions, which execute region split as a "transaction".
29   * See {@link RegionMergeTransactionImpl}
30   */
31  @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
32  @InterfaceStability.Evolving
33  public class RegionMergeTransactionFactory implements Configurable {
34  
35    public static final String MERGE_TRANSACTION_IMPL_KEY =
36        "hbase.regionserver.merge.transaction.impl";
37  
38    private Configuration conf;
39  
40    public RegionMergeTransactionFactory(Configuration conf) {
41      this.conf = conf;
42    }
43  
44    @Override
45    public Configuration getConf() {
46      return conf;
47    }
48  
49    @Override
50    public void setConf(Configuration conf) {
51      this.conf = conf;
52    }
53  
54    /**
55     * Create a merge transaction
56     * @param a region a to merge
57     * @param b region b to merge
58     * @param forcible if false, we will only merge adjacent regions
59     * @return transaction instance
60     */
61    public RegionMergeTransactionImpl create(final Region a, final Region b,
62        final boolean forcible) {
63      // The implementation class must extend RegionMergeTransactionImpl, not only
64      // implement the RegionMergeTransaction interface like you might expect,
65      // because various places such as AssignmentManager use static methods
66      // from RegionMergeTransactionImpl. Whatever we use for implementation must
67      // be compatible, so it's safest to require ? extends RegionMergeTransactionImpl.
68      // If not compatible we will throw a runtime exception from here.
69      return ReflectionUtils.instantiateWithCustomCtor(
70        conf.getClass(MERGE_TRANSACTION_IMPL_KEY, RegionMergeTransactionImpl.class,
71          RegionMergeTransactionImpl.class).getName(),
72        new Class[] { Region.class, Region.class, boolean.class },
73        new Object[] { a, b, forcible });
74    }
75  
76  }