Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Redis SSL #1706

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions bin/ycsb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright (c) 2012 - 2020 YCSB contributors. All rights reserved.
#
Expand Down Expand Up @@ -28,7 +28,7 @@ try:
mod = __import__('argparse')
import argparse
except ImportError:
print >> sys.stderr, '[ERROR] argparse not found. Try installing it via "pip".'
print('[ERROR] argparse not found. Try installing it via "pip".', file=sys.stderr)
exit(1)

BASE_URL = "https://github.com/brianfrankcooper/YCSB/tree/master/"
Expand Down Expand Up @@ -93,6 +93,7 @@ DATABASES = {
"postgrenosql" : "site.ycsb.postgrenosql.PostgreNoSQLDBClient",
"rados" : "site.ycsb.db.RadosClient",
"redis" : "site.ycsb.db.RedisClient",
"redislettuce" : "site.ycsb.db.RedisLettuceClient",
"rest" : "site.ycsb.webservice.rest.RestClient",
"riak" : "site.ycsb.db.riak.RiakKVClient",
"rocksdb" : "site.ycsb.db.rocksdb.RocksDBClient",
Expand All @@ -116,27 +117,27 @@ OPTIONS = {
}

def usage():
output = io.BytesIO()
print >> output, "%s command database [options]" % sys.argv[0]
output = io.StringIO()
print("%s command database [options]" % sys.argv[0], file=output)

print >> output, "\nCommands:"
print("\nCommands:", file=output)
for command in sorted(COMMANDS.keys()):
print >> output, " %s %s" % (command.ljust(14),
COMMANDS[command]["description"])
print(" %s %s" % (command.ljust(14),
COMMANDS[command]["description"]), file=output)

print >> output, "\nDatabases:"
print("\nDatabases:", file=output)
for db in sorted(DATABASES.keys()):
print >> output, " %s %s" % (db.ljust(14), BASE_URL +
db.split("-")[0])
print(" %s %s" % (db.ljust(14), BASE_URL +
db.split("-")[0]), file=output)

print >> output, "\nOptions:"
print("\nOptions:", file=output)
for option in sorted(OPTIONS.keys()):
print >> output, " %s %s" % (option.ljust(14), OPTIONS[option])
print(" %s %s" % (option.ljust(14), OPTIONS[option]), file=output)

print >> output, """\nWorkload Files:
print("""\nWorkload Files:
There are various predefined workloads under workloads/ directory.
See https://github.com/brianfrankcooper/YCSB/wiki/Core-Properties
for the list of workload properties."""
for the list of workload properties.""", file=output)

return output.getvalue()

Expand Down Expand Up @@ -164,7 +165,7 @@ def check_output(*popenargs, **kwargs):
"""
if 'stdout' in kwargs:
raise ValueError('stdout argument not allowed, it will be overridden.')
process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs)
process = subprocess.Popen(stdout=subprocess.PIPE, text=True, *popenargs, **kwargs)
output, unused_err = process.communicate()
retcode = process.poll()
if retcode:
Expand All @@ -177,13 +178,13 @@ def check_output(*popenargs, **kwargs):
return output

def debug(message):
print >> sys.stderr, "[DEBUG] ", message
print("[DEBUG] ", message, file=sys.stderr)

def warn(message):
print >> sys.stderr, "[WARN] ", message
print("[WARN] ", message, file=sys.stderr)

def error(message):
print >> sys.stderr, "[ERROR] ", message
print("[ERROR] ", message, file=sys.stderr)

def find_jars(dir, glob='*.jar'):
jars = []
Expand Down Expand Up @@ -220,7 +221,7 @@ def get_classpath_from_maven(module):
# the last module will be the datastore binding
line = [x for x in mvn_output.splitlines() if x.startswith("classpath=")][-1:]
return line[0][len("classpath="):]
except subprocess.CalledProcessError, err:
except subprocess.CalledProcessError as err:
error("Attempting to generate a classpath from Maven failed "
"with return code '" + str(err.returncode) + "'. The output from "
"Maven follows, try running "
Expand Down Expand Up @@ -311,7 +312,7 @@ def main():
main_classname, "-db", db_classname] + remaining)
if command:
ycsb_command.append(command)
print >> sys.stderr, " ".join(ycsb_command)
print(" ".join(ycsb_command), file=sys.stderr)
try:
return subprocess.call(ycsb_command)
except OSError as e:
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/site/ycsb/Status.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public boolean isOk() {

public static final Status OK = new Status("OK", "The operation completed successfully.");
public static final Status ERROR = new Status("ERROR", "The operation failed.");
public static final Status TIMEOUT = new Status("TIMEOUT", "The operation timeout");
public static final Status NOT_FOUND = new Status("NOT_FOUND", "The requested record was not found.");
public static final Status NOT_IMPLEMENTED = new Status("NOT_IMPLEMENTED", "The operation is not " +
"implemented for the current binding.");
Expand Down
5 changes: 4 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ LICENSE file.
<openjpa.jdbc.version>2.1.1</openjpa.jdbc.version>
<orientdb.version>2.2.37</orientdb.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<redis.version>2.9.0</redis.version>
<redis.version>5.1.2</redis.version>
<redis.lettuce.version>6.2.4.RELEASE</redis.lettuce.version>
<commons.pool2.version>2.11.1</commons.pool2.version>
<riak.version>2.0.5</riak.version>
<rocksdb.version>6.2.2</rocksdb.version>
<s3.version>1.10.20</s3.version>
Expand Down Expand Up @@ -192,6 +194,7 @@ LICENSE file.
<module>postgrenosql</module>
<module>rados</module>
<module>redis</module>
<module>redislettuce</module>
<module>rest</module>
<module>riak</module>
<module>rocksdb</module>
Expand Down
3 changes: 3 additions & 0 deletions redis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ Set host, port, password, and cluster mode in the workload you plan to run.
- `redis.cluster`
* Set the cluster parameter to `true` if redis cluster mode is enabled.
* Default is `false`.
- `redis.ssl`
* Set the ssl parameter to `true` if redis instance has enabled SSL.
* Default is `false`.

Or, you can set configs with the shell command, EG:

Expand Down
43 changes: 24 additions & 19 deletions redis/src/main/java/site/ycsb/db/RedisClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@
import site.ycsb.DBException;
import site.ycsb.Status;
import site.ycsb.StringByteIterator;
import redis.clients.jedis.BasicCommands;
import redis.clients.jedis.DefaultJedisClientConfig;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisCommands;
import redis.clients.jedis.commands.JedisCommands;
import redis.clients.jedis.Protocol;
import redis.clients.jedis.DefaultJedisClientConfig.Builder;

import java.io.Closeable;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.HashSet;
Expand All @@ -61,6 +60,7 @@ public class RedisClient extends DB {
public static final String PASSWORD_PROPERTY = "redis.password";
public static final String CLUSTER_PROPERTY = "redis.cluster";
public static final String TIMEOUT_PROPERTY = "redis.timeout";
public static final String SSL_PROPERTY = "redis.ssl";

public static final String INDEX_KEY = "_indices";

Expand All @@ -77,30 +77,36 @@ public void init() throws DBException {
String host = props.getProperty(HOST_PROPERTY);

boolean clusterEnabled = Boolean.parseBoolean(props.getProperty(CLUSTER_PROPERTY));
boolean sslEnabled = Boolean.parseBoolean(props.getProperty(SSL_PROPERTY));
String password = props.getProperty(PASSWORD_PROPERTY);
if (clusterEnabled) {
Set<HostAndPort> jedisClusterNodes = new HashSet<>();
jedisClusterNodes.add(new HostAndPort(host, port));
jedis = new JedisCluster(jedisClusterNodes);
Builder builder = DefaultJedisClientConfig.builder().ssl(sslEnabled);
if (password != null) {
builder = builder.password(password);
}
jedis = new JedisCluster(jedisClusterNodes, builder.build());
} else {
String redisTimeout = props.getProperty(TIMEOUT_PROPERTY);
if (redisTimeout != null){
jedis = new Jedis(host, port, Integer.parseInt(redisTimeout));
Jedis jedisServer;
if (redisTimeout != null) {
jedisServer = new Jedis(host, port, Integer.parseInt(redisTimeout), sslEnabled);
} else {
jedis = new Jedis(host, port);
jedisServer = new Jedis(host, port, sslEnabled);
}
jedisServer.connect();
jedis = jedisServer;
if (password != null) {
jedisServer.auth(password);
}
((Jedis) jedis).connect();
}

String password = props.getProperty(PASSWORD_PROPERTY);
if (password != null) {
((BasicCommands) jedis).auth(password);
}
}

public void cleanup() throws DBException {
try {
((Closeable) jedis).close();
} catch (IOException e) {
((AutoCloseable) jedis).close();
} catch (Exception e) {
throw new DBException("Closing connection failed.");
}
}
Expand All @@ -123,8 +129,7 @@ public Status read(String table, String key, Set<String> fields,
if (fields == null) {
StringByteIterator.putAllAsByteIterators(result, jedis.hgetAll(key));
} else {
String[] fieldArray =
(String[]) fields.toArray(new String[fields.size()]);
String[] fieldArray = (String[]) fields.toArray(new String[fields.size()]);
List<String> values = jedis.hmget(key, fieldArray);

Iterator<String> fieldIterator = fields.iterator();
Expand Down Expand Up @@ -166,7 +171,7 @@ public Status update(String table, String key,
@Override
public Status scan(String table, String startkey, int recordcount,
Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
Set<String> keys = jedis.zrangeByScore(INDEX_KEY, hash(startkey),
List<String> keys = jedis.zrangeByScore(INDEX_KEY, hash(startkey),
Double.POSITIVE_INFINITY, 0, recordcount);

HashMap<String, ByteIterator> values;
Expand Down
50 changes: 50 additions & 0 deletions redislettuce/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2012 - 2016 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>site.ycsb</groupId>
<artifactId>binding-parent</artifactId>
<version>0.18.0-SNAPSHOT</version>
<relativePath>../binding-parent</relativePath>
</parent>

<artifactId>redislettuce-binding</artifactId>
<name>Redis DB Binding with Lettuce</name>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
<version>${redis.lettuce.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>${commons.pool2.version}</version>
</dependency>
<dependency>
<groupId>site.ycsb</groupId>
<artifactId>core</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Loading