Skip to content

Commit

Permalink
HBASE-23117: Bad enum in hbase:meta info:state column can fail loadMe…
Browse files Browse the repository at this point in the history
…ta and stop startup (#867)

* Handling the BAD value in info:state columns in hbase:meta

* Adding a unit test and region encoded name in the LOG

* Adding a null check for region state to complete the test scenario and fixing the nit

Signed-off-by: Wellington Chevreuil <wchevreuil@apache.org>
Signed-off-by: GuangxuCheng  <guangxucheng@gmail.com>
Signed-off-by: stack <stack@apache.org>
  • Loading branch information
sandeepvinayak authored and saintstack committed Nov 26, 2019
1 parent 643673f commit 45019db
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private void visitMetaEntry(final RegionStateVisitor visitor, final Result resul
if (regionInfo == null) continue;

final int replicaId = regionInfo.getReplicaId();
final State state = getRegionState(result, replicaId);
final State state = getRegionState(result, replicaId, regionInfo);

final ServerName lastHost = hrl.getServerName();
final ServerName regionLocation = getRegionServer(result, replicaId);
Expand Down Expand Up @@ -330,13 +330,22 @@ private static byte[] getServerNameColumn(int replicaId) {
* @return the region state, or null if unknown.
*/
@VisibleForTesting
public static State getRegionState(final Result r, int replicaId) {
public static State getRegionState(final Result r, int replicaId, RegionInfo regionInfo) {
Cell cell = r.getColumnLatestCell(HConstants.CATALOG_FAMILY, getStateColumn(replicaId));
if (cell == null || cell.getValueLength() == 0) {
return null;
}
return State.valueOf(Bytes.toString(cell.getValueArray(), cell.getValueOffset(),
cell.getValueLength()));

String state = Bytes.toString(cell.getValueArray(), cell.getValueOffset(),
cell.getValueLength());
try {
return State.valueOf(state);
} catch (IllegalArgumentException e) {
LOG.warn("BAD value {} in hbase:meta info:state column for region {} , " +
"Consider using HBCK2 setRegionState ENCODED_REGION_NAME STATE",
state, regionInfo.getEncodedName());
return null;
}
}

private static byte[] getStateColumn(int replicaId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3652,7 +3652,7 @@ public boolean evaluate() throws IOException {
}
}
if (RegionStateStore.getRegionState(r,
info.getReplicaId()) != RegionState.State.OPEN) {
info.getReplicaId(), info) != RegionState.State.OPEN) {
return false;
}
}
Expand Down

0 comments on commit 45019db

Please sign in to comment.