HBASE-21464 Splitting blocked with meta NSRE during split transaction

Signed-off-by: Lars Hofhansl <larsh@apache.org>
This commit is contained in:
Andrew Purtell 2018-11-30 15:23:34 -08:00
parent 333cd19728
commit e80cc3286c
No known key found for this signature in database
GPG Key ID: 8597754DD5365CCD
1 changed files with 25 additions and 17 deletions

View File

@ -1231,38 +1231,46 @@ class ConnectionManager {
} }
} }
private volatile RegionLocations metaLocations = null;
private volatile long lastMetaLookupTime = EnvironmentEdgeManager.currentTime();
// cache meta location at most 10 seconds
private final static long META_LOOKUP_CACHE_INTERVAL = 10000;
private RegionLocations locateMeta(final TableName tableName, private RegionLocations locateMeta(final TableName tableName,
boolean useCache, int replicaId) throws IOException { boolean useCache, int replicaId) throws IOException {
// HBASE-10785: We cache the location of the META itself, so that we are not overloading // We cache the location of the META itself, so that we are not overloading
// zookeeper with one request for every region lookup. We cache the META with empty row // zookeeper with one request for every region lookup. If relocating, bypass
// key in MetaCache. // the cache immediately.
byte[] metaCacheKey = HConstants.EMPTY_START_ROW; // use byte[0] as the row for meta
RegionLocations locations = null;
if (useCache) { if (useCache) {
locations = getCachedLocation(tableName, metaCacheKey); long now = EnvironmentEdgeManager.currentTime();
if (locations != null && locations.getRegionLocation(replicaId) != null) { if (now - lastMetaLookupTime < META_LOOKUP_CACHE_INTERVAL) {
return locations; if (metaLocations != null &&
metaLocations.getRegionLocation(replicaId) != null) {
return metaLocations;
}
} else {
useCache = false;
} }
} }
// only one thread should do the lookup. // only one thread should do the lookup.
synchronized (metaRegionLock) { synchronized (metaRegionLock) {
// Check the cache again for a hit in case some other thread made the // Check the cache again for a hit in case some other thread made the
// same query while we were waiting on the lock. // same query while we were waiting on the lock.
if (useCache) { if (useCache) {
locations = getCachedLocation(tableName, metaCacheKey); if (metaLocations != null &&
if (locations != null && locations.getRegionLocation(replicaId) != null) { metaLocations.getRegionLocation(replicaId) != null) {
return locations; return metaLocations;
} }
} }
// Look up from zookeeper // Look up from zookeeper
locations = this.registry.getMetaRegionLocation(); metaLocations = this.registry.getMetaRegionLocation();
if (locations != null) { lastMetaLookupTime = EnvironmentEdgeManager.currentTime();
cacheLocation(tableName, locations); if (metaLocations != null &&
metaLocations.getRegionLocation(replicaId) != null) {
return metaLocations;
} }
return null;
} }
return locations;
} }
/* /*