From 73daff1584581e9210955834921a80346bdfe2a2 Mon Sep 17 00:00:00 2001 From: kimchy Date: Sat, 27 Mar 2010 22:10:56 +0300 Subject: [PATCH] Better exception when failing to create gateway home --- .../index/gateway/fs/FsIndexGateway.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/fs/FsIndexGateway.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/fs/FsIndexGateway.java index 0fce185b0ab..88143037740 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/fs/FsIndexGateway.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/fs/FsIndexGateway.java @@ -25,6 +25,7 @@ import org.elasticsearch.gateway.Gateway; import org.elasticsearch.gateway.fs.FsGateway; import org.elasticsearch.index.AbstractIndexComponent; import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexException; import org.elasticsearch.index.gateway.IndexGateway; import org.elasticsearch.index.gateway.IndexShardGateway; import org.elasticsearch.index.settings.IndexSettings; @@ -64,7 +65,19 @@ public class FsIndexGateway extends AbstractIndexComponent implements IndexGatew indexGatewayHome = new File(location); } this.location = location; - indexGatewayHome.mkdirs(); + + if (!(indexGatewayHome.exists() && indexGatewayHome.isDirectory())) { + boolean result; + for (int i = 0; i < 5; i++) { + result = indexGatewayHome.mkdirs(); + if (result) { + break; + } + } + } + if (!(indexGatewayHome.exists() && indexGatewayHome.isDirectory())) { + throw new IndexException(index, "Failed to create index gateway at [" + indexGatewayHome + "]"); + } } @Override public Class shardGatewayClass() {