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 org.apache.hadoop.classification.InterfaceAudience;
21 import org.apache.hadoop.conf.Configuration;
22 import org.apache.hadoop.hbase.HConstants;
23 import org.apache.hadoop.hbase.HTableDescriptor;
24
25
26
27
28
29
30
31
32
33
34 @InterfaceAudience.Private
35 public class ConstantSizeRegionSplitPolicy extends RegionSplitPolicy {
36 private long desiredMaxFileSize;
37
38 @Override
39 protected void configureForRegion(HRegion region) {
40 super.configureForRegion(region);
41 Configuration conf = getConf();
42 HTableDescriptor desc = region.getTableDesc();
43 if (desc != null) {
44 this.desiredMaxFileSize = desc.getMaxFileSize();
45 }
46 if (this.desiredMaxFileSize <= 0) {
47 this.desiredMaxFileSize = conf.getLong(HConstants.HREGION_MAX_FILESIZE,
48 HConstants.DEFAULT_MAX_FILE_SIZE);
49 }
50 }
51
52 @Override
53 protected boolean shouldSplit() {
54 boolean force = region.shouldForceSplit();
55 boolean foundABigStore = false;
56
57 for (Store store : region.getStores().values()) {
58
59
60 if ((!store.canSplit())) {
61 return false;
62 }
63
64
65 if (store.getSize() > desiredMaxFileSize) {
66 foundABigStore = true;
67 }
68 }
69
70 return foundABigStore || force;
71 }
72
73 long getDesiredMaxFileSize() {
74 return desiredMaxFileSize;
75 }
76 }