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.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 if (region != null) {
54
55
56 String delimiterString = region.getTableDesc().getValue(
57 DELIMITER_KEY);
58 if (delimiterString == null || delimiterString.length() == 0) {
59 LOG.error(DELIMITER_KEY + " not specified for table "
60 + region.getTableDesc().getTableName()
61 + ". Using default RegionSplitPolicy");
62 return;
63 }
64
65 delimiter = Bytes.toBytes(delimiterString);
66 }
67 }
68
69 @Override
70 protected byte[] getSplitPoint() {
71 byte[] splitPoint = super.getSplitPoint();
72 if (splitPoint != null && delimiter != null) {
73
74
75 int index = com.google.common.primitives.Bytes.indexOf(splitPoint, delimiter);
76 if (index < 0) {
77 LOG.warn("Delimiter " + Bytes.toString(delimiter) + " not found for split key "
78 + Bytes.toString(splitPoint));
79 return splitPoint;
80 }
81
82
83 return Arrays.copyOf(splitPoint, Math.min(index, splitPoint.length));
84 } else {
85 return splitPoint;
86 }
87 }
88 }