Skip to content

Commit ef5b91b

Browse files
committed
HBASE-24390 Remove RegionInfoBuilder.FIRST_META_REGIONINFO (#1877)
Signed-off-by: stack <stack@apache.org>
1 parent 2d519b6 commit ef5b91b

File tree

58 files changed

+366
-463
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+366
-463
lines changed

hbase-client/src/main/java/org/apache/hadoop/hbase/client/RawAsyncHBaseAdmin.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2415,13 +2415,6 @@ private CompletableFuture<RegionInfo> getRegionInfo(byte[] regionNameOrEncodedRe
24152415
return failedFuture(new IllegalArgumentException("Passed region name can't be null"));
24162416
}
24172417

2418-
if (Bytes.equals(regionNameOrEncodedRegionName,
2419-
RegionInfoBuilder.FIRST_META_REGIONINFO.getRegionName()) ||
2420-
Bytes.equals(regionNameOrEncodedRegionName,
2421-
RegionInfoBuilder.FIRST_META_REGIONINFO.getEncodedNameAsBytes())) {
2422-
return CompletableFuture.completedFuture(RegionInfoBuilder.FIRST_META_REGIONINFO);
2423-
}
2424-
24252418
CompletableFuture<RegionInfo> future = new CompletableFuture<>();
24262419
addListener(getRegionLocation(regionNameOrEncodedRegionName), (location, err) -> {
24272420
if (err != null) {

hbase-client/src/main/java/org/apache/hadoop/hbase/client/RegionInfoBuilder.java

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,6 @@ public class RegionInfoBuilder {
3737
//TODO: Move NO_HASH to HStoreFile which is really the only place it is used.
3838
public static final String NO_HASH = null;
3939

40-
/**
41-
* RegionInfo for first meta region
42-
* You cannot use this builder to make an instance of the {@link #FIRST_META_REGIONINFO}.
43-
* Just refer to this instance. Also, while the instance is actually a MutableRI, its type is
44-
* just RI so the mutable methods are not available (unless you go casting); it appears
45-
* as immutable (I tried adding Immutable type but it just makes a mess).
46-
*/
47-
// TODO: How come Meta regions still do not have encoded region names? Fix.
48-
// hbase:meta,,1.1588230740 should be the hbase:meta first region name.
49-
public static final RegionInfo FIRST_META_REGIONINFO =
50-
new MutableRegionInfo(1L, TableName.META_TABLE_NAME, RegionInfo.DEFAULT_REPLICA_ID);
51-
5240
private final TableName tableName;
5341
private byte[] startKey = HConstants.EMPTY_START_ROW;
5442
private byte[] endKey = HConstants.EMPTY_END_ROW;
@@ -194,15 +182,6 @@ private static int checkReplicaId(int regionId) {
194182
return regionId;
195183
}
196184

197-
/**
198-
* Private constructor used constructing MutableRegionInfo for the
199-
* first meta regions
200-
*/
201-
private MutableRegionInfo(long regionId, TableName tableName, int replicaId) {
202-
this(tableName, HConstants.EMPTY_START_ROW, HConstants.EMPTY_END_ROW, false, regionId,
203-
replicaId, false);
204-
}
205-
206185
MutableRegionInfo(final TableName tableName, final byte[] startKey, final byte[] endKey,
207186
final boolean split, final long regionId, final int replicaId, boolean offLine) {
208187
this.tableName = checkTableName(tableName);
@@ -320,7 +299,7 @@ public boolean containsRow(byte[] row) {
320299
/** @return true if this region is a meta region */
321300
@Override
322301
public boolean isMetaRegion() {
323-
return tableName.equals(FIRST_META_REGIONINFO.getTable());
302+
return TableName.isMetaTableName(tableName);
324303
}
325304

326305
/**

hbase-client/src/main/java/org/apache/hadoop/hbase/client/ZKConnectionRegistry.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
package org.apache.hadoop.hbase.client;
1919

2020
import static org.apache.hadoop.hbase.client.RegionInfo.DEFAULT_REPLICA_ID;
21-
import static org.apache.hadoop.hbase.client.RegionInfoBuilder.FIRST_META_REGIONINFO;
22-
import static org.apache.hadoop.hbase.client.RegionReplicaUtil.getRegionInfoForDefaultReplica;
23-
import static org.apache.hadoop.hbase.client.RegionReplicaUtil.getRegionInfoForReplica;
2421
import static org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil.lengthOfPBMagic;
2522
import static org.apache.hadoop.hbase.util.FutureUtils.addListener;
2623
import static org.apache.hadoop.hbase.zookeeper.ZKMetadata.removeMetaData;
@@ -35,6 +32,7 @@
3532
import org.apache.hadoop.hbase.HRegionLocation;
3633
import org.apache.hadoop.hbase.RegionLocations;
3734
import org.apache.hadoop.hbase.ServerName;
35+
import org.apache.hadoop.hbase.TableName;
3836
import org.apache.hadoop.hbase.exceptions.DeserializationException;
3937
import org.apache.hadoop.hbase.master.RegionState;
4038
import org.apache.hadoop.hbase.util.Pair;
@@ -161,7 +159,8 @@ private void getMetaRegionLocation(CompletableFuture<RegionLocations> future,
161159
LOG.warn("Meta region is in state " + stateAndServerName.getFirst());
162160
}
163161
locs[DEFAULT_REPLICA_ID] = new HRegionLocation(
164-
getRegionInfoForDefaultReplica(FIRST_META_REGIONINFO), stateAndServerName.getSecond());
162+
RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME).setRegionId(1).build(),
163+
stateAndServerName.getSecond());
165164
tryComplete(remaining, locs, future);
166165
});
167166
} else {
@@ -183,8 +182,8 @@ private void getMetaRegionLocation(CompletableFuture<RegionLocations> future,
183182
locs[replicaId] = null;
184183
} else {
185184
locs[replicaId] =
186-
new HRegionLocation(getRegionInfoForReplica(FIRST_META_REGIONINFO, replicaId),
187-
stateAndServerName.getSecond());
185+
new HRegionLocation(RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME)
186+
.setRegionId(1).setReplicaId(replicaId).build(), stateAndServerName.getSecond());
188187
}
189188
}
190189
tryComplete(remaining, locs, future);

hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/ProtobufUtil.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
import org.apache.hadoop.hbase.client.RegionInfoBuilder;
8383
import org.apache.hadoop.hbase.client.RegionLoadStats;
8484
import org.apache.hadoop.hbase.client.RegionLocateType;
85-
import org.apache.hadoop.hbase.client.RegionReplicaUtil;
8685
import org.apache.hadoop.hbase.client.RegionStatesCount;
8786
import org.apache.hadoop.hbase.client.Result;
8887
import org.apache.hadoop.hbase.client.Scan;
@@ -3155,8 +3154,8 @@ public static RegionState parseMetaRegionStateFrom(final byte[] data, int replic
31553154
if (serverName == null) {
31563155
state = RegionState.State.OFFLINE;
31573156
}
3158-
return new RegionState(RegionReplicaUtil.getRegionInfoForReplica(
3159-
RegionInfoBuilder.FIRST_META_REGIONINFO, replicaId), state, serverName);
3157+
return new RegionState(RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME).setRegionId(1)
3158+
.setReplicaId(replicaId).build(), state, serverName);
31603159
}
31613160

31623161
/**
@@ -3272,9 +3271,6 @@ public static org.apache.hadoop.hbase.client.RegionInfo toRegionInfo(final HBase
32723271
long regionId = proto.getRegionId();
32733272
int defaultReplicaId = org.apache.hadoop.hbase.client.RegionInfo.DEFAULT_REPLICA_ID;
32743273
int replicaId = proto.hasReplicaId()? proto.getReplicaId(): defaultReplicaId;
3275-
if (tableName.equals(TableName.META_TABLE_NAME) && replicaId == defaultReplicaId) {
3276-
return RegionInfoBuilder.FIRST_META_REGIONINFO;
3277-
}
32783274
byte[] startKey = null;
32793275
byte[] endKey = null;
32803276
if (proto.hasStartKey()) {

hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestRegionInfoBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ public void testBuilder() {
8282

8383
@Test
8484
public void testPb() throws DeserializationException {
85-
RegionInfo ri = RegionInfoBuilder.FIRST_META_REGIONINFO;
85+
RegionInfo ri = RegionInfoBuilder.newBuilder(name.getTableName()).build();
8686
byte[] bytes = RegionInfo.toByteArray(ri);
8787
RegionInfo pbri = RegionInfo.parseFrom(bytes);
88-
assertTrue(RegionInfo.COMPARATOR.compare(ri, pbri) == 0);
88+
assertEquals(0, RegionInfo.COMPARATOR.compare(ri, pbri));
8989
}
9090

9191
@Test
@@ -148,7 +148,7 @@ public void testLastRegionCompare() {
148148

149149
@Test
150150
public void testMetaTables() {
151-
assertTrue(RegionInfoBuilder.FIRST_META_REGIONINFO.isMetaRegion());
151+
assertTrue(RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME).build().isMetaRegion());
152152
}
153153

154154
@Test

hbase-it/src/test/java/org/apache/hadoop/hbase/DistributedHBaseCluster.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,19 @@ public boolean waitForActiveAndReadyMaster(long timeout) throws IOException {
300300
return false;
301301
}
302302

303+
@Override
304+
public ServerName getServerHoldingMeta() throws IOException {
305+
HRegionLocation regionLoc = null;
306+
try (RegionLocator locator = connection.getRegionLocator(TableName.META_TABLE_NAME)) {
307+
regionLoc = locator.getRegionLocation(HConstants.EMPTY_START_ROW, true);
308+
}
309+
if (regionLoc == null) {
310+
LOG.warn("Cannot find region server holding first meta region");
311+
return null;
312+
}
313+
return regionLoc.getServerName();
314+
}
315+
303316
@Override
304317
public ServerName getServerHoldingRegion(TableName tn, byte[] regionName) throws IOException {
305318
byte[] startKey = RegionInfo.getStartKey(regionName);

hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@
9090
import org.apache.hadoop.hbase.client.MasterSwitchType;
9191
import org.apache.hadoop.hbase.client.Put;
9292
import org.apache.hadoop.hbase.client.RegionInfo;
93-
import org.apache.hadoop.hbase.client.RegionInfoBuilder;
9493
import org.apache.hadoop.hbase.client.RegionLocateType;
94+
import org.apache.hadoop.hbase.client.RegionReplicaUtil;
9595
import org.apache.hadoop.hbase.client.RegionStatesCount;
9696
import org.apache.hadoop.hbase.client.Result;
9797
import org.apache.hadoop.hbase.client.Scan;
@@ -921,13 +921,16 @@ private void tryMigrateRootTableFromZooKeeper() throws IOException, KeeperExcept
921921
}
922922
}
923923
// start migrating
924-
byte[] row = CatalogFamilyFormat.getMetaKeyForRegion(RegionInfoBuilder.FIRST_META_REGIONINFO);
925-
Put put = new Put(row);
924+
Put put = null;
926925
List<String> metaReplicaNodes = zooKeeper.getMetaReplicaNodes();
927926
StringBuilder info = new StringBuilder("Migrating meta location:");
928927
for (String metaReplicaNode : metaReplicaNodes) {
929928
int replicaId = zooKeeper.getZNodePaths().getMetaReplicaIdFromZnode(metaReplicaNode);
930929
RegionState state = getMetaRegionState(zooKeeper, replicaId);
930+
if (put == null) {
931+
byte[] row = CatalogFamilyFormat.getMetaKeyForRegion(state.getRegion());
932+
put = new Put(row);
933+
}
931934
info.append(" ").append(state);
932935
put.setTimestamp(state.getStamp());
933936
MetaTableAccessor.addRegionInfo(put, state.getRegion());
@@ -939,9 +942,10 @@ private void tryMigrateRootTableFromZooKeeper() throws IOException, KeeperExcept
939942
.setQualifier(RegionStateStore.getStateColumn(replicaId)).setTimestamp(put.getTimestamp())
940943
.setType(Cell.Type.Put).setValue(Bytes.toBytes(state.getState().name())).build());
941944
}
942-
if (!put.isEmpty()) {
945+
if (put != null) {
943946
LOG.info(info.toString());
944-
masterRegion.update(r -> r.put(put));
947+
final Put p = put;
948+
masterRegion.update(r -> r.put(p));
945949
} else {
946950
LOG.info("No meta location avaiable on zookeeper, skip migrating...");
947951
}
@@ -1123,11 +1127,7 @@ private void finishActiveMasterInitialization(MonitoredTask status) throws IOExc
11231127
// Checking if meta needs initializing.
11241128
status.setStatus("Initializing meta table if this is a new deploy");
11251129
InitMetaProcedure initMetaProc = null;
1126-
// Print out state of hbase:meta on startup; helps debugging.
1127-
RegionState rs = this.assignmentManager.getRegionStates().
1128-
getRegionState(RegionInfoBuilder.FIRST_META_REGIONINFO);
1129-
LOG.info("hbase:meta {}", rs);
1130-
if (rs != null && rs.isOffline()) {
1130+
if (!this.assignmentManager.getRegionStates().hasTableRegionStates(TableName.META_TABLE_NAME)) {
11311131
Optional<InitMetaProcedure> optProc = procedureExecutor.getProcedures().stream()
11321132
.filter(p -> p instanceof InitMetaProcedure).map(o -> (InitMetaProcedure) o).findAny();
11331133
initMetaProc = optProc.orElseGet(() -> {
@@ -1306,11 +1306,14 @@ private void finishActiveMasterInitialization(MonitoredTask status) throws IOExc
13061306
/**
13071307
* Check hbase:meta is up and ready for reading. For use during Master startup only.
13081308
* @return True if meta is UP and online and startup can progress. Otherwise, meta is not online
1309-
* and we will hold here until operator intervention.
1309+
* and we will hold here until operator intervention.
13101310
*/
13111311
@VisibleForTesting
1312-
public boolean waitForMetaOnline() {
1313-
return isRegionOnline(RegionInfoBuilder.FIRST_META_REGIONINFO);
1312+
public boolean waitForMetaOnline() throws InterruptedException {
1313+
Optional<RegionInfo> firstMetaRegion =
1314+
this.assignmentManager.getRegionStates().getRegionsOfTable(TableName.META_TABLE_NAME).stream()
1315+
.filter(RegionInfo::isFirst).filter(RegionReplicaUtil::isDefaultReplica).findFirst();
1316+
return firstMetaRegion.isPresent() ? isRegionOnline(firstMetaRegion.get()) : false;
13141317
}
13151318

13161319
/**

hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterStatusServlet.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@
2626
import javax.servlet.http.HttpServletRequest;
2727
import javax.servlet.http.HttpServletResponse;
2828
import org.apache.hadoop.conf.Configuration;
29+
import org.apache.hadoop.hbase.HConstants;
30+
import org.apache.hadoop.hbase.HRegionLocation;
31+
import org.apache.hadoop.hbase.RegionLocations;
2932
import org.apache.hadoop.hbase.ServerName;
30-
import org.apache.hadoop.hbase.client.RegionInfoBuilder;
33+
import org.apache.hadoop.hbase.client.RegionLocateType;
3134
import org.apache.hadoop.hbase.tmpl.master.MasterStatusTmpl;
3235
import org.apache.hadoop.hbase.util.FSUtils;
3336
import org.apache.yetus.audience.InterfaceAudience;
@@ -79,9 +82,13 @@ public void doGet(HttpServletRequest request, HttpServletResponse response)
7982
tmpl.render(response.getWriter(), master);
8083
}
8184

82-
private ServerName getMetaLocationOrNull(HMaster master) {
83-
return master.getAssignmentManager().getRegionStates()
84-
.getRegionState(RegionInfoBuilder.FIRST_META_REGIONINFO).getServerName();
85+
private ServerName getMetaLocationOrNull(HMaster master) throws IOException {
86+
RegionLocations locs = master.locateMeta(HConstants.EMPTY_START_ROW, RegionLocateType.CURRENT);
87+
if (locs == null) {
88+
return null;
89+
}
90+
HRegionLocation loc = locs.getDefaultRegionLocation();
91+
return loc != null ? loc.getServerName() : null;
8592
}
8693

8794
private Map<String, Integer> getFragmentationInfo(

0 commit comments

Comments
 (0)