Skip to content
Snippets Groups Projects
Unverified Commit fb1d1ab3 authored by Jason Tedor's avatar Jason Tedor
Browse files

[elasticsearch] Fix and cleanup index creation

This commit fixes an issue with the index creation logic when the
elasticsearch.newdb flag is set to true. Namely, when running in local
mode the index would never exist (since the node always starts with a
clean temporary directory) but with elasticsearch.newdb an attempt would
be made to delete the index which would cause the workload to fail.

This commit also does a cleanup of the index creation logic using an
explicit create index request and passing the index settings along as
part of that index creation.
parent 0171b673
No related branches found
No related tags found
No related merge requests found
......@@ -30,6 +30,7 @@ import com.yahoo.ycsb.Status;
import com.yahoo.ycsb.StringByteIterator;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.Client;
......@@ -94,9 +95,6 @@ public class ElasticsearchClient extends DB {
Builder settings = Settings.settingsBuilder()
.put("node.local", "true")
.put("path.data", System.getProperty("java.io.tmpdir") + "/esdata")
.put("index.mapping._id.indexed", "true")
.put("index.number_of_shards", "1")
.put("index.number_of_replicas", "0")
.put("path.home", System.getProperty("java.io.tmpdir"));
// if properties file contains elasticsearch user defined properties
......@@ -141,20 +139,23 @@ public class ElasticsearchClient extends DB {
client = node.client();
}
//wait for shards to be ready
client.admin().cluster()
.health(new ClusterHealthRequest("lists").waitForActiveShards(1))
.actionGet();
if (newdb) {
final boolean exists =
client.admin().indices()
.exists(Requests.indicesExistsRequest(indexKey)).actionGet()
.isExists();
if (exists && newdb) {
client.admin().indices().prepareDelete(indexKey).execute().actionGet();
client.admin().indices().prepareCreate(indexKey).execute().actionGet();
} else {
boolean exists = client.admin().indices()
.exists(Requests.indicesExistsRequest(indexKey)).actionGet()
.isExists();
if (!exists) {
client.admin().indices().prepareCreate(indexKey).execute().actionGet();
}
}
if (!exists || newdb) {
client.admin().indices().create(
new CreateIndexRequest(indexKey)
.settings(
Settings.builder()
.put("index.number_of_shards", 1)
.put("index.number_of_replicas", 0)
.put("index.mapping._id.indexed", true)
)).actionGet();
client.admin().cluster().health(new ClusterHealthRequest().waitForGreenStatus()).actionGet();
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment