HBASE-16234 Expect and handle nulls when assigning replicas(Yi Liang)

This commit is contained in:
chenheng 2016-08-01 11:20:05 +08:00
parent 69d170063f
commit 7e6f562754
1 changed files with 25 additions and 23 deletions

View File

@ -1667,6 +1667,25 @@ public class AssignmentManager {
assign(replicaRegionsNotRecordedInMeta(regionsFromMetaScan, (MasterServices)server)); assign(replicaRegionsNotRecordedInMeta(regionsFromMetaScan, (MasterServices)server));
} }
/**
* Get number of replicas of a table
*/
private static int getNumReplicas(MasterServices master, TableName table) {
int numReplica = 1;
try {
HTableDescriptor htd = master.getTableDescriptors().get(table);
if (htd == null) {
LOG.warn("master can not get TableDescriptor from table '" + table);
} else {
numReplica = htd.getRegionReplication();
}
} catch (IOException e){
LOG.warn("Couldn't get the replication attribute of the table " + table + " due to "
+ e.getMessage());
}
return numReplica;
}
/** /**
* Get a list of replica regions that are: * Get a list of replica regions that are:
* not recorded in meta yet. We might not have recorded the locations * not recorded in meta yet. We might not have recorded the locations
@ -1683,9 +1702,9 @@ public class AssignmentManager {
List<HRegionInfo> regionsNotRecordedInMeta = new ArrayList<HRegionInfo>(); List<HRegionInfo> regionsNotRecordedInMeta = new ArrayList<HRegionInfo>();
for (HRegionInfo hri : regionsRecordedInMeta) { for (HRegionInfo hri : regionsRecordedInMeta) {
TableName table = hri.getTable(); TableName table = hri.getTable();
HTableDescriptor htd = master.getTableDescriptors().get(table); if(master.getTableDescriptors().get(table) == null)
// look at the HTD for the replica count. That's the source of truth continue;
int desiredRegionReplication = htd.getRegionReplication(); int desiredRegionReplication = getNumReplicas(master, table);
for (int i = 0; i < desiredRegionReplication; i++) { for (int i = 0; i < desiredRegionReplication; i++) {
HRegionInfo replica = RegionReplicaUtil.getRegionInfoForReplica(hri, i); HRegionInfo replica = RegionReplicaUtil.getRegionInfoForReplica(hri, i);
if (regionsRecordedInMeta.contains(replica)) continue; if (regionsRecordedInMeta.contains(replica)) continue;
@ -1728,8 +1747,7 @@ public class AssignmentManager {
// maybe because it crashed. // maybe because it crashed.
PairOfSameType<HRegionInfo> p = MetaTableAccessor.getMergeRegions(result); PairOfSameType<HRegionInfo> p = MetaTableAccessor.getMergeRegions(result);
if (p.getFirst() != null && p.getSecond() != null) { if (p.getFirst() != null && p.getSecond() != null) {
int numReplicas = ((MasterServices)server).getTableDescriptors().get(p.getFirst(). int numReplicas = getNumReplicas(server, p.getFirst().getTable());
getTable()).getRegionReplication();
for (HRegionInfo merge : p) { for (HRegionInfo merge : p) {
for (int i = 1; i < numReplicas; i++) { for (int i = 1; i < numReplicas; i++) {
replicasToClose.add(RegionReplicaUtil.getRegionInfoForReplica(merge, i)); replicasToClose.add(RegionReplicaUtil.getRegionInfoForReplica(merge, i));
@ -2679,15 +2697,7 @@ public class AssignmentManager {
} }
} }
} }
int numReplicas = 1; int numReplicas = getNumReplicas(server, mergedHri.getTable());
try {
numReplicas = ((MasterServices)server).getTableDescriptors().get(mergedHri.getTable()).
getRegionReplication();
} catch (IOException e) {
LOG.warn("Couldn't get the replication attribute of the table " + mergedHri.getTable() +
" due to " + e.getMessage() + ". The assignment of replicas for the merged region " +
"will not be done");
}
List<HRegionInfo> regions = new ArrayList<HRegionInfo>(); List<HRegionInfo> regions = new ArrayList<HRegionInfo>();
for (int i = 1; i < numReplicas; i++) { for (int i = 1; i < numReplicas; i++) {
regions.add(RegionReplicaUtil.getRegionInfoForReplica(mergedHri, i)); regions.add(RegionReplicaUtil.getRegionInfoForReplica(mergedHri, i));
@ -2708,15 +2718,7 @@ public class AssignmentManager {
// create new regions for the replica, and assign them to match with the // create new regions for the replica, and assign them to match with the
// current replica assignments. If replica1 of parent is assigned to RS1, // current replica assignments. If replica1 of parent is assigned to RS1,
// the replica1s of daughters will be on the same machine // the replica1s of daughters will be on the same machine
int numReplicas = 1; int numReplicas = getNumReplicas(server, parentHri.getTable());
try {
numReplicas = ((MasterServices)server).getTableDescriptors().get(parentHri.getTable()).
getRegionReplication();
} catch (IOException e) {
LOG.warn("Couldn't get the replication attribute of the table " + parentHri.getTable() +
" due to " + e.getMessage() + ". The assignment of daughter replicas " +
"replicas will not be done");
}
// unassign the old replicas // unassign the old replicas
List<HRegionInfo> parentRegion = new ArrayList<HRegionInfo>(); List<HRegionInfo> parentRegion = new ArrayList<HRegionInfo>();
parentRegion.add(parentHri); parentRegion.add(parentHri);