diff --git a/elasticsearch/README.md b/elasticsearch/README.md index 157ccec0c04fe4688da30af531b5fbdc3db4703d..0e863c891628153b98ab2844d0a4320a10cfc075 100644 --- a/elasticsearch/README.md +++ b/elasticsearch/README.md @@ -31,13 +31,28 @@ Clone the YCSB git repository and compile: Now you are ready to run! First, load the data: - ./bin/ycsb load elasticsearch -s -P workloads/workloada + ./bin/ycsb load elasticsearch -s -P workloads/workloada -p path.home=<path> Then, run the workload: - ./bin/ycsb run elasticsearch -s -P workloads/workloada + ./bin/ycsb run elasticsearch -s -P workloads/workloada -p path.home=<path> -For further configuration see below: +Note that the `<path>` specified in each execution should be the same. + +The Elasticsearch 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. + +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 elasticsearch -s -P workloads/workloada -p es.remote=true \ + -p es.hosts.list=<hostname1:port1>,...,<hostnamen:portn>` + +Note that `es.hosts.list` defaults to `localhost:9300`. For further +configuration see below: ### Defaults Configuration The default setting for the Elasticsearch node that is created is as follows: @@ -48,7 +63,7 @@ The default setting for the Elasticsearch node that is created is as follows: es.number_of_replicas=0 es.remote=false es.newdb=false - es.hosts.list=localhost:9200 (only applies if es.remote=true) + es.hosts.list=localhost:9300 (only applies if es.remote=true) ### Custom Configuration If you wish to customize the settings used to create the Elasticsearch node diff --git a/elasticsearch/pom.xml b/elasticsearch/pom.xml index fc028291bbec9b1e0146d99b973cc25d4d268821..7d5671c329c9da7627fff22dd0b19025d68faf71 100644 --- a/elasticsearch/pom.xml +++ b/elasticsearch/pom.xml @@ -29,7 +29,7 @@ LICENSE file. <name>Elasticsearch Binding</name> <packaging>jar</packaging> <properties> - <elasticsearch-version>2.3.2</elasticsearch-version> + <elasticsearch-version>2.3.4</elasticsearch-version> </properties> <dependencies> <dependency> @@ -51,9 +51,9 @@ LICENSE file. <version>${elasticsearch-version}</version> </dependency> <dependency> - <groupId>org.testng</groupId> - <artifactId>testng</artifactId> - <version>6.1.1</version> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.12</version> <scope>test</scope> </dependency> </dependencies> diff --git a/elasticsearch/src/main/java/com/yahoo/ycsb/db/ElasticsearchClient.java b/elasticsearch/src/main/java/com/yahoo/ycsb/db/ElasticsearchClient.java index 6a95d9cefc64c905ebd7d3a6b2c559bf20e5b2f6..76ddee1d2eade0335f34b8977a5c3cd07dcf6cb9 100644 --- a/elasticsearch/src/main/java/com/yahoo/ycsb/db/ElasticsearchClient.java +++ b/elasticsearch/src/main/java/com/yahoo/ycsb/db/ElasticsearchClient.java @@ -82,20 +82,29 @@ public class ElasticsearchClient extends DB { */ @Override public void init() throws DBException { - Properties props = getProperties(); + 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); int numberOfReplicas = parseIntegerProperty(props, "es.number_of_replicas", NUMBER_OF_REPLICAS); - // Check if transport client needs to be used (To connect to multiple - // elasticsearch nodes) - remoteMode = Boolean.parseBoolean(props.getProperty("es.remote", "false")); Boolean newdb = Boolean.parseBoolean(props.getProperty("es.newdb", "false")); Builder settings = Settings.settingsBuilder() .put("cluster.name", DEFAULT_CLUSTER_NAME) .put("node.local", Boolean.toString(!remoteMode)) - .put("path.home", System.getProperty("java.io.tmpdir")); + .put("path.home", pathHome); // if properties file contains elasticsearch user defined properties // add it to the settings file (will overwrite the defaults). diff --git a/elasticsearch/src/test/java/com/yahoo/ycsb/db/ElasticsearchClientTest.java b/elasticsearch/src/test/java/com/yahoo/ycsb/db/ElasticsearchClientTest.java index 69e52ff678f2c29a39fd1e433293f893db2a3e58..d1ad64d187e642cfd2bf2eabc50f853c478b2825 100644 --- a/elasticsearch/src/test/java/com/yahoo/ycsb/db/ElasticsearchClientTest.java +++ b/elasticsearch/src/test/java/com/yahoo/ycsb/db/ElasticsearchClientTest.java @@ -21,25 +21,29 @@ */ package com.yahoo.ycsb.db; -import static org.testng.AssertJUnit.assertEquals; - import com.yahoo.ycsb.ByteIterator; import com.yahoo.ycsb.DBException; import com.yahoo.ycsb.Status; import com.yahoo.ycsb.StringByteIterator; - -import org.testng.annotations.AfterClass; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; import java.util.HashMap; +import java.util.Properties; import java.util.Set; import java.util.Vector; +import static org.junit.Assert.assertEquals; + public class ElasticsearchClientTest { + @ClassRule public final static TemporaryFolder temp = new TemporaryFolder(); protected final static ElasticsearchClient instance = new ElasticsearchClient(); protected final static HashMap<String, ByteIterator> MOCK_DATA; protected final static String MOCK_TABLE = "MOCK_TABLE"; @@ -56,6 +60,9 @@ public class ElasticsearchClientTest { @BeforeClass public static void setUpClass() throws DBException { + final Properties props = new Properties(); + props.put("path.home", temp.getRoot().toString()); + instance.setProperties(props); instance.init(); } @@ -64,13 +71,13 @@ public class ElasticsearchClientTest { instance.cleanup(); } - @BeforeMethod + @Before public void setUp() { instance.insert(MOCK_TABLE, MOCK_KEY1, MOCK_DATA); instance.insert(MOCK_TABLE, MOCK_KEY2, MOCK_DATA); } - @AfterMethod + @After public void tearDown() { instance.delete(MOCK_TABLE, MOCK_KEY1); instance.delete(MOCK_TABLE, MOCK_KEY2);