HBASE-7268 correct local region location cache information can be overwritten (or deleted) w/stale information from an old server, Addendum (Sergey)
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1437851 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a01797c761
commit
963d5f007f
|
@ -1085,7 +1085,7 @@ public class HConnectionManager {
|
||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
deleteCachedLocation(tableName, row);
|
forceDeleteCachedLocation(tableName, row);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query the root or meta region for the location of the meta region
|
// Query the root or meta region for the location of the meta region
|
||||||
|
@ -1221,11 +1221,11 @@ public class HConnectionManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a cached location
|
* Delete a cached location, no matter what it is. Called when we were told to not use cache.
|
||||||
* @param tableName tableName
|
* @param tableName tableName
|
||||||
* @param row
|
* @param row
|
||||||
*/
|
*/
|
||||||
void deleteCachedLocation(final byte [] tableName, final byte [] row) {
|
void forceDeleteCachedLocation(final byte [] tableName, final byte [] row) {
|
||||||
HRegionLocation rl = null;
|
HRegionLocation rl = null;
|
||||||
synchronized (this.cachedRegionLocations) {
|
synchronized (this.cachedRegionLocations) {
|
||||||
Map<byte[], HRegionLocation> tableLocations =
|
Map<byte[], HRegionLocation> tableLocations =
|
||||||
|
@ -1243,7 +1243,7 @@ public class HConnectionManager {
|
||||||
LOG.debug("Removed " + rl.getHostname() + ":" + rl.getPort()
|
LOG.debug("Removed " + rl.getHostname() + ":" + rl.getPort()
|
||||||
+ " as a location of " + rl.getRegionInfo().getRegionNameAsString() +
|
+ " as a location of " + rl.getRegionInfo().getRegionNameAsString() +
|
||||||
" for tableName=" + Bytes.toString(tableName) +
|
" for tableName=" + Bytes.toString(tableName) +
|
||||||
" from cache because of " + Bytes.toStringBinary(row));
|
" from cache to make sure we don't use cache for " + Bytes.toStringBinary(row));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1772,6 +1772,11 @@ public class HConnectionManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the cached location of the region if necessary, based on some error from source.
|
||||||
|
* @param hri The region in question.
|
||||||
|
* @param source The source of the error that prompts us to invalidate cache.
|
||||||
|
*/
|
||||||
void deleteCachedLocation(HRegionInfo hri, HRegionLocation source) {
|
void deleteCachedLocation(HRegionInfo hri, HRegionLocation source) {
|
||||||
boolean isStaleDelete = false;
|
boolean isStaleDelete = false;
|
||||||
HRegionLocation oldLocation = null;
|
HRegionLocation oldLocation = null;
|
||||||
|
@ -1779,12 +1784,14 @@ public class HConnectionManager {
|
||||||
Map<byte[], HRegionLocation> tableLocations =
|
Map<byte[], HRegionLocation> tableLocations =
|
||||||
getTableLocations(hri.getTableName());
|
getTableLocations(hri.getTableName());
|
||||||
oldLocation = tableLocations.get(hri.getStartKey());
|
oldLocation = tableLocations.get(hri.getStartKey());
|
||||||
|
if (oldLocation != null) {
|
||||||
// Do not delete the cache entry if it's not for the same server that gave us the error.
|
// Do not delete the cache entry if it's not for the same server that gave us the error.
|
||||||
isStaleDelete = (source != null) && !oldLocation.equals(source);
|
isStaleDelete = (source != null) && !oldLocation.equals(source);
|
||||||
if (!isStaleDelete) {
|
if (!isStaleDelete) {
|
||||||
tableLocations.remove(hri.getStartKey());
|
tableLocations.remove(hri.getStartKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (isStaleDelete) {
|
if (isStaleDelete) {
|
||||||
LOG.debug("Received an error from " + source.getHostnamePort() + " for region "
|
LOG.debug("Received an error from " + source.getHostnamePort() + " for region "
|
||||||
+ hri.getRegionNameAsString() + "; not removing "
|
+ hri.getRegionNameAsString() + "; not removing "
|
||||||
|
|
|
@ -155,7 +155,7 @@ public class TestHCM {
|
||||||
HConstants.LATEST_TIMESTAMP);
|
HConstants.LATEST_TIMESTAMP);
|
||||||
Assert.assertEquals(conn.getCachedLocation(TABLE_NAME, ROW).getPort(), nextPort);
|
Assert.assertEquals(conn.getCachedLocation(TABLE_NAME, ROW).getPort(), nextPort);
|
||||||
|
|
||||||
conn.deleteCachedLocation(TABLE_NAME.clone(), ROW.clone());
|
conn.forceDeleteCachedLocation(TABLE_NAME.clone(), ROW.clone());
|
||||||
HRegionLocation rl = conn.getCachedLocation(TABLE_NAME, ROW);
|
HRegionLocation rl = conn.getCachedLocation(TABLE_NAME, ROW);
|
||||||
assertNull("What is this location?? " + rl, rl);
|
assertNull("What is this location?? " + rl, rl);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue