From e2861bd7be0e9534d1145fab138edb577ee1723d Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Thu, 23 Apr 2015 15:32:00 -0400 Subject: [PATCH] ensure we only pull system filestores once time --- .../org/elasticsearch/env/Environment.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/elasticsearch/env/Environment.java b/src/main/java/org/elasticsearch/env/Environment.java index dab2d22f3f3..b19407cf262 100644 --- a/src/main/java/org/elasticsearch/env/Environment.java +++ b/src/main/java/org/elasticsearch/env/Environment.java @@ -58,7 +58,20 @@ public class Environment { private final Path logsFile; /** List of filestores on the system */ - private final FileStore[] fileStores; + private static final FileStore[] fileStores; + + /** + * We have to do this in clinit instead of init, because ES code is pretty messy, + * and makes these environments, throws them away, makes them again, etc. + */ + static { + // gather information about filesystems + ArrayList allStores = new ArrayList<>(); + for (FileStore store : PathUtils.getDefaultFileSystem().getFileStores()) { + allStores.add(new ESFileStore(store)); + } + fileStores = allStores.toArray(new ESFileStore[allStores.size()]); + } public Environment() { this(EMPTY_SETTINGS); @@ -109,13 +122,6 @@ public class Environment { } else { logsFile = homeFile.resolve("logs"); } - - // gather information about filesystems - ArrayList allStores = new ArrayList<>(); - for (FileStore store : PathUtils.getDefaultFileSystem().getFileStores()) { - allStores.add(new ESFileStore(store)); - } - fileStores = allStores.toArray(new ESFileStore[allStores.size()]); } /**