HBASE-3654 Weird blocking between getOnlineRegion and createRegionLoad

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1085114 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2011-03-24 20:25:10 +00:00
parent 1cab7fc7b9
commit b500e86e2d
2 changed files with 68 additions and 121 deletions

View File

@ -171,6 +171,8 @@ Release 0.90.2 - Unreleased
HBASE-3627 NPE in EventHandler when region already reassigned
HBASE-3660 HMaster will exit when starting with stale data in cached locations
such as -ROOT- or .META.
HBASE-3654 Weird blocking between getOnlineRegion and createRegionLoad
(Subbu M Iyer via Stack)
IMPROVEMENTS
HBASE-3542 MultiGet methods in Thrift

View File

@ -182,7 +182,7 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler,
* encoded region name. All access should be synchronized.
*/
protected final Map<String, HRegion> onlineRegions =
new HashMap<String, HRegion>();
new ConcurrentHashMap<String, HRegion>();
protected final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
private final LinkedBlockingQueue<HMsg> outboundMsgs = new LinkedBlockingQueue<HMsg>();
@ -688,12 +688,10 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler,
String getOnlineRegionsAsPrintableString() {
StringBuilder sb = new StringBuilder();
synchronized (this.onlineRegions) {
for (HRegion r: this.onlineRegions.values()) {
if (sb.length() > 0) sb.append(", ");
sb.append(r.getRegionInfo().getEncodedName());
}
}
return sb.toString();
}
@ -712,11 +710,9 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler,
// Only print out regions still closing if a small number else will
// swamp the log.
if (count < 10 && LOG.isDebugEnabled()) {
synchronized (this.onlineRegions) {
LOG.debug(this.onlineRegions);
}
}
}
Threads.sleep(1000);
}
}
@ -756,11 +752,9 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler,
HServerLoad hsl = new HServerLoad(requestCount.get(),
(int)(memory.getUsed() / 1024 / 1024),
(int) (memory.getMax() / 1024 / 1024));
synchronized (this.onlineRegions) {
for (HRegion r : this.onlineRegions.values()) {
hsl.addRegionInfo(createRegionLoad(r));
}
}
return hsl;
}
@ -923,9 +917,7 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler,
*/
public HServerLoad.RegionLoad createRegionLoad(final String encodedRegionName) {
HRegion r = null;
synchronized (this.onlineRegions) {
r = this.onlineRegions.get(encodedRegionName);
}
return createRegionLoad(r);
}
@ -1042,7 +1034,6 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler,
@Override
protected void chore() {
synchronized (this.instance.onlineRegions) {
for (HRegion r : this.instance.onlineRegions.values()) {
try {
if (r != null && r.isMajorCompaction()) {
@ -1056,7 +1047,6 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler,
}
}
}
}
/**
* Report the status of the server. A server is online once all the startup is
@ -1154,7 +1144,6 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler,
long memstoreSize = 0;
long requestsCount = 0;
long storefileIndexSize = 0;
synchronized (this.onlineRegions) {
for (Map.Entry<String, HRegion> e : this.onlineRegions.entrySet()) {
HRegion r = e.getValue();
memstoreSize += r.memstoreSize.get();
@ -1168,7 +1157,6 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler,
}
}
}
}
this.metrics.stores.set(stores);
this.metrics.storefiles.set(storefiles);
this.metrics.memstoreSizeMB.set((int) (memstoreSize / (1024 * 1024)));
@ -1547,7 +1535,6 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler,
HRegion root = null;
this.lock.writeLock().lock();
try {
synchronized (this.onlineRegions) {
for (Map.Entry<String, HRegion> e: onlineRegions.entrySet()) {
HRegionInfo hri = e.getValue().getRegionInfo();
if (hri.isRootRegion()) {
@ -1557,7 +1544,6 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler,
}
if (meta != null && root != null) break;
}
}
} finally {
this.lock.writeLock().unlock();
}
@ -1572,7 +1558,6 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler,
void closeUserRegions(final boolean abort) {
this.lock.writeLock().lock();
try {
synchronized (this.onlineRegions) {
for (Map.Entry<String, HRegion> e: this.onlineRegions.entrySet()) {
HRegion r = e.getValue();
if (!r.getRegionInfo().isMetaRegion()) {
@ -1580,7 +1565,6 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler,
closeRegion(r.getRegionInfo(), abort, false);
}
}
}
} finally {
this.lock.writeLock().unlock();
}
@ -2267,7 +2251,6 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler,
public boolean closeRegion(HRegionInfo region, final boolean zk)
throws NotServingRegionException {
LOG.info("Received close region: " + region.getRegionNameAsString());
synchronized (this.onlineRegions) {
boolean hasit = this.onlineRegions.containsKey(region.getEncodedName());
if (!hasit) {
LOG.warn("Received close for region we are not serving; " +
@ -2275,7 +2258,6 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler,
throw new NotServingRegionException("Received close for "
+ region.getRegionNameAsString() + " but we are not serving it");
}
}
return closeRegion(region, false, zk);
}
@ -2376,28 +2358,22 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler,
@QosPriority(priority=HIGH_QOS)
public List<HRegionInfo> getOnlineRegions() {
List<HRegionInfo> list = new ArrayList<HRegionInfo>();
synchronized(this.onlineRegions) {
for (Map.Entry<String,HRegion> e: this.onlineRegions.entrySet()) {
list.add(e.getValue().getRegionInfo());
}
}
Collections.sort(list);
return list;
}
public int getNumberOfOnlineRegions() {
int size = -1;
synchronized (this.onlineRegions) {
size = this.onlineRegions.size();
}
return size;
}
boolean isOnlineRegionsEmpty() {
synchronized (this.onlineRegions) {
return this.onlineRegions.isEmpty();
}
}
/**
* For tests and web ui.
@ -2406,35 +2382,19 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler,
* @see #getOnlineRegions()
*/
public Collection<HRegion> getOnlineRegionsLocalContext() {
synchronized (this.onlineRegions) {
Collection<HRegion> regions = this.onlineRegions.values();
return Collections.unmodifiableCollection(regions);
}
}
@Override
public void addToOnlineRegions(HRegion region) {
lock.writeLock().lock();
try {
synchronized (this.onlineRegions) {
this.onlineRegions.put(region.getRegionInfo().getEncodedName(), region);
}
} finally {
lock.writeLock().unlock();
}
}
@Override
public boolean removeFromOnlineRegions(final String encodedName) {
this.lock.writeLock().lock();
HRegion toReturn = null;
try {
synchronized (this.onlineRegions) {
toReturn = this.onlineRegions.remove(encodedName);
}
} finally {
this.lock.writeLock().unlock();
}
return toReturn != null;
}
@ -2451,20 +2411,16 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler,
}
});
// Copy over all regions. Regions are sorted by size with biggest first.
synchronized (this.onlineRegions) {
for (HRegion region : this.onlineRegions.values()) {
sortedRegions.put(Long.valueOf(region.memstoreSize.get()), region);
}
}
return sortedRegions;
}
@Override
public HRegion getFromOnlineRegions(final String encodedRegionName) {
HRegion r = null;
synchronized (this.onlineRegions) {
r = this.onlineRegions.get(encodedRegionName);
}
return r;
}
@ -2498,17 +2454,12 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler,
protected HRegion getRegion(final byte[] regionName)
throws NotServingRegionException {
HRegion region = null;
this.lock.readLock().lock();
try {
region = getOnlineRegion(regionName);
if (region == null) {
throw new NotServingRegionException("Region is not online: " +
Bytes.toStringBinary(regionName));
}
return region;
} finally {
this.lock.readLock().unlock();
}
}
/**
@ -2519,7 +2470,6 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler,
*/
protected HRegionInfo[] getMostLoadedRegions() {
ArrayList<HRegionInfo> regions = new ArrayList<HRegionInfo>();
synchronized (onlineRegions) {
for (HRegion r : onlineRegions.values()) {
if (r.isClosed() || r.isClosing()) {
continue;
@ -2530,7 +2480,6 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler,
break;
}
}
}
return regions.toArray(new HRegionInfo[regions.size()]);
}
@ -2573,11 +2522,9 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler,
*/
public long getGlobalMemStoreSize() {
long total = 0;
synchronized (onlineRegions) {
for (HRegion region : onlineRegions.values()) {
total += region.memstoreSize.get();
}
}
return total;
}
@ -2675,7 +2622,6 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler,
}
public HRegionInfo[] getRegionsAssignment() throws IOException {
synchronized (this.onlineRegions) {
HRegionInfo [] regions = new HRegionInfo[getNumberOfOnlineRegions()];
Iterator<HRegion> ite = onlineRegions.values().iterator();
for (int i = 0; ite.hasNext(); i++) {
@ -2683,7 +2629,6 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler,
}
return regions;
}
}
/** {@inheritDoc} */
@Override