001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.client; 019 020import org.apache.hadoop.hbase.HConstants; 021import org.apache.hadoop.hbase.TableName; 022import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; 023import org.apache.yetus.audience.InterfaceAudience; 024 025@InterfaceAudience.Private 026public class RegionInfoBuilder { 027 028 /** A non-capture group so that this can be embedded. */ 029 public static final String ENCODED_REGION_NAME_REGEX = "(?:[a-f0-9]+)"; 030 031 // TODO: Move NO_HASH to HStoreFile which is really the only place it is used. 032 public static final String NO_HASH = null; 033 034 public static final RegionInfo UNDEFINED = 035 RegionInfoBuilder.newBuilder(TableName.valueOf("__UNDEFINED__")).build(); 036 037 /** 038 * RegionInfo for first meta region You cannot use this builder to make an instance of the 039 * {@link #FIRST_META_REGIONINFO}. Just refer to this instance. Also, while the instance is 040 * actually a MutableRI, its type is just RI so the mutable methods are not available (unless you 041 * go casting); it appears as immutable (I tried adding Immutable type but it just makes a mess). 042 */ 043 // TODO: How come Meta regions still do not have encoded region names? Fix. 044 // hbase:meta,,1.1588230740 should be the hbase:meta first region name. 045 public static final RegionInfo FIRST_META_REGIONINFO = 046 new MutableRegionInfo(1L, TableName.META_TABLE_NAME, RegionInfo.DEFAULT_REPLICA_ID); 047 048 private final TableName tableName; 049 private byte[] startKey = HConstants.EMPTY_START_ROW; 050 private byte[] endKey = HConstants.EMPTY_END_ROW; 051 private long regionId = EnvironmentEdgeManager.currentTime(); 052 private int replicaId = RegionInfo.DEFAULT_REPLICA_ID; 053 private boolean offLine = false; 054 private boolean split = false; 055 056 public static RegionInfoBuilder newBuilder(TableName tableName) { 057 return new RegionInfoBuilder(tableName); 058 } 059 060 public static RegionInfoBuilder newBuilder(RegionInfo regionInfo) { 061 return new RegionInfoBuilder(regionInfo); 062 } 063 064 private RegionInfoBuilder(TableName tableName) { 065 this.tableName = tableName; 066 } 067 068 private RegionInfoBuilder(RegionInfo regionInfo) { 069 this.tableName = regionInfo.getTable(); 070 this.startKey = regionInfo.getStartKey(); 071 this.endKey = regionInfo.getEndKey(); 072 this.offLine = regionInfo.isOffline(); 073 this.split = regionInfo.isSplit(); 074 this.regionId = regionInfo.getRegionId(); 075 this.replicaId = regionInfo.getReplicaId(); 076 } 077 078 public RegionInfoBuilder setStartKey(byte[] startKey) { 079 this.startKey = startKey; 080 return this; 081 } 082 083 public RegionInfoBuilder setEndKey(byte[] endKey) { 084 this.endKey = endKey; 085 return this; 086 } 087 088 public RegionInfoBuilder setRegionId(long regionId) { 089 this.regionId = regionId; 090 return this; 091 } 092 093 public RegionInfoBuilder setReplicaId(int replicaId) { 094 this.replicaId = replicaId; 095 return this; 096 } 097 098 public RegionInfoBuilder setSplit(boolean split) { 099 this.split = split; 100 return this; 101 } 102 103 @Deprecated 104 public RegionInfoBuilder setOffline(boolean offLine) { 105 this.offLine = offLine; 106 return this; 107 } 108 109 public RegionInfo build() { 110 return new MutableRegionInfo(tableName, startKey, endKey, split, regionId, replicaId, offLine); 111 } 112 113}