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:
Zhihong Yu 2013-01-24 03:19:29 +00:00
parent a01797c761
commit 963d5f007f
2 changed files with 16 additions and 9 deletions

View File

@ -1085,7 +1085,7 @@ public class HConnectionManager {
return location;
}
} else {
deleteCachedLocation(tableName, row);
forceDeleteCachedLocation(tableName, row);
}
// 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 row
*/
void deleteCachedLocation(final byte [] tableName, final byte [] row) {
void forceDeleteCachedLocation(final byte [] tableName, final byte [] row) {
HRegionLocation rl = null;
synchronized (this.cachedRegionLocations) {
Map<byte[], HRegionLocation> tableLocations =
@ -1243,7 +1243,7 @@ public class HConnectionManager {
LOG.debug("Removed " + rl.getHostname() + ":" + rl.getPort()
+ " as a location of " + rl.getRegionInfo().getRegionNameAsString() +
" 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) {
boolean isStaleDelete = false;
HRegionLocation oldLocation = null;
@ -1779,10 +1784,12 @@ public class HConnectionManager {
Map<byte[], HRegionLocation> tableLocations =
getTableLocations(hri.getTableName());
oldLocation = tableLocations.get(hri.getStartKey());
// 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);
if (!isStaleDelete) {
tableLocations.remove(hri.getStartKey());
if (oldLocation != null) {
// 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);
if (!isStaleDelete) {
tableLocations.remove(hri.getStartKey());
}
}
}
if (isStaleDelete) {

View File

@ -155,7 +155,7 @@ public class TestHCM {
HConstants.LATEST_TIMESTAMP);
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);
assertNull("What is this location?? " + rl, rl);