1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.regionserver;
20
21 import java.util.Arrays;
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.hbase.util.Bytes;
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 @InterfaceAudience.Private
42 public class DelimitedKeyPrefixRegionSplitPolicy extends IncreasingToUpperBoundRegionSplitPolicy {
43
44 private static final Log LOG = LogFactory
45 .getLog(DelimitedKeyPrefixRegionSplitPolicy.class);
46 public static final String DELIMITER_KEY = "DelimitedKeyPrefixRegionSplitPolicy.delimiter";
47
48 private byte[] delimiter = null;
49
50 @Override
51 protected void configureForRegion(HRegion region) {
52 super.configureForRegion(region);
53
54 String delimiterString = region.getTableDesc().getValue(DELIMITER_KEY);
55 if (delimiterString == null || delimiterString.length() == 0) {
56 LOG.error(DELIMITER_KEY + " not specified for table " + region.getTableDesc().getTableName() +
57 ". Using default RegionSplitPolicy");
58 return;
59 }
60 delimiter = Bytes.toBytes(delimiterString);
61 }
62
63 @Override
64 protected byte[] getSplitPoint() {
65 byte[] splitPoint = super.getSplitPoint();
66 if (splitPoint != null && delimiter != null) {
67
68
69 int index = com.google.common.primitives.Bytes.indexOf(splitPoint, delimiter);
70 if (index < 0) {
71 LOG.warn("Delimiter " + Bytes.toString(delimiter) + " not found for split key "
72 + Bytes.toString(splitPoint));
73 return splitPoint;
74 }
75
76
77 return Arrays.copyOf(splitPoint, Math.min(index, splitPoint.length));
78 } else {
79 return splitPoint;
80 }
81 }
82 }