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 import java.util.Random;
27
28
29
30
31
32
33
34
35
36
37 @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.CONFIG)
38 public class ConstantSizeRegionSplitPolicy extends RegionSplitPolicy {
39 private static final Random RANDOM = new Random();
40
41 private long desiredMaxFileSize;
42
43 @Override
44 protected void configureForRegion(HRegion region) {
45 super.configureForRegion(region);
46 Configuration conf = getConf();
47 HTableDescriptor desc = region.getTableDesc();
48 if (desc != null) {
49 this.desiredMaxFileSize = desc.getMaxFileSize();
50 }
51 if (this.desiredMaxFileSize <= 0) {
52 this.desiredMaxFileSize = conf.getLong(HConstants.HREGION_MAX_FILESIZE,
53 HConstants.DEFAULT_MAX_FILE_SIZE);
54 }
55 float jitter = conf.getFloat("hbase.hregion.max.filesize.jitter", Float.NaN);
56 if (!Float.isNaN(jitter)) {
57 this.desiredMaxFileSize += (long)(desiredMaxFileSize * (RANDOM.nextFloat() - 0.5D) * jitter);
58 }
59 }
60
61 @Override
62 protected boolean shouldSplit() {
63 boolean force = region.shouldForceSplit();
64 boolean foundABigStore = false;
65
66 for (Store store : region.getStores().values()) {
67
68
69 if ((!store.canSplit())) {
70 return false;
71 }
72
73
74 if (store.getSize() > desiredMaxFileSize) {
75 foundABigStore = true;
76 }
77 }
78
79 return foundABigStore || force;
80 }
81
82 long getDesiredMaxFileSize() {
83 return desiredMaxFileSize;
84 }
85 }