From d66e856a5daa969432a929eba58a7125267af6d6 Mon Sep 17 00:00:00 2001 From: Jason Tedor <jason@tedor.me> Date: Mon, 7 Aug 2017 21:38:56 +0900 Subject: [PATCH] Elasticsearch 5: Remove support for embedded node Upstream Elasticsearch does not support embedded nodes as of Elasticsearch 5. This commit removes the usage of embedded nodes within YCSB. --- elasticsearch5/README.md | 20 ++--- .../elasticsearch5/ElasticsearchClient.java | 88 ++++++------------- 2 files changed, 31 insertions(+), 77 deletions(-) diff --git a/elasticsearch5/README.md b/elasticsearch5/README.md index b87fc874..74646ae6 100644 --- a/elasticsearch5/README.md +++ b/elasticsearch5/README.md @@ -39,16 +39,11 @@ Then, run the workload: Note that the `<path>` specified in each execution should be the same. -The Elasticsearch 5 binding has two modes of operation, embedded mode and remote -mode. In embedded mode, the client creates an embedded instance of -Elasticsearch that uses the specified `<path>` to persist data between -executions. +The Elasticsearch 5 binding requires a standalone instance of Elasticsearch. +You must specify a hosts list for the transport client to connect to via +`-p es.hosts.list=<hostname1:port1>,...,<hostnamen:portn>`: -In remote mode, the client will hit a standalone instance of Elasticsearch. To -use remote mode, add the flags `-p es.remote=true` and specify a hosts list via -`-p es.hosts.list=<hostname1:port1>,...,<hostnamen:portn>`. - - ./bin/ycsb run elasticsearch5 -s -P workloads/workloada -p es.remote=true \ + ./bin/ycsb run elasticsearch5 -s -P workloads/workloada \ -p es.hosts.list=<hostname1:port1>,...,<hostnamen:portn>` Note that `es.hosts.list` defaults to `localhost:9300`. For further @@ -61,9 +56,8 @@ The default setting for the Elasticsearch node that is created is as follows: es.index.key=es.ycsb es.number_of_shards=1 es.number_of_replicas=0 - es.remote=false es.newdb=false - es.hosts.list=localhost:9300 (only applies if es.remote=true) + es.hosts.list=localhost:9300 ### Custom Configuration If you wish to customize the settings used to create the Elasticsearch node @@ -82,10 +76,6 @@ If you wish to change the default index name you can set the following property: es.index.key=my_index_key -If you wish to run against a remote cluster you can set the following property: - - es.remote=true - By default this will use localhost:9300 as a seed node to discover the cluster. You can also specify diff --git a/elasticsearch5/src/main/java/com/yahoo/ycsb/db/elasticsearch5/ElasticsearchClient.java b/elasticsearch5/src/main/java/com/yahoo/ycsb/db/elasticsearch5/ElasticsearchClient.java index 52c41776..386ba7c8 100644 --- a/elasticsearch5/src/main/java/com/yahoo/ycsb/db/elasticsearch5/ElasticsearchClient.java +++ b/elasticsearch5/src/main/java/com/yahoo/ycsb/db/elasticsearch5/ElasticsearchClient.java @@ -17,25 +17,25 @@ package com.yahoo.ycsb.db.elasticsearch5; -import com.yahoo.ycsb.*; -import org.apache.http.HttpHost; +import com.yahoo.ycsb.ByteIterator; +import com.yahoo.ycsb.DB; +import com.yahoo.ycsb.DBException; +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.delete.DeleteResponse; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.client.Client; import org.elasticsearch.client.Requests; -import org.elasticsearch.client.RestClient; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.node.Node; -import org.elasticsearch.node.NodeValidationException; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.transport.client.PreBuiltTransportClient; -import java.io.IOException; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.HashMap; @@ -58,12 +58,10 @@ public class ElasticsearchClient extends DB { private static final String DEFAULT_REMOTE_HOST = "localhost:9300"; private static final int NUMBER_OF_SHARDS = 1; private static final int NUMBER_OF_REPLICAS = 0; - private Node node; private Client client; private String indexKey; - private Boolean remoteMode; - /** + * * Initialize any state for this DB. Called once per DB instance; there is one * DB instance per client thread. */ @@ -71,16 +69,8 @@ public class ElasticsearchClient extends DB { public void init() throws DBException { final Properties props = getProperties(); - // Check if transport client needs to be used (To connect to multiple elasticsearch nodes) - remoteMode = Boolean.parseBoolean(props.getProperty("es.remote", "false")); - final String pathHome = props.getProperty("path.home"); - // when running in embedded mode, require path.home - if (!remoteMode && (pathHome == null || pathHome.isEmpty())) { - throw new IllegalArgumentException("path.home must be specified when running in embedded mode"); - } - this.indexKey = props.getProperty("es.index.key", DEFAULT_INDEX_KEY); int numberOfShards = parseIntegerProperty(props, "es.number_of_shards", NUMBER_OF_SHARDS); @@ -105,46 +95,29 @@ public class ElasticsearchClient extends DB { final String clusterName = settings.get("cluster.name"); System.err.println("Elasticsearch starting node = " + clusterName); System.err.println("Elasticsearch node path.home = " + settings.get("path.home")); - System.err.println("Elasticsearch Remote Mode = " + remoteMode); - // Remote mode support for connecting to remote elasticsearch cluster - if(remoteMode) { - RestClient restClient = RestClient.builder( - new HttpHost("localhost", 9200, "http")).build(); - } - if (remoteMode) { - settings.put("client.transport.sniff", true) - .put("client.transport.ignore_cluster_name", false) - .put("client.transport.ping_timeout", "30s") - .put("client.transport.nodes_sampler_interval", "30s"); - // Default it to localhost:9300 - String[] nodeList = props.getProperty("es.hosts.list", DEFAULT_REMOTE_HOST).split(","); - System.out.println("Elasticsearch Remote Hosts = " + props.getProperty("es.hosts.list", DEFAULT_REMOTE_HOST)); - TransportClient tClient = new PreBuiltTransportClient(settings.build()); - for (String h : nodeList) { - String[] nodes = h.split(":"); - try { - tClient.addTransportAddress(new InetSocketTransportAddress( - InetAddress.getByName(nodes[0]), - Integer.parseInt(nodes[1]) - )); - } catch (NumberFormatException e) { - throw new IllegalArgumentException("Unable to parse port number.", e); - } catch (UnknownHostException e) { - throw new IllegalArgumentException("Unable to Identify host.", e); - } - } - client = tClient; - } else { // Start node only if transport client mode is disabled - settings.put("transport.type", "local"); - settings.put("http.enabled", "false"); - node = new Node(settings.build()); + + settings.put("client.transport.sniff", true) + .put("client.transport.ignore_cluster_name", false) + .put("client.transport.ping_timeout", "30s") + .put("client.transport.nodes_sampler_interval", "30s"); + // Default it to localhost:9300 + String[] nodeList = props.getProperty("es.hosts.list", DEFAULT_REMOTE_HOST).split(","); + System.out.println("Elasticsearch Remote Hosts = " + props.getProperty("es.hosts.list", DEFAULT_REMOTE_HOST)); + TransportClient tClient = new PreBuiltTransportClient(settings.build()); + for (String h : nodeList) { + String[] nodes = h.split(":"); try { - node.start(); - } catch (NodeValidationException e) { - throw new DBException(e); + tClient.addTransportAddress(new InetSocketTransportAddress( + InetAddress.getByName(nodes[0]), + Integer.parseInt(nodes[1]) + )); + } catch (NumberFormatException e) { + throw new IllegalArgumentException("Unable to parse port number.", e); + } catch (UnknownHostException e) { + throw new IllegalArgumentException("Unable to Identify host.", e); } - client = node.client(); } + client = tClient; final boolean exists = client.admin().indices() @@ -176,15 +149,6 @@ public class ElasticsearchClient extends DB { client.close(); client = null; } - - if (!remoteMode && node != null && !node.isClosed()) { - try { - node.close(); - node = null; - } catch (IOException e) { - throw new DBException(e); - } - } } @Override -- GitLab