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