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 double jitter = conf.getDouble("hbase.hregion.max.filesize.jitter", 0.25D);
56 this.desiredMaxFileSize += (long)(desiredMaxFileSize * (RANDOM.nextFloat() - 0.5D) * jitter);
57 }
58
59 @Override
60 protected boolean shouldSplit() {
61 boolean force = region.shouldForceSplit();
62 boolean foundABigStore = false;
63
64 for (Store store : region.getStores()) {
65
66
67 if ((!store.canSplit())) {
68 return false;
69 }
70
71
72 if (store.getSize() > desiredMaxFileSize) {
73 foundABigStore = true;
74 }
75 }
76
77 return foundABigStore || force;
78 }
79
80 long getDesiredMaxFileSize() {
81 return desiredMaxFileSize;
82 }
83 }