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.io.IOException;
21 import java.util.List;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.apache.hadoop.hbase.classification.InterfaceAudience;
26 import org.apache.hadoop.conf.Configuration;
27 import org.apache.hadoop.hbase.TableName;
28 import org.apache.hadoop.hbase.HConstants;
29 import org.apache.hadoop.hbase.HTableDescriptor;
30
31
32
33
34
35
36
37
38
39
40
41 @InterfaceAudience.Private
42 public class IncreasingToUpperBoundRegionSplitPolicy
43 extends ConstantSizeRegionSplitPolicy {
44 static final Log LOG =
45 LogFactory.getLog(IncreasingToUpperBoundRegionSplitPolicy.class);
46 private long initialSize;
47
48 @Override
49 protected void configureForRegion(HRegion region) {
50 super.configureForRegion(region);
51 Configuration conf = getConf();
52 this.initialSize = conf.getLong("hbase.increasing.policy.initial.size", -1);
53 if (this.initialSize > 0) {
54 return;
55 }
56 HTableDescriptor desc = region.getTableDesc();
57 if (desc != null) {
58 this.initialSize = 2*desc.getMemStoreFlushSize();
59 }
60 if (this.initialSize <= 0) {
61 this.initialSize = 2*conf.getLong(HConstants.HREGION_MEMSTORE_FLUSH_SIZE,
62 HTableDescriptor.DEFAULT_MEMSTORE_FLUSH_SIZE);
63 }
64 }
65
66 @Override
67 protected boolean shouldSplit() {
68 boolean force = region.shouldForceSplit();
69 boolean foundABigStore = false;
70
71 int tableRegionsCount = getCountOfCommonTableRegions();
72
73 long sizeToCheck = getSizeToCheck(tableRegionsCount);
74
75 for (Store store : region.getStores()) {
76
77
78 if ((!store.canSplit())) {
79 return false;
80 }
81
82
83 long size = store.getSize();
84 if (size > sizeToCheck) {
85 LOG.debug("ShouldSplit because " + store.getColumnFamilyName() +
86 " size=" + size + ", sizeToCheck=" + sizeToCheck +
87 ", regionsWithCommonTable=" + tableRegionsCount);
88 foundABigStore = true;
89 }
90 }
91
92 return foundABigStore | force;
93 }
94
95
96
97
98
99 protected long getSizeToCheck(final int tableRegionsCount) {
100
101 return tableRegionsCount == 0 || tableRegionsCount > 100 ? getDesiredMaxFileSize():
102 Math.min(getDesiredMaxFileSize(),
103 this.initialSize * tableRegionsCount * tableRegionsCount * tableRegionsCount);
104 }
105
106
107
108
109
110 private int getCountOfCommonTableRegions() {
111 RegionServerServices rss = this.region.getRegionServerServices();
112
113 if (rss == null) return 0;
114 TableName tablename = this.region.getTableDesc().getTableName();
115 int tableRegionsCount = 0;
116 try {
117 List<Region> hri = rss.getOnlineRegions(tablename);
118 tableRegionsCount = hri == null || hri.isEmpty()? 0: hri.size();
119 } catch (IOException e) {
120 LOG.debug("Failed getOnlineRegions " + tablename, e);
121 }
122 return tableRegionsCount;
123 }
124 }