HBASE-26412 Handle sink failure in RegionReplicationSink (#3815)
[hbase.git] / hbase-server / src / main / java / org / apache / hadoop / hbase / regionserver / KeyPrefixRegionSplitRestriction.java
blob41fcc2a86216115a431b9aabeb92fb7da63c87cb
1 /*
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 java.util.Arrays;
22 import org.apache.hadoop.conf.Configuration;
23 import org.apache.hadoop.hbase.client.TableDescriptor;
24 import org.apache.yetus.audience.InterfaceAudience;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 /**
29 * A {@link RegionSplitRestriction} implementation that groups rows by a prefix of the row-key.
30 * <p>
31 * This ensures that a region is not split "inside" a prefix of a row key.
32 * I.e. rows can be co-located in a region by their prefix.
34 @InterfaceAudience.Private
35 public class KeyPrefixRegionSplitRestriction extends RegionSplitRestriction {
36 private static final Logger LOG =
37 LoggerFactory.getLogger(KeyPrefixRegionSplitRestriction.class);
39 public static final String PREFIX_LENGTH_KEY =
40 "hbase.regionserver.region.split_restriction.prefix_length";
42 private int prefixLength;
44 @Override
45 public void initialize(TableDescriptor tableDescriptor, Configuration conf) throws IOException {
46 String prefixLengthString = tableDescriptor.getValue(PREFIX_LENGTH_KEY);
47 if (prefixLengthString == null) {
48 prefixLengthString = conf.get(PREFIX_LENGTH_KEY);
49 if (prefixLengthString == null) {
50 LOG.error("{} not specified for table {}. "
51 + "Using the default RegionSplitRestriction", PREFIX_LENGTH_KEY,
52 tableDescriptor.getTableName());
53 return;
56 try {
57 prefixLength = Integer.parseInt(prefixLengthString);
58 } catch (NumberFormatException ignored) {
60 if (prefixLength <= 0) {
61 LOG.error("Invalid value for {} for table {}:{}. "
62 + "Using the default RegionSplitRestriction", PREFIX_LENGTH_KEY,
63 tableDescriptor.getTableName(), prefixLengthString);
67 @Override
68 public byte[] getRestrictedSplitPoint(byte[] splitPoint) {
69 if (prefixLength > 0) {
70 // group split keys by a prefix
71 return Arrays.copyOf(splitPoint, Math.min(prefixLength, splitPoint.length));
72 } else {
73 return splitPoint;