зеркало из https://github.com/Azure/YCSB.git
[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.
This commit is contained in:
Родитель
0171b673fb
Коммит
fb1d1ab3a9
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче