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