From 119aa4af2084e3c80818b6a256efede9f77cd208 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Tue, 18 Nov 2014 14:02:41 +0100 Subject: [PATCH] [STORE] Use DistributorDirectory only if there are more than one data direcotry We don't need the overhead of DistributorDirectory if there is only a single directory in the distributor. --- .../elasticsearch/index/store/DirectoryService.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/elasticsearch/index/store/DirectoryService.java b/src/main/java/org/elasticsearch/index/store/DirectoryService.java index 7278ecf129f..81d8910ed4c 100644 --- a/src/main/java/org/elasticsearch/index/store/DirectoryService.java +++ b/src/main/java/org/elasticsearch/index/store/DirectoryService.java @@ -20,6 +20,7 @@ package org.elasticsearch.index.store; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.FilterDirectory; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.index.shard.AbstractIndexShardComponent; @@ -43,8 +44,18 @@ public abstract class DirectoryService extends AbstractIndexShardComponent { /** * Creates a new Directory from the given distributor. * The default implementation returns a new {@link org.elasticsearch.index.store.DistributorDirectory} + * if there is more than one data path in the distributor. */ - public Directory newFromDistributor(Distributor distributor) throws IOException { + public Directory newFromDistributor(final Distributor distributor) throws IOException { + if (distributor.all().length == 1) { + // use filter dir for consistent toString methods + return new FilterDirectory(distributor.primary()) { + @Override + public String toString() { + return distributor.toString(); + } + }; + } return new DistributorDirectory(distributor); } } \ No newline at end of file