HBASE-19530 New regions should always be added with state CLOSED

This commit is contained in:
Apekshit Sharma 2017-12-15 17:30:21 -08:00
parent 4db2f51169
commit 15a4aa0ce1
1 changed files with 30 additions and 6 deletions

View File

@ -56,6 +56,7 @@ import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.client.TableState; import org.apache.hadoop.hbase.client.TableState;
import org.apache.hadoop.hbase.exceptions.DeserializationException; import org.apache.hadoop.hbase.exceptions.DeserializationException;
import org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel; import org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel;
import org.apache.hadoop.hbase.master.RegionState;
import org.apache.hadoop.hbase.protobuf.ProtobufUtil; import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
import org.apache.hadoop.hbase.protobuf.generated.ClientProtos; import org.apache.hadoop.hbase.protobuf.generated.ClientProtos;
import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionSpecifier; import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionSpecifier;
@ -872,10 +873,19 @@ public class MetaTableAccessor {
* *
* @return HConstants.TABLE_STATE_QUALIFIER * @return HConstants.TABLE_STATE_QUALIFIER
*/ */
protected static byte[] getStateColumn() { protected static byte[] getTableStateColumn() {
return HConstants.TABLE_STATE_QUALIFIER; return HConstants.TABLE_STATE_QUALIFIER;
} }
/**
* Returns the column qualifier for serialized region state
*
* @return HConstants.TABLE_STATE_QUALIFIER
*/
protected static byte[] getRegionStateColumn() {
return HConstants.STATE_QUALIFIER;
}
/** /**
* Returns the column qualifier for server column for replicaId * Returns the column qualifier for server column for replicaId
* @param replicaId the replicaId of the region * @param replicaId the replicaId of the region
@ -1101,7 +1111,7 @@ public class MetaTableAccessor {
public static TableState getTableState(Connection conn, TableName tableName) public static TableState getTableState(Connection conn, TableName tableName)
throws IOException { throws IOException {
Table metaHTable = getMetaHTable(conn); Table metaHTable = getMetaHTable(conn);
Get get = new Get(tableName.getName()).addColumn(getTableFamily(), getStateColumn()); Get get = new Get(tableName.getName()).addColumn(getTableFamily(), getTableStateColumn());
long time = EnvironmentEdgeManager.currentTime(); long time = EnvironmentEdgeManager.currentTime();
get.setTimeRange(0, time); get.setTimeRange(0, time);
Result result = Result result =
@ -1152,7 +1162,7 @@ public class MetaTableAccessor {
@Nullable @Nullable
public static TableState getTableState(Result r) public static TableState getTableState(Result r)
throws IOException { throws IOException {
Cell cell = r.getColumnLatestCell(getTableFamily(), getStateColumn()); Cell cell = r.getColumnLatestCell(getTableFamily(), getTableStateColumn());
if (cell == null) return null; if (cell == null) return null;
try { try {
return TableState.parseFrom(TableName.valueOf(r.getRow()), return TableState.parseFrom(TableName.valueOf(r.getRow()),
@ -1556,7 +1566,8 @@ public class MetaTableAccessor {
* @param regionInfo region information * @param regionInfo region information
* @throws IOException if problem connecting or updating meta * @throws IOException if problem connecting or updating meta
*/ */
public static void addRegionToMeta(Connection connection, @VisibleForTesting
static void addRegionToMeta(Connection connection,
RegionInfo regionInfo) RegionInfo regionInfo)
throws IOException { throws IOException {
putToMetaTable(connection, makePutFromRegionInfo(regionInfo)); putToMetaTable(connection, makePutFromRegionInfo(regionInfo));
@ -1574,6 +1585,18 @@ public class MetaTableAccessor {
addRegionToMeta(meta, regionInfo, null, null); addRegionToMeta(meta, regionInfo, null, null);
} }
static void addRegionStateToPut(Put put, RegionState.State state)
throws IOException {
put.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY)
.setRow(put.getRow())
.setFamily(HConstants.CATALOG_FAMILY)
.setQualifier(getRegionStateColumn())
.setTimestamp(put.getTimeStamp())
.setType(CellBuilder.DataType.Put)
.setValue(Bytes.toBytes(state.name()))
.build());
}
/** /**
* Adds a (single) hbase:meta row for the specified new region and its daughters. Note that this * Adds a (single) hbase:meta row for the specified new region and its daughters. Note that this
* does not add its daughter's as different rows, but adds information about the daughters * does not add its daughter's as different rows, but adds information about the daughters
@ -1589,6 +1612,7 @@ public class MetaTableAccessor {
public static void addRegionToMeta(Table meta, RegionInfo regionInfo, public static void addRegionToMeta(Table meta, RegionInfo regionInfo,
RegionInfo splitA, RegionInfo splitB) throws IOException { RegionInfo splitA, RegionInfo splitB) throws IOException {
Put put = makePutFromRegionInfo(regionInfo); Put put = makePutFromRegionInfo(regionInfo);
addRegionStateToPut(put, RegionState.State.CLOSED);
addDaughtersToPut(put, splitA, splitB); addDaughtersToPut(put, splitA, splitB);
meta.put(put); meta.put(put);
if (METALOG.isDebugEnabled()) { if (METALOG.isDebugEnabled()) {
@ -1835,7 +1859,7 @@ public class MetaTableAccessor {
public static Put makePutFromTableState(TableState state) { public static Put makePutFromTableState(TableState state) {
long time = EnvironmentEdgeManager.currentTime(); long time = EnvironmentEdgeManager.currentTime();
Put put = new Put(state.getTableName().getName(), time); Put put = new Put(state.getTableName().getName(), time);
put.addColumn(getTableFamily(), getStateColumn(), state.convert().toByteArray()); put.addColumn(getTableFamily(), getTableStateColumn(), state.convert().toByteArray());
return put; return put;
} }
@ -1848,7 +1872,7 @@ public class MetaTableAccessor {
throws IOException { throws IOException {
long time = EnvironmentEdgeManager.currentTime(); long time = EnvironmentEdgeManager.currentTime();
Delete delete = new Delete(table.getName()); Delete delete = new Delete(table.getName());
delete.addColumns(getTableFamily(), getStateColumn(), time); delete.addColumns(getTableFamily(), getTableStateColumn(), time);
deleteFromMetaTable(connection, delete); deleteFromMetaTable(connection, delete);
LOG.info("Deleted table " + table + " state from META"); LOG.info("Deleted table " + table + " state from META");
} }