HDFS-16973. RBF: MountTableResolver cache size lookup should take read lock (#5533)
This commit is contained in:
parent
69b90b5698
commit
422bf3b24c
|
@ -678,11 +678,16 @@ public class MountTableResolver
|
|||
* @return Size of the cache.
|
||||
* @throws IOException If the cache is not initialized.
|
||||
*/
|
||||
protected long getCacheSize() throws IOException{
|
||||
if (this.locationCache != null) {
|
||||
return this.locationCache.size();
|
||||
protected long getCacheSize() throws IOException {
|
||||
this.readLock.lock();
|
||||
try {
|
||||
if (this.locationCache != null) {
|
||||
return this.locationCache.size();
|
||||
}
|
||||
throw new IOException("localCache is null");
|
||||
} finally {
|
||||
this.readLock.unlock();
|
||||
}
|
||||
throw new IOException("localCache is null");
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
|
|
@ -552,6 +552,16 @@ public class TestMountTableResolver {
|
|||
|
||||
assertEquals(100000, mountTable.getMountPoints("/").size());
|
||||
assertEquals(100000, mountTable.getMounts("/").size());
|
||||
// test concurrency for mount table cache size when it gets updated frequently
|
||||
for (int i = 0; i < 20; i++) {
|
||||
mountTable.getDestinationForPath("/" + i);
|
||||
if (i >= 10) {
|
||||
assertEquals(TEST_MAX_CACHE_SIZE, mountTable.getCacheSize());
|
||||
} else {
|
||||
assertEquals(i + 1, mountTable.getCacheSize());
|
||||
}
|
||||
}
|
||||
assertEquals(TEST_MAX_CACHE_SIZE, mountTable.getCacheSize());
|
||||
|
||||
// Add 1000 entries in deep list
|
||||
mountTable.refreshEntries(emptyList);
|
||||
|
|
Loading…
Reference in New Issue