diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java hbase-server/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java index 934e590..9c7bd84 100644 --- hbase-server/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java +++ hbase-server/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java @@ -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 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 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) { diff --git hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java index 59e79f6..0c6d6d6 100644 --- hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java +++ hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java @@ -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);