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.util.Bytes;
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 flushSize;
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.flushSize = desc.getMemStoreFlushSize();
53 }
54 if (this.flushSize <= 0) {
55 this.flushSize = conf.getLong(HConstants.HREGION_MEMSTORE_FLUSH_SIZE,
56 HTableDescriptor.DEFAULT_MEMSTORE_FLUSH_SIZE);
57 }
58 }
59
60 @Override
61 protected boolean shouldSplit() {
62 if (region.shouldForceSplit()) return true;
63 boolean foundABigStore = false;
64
65 int tableRegionsCount = getCountOfCommonTableRegions();
66
67 long sizeToCheck = getSizeToCheck(tableRegionsCount);
68
69 for (Store store : region.getStores().values()) {
70
71
72 if ((!store.canSplit())) {
73 return false;
74 }
75
76
77 long size = store.getSize();
78 if (size > sizeToCheck) {
79 LOG.debug("ShouldSplit because " + store.getColumnFamilyName() +
80 " size=" + size + ", sizeToCheck=" + sizeToCheck +
81 ", regionsWithCommonTable=" + tableRegionsCount);
82 foundABigStore = true;
83 break;
84 }
85 }
86
87 return foundABigStore;
88 }
89
90
91
92
93
94 long getSizeToCheck(final int tableRegionsCount) {
95 return tableRegionsCount == 0? getDesiredMaxFileSize():
96 Math.min(getDesiredMaxFileSize(),
97 this.flushSize * (tableRegionsCount * tableRegionsCount));
98 }
99
100
101
102
103
104 private int getCountOfCommonTableRegions() {
105 RegionServerServices rss = this.region.getRegionServerServices();
106
107 if (rss == null) return 0;
108 byte [] tablename = this.region.getTableDesc().getName();
109 int tableRegionsCount = 0;
110 try {
111 List<HRegion> hri = rss.getOnlineRegions(tablename);
112 tableRegionsCount = hri == null || hri.isEmpty()? 0: hri.size();
113 } catch (IOException e) {
114 LOG.debug("Failed getOnlineRegions " + Bytes.toString(tablename), e);
115 }
116 return tableRegionsCount;
117 }
118 }