2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org
.apache
.hadoop
.hbase
.regionserver
;
20 import java
.io
.IOException
;
21 import org
.apache
.hadoop
.conf
.Configuration
;
22 import org
.apache
.hadoop
.hbase
.client
.TableDescriptor
;
23 import org
.apache
.yetus
.audience
.InterfaceAudience
;
24 import org
.slf4j
.Logger
;
25 import org
.slf4j
.LoggerFactory
;
28 * A split restriction that restricts the pattern of the split point.
30 * The difference between {@link RegionSplitPolicy} and RegionSplitRestriction is that
31 * RegionSplitRestriction defines how to split while {@link RegionSplitPolicy} defines when we need
34 * We can specify a split restriction, "KeyPrefix" or "DelimitedKeyPrefix", to a table with the
35 * "hbase.regionserver.region.split_restriction.type" property. The "KeyPrefix" split restriction
36 * groups rows by a prefix of the row-key. And the "DelimitedKeyPrefix" split restriction groups
37 * rows by a prefix of the row-key with a delimiter.
42 * # Create a table with a "KeyPrefix" split restriction, where the prefix length is 2 bytes
43 * hbase> create 'tbl1', 'fam',
44 * {CONFIGURATION => {'hbase.regionserver.region.split_restriction.type' => 'KeyPrefix',
45 * 'hbase.regionserver.region.split_restriction.prefix_length' => '2'}}
47 * # Create a table with a "DelimitedKeyPrefix" split restriction, where the delimiter is a comma
48 * hbase> create 'tbl2', 'fam',
49 * {CONFIGURATION => {'hbase.regionserver.region.split_restriction.type' => 'DelimitedKeyPrefix',
50 * 'hbase.regionserver.region.split_restriction.delimiter' => ','}}
54 * Instead of specifying a split restriction to a table directly, we can also set the properties
55 * in hbase-site.xml. In this case, the specified split restriction is applied for all the tables.
57 * Note that the split restriction is also applied to a user-specified split point so that we don't
58 * allow users to break the restriction.
60 * @see NoRegionSplitRestriction
61 * @see KeyPrefixRegionSplitRestriction
62 * @see DelimitedKeyPrefixRegionSplitRestriction
64 @InterfaceAudience.Private
65 public abstract class RegionSplitRestriction
{
66 private static final Logger LOG
= LoggerFactory
.getLogger(RegionSplitRestriction
.class);
68 public static final String RESTRICTION_TYPE_KEY
=
69 "hbase.regionserver.region.split_restriction.type";
71 public static final String RESTRICTION_TYPE_NONE
= "None";
72 public static final String RESTRICTION_TYPE_KEY_PREFIX
= "KeyPrefix";
73 public static final String RESTRICTION_TYPE_DELIMITED_KEY_PREFIX
= "DelimitedKeyPrefix";
76 * Create the RegionSplitRestriction configured for the given table.
78 * @param tableDescriptor the table descriptor
79 * @param conf the configuration
80 * @return a RegionSplitRestriction instance
81 * @throws IOException if an error occurs
83 public static RegionSplitRestriction
create(TableDescriptor tableDescriptor
,
84 Configuration conf
) throws IOException
{
85 String type
= tableDescriptor
.getValue(RESTRICTION_TYPE_KEY
);
87 type
= conf
.get(RESTRICTION_TYPE_KEY
, RESTRICTION_TYPE_NONE
);
90 RegionSplitRestriction ret
;
92 case RESTRICTION_TYPE_NONE
:
93 ret
= new NoRegionSplitRestriction();
95 case RESTRICTION_TYPE_KEY_PREFIX
:
96 ret
= new KeyPrefixRegionSplitRestriction();
98 case RESTRICTION_TYPE_DELIMITED_KEY_PREFIX
:
99 ret
= new DelimitedKeyPrefixRegionSplitRestriction();
102 LOG
.warn("Invalid RegionSplitRestriction type specified: {}. "
103 + "Using the default RegionSplitRestriction", type
);
104 ret
= new NoRegionSplitRestriction();
107 ret
.initialize(tableDescriptor
, conf
);
112 * Initialize the RegionSplitRestriction instance
114 * @param tableDescriptor the table descriptor
115 * @param conf the configuration
116 * @throws IOException if an error occurs
118 public abstract void initialize(TableDescriptor tableDescriptor
, Configuration conf
)
122 * Returns a restricted split point.
124 * @param splitPoint the split point determined by {@link RegionSplitPolicy} or specified by a
126 * @return the restricted split point
128 public abstract byte[] getRestrictedSplitPoint(byte[] splitPoint
);