Skip to content
Snippets Groups Projects
Commit 9520ff23 authored by Sean Busbey's avatar Sean Busbey
Browse files

Merge pull request #493 from allanbank/nosqldb-cleanup

Nosqldb re-added to the build and checkstyle cleanup
parents 808152d4 89d3de0e
No related branches found
No related tags found
No related merge requests found
...@@ -124,6 +124,11 @@ LICENSE file. ...@@ -124,6 +124,11 @@ LICENSE file.
<artifactId>mongodb-binding</artifactId> <artifactId>mongodb-binding</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>com.yahoo.ycsb</groupId>
<artifactId>nosqldb-binding</artifactId>
<version>${project.version}</version>
</dependency>
<dependency> <dependency>
<groupId>com.yahoo.ycsb</groupId> <groupId>com.yahoo.ycsb</groupId>
<artifactId>orientdb-binding</artifactId> <artifactId>orientdb-binding</artifactId>
......
...@@ -27,12 +27,13 @@ LICENSE file. ...@@ -27,12 +27,13 @@ LICENSE file.
<artifactId>nosqldb-binding</artifactId> <artifactId>nosqldb-binding</artifactId>
<name>Oracle NoSQL Database Binding</name> <name>Oracle NoSQL Database Binding</name>
<packaging>jar</packaging>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.oracle</groupId> <groupId>com.oracle.kv</groupId>
<artifactId>kvclient</artifactId> <artifactId>oracle-nosql-client</artifactId>
<version>1.2.123</version> <version>3.0.5</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.yahoo.ycsb</groupId> <groupId>com.yahoo.ycsb</groupId>
...@@ -41,4 +42,28 @@ LICENSE file. ...@@ -41,4 +42,28 @@ LICENSE file.
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.15</version>
<configuration>
<consoleOutput>true</consoleOutput>
<configLocation>../checkstyle.xml</configLocation>
<failOnViolation>true</failOnViolation>
<failsOnError>true</failsOnError>
</configuration>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<goals>
<goal>checkstyle</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project> </project>
...@@ -42,197 +42,209 @@ import com.yahoo.ycsb.ByteArrayByteIterator; ...@@ -42,197 +42,209 @@ import com.yahoo.ycsb.ByteArrayByteIterator;
import com.yahoo.ycsb.ByteIterator; import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.DB; import com.yahoo.ycsb.DB;
import com.yahoo.ycsb.DBException; import com.yahoo.ycsb.DBException;
import com.yahoo.ycsb.Status;
/** /**
* A database interface layer for Oracle NoSQL Database. * A database interface layer for Oracle NoSQL Database.
*/ */
public class NoSqlDbClient extends DB { public class NoSqlDbClient extends DB {
public static final int OK = 0; private KVStore store;
public static final int ERROR = -1;
private int getPropertyInt(Properties properties, String key,
KVStore store; int defaultValue) throws DBException {
String p = properties.getProperty(key);
private int getPropertyInt(Properties properties, String key, int defaultValue) throws DBException { int i = defaultValue;
String p = properties.getProperty(key); if (p != null) {
int i = defaultValue; try {
if (p != null) { i = Integer.parseInt(p);
try { } catch (NumberFormatException e) {
i = Integer.parseInt(p); throw new DBException("Illegal number format in " + key + " property");
} catch (NumberFormatException e) { }
throw new DBException("Illegal number format in " + key + " property"); }
} return i;
} }
return i;
} @Override
public void init() throws DBException {
@Override Properties properties = getProperties();
public void init() throws DBException {
Properties properties = getProperties(); /* Mandatory properties */
String storeName = properties.getProperty("storeName", "kvstore");
/* Mandatory properties */ String[] helperHosts =
String storeName = properties.getProperty("storeName", "kvstore"); properties.getProperty("helperHost", "localhost:5000").split(",");
String[] helperHosts = properties.getProperty("helperHost", "localhost:5000").split(",");
KVStoreConfig config = new KVStoreConfig(storeName, helperHosts);
KVStoreConfig config = new KVStoreConfig(storeName, helperHosts);
/* Optional properties */
/* Optional properties */ String p;
String p;
p = properties.getProperty("consistency");
p = properties.getProperty("consistency"); if (p != null) {
if (p != null) { if (p.equalsIgnoreCase("ABSOLUTE")) {
if (p.equalsIgnoreCase("ABSOLUTE")) { config.setConsistency(Consistency.ABSOLUTE);
config.setConsistency(Consistency.ABSOLUTE); } else if (p.equalsIgnoreCase("NONE_REQUIRED")) {
} else if (p.equalsIgnoreCase("NONE_REQUIRED")) { config.setConsistency(Consistency.NONE_REQUIRED);
config.setConsistency(Consistency.NONE_REQUIRED); } else {
} else { throw new DBException("Illegal value in consistency property");
throw new DBException("Illegal value in consistency property"); }
} }
}
p = properties.getProperty("durability");
p = properties.getProperty("durability"); if (p != null) {
if (p != null) { if (p.equalsIgnoreCase("COMMIT_NO_SYNC")) {
if (p.equalsIgnoreCase("COMMIT_NO_SYNC")) { config.setDurability(Durability.COMMIT_NO_SYNC);
config.setDurability(Durability.COMMIT_NO_SYNC); } else if (p.equalsIgnoreCase("COMMIT_SYNC")) {
} else if (p.equalsIgnoreCase("COMMIT_SYNC")) { config.setDurability(Durability.COMMIT_SYNC);
config.setDurability(Durability.COMMIT_SYNC); } else if (p.equalsIgnoreCase("COMMIT_WRITE_NO_SYNC")) {
} else if (p.equalsIgnoreCase("COMMIT_WRITE_NO_SYNC")) { config.setDurability(Durability.COMMIT_WRITE_NO_SYNC);
config.setDurability(Durability.COMMIT_WRITE_NO_SYNC); } else {
} else { throw new DBException("Illegal value in durability property");
throw new DBException("Illegal value in durability property"); }
} }
}
int maxActiveRequests =
int maxActiveRequests = getPropertyInt(properties, getPropertyInt(properties, "requestLimit.maxActiveRequests",
"requestLimit.maxActiveRequests", RequestLimitConfig.DEFAULT_MAX_ACTIVE_REQUESTS); RequestLimitConfig.DEFAULT_MAX_ACTIVE_REQUESTS);
int requestThresholdPercent = getPropertyInt(properties, int requestThresholdPercent =
"requestLimit.requestThresholdPercent", RequestLimitConfig.DEFAULT_REQUEST_THRESHOLD_PERCENT); getPropertyInt(properties, "requestLimit.requestThresholdPercent",
int nodeLimitPercent = getPropertyInt(properties, RequestLimitConfig.DEFAULT_REQUEST_THRESHOLD_PERCENT);
"requestLimit.nodeLimitPercent", RequestLimitConfig.DEFAULT_NODE_LIMIT_PERCENT); int nodeLimitPercent =
RequestLimitConfig requestLimitConfig; getPropertyInt(properties, "requestLimit.nodeLimitPercent",
/* It is said that the constructor could throw NodeRequestLimitException in Javadoc, the exception is not provided */ RequestLimitConfig.DEFAULT_NODE_LIMIT_PERCENT);
// try { RequestLimitConfig requestLimitConfig;
requestLimitConfig = new RequestLimitConfig(maxActiveRequests, requestThresholdPercent, nodeLimitPercent); /*
// } catch (NodeRequestLimitException e) { * It is said that the constructor could throw NodeRequestLimitException in
// throw new DBException(e); * Javadoc, the exception is not provided
// } */
config.setRequestLimit(requestLimitConfig); // try {
requestLimitConfig = new RequestLimitConfig(maxActiveRequests,
p = properties.getProperty("requestTimeout"); requestThresholdPercent, nodeLimitPercent);
if (p != null) { // } catch (NodeRequestLimitException e) {
long timeout = 1; // throw new DBException(e);
try { // }
timeout = Long.parseLong(p); config.setRequestLimit(requestLimitConfig);
} catch (NumberFormatException e) {
throw new DBException("Illegal number format in requestTimeout property"); p = properties.getProperty("requestTimeout");
} if (p != null) {
try { long timeout = 1;
// TODO Support other TimeUnit try {
config.setRequestTimeout(timeout, TimeUnit.SECONDS); timeout = Long.parseLong(p);
} catch (IllegalArgumentException e) { } catch (NumberFormatException e) {
throw new DBException(e); throw new DBException(
} "Illegal number format in requestTimeout property");
} }
try {
try { // TODO Support other TimeUnit
store = KVStoreFactory.getStore(config); config.setRequestTimeout(timeout, TimeUnit.SECONDS);
} catch (FaultException e) { } catch (IllegalArgumentException e) {
throw new DBException(e); throw new DBException(e);
} }
} }
@Override try {
public void cleanup() throws DBException { store = KVStoreFactory.getStore(config);
store.close(); } catch (FaultException e) {
} throw new DBException(e);
}
/** }
* Create a key object.
* We map "table" and (YCSB's) "key" to a major component of the oracle.kv.Key, @Override
* and "field" to a minor component. public void cleanup() throws DBException {
* store.close();
* @return An oracle.kv.Key object. }
*/
private static Key createKey(String table, String key, String field) { /**
List<String> majorPath = new ArrayList<String>(); * Create a key object. We map "table" and (YCSB's) "key" to a major component
majorPath.add(table); * of the oracle.kv.Key, and "field" to a minor component.
majorPath.add(key); *
if (field == null) { * @return An oracle.kv.Key object.
return Key.createKey(majorPath); */
} private static Key createKey(String table, String key, String field) {
List<String> majorPath = new ArrayList<String>();
return Key.createKey(majorPath, field); majorPath.add(table);
} majorPath.add(key);
if (field == null) {
private static Key createKey(String table, String key) { return Key.createKey(majorPath);
return createKey(table, key, null); }
}
return Key.createKey(majorPath, field);
private static String getFieldFromKey(Key key) { }
return key.getMinorPath().get(0);
} private static Key createKey(String table, String key) {
return createKey(table, key, null);
@Override }
public int read(String table, String key, Set<String> fields, HashMap<String, ByteIterator> result) {
Key kvKey = createKey(table, key); private static String getFieldFromKey(Key key) {
SortedMap<Key, ValueVersion> kvResult; return key.getMinorPath().get(0);
try { }
kvResult = store.multiGet(kvKey, null, null);
} catch (FaultException e) { @Override
System.err.println(e); public Status read(String table, String key, Set<String> fields,
return ERROR; HashMap<String, ByteIterator> result) {
} Key kvKey = createKey(table, key);
SortedMap<Key, ValueVersion> kvResult;
for (Map.Entry<Key, ValueVersion> entry : kvResult.entrySet()) { try {
/* If fields is null, read all fields */ kvResult = store.multiGet(kvKey, null, null);
String field = getFieldFromKey(entry.getKey()); } catch (FaultException e) {
if (fields != null && !fields.contains(field)) { System.err.println(e);
continue; return Status.ERROR;
} }
result.put(field, new ByteArrayByteIterator(entry.getValue().getValue().getValue()));
} for (Map.Entry<Key, ValueVersion> entry : kvResult.entrySet()) {
/* If fields is null, read all fields */
return OK; String field = getFieldFromKey(entry.getKey());
} if (fields != null && !fields.contains(field)) {
continue;
@Override }
public int scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) { result.put(field,
System.err.println("Oracle NoSQL Database does not support Scan semantics"); new ByteArrayByteIterator(entry.getValue().getValue().getValue()));
return ERROR; }
}
return Status.OK;
@Override }
public int update(String table, String key, HashMap<String, ByteIterator> values) {
for (Map.Entry<String, ByteIterator> entry : values.entrySet()) { @Override
Key kvKey = createKey(table, key, entry.getKey()); public Status scan(String table, String startkey, int recordcount,
Value kvValue = Value.createValue(entry.getValue().toArray()); Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
try { System.err.println("Oracle NoSQL Database does not support Scan semantics");
store.put(kvKey, kvValue); return Status.ERROR;
} catch (FaultException e) { }
System.err.println(e);
return ERROR; @Override
} public Status update(String table, String key,
} HashMap<String, ByteIterator> values) {
for (Map.Entry<String, ByteIterator> entry : values.entrySet()) {
return OK; Key kvKey = createKey(table, key, entry.getKey());
} Value kvValue = Value.createValue(entry.getValue().toArray());
try {
@Override store.put(kvKey, kvValue);
public int insert(String table, String key, HashMap<String, ByteIterator> values) { } catch (FaultException e) {
return update(table, key, values); System.err.println(e);
} return Status.ERROR;
}
@Override }
public int delete(String table, String key) {
Key kvKey = createKey(table, key); return Status.OK;
try { }
store.multiDelete(kvKey, null, null);
} catch (FaultException e) { @Override
System.err.println(e); public Status insert(String table, String key,
return ERROR; HashMap<String, ByteIterator> values) {
} return update(table, key, values);
}
return OK;
} @Override
public Status delete(String table, String key) {
Key kvKey = createKey(table, key);
try {
store.multiDelete(kvKey, null, null);
} catch (FaultException e) {
System.err.println(e);
return Status.ERROR;
}
return Status.OK;
}
} }
/*
* Copyright (c) 2014, Yahoo!, Inc. 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.
*/
/**
* The YCSB binding for <a href=
* "http://www.oracle.com/us/products/database/nosql/overview/index.html">Oracle
* 's NoSQL DB</a>.
*/
package com.yahoo.ycsb.db;
...@@ -37,7 +37,6 @@ LICENSE file. ...@@ -37,7 +37,6 @@ LICENSE file.
</scm> </scm>
<dependencyManagement> <dependencyManagement>
<dependencies> <dependencies>
<!-- voldemort -->
<dependency> <dependency>
<groupId>checkstyle</groupId> <groupId>checkstyle</groupId>
<artifactId>checkstyle</artifactId> <artifactId>checkstyle</artifactId>
...@@ -121,7 +120,7 @@ LICENSE file. ...@@ -121,7 +120,7 @@ LICENSE file.
<!--<module>mapkeeper</module>--> <!--<module>mapkeeper</module>-->
<module>memcached</module> <module>memcached</module>
<module>mongodb</module> <module>mongodb</module>
<!--module>nosqldb</module--> <module>nosqldb</module>
<module>orientdb</module> <module>orientdb</module>
<module>redis</module> <module>redis</module>
<module>s3</module> <module>s3</module>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment