Skip to content

Commit

Permalink
[elasticsearch,elasticsearch5] Add Elasticsearch 5.x binding
Browse files Browse the repository at this point in the history
  • Loading branch information
risdenk committed Feb 8, 2017
1 parent 68fbbb0 commit c3cfc98
Show file tree
Hide file tree
Showing 13 changed files with 883 additions and 41 deletions.
3 changes: 2 additions & 1 deletion bin/bindings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ aerospike:com.yahoo.ycsb.db.AerospikeClient
asynchbase:com.yahoo.ycsb.db.AsyncHBaseClient
arangodb:com.yahoo.ycsb.db.ArangoDBClient
arangodb3:com.yahoo.ycsb.db.arangodb.ArangoDB3Client
azuredocumentdb:com.yahoo.ycsb.db.azuredocumentdb.AzureDocumentDBClient
azuretablestorage:com.yahoo.ycsb.db.azuretablestorage.AzureClient
basic:com.yahoo.ycsb.BasicDB
cassandra-cql:com.yahoo.ycsb.db.CassandraCQLClient
cassandra2-cql:com.yahoo.ycsb.db.CassandraCQLClient
couchbase:com.yahoo.ycsb.db.CouchbaseClient
couchbase2:com.yahoo.ycsb.db.couchbase2.Couchbase2Client
azuredocumentdb:com.yahoo.ycsb.db.azuredocumentdb.AzureDocumentDBClient
dynamodb:com.yahoo.ycsb.db.DynamoDBClient
elasticsearch:com.yahoo.ycsb.db.ElasticsearchClient
elasticsearch5:com.yahoo.ycsb.db.elasticsearch5.ElasticsearchClient
geode:com.yahoo.ycsb.db.GeodeClient
googlebigtable:com.yahoo.ycsb.db.GoogleBigtableClient
googledatastore:com.yahoo.ycsb.db.GoogleDatastoreClient
Expand Down
5 changes: 5 additions & 0 deletions distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ LICENSE file.
<artifactId>elasticsearch-binding</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.yahoo.ycsb</groupId>
<artifactId>elasticsearch5-binding</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.yahoo.ycsb</groupId>
<artifactId>geode-binding</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2012 YCSB contributors. All rights reserved.
* Copyright (c) 2012-2017 YCSB contributors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You
Expand Down Expand Up @@ -30,7 +30,6 @@
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;

Expand All @@ -44,15 +43,15 @@
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";
protected final static String MOCK_KEY0 = "0";
protected final static String MOCK_KEY1 = "1";
protected final static String MOCK_KEY2 = "2";
private final static ElasticsearchClient instance = new ElasticsearchClient();
private final static HashMap<String, ByteIterator> MOCK_DATA;
private final static String MOCK_TABLE = "MOCK_TABLE";
private final static String MOCK_KEY0 = "0";
private final static String MOCK_KEY1 = "1";
private final static String MOCK_KEY2 = "2";

static {
MOCK_DATA = new HashMap<String, ByteIterator>(10);
MOCK_DATA = new HashMap<>(10);
for (int i = 1; i <= 10; i++) {
MOCK_DATA.put("field" + i, new StringByteIterator("value" + i));
}
Expand Down Expand Up @@ -88,7 +87,6 @@ public void tearDown() {
*/
@Test
public void testInsert() {
System.out.println("insert");
Status result = instance.insert(MOCK_TABLE, MOCK_KEY0, MOCK_DATA);
assertEquals(Status.OK, result);
}
Expand All @@ -98,7 +96,6 @@ public void testInsert() {
*/
@Test
public void testDelete() {
System.out.println("delete");
Status result = instance.delete(MOCK_TABLE, MOCK_KEY1);
assertEquals(Status.OK, result);
}
Expand All @@ -108,9 +105,8 @@ public void testDelete() {
*/
@Test
public void testRead() {
System.out.println("read");
Set<String> fields = MOCK_DATA.keySet();
HashMap<String, ByteIterator> resultParam = new HashMap<String, ByteIterator>(10);
HashMap<String, ByteIterator> resultParam = new HashMap<>(10);
Status result = instance.read(MOCK_TABLE, MOCK_KEY1, fields, resultParam);
assertEquals(Status.OK, result);
}
Expand All @@ -120,9 +116,8 @@ public void testRead() {
*/
@Test
public void testUpdate() {
System.out.println("update");
int i;
HashMap<String, ByteIterator> newValues = new HashMap<String, ByteIterator>(10);
HashMap<String, ByteIterator> newValues = new HashMap<>(10);

for (i = 1; i <= 10; i++) {
newValues.put("field" + i, new StringByteIterator("newvalue" + i));
Expand All @@ -132,24 +127,22 @@ public void testUpdate() {
assertEquals(Status.OK, result);

//validate that the values changed
HashMap<String, ByteIterator> resultParam = new HashMap<String, ByteIterator>(10);
HashMap<String, ByteIterator> resultParam = new HashMap<>(10);
instance.read(MOCK_TABLE, MOCK_KEY1, MOCK_DATA.keySet(), resultParam);

for (i = 1; i <= 10; i++) {
assertEquals("newvalue" + i, resultParam.get("field" + i).toString());
}

}

/**
* Test of scan method, of class ElasticsearchClient.
*/
@Test
public void testScan() {
System.out.println("scan");
int recordcount = 10;
Set<String> fields = MOCK_DATA.keySet();
Vector<HashMap<String, ByteIterator>> resultParam = new Vector<HashMap<String, ByteIterator>>(10);
Vector<HashMap<String, ByteIterator>> resultParam = new Vector<>(10);
Status result = instance.scan(MOCK_TABLE, MOCK_KEY1, recordcount, fields, resultParam);
assertEquals(Status.OK, result);
}
Expand Down
94 changes: 94 additions & 0 deletions elasticsearch5/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<!--
Copyright (c) 2017 YCSB contributors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you
may not use this file except in compliance with the License. You
may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied. See the License for the specific language governing
permissions and limitations under the License. See accompanying
LICENSE file.
-->

## Quick Start

This section describes how to run YCSB on Elasticsearch 5.x running locally.

### 1. Set Up YCSB

Clone the YCSB git repository and compile:

git clone git://github.com/brianfrankcooper/YCSB.git
cd YCSB
mvn clean package

### 2. Run YCSB

Now you are ready to run! First, load the data:

./bin/ycsb load elasticsearch5 -s -P workloads/workloada -p path.home=<path>

Then, run the workload:

./bin/ycsb run elasticsearch5 -s -P workloads/workloada -p path.home=<path>

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.

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 \
-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:

cluster.name=es.ycsb.cluster
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)

### Custom Configuration
If you wish to customize the settings used to create the Elasticsearch node
you can created a new property file that contains your desired Elasticsearch
node settings and pass it in via the parameter to 'bin/ycsb' script. Note that
the default properties will be kept if you don't explicitly overwrite them.

Assuming that we have a properties file named "myproperties.data" that contains
custom Elasticsearch node configuration you can execute the following to
pass it into the Elasticsearch client:


./bin/ycsb run elasticsearch5 -P workloads/workloada -P myproperties.data -s

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

es.hosts.list=(\w+:\d+)+

(a comma-separated list of host/port pairs) to change this.
78 changes: 78 additions & 0 deletions elasticsearch5/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2017 YCSB contributors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you
may not use this file except in compliance with the License. You
may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied. See the License for the specific language governing
permissions and limitations under the License. See accompanying
LICENSE file.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.yahoo.ycsb</groupId>
<artifactId>binding-parent</artifactId>
<version>0.13.0-SNAPSHOT</version>
<relativePath>../binding-parent</relativePath>
</parent>

<properties>
<!-- Skip tests by default. will be activated by jdk8 profile -->
<skipTests>true</skipTests>
</properties>

<artifactId>elasticsearch5-binding</artifactId>
<name>Elasticsearch 5.x Binding</name>
<packaging>jar</packaging>
<dependencies>
<dependency>
<!-- jna is supported in ES and will be used when provided
otherwise a fallback is used -->
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>com.yahoo.ycsb</groupId>
<artifactId>core</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>${elasticsearch5-version}</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>rest</artifactId>
<version>${elasticsearch5-version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Loading

0 comments on commit c3cfc98

Please sign in to comment.