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
.client
;
20 import org
.apache
.hadoop
.hbase
.HConstants
;
21 import org
.apache
.hadoop
.hbase
.TableName
;
22 import org
.apache
.hadoop
.hbase
.util
.EnvironmentEdgeManager
;
23 import org
.apache
.yetus
.audience
.InterfaceAudience
;
25 @InterfaceAudience.Private
26 public class RegionInfoBuilder
{
28 /** A non-capture group so that this can be embedded. */
29 public static final String ENCODED_REGION_NAME_REGEX
= "(?:[a-f0-9]+)";
31 //TODO: Move NO_HASH to HStoreFile which is really the only place it is used.
32 public static final String NO_HASH
= null;
34 public static final RegionInfo UNDEFINED
=
35 RegionInfoBuilder
.newBuilder(TableName
.valueOf("__UNDEFINED__")).build();
38 * RegionInfo for first meta region
39 * You cannot use this builder to make an instance of the {@link #FIRST_META_REGIONINFO}.
40 * Just refer to this instance. Also, while the instance is actually a MutableRI, its type is
41 * just RI so the mutable methods are not available (unless you go casting); it appears
42 * as immutable (I tried adding Immutable type but it just makes a mess).
44 // TODO: How come Meta regions still do not have encoded region names? Fix.
45 // hbase:meta,,1.1588230740 should be the hbase:meta first region name.
46 public static final RegionInfo FIRST_META_REGIONINFO
=
47 new MutableRegionInfo(1L, TableName
.META_TABLE_NAME
, RegionInfo
.DEFAULT_REPLICA_ID
);
49 private final TableName tableName
;
50 private byte[] startKey
= HConstants
.EMPTY_START_ROW
;
51 private byte[] endKey
= HConstants
.EMPTY_END_ROW
;
52 private long regionId
= EnvironmentEdgeManager
.currentTime();
53 private int replicaId
= RegionInfo
.DEFAULT_REPLICA_ID
;
54 private boolean offLine
= false;
55 private boolean split
= false;
57 public static RegionInfoBuilder
newBuilder(TableName tableName
) {
58 return new RegionInfoBuilder(tableName
);
61 public static RegionInfoBuilder
newBuilder(RegionInfo regionInfo
) {
62 return new RegionInfoBuilder(regionInfo
);
65 private RegionInfoBuilder(TableName tableName
) {
66 this.tableName
= tableName
;
69 private RegionInfoBuilder(RegionInfo regionInfo
) {
70 this.tableName
= regionInfo
.getTable();
71 this.startKey
= regionInfo
.getStartKey();
72 this.endKey
= regionInfo
.getEndKey();
73 this.offLine
= regionInfo
.isOffline();
74 this.split
= regionInfo
.isSplit();
75 this.regionId
= regionInfo
.getRegionId();
76 this.replicaId
= regionInfo
.getReplicaId();
79 public RegionInfoBuilder
setStartKey(byte[] startKey
) {
80 this.startKey
= startKey
;
84 public RegionInfoBuilder
setEndKey(byte[] endKey
) {
89 public RegionInfoBuilder
setRegionId(long regionId
) {
90 this.regionId
= regionId
;
94 public RegionInfoBuilder
setReplicaId(int replicaId
) {
95 this.replicaId
= replicaId
;
99 public RegionInfoBuilder
setSplit(boolean split
) {
105 public RegionInfoBuilder
setOffline(boolean offLine
) {
106 this.offLine
= offLine
;
110 public RegionInfo
build() {
111 return new MutableRegionInfo(tableName
, startKey
, endKey
, split
,
112 regionId
, replicaId
, offLine
);