Skip to content

Commit

Permalink
HBASE-23596 HBCKServerCrashProcedure can double assign
Browse files Browse the repository at this point in the history
  • Loading branch information
saintstack committed Dec 19, 2019
1 parent a841bf1 commit 16d2c4b
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.hadoop.hbase.MetaTableAccessor;
import org.apache.hadoop.hbase.ServerName;
Expand Down Expand Up @@ -65,13 +67,13 @@ public HBCKServerCrashProcedure(final MasterProcedureEnv env, final ServerName s
public HBCKServerCrashProcedure() {}

/**
* Adds Regions found by super method any found scanning hbase:meta.
* Adds Regions found by super method to any found scanning hbase:meta.
*/
@Override
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value="NP_NULL_ON_SOME_PATH_EXCEPTION",
justification="FindBugs seems confused on ps in below.")
List<RegionInfo> getRegionsOnCrashedServer(MasterProcedureEnv env) {
// Super can return immutable emptyList.
// Super will return an immutable list (empty if nothing on this server).
List<RegionInfo> ris = super.getRegionsOnCrashedServer(env);
List<Pair<RegionInfo, ServerName>> ps = null;
try {
Expand All @@ -84,12 +86,13 @@ List<RegionInfo> getRegionsOnCrashedServer(MasterProcedureEnv env) {
LOG.warn("No regions found in hbase:meta");
return ris;
}
List<RegionInfo> aggregate = ris == null || ris.isEmpty()?
new ArrayList<>(): new ArrayList<>(ris);
// Use a Set here in case same Region in master memory and in hbase:meta (the usual case!).
// Otherwise, we will double-assign.
Set<RegionInfo> aggregate = new HashSet<>(ris);
int before = aggregate.size();
ps.stream().filter(p -> p.getSecond() != null && p.getSecond().equals(getServerName())).
forEach(p -> aggregate.add(p.getFirst()));
LOG.info("Found {} mentions of {} in hbase:meta", aggregate.size() - before, getServerName());
return aggregate;
return new ArrayList<RegionInfo>(aggregate);
}
}

0 comments on commit 16d2c4b

Please sign in to comment.