HDFS-16973. RBF: MountTableResolver cache size lookup should take read lock (#5533)

This commit is contained in:
Viraj Jasani 2023-04-05 14:06:38 -07:00 committed by GitHub
parent 69b90b5698
commit 422bf3b24c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 4 deletions

View File

@ -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

View File

@ -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);