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.classification.InterfaceAudience;
21  import org.apache.hadoop.conf.Configuration;
22  import org.apache.hadoop.hbase.HBaseInterfaceAudience;
23  import org.apache.hadoop.hbase.HConstants;
24  import org.apache.hadoop.hbase.HTableDescriptor;
25  
26  /**
27   * A {@link RegionSplitPolicy} implementation which splits a region
28   * as soon as any of its store files exceeds a maximum configurable
29   * size.
30   * <p>
31   * This is the default split policy. From 0.94.0 on the default split policy has
32   * changed to {@link IncreasingToUpperBoundRegionSplitPolicy}
33   * </p>
34   */
35  @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.CONFIG)
36  public class ConstantSizeRegionSplitPolicy extends RegionSplitPolicy {
37    private long desiredMaxFileSize;
38  
39    @Override
40    protected void configureForRegion(HRegion region) {
41      super.configureForRegion(region);
42      Configuration conf = getConf();
43      HTableDescriptor desc = region.getTableDesc();
44      if (desc != null) {
45        this.desiredMaxFileSize = desc.getMaxFileSize();
46      }
47      if (this.desiredMaxFileSize <= 0) {
48        this.desiredMaxFileSize = conf.getLong(HConstants.HREGION_MAX_FILESIZE,
49          HConstants.DEFAULT_MAX_FILE_SIZE);
50      }
51    }
52  
53    @Override
54    protected boolean shouldSplit() {
55      boolean force = region.shouldForceSplit();
56      boolean foundABigStore = false;
57  
58      for (Store store : region.getStores().values()) {
59        // If any of the stores are unable to split (eg they contain reference files)
60        // then don't split
61        if ((!store.canSplit())) {
62          return false;
63        }
64  
65        // Mark if any store is big enough
66        if (store.getSize() > desiredMaxFileSize) {
67          foundABigStore = true;
68        }
69      }
70  
71      return foundABigStore || force;
72    }
73  
74    long getDesiredMaxFileSize() {
75      return desiredMaxFileSize;
76    }
77  }