Apache Lucene open-source search software
SOLR-11873: Use time based expiration cache in all necessary places in HdfsDirectoryFactory.
markrmiller13773755b828
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 9c0022677c2..8f0ea2ad6d3 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -178,6 +178,8 @@ Bug Fixes* SOLR-10525: Stacked recovery requests do no cancel an in progress recovery first. (Mike Drob via Cao Manh Dat)+* SOLR-11873: Use time based expiration cache in all necessary places in HdfsDirectoryFactory. (Mihaly Toth via Mark Miller)+Optimizations----------------------diff --git a/solr/core/src/java/org/apache/solr/core/HdfsDirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/HdfsDirectoryFactory.javaindex f248152b4fc..761745bab97 100644--- a/solr/core/src/java/org/apache/solr/core/HdfsDirectoryFactory.java+++ b/solr/core/src/java/org/apache/solr/core/HdfsDirectoryFactory.java@@ -322,14 +322,7 @@ public class HdfsDirectoryFactory extends CachingDirectoryFactory implements Sol@Overridepublic boolean exists(String path) {final Path hdfsDirPath = new Path(path);- final Configuration conf = getConf();- FileSystem fileSystem = null;- try {- // no need to close the fs, the cache will do it- fileSystem = tmpFsCache.get(path, () -> FileSystem.get(hdfsDirPath.toUri(), conf));- } catch (ExecutionException e) {- throw new RuntimeException(e);- }+ FileSystem fileSystem = getCachedFileSystem(path);try {return fileSystem.exists(hdfsDirPath);@@ -349,16 +342,8 @@ public class HdfsDirectoryFactory extends CachingDirectoryFactory implements Solprotected synchronized void removeDirectory(final CacheValue cacheValue)throws IOException {- final Configuration conf = getConf();- FileSystem fileSystem = null;-- try {- // no need to close the fs, the cache will do it- fileSystem = tmpFsCache.get(cacheValue.path, () -> FileSystem.get(new Path(cacheValue.path).toUri(), conf));- } catch (ExecutionException e) {- throw new RuntimeException(e);- }-+ FileSystem fileSystem = getCachedFileSystem(cacheValue.path);+try {boolean success = fileSystem.delete(new Path(cacheValue.path), true);if (!success) {@@ -438,11 +423,9 @@ public class HdfsDirectoryFactory extends CachingDirectoryFactory implements Sol@Overridepublic long size(String path) throws IOException {Path hdfsDirPath = new Path(path);- FileSystem fileSystem = null;+ FileSystem fileSystem = getCachedFileSystem(path);try {- fileSystem = FileSystem.newInstance(hdfsDirPath.toUri(), getConf());- long size = fileSystem.getContentSummary(hdfsDirPath).getLength();- return size;+ return fileSystem.getContentSummary(hdfsDirPath).getLength();} catch (IOException e) {LOG.error("Error checking if hdfs path exists", e);throw new SolrException(ErrorCode.SERVER_ERROR, "Error checking if hdfs path exists", e);@@ -450,7 +433,16 @@ public class HdfsDirectoryFactory extends CachingDirectoryFactory implements SolIOUtils.closeQuietly(fileSystem);}}-++ private FileSystem getCachedFileSystem(String path) {+ try {+ // no need to close the fs, the cache will do it+ return tmpFsCache.get(path, () -> FileSystem.get(new Path(path).toUri(), getConf()));+ } catch (ExecutionException e) {+ throw new RuntimeException(e);+ }+ }+public String getConfDir() {return confDir;}@@ -515,13 +507,7 @@ public class HdfsDirectoryFactory extends CachingDirectoryFactory implements Sol// Get the FileSystem objectfinal Path dataDirPath = new Path(dataDir);- final Configuration conf = getConf();- FileSystem fileSystem = null;- try {- fileSystem = tmpFsCache.get(dataDir, () -> FileSystem.get(dataDirPath.toUri(), conf));- } catch (ExecutionException e) {- throw new RuntimeException(e);- }+ FileSystem fileSystem = getCachedFileSystem(dataDir);boolean pathExists = false;try {