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.hbase.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
28
29
30
31
32
33
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
60
61 if ((!store.canSplit())) {
62 return false;
63 }
64
65
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 }