1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.regionserver;
19
20 import java.io.IOException;
21 import java.util.List;
22
23 import org.apache.hadoop.hbase.classification.InterfaceAudience;
24 import org.apache.hadoop.conf.Configuration;
25 import org.apache.hadoop.conf.Configured;
26 import org.apache.hadoop.hbase.HBaseInterfaceAudience;
27 import org.apache.hadoop.hbase.HConstants;
28 import org.apache.hadoop.hbase.HTableDescriptor;
29 import org.apache.hadoop.util.ReflectionUtils;
30
31 import com.google.common.base.Preconditions;
32
33
34
35
36
37
38
39 @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.CONFIG)
40 public abstract class RegionSplitPolicy extends Configured {
41 private static final Class<? extends RegionSplitPolicy>
42 DEFAULT_SPLIT_POLICY_CLASS = IncreasingToUpperBoundRegionSplitPolicy.class;
43
44
45
46
47 protected HRegion region;
48
49
50
51
52
53 protected void configureForRegion(HRegion region) {
54 Preconditions.checkState(
55 this.region == null,
56 "Policy already configured for region {}",
57 this.region);
58
59 this.region = region;
60 }
61
62
63
64
65 protected abstract boolean shouldSplit();
66
67
68
69
70
71
72 protected byte[] getSplitPoint() {
73 byte[] explicitSplitPoint = this.region.getExplicitSplitPoint();
74 if (explicitSplitPoint != null) {
75 return explicitSplitPoint;
76 }
77 List<Store> stores = region.getStores();
78
79 byte[] splitPointFromLargestStore = null;
80 long largestStoreSize = 0;
81 for (Store s : stores) {
82 byte[] splitPoint = s.getSplitPoint();
83 long storeSize = s.getSize();
84 if (splitPoint != null && largestStoreSize < storeSize) {
85 splitPointFromLargestStore = splitPoint;
86 largestStoreSize = storeSize;
87 }
88 }
89
90 return splitPointFromLargestStore;
91 }
92
93
94
95
96
97
98
99
100 public static RegionSplitPolicy create(HRegion region,
101 Configuration conf) throws IOException {
102 Class<? extends RegionSplitPolicy> clazz = getSplitPolicyClass(
103 region.getTableDesc(), conf);
104 RegionSplitPolicy policy = ReflectionUtils.newInstance(clazz, conf);
105 policy.configureForRegion(region);
106 return policy;
107 }
108
109 public static Class<? extends RegionSplitPolicy> getSplitPolicyClass(
110 HTableDescriptor htd, Configuration conf) throws IOException {
111 String className = htd.getRegionSplitPolicyClassName();
112 if (className == null) {
113 className = conf.get(HConstants.HBASE_REGION_SPLIT_POLICY_KEY,
114 DEFAULT_SPLIT_POLICY_CLASS.getName());
115 }
116
117 try {
118 Class<? extends RegionSplitPolicy> clazz =
119 Class.forName(className).asSubclass(RegionSplitPolicy.class);
120 return clazz;
121 } catch (Exception e) {
122 throw new IOException(
123 "Unable to load configured region split policy '" +
124 className + "' for table '" + htd.getTableName() + "'",
125 e);
126 }
127 }
128
129
130
131
132
133
134
135
136
137
138 @Deprecated
139 protected boolean skipStoreFileRangeCheck() {
140 return false;
141 }
142
143
144
145
146
147
148 protected boolean skipStoreFileRangeCheck(String familyName) {
149 return skipStoreFileRangeCheck();
150 }
151 }