Skip to content

Commit

Permalink
HBASE-24390 Remove RegionInfoBuilder.FIRST_META_REGIONINFO (#1877)
Browse files Browse the repository at this point in the history
Signed-off-by: stack <[email protected]>
  • Loading branch information
Apache9 committed Jul 19, 2020
1 parent 2d519b6 commit ef5b91b
Show file tree
Hide file tree
Showing 58 changed files with 366 additions and 463 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2415,13 +2415,6 @@ private CompletableFuture<RegionInfo> getRegionInfo(byte[] regionNameOrEncodedRe
return failedFuture(new IllegalArgumentException("Passed region name can't be null"));
}

if (Bytes.equals(regionNameOrEncodedRegionName,
RegionInfoBuilder.FIRST_META_REGIONINFO.getRegionName()) ||
Bytes.equals(regionNameOrEncodedRegionName,
RegionInfoBuilder.FIRST_META_REGIONINFO.getEncodedNameAsBytes())) {
return CompletableFuture.completedFuture(RegionInfoBuilder.FIRST_META_REGIONINFO);
}

CompletableFuture<RegionInfo> future = new CompletableFuture<>();
addListener(getRegionLocation(regionNameOrEncodedRegionName), (location, err) -> {
if (err != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,6 @@ public class RegionInfoBuilder {
//TODO: Move NO_HASH to HStoreFile which is really the only place it is used.
public static final String NO_HASH = null;

/**
* RegionInfo for first meta region
* You cannot use this builder to make an instance of the {@link #FIRST_META_REGIONINFO}.
* Just refer to this instance. Also, while the instance is actually a MutableRI, its type is
* just RI so the mutable methods are not available (unless you go casting); it appears
* as immutable (I tried adding Immutable type but it just makes a mess).
*/
// TODO: How come Meta regions still do not have encoded region names? Fix.
// hbase:meta,,1.1588230740 should be the hbase:meta first region name.
public static final RegionInfo FIRST_META_REGIONINFO =
new MutableRegionInfo(1L, TableName.META_TABLE_NAME, RegionInfo.DEFAULT_REPLICA_ID);

private final TableName tableName;
private byte[] startKey = HConstants.EMPTY_START_ROW;
private byte[] endKey = HConstants.EMPTY_END_ROW;
Expand Down Expand Up @@ -194,15 +182,6 @@ private static int checkReplicaId(int regionId) {
return regionId;
}

/**
* Private constructor used constructing MutableRegionInfo for the
* first meta regions
*/
private MutableRegionInfo(long regionId, TableName tableName, int replicaId) {
this(tableName, HConstants.EMPTY_START_ROW, HConstants.EMPTY_END_ROW, false, regionId,
replicaId, false);
}

MutableRegionInfo(final TableName tableName, final byte[] startKey, final byte[] endKey,
final boolean split, final long regionId, final int replicaId, boolean offLine) {
this.tableName = checkTableName(tableName);
Expand Down Expand Up @@ -320,7 +299,7 @@ public boolean containsRow(byte[] row) {
/** @return true if this region is a meta region */
@Override
public boolean isMetaRegion() {
return tableName.equals(FIRST_META_REGIONINFO.getTable());
return TableName.isMetaTableName(tableName);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
package org.apache.hadoop.hbase.client;

import static org.apache.hadoop.hbase.client.RegionInfo.DEFAULT_REPLICA_ID;
import static org.apache.hadoop.hbase.client.RegionInfoBuilder.FIRST_META_REGIONINFO;
import static org.apache.hadoop.hbase.client.RegionReplicaUtil.getRegionInfoForDefaultReplica;
import static org.apache.hadoop.hbase.client.RegionReplicaUtil.getRegionInfoForReplica;
import static org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil.lengthOfPBMagic;
import static org.apache.hadoop.hbase.util.FutureUtils.addListener;
import static org.apache.hadoop.hbase.zookeeper.ZKMetadata.removeMetaData;
Expand All @@ -35,6 +32,7 @@
import org.apache.hadoop.hbase.HRegionLocation;
import org.apache.hadoop.hbase.RegionLocations;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.exceptions.DeserializationException;
import org.apache.hadoop.hbase.master.RegionState;
import org.apache.hadoop.hbase.util.Pair;
Expand Down Expand Up @@ -161,7 +159,8 @@ private void getMetaRegionLocation(CompletableFuture<RegionLocations> future,
LOG.warn("Meta region is in state " + stateAndServerName.getFirst());
}
locs[DEFAULT_REPLICA_ID] = new HRegionLocation(
getRegionInfoForDefaultReplica(FIRST_META_REGIONINFO), stateAndServerName.getSecond());
RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME).setRegionId(1).build(),
stateAndServerName.getSecond());
tryComplete(remaining, locs, future);
});
} else {
Expand All @@ -183,8 +182,8 @@ private void getMetaRegionLocation(CompletableFuture<RegionLocations> future,
locs[replicaId] = null;
} else {
locs[replicaId] =
new HRegionLocation(getRegionInfoForReplica(FIRST_META_REGIONINFO, replicaId),
stateAndServerName.getSecond());
new HRegionLocation(RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME)
.setRegionId(1).setReplicaId(replicaId).build(), stateAndServerName.getSecond());
}
}
tryComplete(remaining, locs, future);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
import org.apache.hadoop.hbase.client.RegionInfoBuilder;
import org.apache.hadoop.hbase.client.RegionLoadStats;
import org.apache.hadoop.hbase.client.RegionLocateType;
import org.apache.hadoop.hbase.client.RegionReplicaUtil;
import org.apache.hadoop.hbase.client.RegionStatesCount;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Scan;
Expand Down Expand Up @@ -3155,8 +3154,8 @@ public static RegionState parseMetaRegionStateFrom(final byte[] data, int replic
if (serverName == null) {
state = RegionState.State.OFFLINE;
}
return new RegionState(RegionReplicaUtil.getRegionInfoForReplica(
RegionInfoBuilder.FIRST_META_REGIONINFO, replicaId), state, serverName);
return new RegionState(RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME).setRegionId(1)
.setReplicaId(replicaId).build(), state, serverName);
}

/**
Expand Down Expand Up @@ -3272,9 +3271,6 @@ public static org.apache.hadoop.hbase.client.RegionInfo toRegionInfo(final HBase
long regionId = proto.getRegionId();
int defaultReplicaId = org.apache.hadoop.hbase.client.RegionInfo.DEFAULT_REPLICA_ID;
int replicaId = proto.hasReplicaId()? proto.getReplicaId(): defaultReplicaId;
if (tableName.equals(TableName.META_TABLE_NAME) && replicaId == defaultReplicaId) {
return RegionInfoBuilder.FIRST_META_REGIONINFO;
}
byte[] startKey = null;
byte[] endKey = null;
if (proto.hasStartKey()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ public void testBuilder() {

@Test
public void testPb() throws DeserializationException {
RegionInfo ri = RegionInfoBuilder.FIRST_META_REGIONINFO;
RegionInfo ri = RegionInfoBuilder.newBuilder(name.getTableName()).build();
byte[] bytes = RegionInfo.toByteArray(ri);
RegionInfo pbri = RegionInfo.parseFrom(bytes);
assertTrue(RegionInfo.COMPARATOR.compare(ri, pbri) == 0);
assertEquals(0, RegionInfo.COMPARATOR.compare(ri, pbri));
}

@Test
Expand Down Expand Up @@ -148,7 +148,7 @@ public void testLastRegionCompare() {

@Test
public void testMetaTables() {
assertTrue(RegionInfoBuilder.FIRST_META_REGIONINFO.isMetaRegion());
assertTrue(RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME).build().isMetaRegion());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,19 @@ public boolean waitForActiveAndReadyMaster(long timeout) throws IOException {
return false;
}

@Override
public ServerName getServerHoldingMeta() throws IOException {
HRegionLocation regionLoc = null;
try (RegionLocator locator = connection.getRegionLocator(TableName.META_TABLE_NAME)) {
regionLoc = locator.getRegionLocation(HConstants.EMPTY_START_ROW, true);
}
if (regionLoc == null) {
LOG.warn("Cannot find region server holding first meta region");
return null;
}
return regionLoc.getServerName();
}

@Override
public ServerName getServerHoldingRegion(TableName tn, byte[] regionName) throws IOException {
byte[] startKey = RegionInfo.getStartKey(regionName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@
import org.apache.hadoop.hbase.client.MasterSwitchType;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.RegionInfo;
import org.apache.hadoop.hbase.client.RegionInfoBuilder;
import org.apache.hadoop.hbase.client.RegionLocateType;
import org.apache.hadoop.hbase.client.RegionReplicaUtil;
import org.apache.hadoop.hbase.client.RegionStatesCount;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Scan;
Expand Down Expand Up @@ -921,13 +921,16 @@ private void tryMigrateRootTableFromZooKeeper() throws IOException, KeeperExcept
}
}
// start migrating
byte[] row = CatalogFamilyFormat.getMetaKeyForRegion(RegionInfoBuilder.FIRST_META_REGIONINFO);
Put put = new Put(row);
Put put = null;
List<String> metaReplicaNodes = zooKeeper.getMetaReplicaNodes();
StringBuilder info = new StringBuilder("Migrating meta location:");
for (String metaReplicaNode : metaReplicaNodes) {
int replicaId = zooKeeper.getZNodePaths().getMetaReplicaIdFromZnode(metaReplicaNode);
RegionState state = getMetaRegionState(zooKeeper, replicaId);
if (put == null) {
byte[] row = CatalogFamilyFormat.getMetaKeyForRegion(state.getRegion());
put = new Put(row);
}
info.append(" ").append(state);
put.setTimestamp(state.getStamp());
MetaTableAccessor.addRegionInfo(put, state.getRegion());
Expand All @@ -939,9 +942,10 @@ private void tryMigrateRootTableFromZooKeeper() throws IOException, KeeperExcept
.setQualifier(RegionStateStore.getStateColumn(replicaId)).setTimestamp(put.getTimestamp())
.setType(Cell.Type.Put).setValue(Bytes.toBytes(state.getState().name())).build());
}
if (!put.isEmpty()) {
if (put != null) {
LOG.info(info.toString());
masterRegion.update(r -> r.put(put));
final Put p = put;
masterRegion.update(r -> r.put(p));
} else {
LOG.info("No meta location avaiable on zookeeper, skip migrating...");
}
Expand Down Expand Up @@ -1123,11 +1127,7 @@ private void finishActiveMasterInitialization(MonitoredTask status) throws IOExc
// Checking if meta needs initializing.
status.setStatus("Initializing meta table if this is a new deploy");
InitMetaProcedure initMetaProc = null;
// Print out state of hbase:meta on startup; helps debugging.
RegionState rs = this.assignmentManager.getRegionStates().
getRegionState(RegionInfoBuilder.FIRST_META_REGIONINFO);
LOG.info("hbase:meta {}", rs);
if (rs != null && rs.isOffline()) {
if (!this.assignmentManager.getRegionStates().hasTableRegionStates(TableName.META_TABLE_NAME)) {
Optional<InitMetaProcedure> optProc = procedureExecutor.getProcedures().stream()
.filter(p -> p instanceof InitMetaProcedure).map(o -> (InitMetaProcedure) o).findAny();
initMetaProc = optProc.orElseGet(() -> {
Expand Down Expand Up @@ -1306,11 +1306,14 @@ private void finishActiveMasterInitialization(MonitoredTask status) throws IOExc
/**
* Check hbase:meta is up and ready for reading. For use during Master startup only.
* @return True if meta is UP and online and startup can progress. Otherwise, meta is not online
* and we will hold here until operator intervention.
* and we will hold here until operator intervention.
*/
@VisibleForTesting
public boolean waitForMetaOnline() {
return isRegionOnline(RegionInfoBuilder.FIRST_META_REGIONINFO);
public boolean waitForMetaOnline() throws InterruptedException {
Optional<RegionInfo> firstMetaRegion =
this.assignmentManager.getRegionStates().getRegionsOfTable(TableName.META_TABLE_NAME).stream()
.filter(RegionInfo::isFirst).filter(RegionReplicaUtil::isDefaultReplica).findFirst();
return firstMetaRegion.isPresent() ? isRegionOnline(firstMetaRegion.get()) : false;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HRegionLocation;
import org.apache.hadoop.hbase.RegionLocations;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.client.RegionInfoBuilder;
import org.apache.hadoop.hbase.client.RegionLocateType;
import org.apache.hadoop.hbase.tmpl.master.MasterStatusTmpl;
import org.apache.hadoop.hbase.util.FSUtils;
import org.apache.yetus.audience.InterfaceAudience;
Expand Down Expand Up @@ -79,9 +82,13 @@ public void doGet(HttpServletRequest request, HttpServletResponse response)
tmpl.render(response.getWriter(), master);
}

private ServerName getMetaLocationOrNull(HMaster master) {
return master.getAssignmentManager().getRegionStates()
.getRegionState(RegionInfoBuilder.FIRST_META_REGIONINFO).getServerName();
private ServerName getMetaLocationOrNull(HMaster master) throws IOException {
RegionLocations locs = master.locateMeta(HConstants.EMPTY_START_ROW, RegionLocateType.CURRENT);
if (locs == null) {
return null;
}
HRegionLocation loc = locs.getDefaultRegionLocation();
return loc != null ? loc.getServerName() : null;
}

private Map<String, Integer> getFragmentationInfo(
Expand Down
Loading

0 comments on commit ef5b91b

Please sign in to comment.