Skip to content
Snippets Groups Projects
Commit 89d3de0e authored by Robert J. Moore's avatar Robert J. Moore
Browse files

[nosqldb] Checkstyle updates for Oracle's NoSQL DB binding.

parent 55b7a391
No related branches found
No related tags found
No related merge requests found
...@@ -42,4 +42,28 @@ LICENSE file. ...@@ -42,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>
...@@ -48,189 +48,203 @@ import com.yahoo.ycsb.Status; ...@@ -48,189 +48,203 @@ 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 {
KVStore store; private KVStore store;
private int getPropertyInt(Properties properties, String key, int defaultValue) throws DBException { private int getPropertyInt(Properties properties, String key,
String p = properties.getProperty(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 = properties.getProperty("helperHost", "localhost:5000").split(","); String storeName = properties.getProperty("storeName", "kvstore");
String[] helperHosts =
KVStoreConfig config = new KVStoreConfig(storeName, helperHosts); properties.getProperty("helperHost", "localhost:5000").split(",");
/* Optional properties */ KVStoreConfig config = new KVStoreConfig(storeName, helperHosts);
String p;
/* Optional properties */
p = properties.getProperty("consistency"); String p;
if (p != null) {
if (p.equalsIgnoreCase("ABSOLUTE")) { p = properties.getProperty("consistency");
config.setConsistency(Consistency.ABSOLUTE); if (p != null) {
} else if (p.equalsIgnoreCase("NONE_REQUIRED")) { if (p.equalsIgnoreCase("ABSOLUTE")) {
config.setConsistency(Consistency.NONE_REQUIRED); config.setConsistency(Consistency.ABSOLUTE);
} else { } else if (p.equalsIgnoreCase("NONE_REQUIRED")) {
throw new DBException("Illegal value in consistency property"); config.setConsistency(Consistency.NONE_REQUIRED);
} } else {
} throw new DBException("Illegal value in consistency property");
}
p = properties.getProperty("durability"); }
if (p != null) {
if (p.equalsIgnoreCase("COMMIT_NO_SYNC")) { p = properties.getProperty("durability");
config.setDurability(Durability.COMMIT_NO_SYNC); if (p != null) {
} else if (p.equalsIgnoreCase("COMMIT_SYNC")) { if (p.equalsIgnoreCase("COMMIT_NO_SYNC")) {
config.setDurability(Durability.COMMIT_SYNC); config.setDurability(Durability.COMMIT_NO_SYNC);
} else if (p.equalsIgnoreCase("COMMIT_WRITE_NO_SYNC")) { } else if (p.equalsIgnoreCase("COMMIT_SYNC")) {
config.setDurability(Durability.COMMIT_WRITE_NO_SYNC); config.setDurability(Durability.COMMIT_SYNC);
} else { } else if (p.equalsIgnoreCase("COMMIT_WRITE_NO_SYNC")) {
throw new DBException("Illegal value in durability property"); config.setDurability(Durability.COMMIT_WRITE_NO_SYNC);
} } else {
} throw new DBException("Illegal value in durability property");
}
int maxActiveRequests = getPropertyInt(properties, }
"requestLimit.maxActiveRequests", RequestLimitConfig.DEFAULT_MAX_ACTIVE_REQUESTS);
int requestThresholdPercent = getPropertyInt(properties, int maxActiveRequests =
"requestLimit.requestThresholdPercent", RequestLimitConfig.DEFAULT_REQUEST_THRESHOLD_PERCENT); getPropertyInt(properties, "requestLimit.maxActiveRequests",
int nodeLimitPercent = getPropertyInt(properties, RequestLimitConfig.DEFAULT_MAX_ACTIVE_REQUESTS);
"requestLimit.nodeLimitPercent", RequestLimitConfig.DEFAULT_NODE_LIMIT_PERCENT); int requestThresholdPercent =
RequestLimitConfig requestLimitConfig; getPropertyInt(properties, "requestLimit.requestThresholdPercent",
/* It is said that the constructor could throw NodeRequestLimitException in Javadoc, the exception is not provided */ RequestLimitConfig.DEFAULT_REQUEST_THRESHOLD_PERCENT);
// try { int nodeLimitPercent =
requestLimitConfig = new RequestLimitConfig(maxActiveRequests, requestThresholdPercent, nodeLimitPercent); getPropertyInt(properties, "requestLimit.nodeLimitPercent",
// } catch (NodeRequestLimitException e) { RequestLimitConfig.DEFAULT_NODE_LIMIT_PERCENT);
// throw new DBException(e); RequestLimitConfig requestLimitConfig;
// } /*
config.setRequestLimit(requestLimitConfig); * It is said that the constructor could throw NodeRequestLimitException in
* Javadoc, the exception is not provided
p = properties.getProperty("requestTimeout"); */
if (p != null) { // try {
long timeout = 1; requestLimitConfig = new RequestLimitConfig(maxActiveRequests,
try { requestThresholdPercent, nodeLimitPercent);
timeout = Long.parseLong(p); // } catch (NodeRequestLimitException e) {
} catch (NumberFormatException e) { // throw new DBException(e);
throw new DBException("Illegal number format in requestTimeout property"); // }
} config.setRequestLimit(requestLimitConfig);
try {
// TODO Support other TimeUnit p = properties.getProperty("requestTimeout");
config.setRequestTimeout(timeout, TimeUnit.SECONDS); if (p != null) {
} catch (IllegalArgumentException e) { long timeout = 1;
throw new DBException(e); try {
} timeout = Long.parseLong(p);
} } catch (NumberFormatException e) {
throw new DBException(
try { "Illegal number format in requestTimeout property");
store = KVStoreFactory.getStore(config); }
} catch (FaultException e) { try {
throw new DBException(e); // TODO Support other TimeUnit
} config.setRequestTimeout(timeout, TimeUnit.SECONDS);
} } catch (IllegalArgumentException e) {
throw new DBException(e);
@Override }
public void cleanup() throws DBException { }
store.close();
} try {
store = KVStoreFactory.getStore(config);
/** } catch (FaultException e) {
* Create a key object. throw new DBException(e);
* We map "table" and (YCSB's) "key" to a major component of the oracle.kv.Key, }
* and "field" to a minor component. }
*
* @return An oracle.kv.Key object. @Override
*/ public void cleanup() throws DBException {
private static Key createKey(String table, String key, String field) { store.close();
List<String> majorPath = new ArrayList<String>(); }
majorPath.add(table);
majorPath.add(key); /**
if (field == null) { * Create a key object. We map "table" and (YCSB's) "key" to a major component
return Key.createKey(majorPath); * of the oracle.kv.Key, and "field" to a minor component.
} *
* @return An oracle.kv.Key object.
return Key.createKey(majorPath, field); */
} private static Key createKey(String table, String key, String field) {
List<String> majorPath = new ArrayList<String>();
private static Key createKey(String table, String key) { majorPath.add(table);
return createKey(table, key, null); majorPath.add(key);
} if (field == null) {
return Key.createKey(majorPath);
private static String getFieldFromKey(Key key) { }
return key.getMinorPath().get(0);
} return Key.createKey(majorPath, field);
}
@Override
public Status read(String table, String key, Set<String> fields, HashMap<String, ByteIterator> result) { private static Key createKey(String table, String key) {
Key kvKey = createKey(table, key); return createKey(table, key, null);
SortedMap<Key, ValueVersion> kvResult; }
try {
kvResult = store.multiGet(kvKey, null, null); private static String getFieldFromKey(Key key) {
} catch (FaultException e) { return key.getMinorPath().get(0);
System.err.println(e); }
return Status.ERROR;
} @Override
public Status read(String table, String key, Set<String> fields,
for (Map.Entry<Key, ValueVersion> entry : kvResult.entrySet()) { HashMap<String, ByteIterator> result) {
/* If fields is null, read all fields */ Key kvKey = createKey(table, key);
String field = getFieldFromKey(entry.getKey()); SortedMap<Key, ValueVersion> kvResult;
if (fields != null && !fields.contains(field)) { try {
continue; kvResult = store.multiGet(kvKey, null, null);
} } catch (FaultException e) {
result.put(field, new ByteArrayByteIterator(entry.getValue().getValue().getValue())); System.err.println(e);
} return Status.ERROR;
}
return Status.OK;
} for (Map.Entry<Key, ValueVersion> entry : kvResult.entrySet()) {
/* If fields is null, read all fields */
@Override String field = getFieldFromKey(entry.getKey());
public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) { if (fields != null && !fields.contains(field)) {
System.err.println("Oracle NoSQL Database does not support Scan semantics"); continue;
return Status.ERROR; }
} result.put(field,
new ByteArrayByteIterator(entry.getValue().getValue().getValue()));
@Override }
public Status update(String table, String key, HashMap<String, ByteIterator> values) {
for (Map.Entry<String, ByteIterator> entry : values.entrySet()) { return Status.OK;
Key kvKey = createKey(table, key, entry.getKey()); }
Value kvValue = Value.createValue(entry.getValue().toArray());
try { @Override
store.put(kvKey, kvValue); public Status scan(String table, String startkey, int recordcount,
} catch (FaultException e) { Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
System.err.println(e); System.err.println("Oracle NoSQL Database does not support Scan semantics");
return Status.ERROR; return Status.ERROR;
} }
}
@Override
return Status.OK; public Status 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 insert(String table, String key, HashMap<String, ByteIterator> values) { Value kvValue = Value.createValue(entry.getValue().toArray());
return update(table, key, values); try {
} store.put(kvKey, kvValue);
} catch (FaultException e) {
@Override System.err.println(e);
public Status delete(String table, String key) { return Status.ERROR;
Key kvKey = createKey(table, key); }
try { }
store.multiDelete(kvKey, null, null);
} catch (FaultException e) { return Status.OK;
System.err.println(e); }
return Status.ERROR;
} @Override
public Status insert(String table, String key,
return Status.OK; HashMap<String, ByteIterator> values) {
} return update(table, key, values);
}
@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;
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