[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.
This commit is contained in:
Simon Willnauer 2014-11-18 14:02:41 +01:00
parent c6c709eda2
commit 119aa4af20
1 changed files with 12 additions and 1 deletions

View File

@ -20,6 +20,7 @@
package org.elasticsearch.index.store; package org.elasticsearch.index.store;
import org.apache.lucene.store.Directory; import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FilterDirectory;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.index.shard.AbstractIndexShardComponent; import org.elasticsearch.index.shard.AbstractIndexShardComponent;
@ -43,8 +44,18 @@ public abstract class DirectoryService extends AbstractIndexShardComponent {
/** /**
* Creates a new Directory from the given distributor. * Creates a new Directory from the given distributor.
* The default implementation returns a new {@link org.elasticsearch.index.store.DistributorDirectory} * 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); return new DistributorDirectory(distributor);
} }
} }