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