HBASE-2293 CME in RegionManager#isMetaServer

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@919708 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jean-Daniel Cryans 2010-03-06 07:00:03 +00:00
parent 83258ba826
commit 6eab8932c8
2 changed files with 43 additions and 28 deletions

View File

@ -225,6 +225,7 @@ Release 0.21.0 - Unreleased
half-written hfile (Ruslan Salyakhov via Stack) half-written hfile (Ruslan Salyakhov via Stack)
HBASE-2281 Hbase shell does not work when started from the build dir HBASE-2281 Hbase shell does not work when started from the build dir
(Alexey Kovyrin via Stack) (Alexey Kovyrin via Stack)
HBASE-2293 CME in RegionManager#isMetaServer
IMPROVEMENTS IMPROVEMENTS
HBASE-1760 Cleanup TODOs in HTable HBASE-1760 Cleanup TODOs in HTable

View File

@ -330,7 +330,9 @@ public class RegionManager implements HConstants {
String regionName = rs.getRegionInfo().getRegionNameAsString(); String regionName = rs.getRegionInfo().getRegionNameAsString();
LOG.info("Assigning region " + regionName + " to " + sinfo.getServerName()); LOG.info("Assigning region " + regionName + " to " + sinfo.getServerName());
rs.setPendingOpen(sinfo.getServerName()); rs.setPendingOpen(sinfo.getServerName());
synchronized (this.regionsInTransition) {
this.regionsInTransition.put(regionName, rs); this.regionsInTransition.put(regionName, rs);
}
returnMsgs.add(new HMsg(HMsg.Type.MSG_REGION_OPEN, rs.getRegionInfo())); returnMsgs.add(new HMsg(HMsg.Type.MSG_REGION_OPEN, rs.getRegionInfo()));
} }
@ -378,9 +380,11 @@ public class RegionManager implements HConstants {
Set<RegionState> regionsToAssign = new HashSet<RegionState>(); Set<RegionState> regionsToAssign = new HashSet<RegionState>();
boolean isMetaServer = isMetaServer(addr); boolean isMetaServer = isMetaServer(addr);
RegionState rootState = null;
// Handle if root is unassigned... only assign root if root is offline. // Handle if root is unassigned... only assign root if root is offline.
RegionState rootState = regionsInTransition.get(HRegionInfo.ROOT_REGIONINFO.getRegionNameAsString()); synchronized (this.regionsInTransition) {
rootState = regionsInTransition.get(HRegionInfo.ROOT_REGIONINFO.getRegionNameAsString());
}
if (rootState != null && rootState.isUnassigned()) { if (rootState != null && rootState.isUnassigned()) {
// make sure root isnt assigned here first. // make sure root isnt assigned here first.
// if so return 'empty list' // if so return 'empty list'
@ -400,8 +404,7 @@ public class RegionManager implements HConstants {
if (reassigningMetas && isMetaOrRoot && !isSingleServer) { if (reassigningMetas && isMetaOrRoot && !isSingleServer) {
return regionsToAssign; // dont assign anything to this server. return regionsToAssign; // dont assign anything to this server.
} }
synchronized (this.regionsInTransition) {
synchronized(regionsInTransition) {
for (RegionState s: regionsInTransition.values()) { for (RegionState s: regionsInTransition.values()) {
HRegionInfo i = s.getRegionInfo(); HRegionInfo i = s.getRegionInfo();
if (i == null) { if (i == null) {
@ -836,6 +839,7 @@ public class RegionManager implements HConstants {
* @return true if server is transitioning the ROOT table * @return true if server is transitioning the ROOT table
*/ */
public boolean isRootServerCandidate(final String server) { public boolean isRootServerCandidate(final String server) {
synchronized (this.regionsInTransition) {
for (RegionState s : regionsInTransition.values()) { for (RegionState s : regionsInTransition.values()) {
if (s.getRegionInfo().isRootRegion() if (s.getRegionInfo().isRootRegion()
&& !s.isUnassigned() && !s.isUnassigned()
@ -845,6 +849,7 @@ public class RegionManager implements HConstants {
return true; return true;
} }
} }
}
return false; return false;
} }
@ -855,6 +860,7 @@ public class RegionManager implements HConstants {
* @return if this server was transitioning a META table then a not null HRegionInfo pointing to it * @return if this server was transitioning a META table then a not null HRegionInfo pointing to it
*/ */
public HRegionInfo getMetaServerRegionInfo(final String server) { public HRegionInfo getMetaServerRegionInfo(final String server) {
synchronized (this.regionsInTransition) {
for (RegionState s : regionsInTransition.values()) { for (RegionState s : regionsInTransition.values()) {
if (s.getRegionInfo().isMetaRegion() if (s.getRegionInfo().isMetaRegion()
&& !s.isUnassigned() && !s.isUnassigned()
@ -864,6 +870,7 @@ public class RegionManager implements HConstants {
return s.getRegionInfo(); return s.getRegionInfo();
} }
} }
}
return null; return null;
} }
@ -910,26 +917,32 @@ public class RegionManager implements HConstants {
* @param info * @param info
*/ */
public void removeRegion(HRegionInfo info) { public void removeRegion(HRegionInfo info) {
synchronized (this.regionsInTransition) {
this.regionsInTransition.remove(info.getRegionNameAsString()); this.regionsInTransition.remove(info.getRegionNameAsString());
} }
}
/** /**
* @param regionName * @param regionName
* @return true if the named region is in a transition state * @return true if the named region is in a transition state
*/ */
public boolean regionIsInTransition(String regionName) { public boolean regionIsInTransition(String regionName) {
synchronized (this.regionsInTransition) {
return regionsInTransition.containsKey(regionName); return regionsInTransition.containsKey(regionName);
} }
}
/** /**
* @param regionName * @param regionName
* @return true if the region is unassigned, pendingOpen or open * @return true if the region is unassigned, pendingOpen or open
*/ */
public boolean regionIsOpening(String regionName) { public boolean regionIsOpening(String regionName) {
synchronized (this.regionsInTransition) {
RegionState state = regionsInTransition.get(regionName); RegionState state = regionsInTransition.get(regionName);
if (state != null) { if (state != null) {
return state.isOpening(); return state.isOpening();
} }
}
return false; return false;
} }
@ -939,17 +952,18 @@ public class RegionManager implements HConstants {
* @param force if true mark region unassigned whatever its current state * @param force if true mark region unassigned whatever its current state
*/ */
public void setUnassigned(HRegionInfo info, boolean force) { public void setUnassigned(HRegionInfo info, boolean force) {
RegionState s = null;
synchronized(this.regionsInTransition) { synchronized(this.regionsInTransition) {
RegionState s = regionsInTransition.get(info.getRegionNameAsString()); s = regionsInTransition.get(info.getRegionNameAsString());
if (s == null) { if (s == null) {
s = new RegionState(info); s = new RegionState(info);
regionsInTransition.put(info.getRegionNameAsString(), s); regionsInTransition.put(info.getRegionNameAsString(), s);
} }
}
if (force || (!s.isPendingOpen() || !s.isOpen())) { if (force || (!s.isPendingOpen() || !s.isOpen())) {
s.setUnassigned(); s.setUnassigned();
} }
} }
}
/** /**
* Check if a region is on the unassigned list * Check if a region is on the unassigned list