HDFS-16973. RBF: MountTableResolver cache size lookup should take read lock (#5533)
This commit is contained in:
parent
69b90b5698
commit
422bf3b24c
|
@ -679,10 +679,15 @@ public class MountTableResolver
|
||||||
* @throws IOException If the cache is not initialized.
|
* @throws IOException If the cache is not initialized.
|
||||||
*/
|
*/
|
||||||
protected long getCacheSize() throws IOException {
|
protected long getCacheSize() throws IOException {
|
||||||
|
this.readLock.lock();
|
||||||
|
try {
|
||||||
if (this.locationCache != null) {
|
if (this.locationCache != null) {
|
||||||
return this.locationCache.size();
|
return this.locationCache.size();
|
||||||
}
|
}
|
||||||
throw new IOException("localCache is null");
|
throw new IOException("localCache is null");
|
||||||
|
} finally {
|
||||||
|
this.readLock.unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
|
|
@ -552,6 +552,16 @@ public class TestMountTableResolver {
|
||||||
|
|
||||||
assertEquals(100000, mountTable.getMountPoints("/").size());
|
assertEquals(100000, mountTable.getMountPoints("/").size());
|
||||||
assertEquals(100000, mountTable.getMounts("/").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
|
// Add 1000 entries in deep list
|
||||||
mountTable.refreshEntries(emptyList);
|
mountTable.refreshEntries(emptyList);
|
||||||
|
|
Loading…
Reference in New Issue