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