From f8072b92a005e37c0a052922df956f2be16a1668 Mon Sep 17 00:00:00 2001 From: Jason Tedor <jason@tedor.me> Date: Tue, 12 Jul 2016 08:25:48 -0400 Subject: [PATCH] [elasticsearch] require path.home in embedded mode Today when running the Elasticsearch binding in embedded mode, a temporary directory is used. This can be confusing for running usual load-then-run style workflows because the temporary directory will not be the same between runs. Instead, we should just require a directory when running in embedded mode and this commit makes this the case. --- .../yahoo/ycsb/db/ElasticsearchClient.java | 19 ++++++++++++++----- .../ycsb/db/ElasticsearchClientTest.java | 8 ++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) 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 6a95d9ce..76ddee1d 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 3912c221..d1ad64d1 100644 --- a/elasticsearch/src/test/java/com/yahoo/ycsb/db/ElasticsearchClientTest.java +++ b/elasticsearch/src/test/java/com/yahoo/ycsb/db/ElasticsearchClientTest.java @@ -29,9 +29,13 @@ 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; @@ -39,6 +43,7 @@ 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"; @@ -55,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(); } -- GitLab