Skip to content

Commit 7a1c341

Browse files
committed
HDFS-16973. RBF: MountTableResolver cache size lookup should take read lock
1 parent 937caf7 commit 7a1c341

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/resolver/MountTableResolver.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -678,11 +678,16 @@ private List<MountTable> getTreeValues(final String path, boolean reverse) {
678678
* @return Size of the cache.
679679
* @throws IOException If the cache is not initialized.
680680
*/
681-
protected long getCacheSize() throws IOException{
682-
if (this.locationCache != null) {
683-
return this.locationCache.size();
681+
protected long getCacheSize() throws IOException {
682+
this.readLock.lock();
683+
try {
684+
if (this.locationCache != null) {
685+
return this.locationCache.size();
686+
}
687+
throw new IOException("localCache is null");
688+
} finally {
689+
this.readLock.unlock();
684690
}
685-
throw new IOException("localCache is null");
686691
}
687692

688693
@VisibleForTesting

hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/resolver/TestMountTableResolver.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,10 @@ public void testMountTableScalability() throws IOException {
552552

553553
assertEquals(100000, mountTable.getMountPoints("/").size());
554554
assertEquals(100000, mountTable.getMounts("/").size());
555+
for (int i = 0; i < 20; i++) {
556+
mountTable.getDestinationForPath("/" + i);
557+
}
558+
assertEquals(TEST_MAX_CACHE_SIZE, mountTable.getCacheSize());
555559

556560
// Add 1000 entries in deep list
557561
mountTable.refreshEntries(emptyList);

0 commit comments

Comments
 (0)