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.util.Random;
21
22 import org.apache.hadoop.conf.Configuration;
23 import org.apache.hadoop.hbase.HBaseInterfaceAudience;
24 import org.apache.hadoop.hbase.HConstants;
25 import org.apache.hadoop.hbase.HTableDescriptor;
26 import org.apache.hadoop.hbase.classification.InterfaceAudience;
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 private double jitterRate;
43
44 @Override
45 protected void configureForRegion(HRegion region) {
46 super.configureForRegion(region);
47 Configuration conf = getConf();
48 HTableDescriptor desc = region.getTableDesc();
49 if (desc != null) {
50 this.desiredMaxFileSize = desc.getMaxFileSize();
51 }
52 if (this.desiredMaxFileSize <= 0) {
53 this.desiredMaxFileSize = conf.getLong(HConstants.HREGION_MAX_FILESIZE,
54 HConstants.DEFAULT_MAX_FILE_SIZE);
55 }
56 double jitter = conf.getDouble("hbase.hregion.max.filesize.jitter", 0.25D);
57 this.jitterRate = (RANDOM.nextFloat() - 0.5D) * jitter;
58 long jitterValue = (long) (this.desiredMaxFileSize * this.jitterRate);
59
60 if (this.jitterRate > 0 && jitterValue > (Long.MAX_VALUE - this.desiredMaxFileSize)) {
61 this.desiredMaxFileSize = Long.MAX_VALUE;
62 } else {
63 this.desiredMaxFileSize += jitterValue;
64 }
65 }
66
67 @Override
68 protected boolean shouldSplit() {
69 boolean force = region.shouldForceSplit();
70 boolean foundABigStore = false;
71
72 for (Store store : region.getStores()) {
73
74
75 if ((!store.canSplit())) {
76 return false;
77 }
78
79
80 if (store.getSize() > desiredMaxFileSize) {
81 foundABigStore = true;
82 }
83 }
84
85 return foundABigStore || force;
86 }
87
88 long getDesiredMaxFileSize() {
89 return desiredMaxFileSize;
90 }
91
92 @InterfaceAudience.Private
93 public boolean positiveJitterRate() {
94 return this.jitterRate > 0;
95 }
96 }