Replaces numeric status codes with a canonical set of Status objects,
each with a short name and description.
Bindings with more specific errors (e.g., timeouts) return additional
statuses.

This changes the default output from messages like:

   [UPDATE], Return=0, 511

To:

   [UPDATE], Return=OK, 511
This commit is contained in:
Connor McCoy 2015-11-03 08:07:07 -08:00
Родитель 28a090a729
Коммит 5113c2e3d2
43 изменённых файлов: 744 добавлений и 766 удалений

Просмотреть файл

@ -22,7 +22,7 @@ import com.yahoo.ycsb.ByteArrayByteIterator;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.DB;
import com.yahoo.ycsb.DBException;
import com.yahoo.ycsb.StatusCode;
import com.yahoo.ycsb.Status;
import org.apache.accumulo.core.client.AccumuloException;
import org.apache.accumulo.core.client.AccumuloSecurityException;
@ -199,14 +199,14 @@ public class AccumuloClient extends DB {
}
@Override
public int read(String t, String key, Set<String> fields,
public Status read(String t, String key, Set<String> fields,
HashMap<String, ByteIterator> result) {
try {
checkTable(t);
} catch (TableNotFoundException e) {
System.err.println("Error trying to connect to Accumulo table." + e);
return StatusCode.ERROR;
return Status.ERROR;
}
try {
@ -219,20 +219,20 @@ public class AccumuloClient extends DB {
}
} catch (Exception e) {
System.err.println("Error trying to reading Accumulo table" + key + e);
return StatusCode.ERROR;
return Status.ERROR;
}
return StatusCode.OK;
return Status.OK;
}
@Override
public int scan(String t, String startkey, int recordcount,
public Status scan(String t, String startkey, int recordcount,
Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
try {
checkTable(t);
} catch (TableNotFoundException e) {
System.err.println("Error trying to connect to Accumulo table." + e);
return StatusCode.ERROR;
return Status.ERROR;
}
// There doesn't appear to be a way to create a range for a given
@ -283,17 +283,17 @@ public class AccumuloClient extends DB {
new ByteArrayByteIterator(buf));
}
return StatusCode.OK;
return Status.OK;
}
@Override
public int update(String t, String key,
public Status update(String t, String key,
HashMap<String, ByteIterator> values) {
try {
checkTable(t);
} catch (TableNotFoundException e) {
System.err.println("Error trying to connect to Accumulo table." + e);
return StatusCode.ERROR;
return Status.ERROR;
}
Mutation mutInsert = new Mutation(new Text(key));
@ -315,29 +315,29 @@ public class AccumuloClient extends DB {
} catch (MutationsRejectedException e) {
System.err.println("Error performing update.");
e.printStackTrace();
return StatusCode.ERROR;
return Status.ERROR;
} catch (KeeperException e) {
System.err.println("Error notifying the Zookeeper Queue.");
e.printStackTrace();
return StatusCode.ERROR;
return Status.ERROR;
}
return StatusCode.OK;
return Status.OK;
}
@Override
public int insert(String t, String key,
public Status insert(String t, String key,
HashMap<String, ByteIterator> values) {
return update(t, key, values);
}
@Override
public int delete(String t, String key) {
public Status delete(String t, String key) {
try {
checkTable(t);
} catch (TableNotFoundException e) {
System.err.println("Error trying to connect to Accumulo table." + e);
return StatusCode.ERROR;
return Status.ERROR;
}
try {
@ -345,14 +345,14 @@ public class AccumuloClient extends DB {
} catch (MutationsRejectedException e) {
System.err.println("Error performing delete.");
e.printStackTrace();
return StatusCode.ERROR;
return Status.ERROR;
} catch (RuntimeException e) {
System.err.println("Error performing delete.");
e.printStackTrace();
return StatusCode.ERROR;
return Status.ERROR;
}
return StatusCode.OK;
return Status.OK;
}
// These functions are adapted from RowOperations.java:
@ -412,7 +412,7 @@ public class AccumuloClient extends DB {
HashMap<String, ByteIterator> result =
new HashMap<String, ByteIterator>();
int retval = read(usertable, strKey, fields, result);
read(usertable, strKey, fields, result);
// If the results are empty, the key is enqueued in
// Zookeeper
// and tried again, until the results are found.
@ -438,7 +438,7 @@ public class AccumuloClient extends DB {
}
public int presplit(String t, String[] keys)
public Status presplit(String t, String[] keys)
throws TableNotFoundException, AccumuloException,
AccumuloSecurityException {
TreeSet<Text> splits = new TreeSet<Text>();
@ -446,7 +446,7 @@ public class AccumuloClient extends DB {
splits.add(new Text(keys[i]));
}
connector.tableOperations().addSplits(t, splits);
return StatusCode.OK;
return Status.OK;
}
}

Просмотреть файл

@ -28,7 +28,7 @@ import com.aerospike.client.policy.WritePolicy;
import com.yahoo.ycsb.ByteArrayByteIterator;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.DBException;
import com.yahoo.ycsb.StatusCode;
import com.yahoo.ycsb.Status;
import java.util.HashMap;
import java.util.Map;
@ -97,7 +97,7 @@ public class AerospikeClient extends com.yahoo.ycsb.DB {
}
@Override
public int read(String table, String key, Set<String> fields,
public Status read(String table, String key, Set<String> fields,
HashMap<String, ByteIterator> result) {
try {
Record record;
@ -111,7 +111,7 @@ public class AerospikeClient extends com.yahoo.ycsb.DB {
if (record == null) {
System.err.println("Record key " + key + " not found (read)");
return StatusCode.ERROR;
return Status.ERROR;
}
for (Map.Entry<String, Object> entry: record.bins.entrySet()) {
@ -119,21 +119,21 @@ public class AerospikeClient extends com.yahoo.ycsb.DB {
new ByteArrayByteIterator((byte[])entry.getValue()));
}
return StatusCode.OK;
return Status.OK;
} catch (AerospikeException e) {
System.err.println("Error while reading key " + key + ": " + e);
return StatusCode.ERROR;
return Status.ERROR;
}
}
@Override
public int scan(String table, String start, int count, Set<String> fields,
public Status scan(String table, String start, int count, Set<String> fields,
Vector<HashMap<String, ByteIterator>> result) {
System.err.println("Scan not implemented");
return StatusCode.ERROR;
return Status.ERROR;
}
private int write(String table, String key, WritePolicy writePolicy,
private Status write(String table, String key, WritePolicy writePolicy,
HashMap<String, ByteIterator> values) {
Bin[] bins = new Bin[values.size()];
int index = 0;
@ -147,37 +147,37 @@ public class AerospikeClient extends com.yahoo.ycsb.DB {
try {
client.put(writePolicy, keyObj, bins);
return StatusCode.OK;
return Status.OK;
} catch (AerospikeException e) {
System.err.println("Error while writing key " + key + ": " + e);
return StatusCode.ERROR;
return Status.ERROR;
}
}
@Override
public int update(String table, String key,
public Status update(String table, String key,
HashMap<String, ByteIterator> values) {
return write(table, key, updatePolicy, values);
}
@Override
public int insert(String table, String key,
public Status insert(String table, String key,
HashMap<String, ByteIterator> values) {
return write(table, key, insertPolicy, values);
}
@Override
public int delete(String table, String key) {
public Status delete(String table, String key) {
try {
if (!client.delete(deletePolicy, new Key(namespace, table, key))) {
System.err.println("Record key " + key + " not found (delete)");
return StatusCode.ERROR;
return Status.ERROR;
}
return StatusCode.OK;
return Status.OK;
} catch (AerospikeException e) {
System.err.println("Error while deleting key " + key + ": " + e);
return StatusCode.ERROR;
return Status.ERROR;
}
}
}

Просмотреть файл

@ -187,7 +187,7 @@ public class CassandraCQLClient extends DB {
* @return Zero on success, a non-zero error code on error
*/
@Override
public int read(String table, String key, Set<String> fields,
public Status read(String table, String key, Set<String> fields,
HashMap<String, ByteIterator> result) {
try {
@ -229,12 +229,12 @@ public class CassandraCQLClient extends DB {
}
return StatusCode.OK;
return Status.OK;
} catch (Exception e) {
e.printStackTrace();
System.out.println("Error reading key: " + key);
return StatusCode.ERROR;
return Status.ERROR;
}
}
@ -260,7 +260,7 @@ public class CassandraCQLClient extends DB {
* @return Zero on success, a non-zero error code on error
*/
@Override
public int scan(String table, String startkey, int recordcount,
public Status scan(String table, String startkey, int recordcount,
Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
try {
@ -320,12 +320,12 @@ public class CassandraCQLClient extends DB {
result.add(tuple);
}
return StatusCode.OK;
return Status.OK;
} catch (Exception e) {
e.printStackTrace();
System.out.println("Error scanning with startkey: " + startkey);
return StatusCode.ERROR;
return Status.ERROR;
}
}
@ -344,7 +344,7 @@ public class CassandraCQLClient extends DB {
* @return Zero on success, a non-zero error code on error
*/
@Override
public int update(String table, String key,
public Status update(String table, String key,
HashMap<String, ByteIterator> values) {
// Insert and updates provide the same functionality
return insert(table, key, values);
@ -364,7 +364,7 @@ public class CassandraCQLClient extends DB {
* @return Zero on success, a non-zero error code on error
*/
@Override
public int insert(String table, String key,
public Status insert(String table, String key,
HashMap<String, ByteIterator> values) {
try {
@ -390,12 +390,12 @@ public class CassandraCQLClient extends DB {
ResultSet rs = session.execute(insertStmt);
return StatusCode.OK;
return Status.OK;
} catch (Exception e) {
e.printStackTrace();
}
return StatusCode.ERROR;
return Status.ERROR;
}
/**
@ -408,7 +408,7 @@ public class CassandraCQLClient extends DB {
* @return Zero on success, a non-zero error code on error
*/
@Override
public int delete(String table, String key) {
public Status delete(String table, String key) {
try {
Statement stmt;
@ -421,15 +421,15 @@ public class CassandraCQLClient extends DB {
System.out.println(stmt.toString());
}
ResultSet rs = session.execute(stmt);
session.execute(stmt);
return StatusCode.OK;
return Status.OK;
} catch (Exception e) {
e.printStackTrace();
System.out.println("Error deleting key: " + key);
}
return StatusCode.ERROR;
return Status.ERROR;
}
}

Просмотреть файл

@ -17,15 +17,13 @@
package com.yahoo.ycsb.db;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.Vector;
import com.yahoo.ycsb.ByteArrayByteIterator;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.DB;
import com.yahoo.ycsb.DBException;
import com.yahoo.ycsb.Status;
import com.yahoo.ycsb.StringByteIterator;
import com.yahoo.ycsb.Utils;
import org.apache.cassandra.thrift.AuthenticationRequest;
import org.apache.cassandra.thrift.Cassandra;
@ -45,12 +43,15 @@ import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import com.yahoo.ycsb.ByteArrayByteIterator;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.DB;
import com.yahoo.ycsb.DBException;
import com.yahoo.ycsb.StringByteIterator;
import com.yahoo.ycsb.Utils;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.Vector;
//XXXX if we do replication, fix the consistency levels
/**
@ -221,7 +222,7 @@ public class CassandraClient10 extends DB {
* A HashMap of field/value pairs for the result
* @return Zero on success, a non-zero error code on error
*/
public int read(String table, String key, Set<String> fields,
public Status read(String table, String key, Set<String> fields,
HashMap<String, ByteIterator> result) {
if (!tableName.equals(table)) {
try {
@ -230,7 +231,7 @@ public class CassandraClient10 extends DB {
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace(System.out);
return ERROR;
return Status.ERROR;
}
}
@ -286,7 +287,7 @@ public class CassandraClient10 extends DB {
.println("ConsistencyLevel=" + readConsistencyLevel.toString());
}
return OK;
return Status.OK;
} catch (Exception e) {
errorexception = e;
}
@ -299,7 +300,7 @@ public class CassandraClient10 extends DB {
}
errorexception.printStackTrace();
errorexception.printStackTrace(System.out);
return ERROR;
return Status.ERROR;
}
@ -320,7 +321,7 @@ public class CassandraClient10 extends DB {
* pairs for one record
* @return Zero on success, a non-zero error code on error
*/
public int scan(String table, String startkey, int recordcount,
public Status scan(String table, String startkey, int recordcount,
Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
if (!tableName.equals(table)) {
try {
@ -329,7 +330,7 @@ public class CassandraClient10 extends DB {
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace(System.out);
return ERROR;
return Status.ERROR;
}
}
@ -392,7 +393,7 @@ public class CassandraClient10 extends DB {
}
}
return OK;
return Status.OK;
} catch (Exception e) {
errorexception = e;
}
@ -404,7 +405,7 @@ public class CassandraClient10 extends DB {
}
errorexception.printStackTrace();
errorexception.printStackTrace(System.out);
return ERROR;
return Status.ERROR;
}
/**
@ -420,7 +421,7 @@ public class CassandraClient10 extends DB {
* A HashMap of field/value pairs to update in the record
* @return Zero on success, a non-zero error code on error
*/
public int update(String table, String key,
public Status update(String table, String key,
HashMap<String, ByteIterator> values) {
return insert(table, key, values);
}
@ -438,7 +439,7 @@ public class CassandraClient10 extends DB {
* A HashMap of field/value pairs to insert in the record
* @return Zero on success, a non-zero error code on error
*/
public int insert(String table, String key,
public Status insert(String table, String key,
HashMap<String, ByteIterator> values) {
if (!tableName.equals(table)) {
try {
@ -447,7 +448,7 @@ public class CassandraClient10 extends DB {
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace(System.out);
return ERROR;
return Status.ERROR;
}
}
@ -487,7 +488,7 @@ public class CassandraClient10 extends DB {
.println("ConsistencyLevel=" + writeConsistencyLevel.toString());
}
return OK;
return Status.OK;
} catch (Exception e) {
errorexception = e;
}
@ -500,7 +501,7 @@ public class CassandraClient10 extends DB {
errorexception.printStackTrace();
errorexception.printStackTrace(System.out);
return ERROR;
return Status.ERROR;
}
/**
@ -512,7 +513,7 @@ public class CassandraClient10 extends DB {
* The record key of the record to delete.
* @return Zero on success, a non-zero error code on error
*/
public int delete(String table, String key) {
public Status delete(String table, String key) {
if (!tableName.equals(table)) {
try {
client.set_keyspace(table);
@ -520,7 +521,7 @@ public class CassandraClient10 extends DB {
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace(System.out);
return ERROR;
return Status.ERROR;
}
}
@ -536,7 +537,7 @@ public class CassandraClient10 extends DB {
.println("ConsistencyLevel=" + deleteConsistencyLevel.toString());
}
return OK;
return Status.OK;
} catch (Exception e) {
errorexception = e;
}
@ -548,7 +549,7 @@ public class CassandraClient10 extends DB {
}
errorexception.printStackTrace();
errorexception.printStackTrace(System.out);
return ERROR;
return Status.ERROR;
}
public static void main(String[] args) {
@ -570,7 +571,7 @@ public class CassandraClient10 extends DB {
vals.put("age", new StringByteIterator("57"));
vals.put("middlename", new StringByteIterator("bradley"));
vals.put("favoritecolor", new StringByteIterator("blue"));
int res = cli.insert("usertable", "BrianFrankCooper", vals);
Status res = cli.insert("usertable", "BrianFrankCooper", vals);
System.out.println("Result of insert: " + res);
HashMap<String, ByteIterator> result = new HashMap<String, ByteIterator>();

Просмотреть файл

@ -17,15 +17,13 @@
package com.yahoo.ycsb.db;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.Vector;
import com.yahoo.ycsb.ByteArrayByteIterator;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.DB;
import com.yahoo.ycsb.DBException;
import com.yahoo.ycsb.Status;
import com.yahoo.ycsb.StringByteIterator;
import com.yahoo.ycsb.Utils;
import org.apache.cassandra.thrift.AuthenticationRequest;
import org.apache.cassandra.thrift.Cassandra;
@ -45,20 +43,21 @@ import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import com.yahoo.ycsb.ByteArrayByteIterator;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.DB;
import com.yahoo.ycsb.DBException;
import com.yahoo.ycsb.StringByteIterator;
import com.yahoo.ycsb.Utils;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.Vector;
//XXXX if we do replication, fix the consistency levels
/**
* Cassandra 0.7 client for YCSB framework.
*/
public class CassandraClient7 extends DB {
public static final int OK = 0;
public static final int ERROR = -1;
public static final ByteBuffer EMPTY_BYTE_BUFFER =
ByteBuffer.wrap(new byte[0]);
@ -188,7 +187,7 @@ public class CassandraClient7 extends DB {
* A HashMap of field/value pairs for the result
* @return Zero on success, a non-zero error code on error
*/
public int read(String table, String key, Set<String> fields,
public Status read(String table, String key, Set<String> fields,
HashMap<String, ByteIterator> result) {
if (!tableName.equals(table)) {
try {
@ -197,7 +196,7 @@ public class CassandraClient7 extends DB {
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace(System.out);
return ERROR;
return Status.ERROR;
}
}
@ -253,7 +252,7 @@ public class CassandraClient7 extends DB {
System.out.println();
}
return OK;
return Status.OK;
} catch (Exception e) {
errorexception = e;
}
@ -266,7 +265,7 @@ public class CassandraClient7 extends DB {
}
errorexception.printStackTrace();
errorexception.printStackTrace(System.out);
return ERROR;
return Status.ERROR;
}
@ -287,7 +286,7 @@ public class CassandraClient7 extends DB {
* pairs for one record
* @return Zero on success, a non-zero error code on error
*/
public int scan(String table, String startkey, int recordcount,
public Status scan(String table, String startkey, int recordcount,
Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
if (!tableName.equals(table)) {
try {
@ -296,7 +295,7 @@ public class CassandraClient7 extends DB {
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace(System.out);
return ERROR;
return Status.ERROR;
}
}
@ -359,7 +358,7 @@ public class CassandraClient7 extends DB {
}
}
return OK;
return Status.OK;
} catch (Exception e) {
errorexception = e;
}
@ -371,7 +370,7 @@ public class CassandraClient7 extends DB {
}
errorexception.printStackTrace();
errorexception.printStackTrace(System.out);
return ERROR;
return Status.ERROR;
}
/**
@ -387,7 +386,7 @@ public class CassandraClient7 extends DB {
* A HashMap of field/value pairs to update in the record
* @return Zero on success, a non-zero error code on error
*/
public int update(String table, String key,
public Status update(String table, String key,
HashMap<String, ByteIterator> values) {
return insert(table, key, values);
}
@ -405,7 +404,7 @@ public class CassandraClient7 extends DB {
* A HashMap of field/value pairs to insert in the record
* @return Zero on success, a non-zero error code on error
*/
public int insert(String table, String key,
public Status insert(String table, String key,
HashMap<String, ByteIterator> values) {
if (!tableName.equals(table)) {
try {
@ -414,7 +413,7 @@ public class CassandraClient7 extends DB {
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace(System.out);
return ERROR;
return Status.ERROR;
}
}
@ -449,7 +448,7 @@ public class CassandraClient7 extends DB {
mutationMap.clear();
record.clear();
return OK;
return Status.OK;
} catch (Exception e) {
errorexception = e;
}
@ -462,7 +461,7 @@ public class CassandraClient7 extends DB {
errorexception.printStackTrace();
errorexception.printStackTrace(System.out);
return ERROR;
return Status.ERROR;
}
/**
@ -474,7 +473,7 @@ public class CassandraClient7 extends DB {
* The record key of the record to delete.
* @return Zero on success, a non-zero error code on error
*/
public int delete(String table, String key) {
public Status delete(String table, String key) {
if (!tableName.equals(table)) {
try {
client.set_keyspace(table);
@ -482,7 +481,7 @@ public class CassandraClient7 extends DB {
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace(System.out);
return ERROR;
return Status.ERROR;
}
}
@ -496,7 +495,7 @@ public class CassandraClient7 extends DB {
System.out.println("Delete key: " + key);
}
return OK;
return Status.OK;
} catch (Exception e) {
errorexception = e;
}
@ -508,7 +507,7 @@ public class CassandraClient7 extends DB {
}
errorexception.printStackTrace();
errorexception.printStackTrace(System.out);
return ERROR;
return Status.ERROR;
}
public static void main(String[] args) {
@ -530,8 +529,8 @@ public class CassandraClient7 extends DB {
vals.put("age", new StringByteIterator("57"));
vals.put("middlename", new StringByteIterator("bradley"));
vals.put("favoritecolor", new StringByteIterator("blue"));
int res = cli.insert("usertable", "BrianFrankCooper", vals);
System.out.println("Result of insert: " + res);
Status res = cli.insert("usertable", "BrianFrankCooper", vals);
System.out.println("Result of insert: " + res.getName());
HashMap<String, ByteIterator> result = new HashMap<String, ByteIterator>();
HashSet<String> fields = new HashSet<String>();
@ -539,12 +538,12 @@ public class CassandraClient7 extends DB {
fields.add("age");
fields.add("favoritecolor");
res = cli.read("usertable", "BrianFrankCooper", null, result);
System.out.println("Result of read: " + res);
System.out.println("Result of read: " + res.getName());
for (String s : result.keySet()) {
System.out.println("[" + s + "]=[" + result.get(s) + "]");
}
res = cli.delete("usertable", "BrianFrankCooper");
System.out.println("Result of delete: " + res);
System.out.println("Result of delete: " + res.getName());
}
}

Просмотреть файл

@ -41,8 +41,6 @@ import org.apache.cassandra.thrift.*;
* Cassandra 0.8 client for YCSB framework.
*/
public class CassandraClient8 extends DB {
public static final int OK = 0;
public static final int ERROR = -1;
public static final ByteBuffer EMPTY_BYTE_BUFFER =
ByteBuffer.wrap(new byte[0]);
@ -172,7 +170,7 @@ public class CassandraClient8 extends DB {
* A HashMap of field/value pairs for the result
* @return Zero on success, a non-zero error code on error
*/
public int read(String table, String key, Set<String> fields,
public Status read(String table, String key, Set<String> fields,
HashMap<String, ByteIterator> result) {
if (!tableName.equals(table)) {
try {
@ -181,7 +179,7 @@ public class CassandraClient8 extends DB {
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace(System.out);
return ERROR;
return Status.ERROR;
}
}
@ -235,7 +233,7 @@ public class CassandraClient8 extends DB {
System.out.println();
}
return OK;
return Status.OK;
} catch (Exception e) {
errorexception = e;
}
@ -248,7 +246,7 @@ public class CassandraClient8 extends DB {
}
errorexception.printStackTrace();
errorexception.printStackTrace(System.out);
return ERROR;
return Status.ERROR;
}
@ -269,7 +267,7 @@ public class CassandraClient8 extends DB {
* pairs for one record
* @return Zero on success, a non-zero error code on error
*/
public int scan(String table, String startkey, int recordcount,
public Status scan(String table, String startkey, int recordcount,
Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
if (!tableName.equals(table)) {
try {
@ -278,7 +276,7 @@ public class CassandraClient8 extends DB {
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace(System.out);
return ERROR;
return Status.ERROR;
}
}
@ -339,7 +337,7 @@ public class CassandraClient8 extends DB {
}
}
return OK;
return Status.OK;
} catch (Exception e) {
errorexception = e;
}
@ -351,7 +349,7 @@ public class CassandraClient8 extends DB {
}
errorexception.printStackTrace();
errorexception.printStackTrace(System.out);
return ERROR;
return Status.ERROR;
}
/**
@ -367,7 +365,7 @@ public class CassandraClient8 extends DB {
* A HashMap of field/value pairs to update in the record
* @return Zero on success, a non-zero error code on error
*/
public int update(String table, String key,
public Status update(String table, String key,
HashMap<String, ByteIterator> values) {
return insert(table, key, values);
}
@ -385,7 +383,7 @@ public class CassandraClient8 extends DB {
* A HashMap of field/value pairs to insert in the record
* @return Zero on success, a non-zero error code on error
*/
public int insert(String table, String key,
public Status insert(String table, String key,
HashMap<String, ByteIterator> values) {
if (!tableName.equals(table)) {
try {
@ -394,7 +392,7 @@ public class CassandraClient8 extends DB {
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace(System.out);
return ERROR;
return Status.ERROR;
}
}
@ -429,7 +427,7 @@ public class CassandraClient8 extends DB {
mutationMap.clear();
record.clear();
return OK;
return Status.OK;
} catch (Exception e) {
errorexception = e;
}
@ -442,7 +440,7 @@ public class CassandraClient8 extends DB {
errorexception.printStackTrace();
errorexception.printStackTrace(System.out);
return ERROR;
return Status.ERROR;
}
/**
@ -454,7 +452,7 @@ public class CassandraClient8 extends DB {
* The record key of the record to delete.
* @return Zero on success, a non-zero error code on error
*/
public int delete(String table, String key) {
public Status delete(String table, String key) {
if (!tableName.equals(table)) {
try {
client.set_keyspace(table);
@ -462,7 +460,7 @@ public class CassandraClient8 extends DB {
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace(System.out);
return ERROR;
return Status.ERROR;
}
}
@ -476,7 +474,7 @@ public class CassandraClient8 extends DB {
System.out.println("Delete key: " + key);
}
return OK;
return Status.OK;
} catch (Exception e) {
errorexception = e;
}
@ -488,7 +486,7 @@ public class CassandraClient8 extends DB {
}
errorexception.printStackTrace();
errorexception.printStackTrace(System.out);
return ERROR;
return Status.ERROR;
}
public static void main(String[] args) {
@ -510,7 +508,7 @@ public class CassandraClient8 extends DB {
vals.put("age", new StringByteIterator("57"));
vals.put("middlename", new StringByteIterator("bradley"));
vals.put("favoritecolor", new StringByteIterator("blue"));
int res = cli.insert("usertable", "BrianFrankCooper", vals);
Status res = cli.insert("usertable", "BrianFrankCooper", vals);
System.out.println("Result of insert: " + res);
HashMap<String, ByteIterator> result = new HashMap<String, ByteIterator>();

Просмотреть файл

@ -35,7 +35,7 @@ import com.yahoo.ycsb.ByteArrayByteIterator;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.DB;
import com.yahoo.ycsb.DBException;
import com.yahoo.ycsb.StatusCode;
import com.yahoo.ycsb.Status;
import java.nio.ByteBuffer;
import java.util.HashMap;
@ -211,7 +211,7 @@ public class CassandraCQLClient extends DB {
* @return Zero on success, a non-zero error code on error
*/
@Override
public int read(String table, String key, Set<String> fields,
public Status read(String table, String key, Set<String> fields,
HashMap<String, ByteIterator> result) {
try {
Statement stmt;
@ -237,7 +237,7 @@ public class CassandraCQLClient extends DB {
ResultSet rs = session.execute(stmt);
if (rs.isExhausted()) {
return StatusCode.NOT_FOUND;
return Status.NOT_FOUND;
}
// Should be only 1 row
@ -253,12 +253,12 @@ public class CassandraCQLClient extends DB {
}
}
return StatusCode.OK;
return Status.OK;
} catch (Exception e) {
e.printStackTrace();
System.out.println("Error reading key: " + key);
return StatusCode.ERROR;
return Status.ERROR;
}
}
@ -284,7 +284,7 @@ public class CassandraCQLClient extends DB {
* @return Zero on success, a non-zero error code on error
*/
@Override
public int scan(String table, String startkey, int recordcount,
public Status scan(String table, String startkey, int recordcount,
Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
try {
@ -344,12 +344,12 @@ public class CassandraCQLClient extends DB {
result.add(tuple);
}
return StatusCode.OK;
return Status.OK;
} catch (Exception e) {
e.printStackTrace();
System.out.println("Error scanning with startkey: " + startkey);
return StatusCode.ERROR;
return Status.ERROR;
}
}
@ -368,7 +368,7 @@ public class CassandraCQLClient extends DB {
* @return Zero on success, a non-zero error code on error
*/
@Override
public int update(String table, String key,
public Status update(String table, String key,
HashMap<String, ByteIterator> values) {
// Insert and updates provide the same functionality
return insert(table, key, values);
@ -388,7 +388,7 @@ public class CassandraCQLClient extends DB {
* @return Zero on success, a non-zero error code on error
*/
@Override
public int insert(String table, String key,
public Status insert(String table, String key,
HashMap<String, ByteIterator> values) {
try {
@ -414,12 +414,12 @@ public class CassandraCQLClient extends DB {
ResultSet rs = session.execute(insertStmt);
return StatusCode.OK;
return Status.OK;
} catch (Exception e) {
e.printStackTrace();
}
return StatusCode.ERROR;
return Status.ERROR;
}
/**
@ -432,7 +432,7 @@ public class CassandraCQLClient extends DB {
* @return Zero on success, a non-zero error code on error
*/
@Override
public int delete(String table, String key) {
public Status delete(String table, String key) {
try {
Statement stmt;
@ -447,13 +447,13 @@ public class CassandraCQLClient extends DB {
ResultSet rs = session.execute(stmt);
return StatusCode.OK;
return Status.OK;
} catch (Exception e) {
e.printStackTrace();
System.out.println("Error deleting key: " + key);
}
return StatusCode.ERROR;
return Status.ERROR;
}
}

Просмотреть файл

@ -33,6 +33,7 @@ import com.datastax.driver.core.querybuilder.Insert;
import com.datastax.driver.core.querybuilder.QueryBuilder;
import com.datastax.driver.core.querybuilder.Select;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.Status;
import com.yahoo.ycsb.StringByteIterator;
import com.yahoo.ycsb.measurements.Measurements;
import com.yahoo.ycsb.workloads.CoreWorkload;
@ -101,9 +102,9 @@ public class CassandraCQLClientTest {
@Test
public void testReadMissingRow() throws Exception {
final HashMap<String, ByteIterator> result = new HashMap<String, ByteIterator>();
final int status = client.read(TABLE, "Missing row", null, result);
final Status status = client.read(TABLE, "Missing row", null, result);
assertThat(result.size(), is(0));
assertThat(status, is(CassandraCQLClient.NOT_FOUND));
assertThat(status, is(Status.NOT_FOUND));
}
private void insertRow() {
@ -121,8 +122,8 @@ public class CassandraCQLClientTest {
insertRow();
final HashMap<String, ByteIterator> result = new HashMap<String, ByteIterator>();
final int status = client.read(CoreWorkload.table, DEFAULT_ROW_KEY, null, result);
assertThat(status, is(CassandraCQLClient.OK));
final Status status = client.read(CoreWorkload.table, DEFAULT_ROW_KEY, null, result);
assertThat(status, is(Status.OK));
assertThat(result.entrySet(), hasSize(11));
assertThat(result, hasEntry("field2", null));
@ -142,8 +143,8 @@ public class CassandraCQLClientTest {
insertRow();
final HashMap<String, ByteIterator> result = new HashMap<String, ByteIterator>();
final Set<String> fields = Sets.newHashSet("field1");
final int status = client.read(CoreWorkload.table, DEFAULT_ROW_KEY, fields, result);
assertThat(status, is(CassandraCQLClient.OK));
final Status status = client.read(CoreWorkload.table, DEFAULT_ROW_KEY, fields, result);
assertThat(status, is(Status.OK));
assertThat(result.entrySet(), hasSize(1));
final Map<String, String> strResult = StringByteIterator.getStringMap(result);
assertThat(strResult, hasEntry("field1", "value2"));
@ -156,8 +157,8 @@ public class CassandraCQLClientTest {
input.put("field0", "value1");
input.put("field1", "value2");
final int status = client.insert(TABLE, key, StringByteIterator.getByteIteratorMap(input));
assertThat(status, is(CassandraCQLClient.OK));
final Status status = client.insert(TABLE, key, StringByteIterator.getByteIteratorMap(input));
assertThat(status, is(Status.OK));
// Verify result
final Select selectStmt =

Просмотреть файл

@ -109,7 +109,7 @@ public class BasicDB extends DB
* @param result A HashMap of field/value pairs for the result
* @return Zero on success, a non-zero error code on error
*/
public int read(String table, String key, Set<String> fields, HashMap<String,ByteIterator> result)
public Status read(String table, String key, Set<String> fields, HashMap<String,ByteIterator> result)
{
delay();
@ -131,7 +131,7 @@ public class BasicDB extends DB
System.out.println("]");
}
return 0;
return Status.OK;
}
/**
@ -144,7 +144,7 @@ public class BasicDB extends DB
* @param result A Vector of HashMaps, where each HashMap is a set field/value pairs for one record
* @return Zero on success, a non-zero error code on error
*/
public int scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String,ByteIterator>> result)
public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String,ByteIterator>> result)
{
delay();
@ -166,7 +166,7 @@ public class BasicDB extends DB
System.out.println("]");
}
return 0;
return Status.OK;
}
/**
@ -178,7 +178,7 @@ public class BasicDB extends DB
* @param values A HashMap of field/value pairs to update in the record
* @return Zero on success, a non-zero error code on error
*/
public int update(String table, String key, HashMap<String,ByteIterator> values)
public Status update(String table, String key, HashMap<String,ByteIterator> values)
{
delay();
@ -195,7 +195,7 @@ public class BasicDB extends DB
System.out.println("]");
}
return 0;
return Status.OK;
}
/**
@ -207,7 +207,7 @@ public class BasicDB extends DB
* @param values A HashMap of field/value pairs to insert in the record
* @return Zero on success, a non-zero error code on error
*/
public int insert(String table, String key, HashMap<String,ByteIterator> values)
public Status insert(String table, String key, HashMap<String,ByteIterator> values)
{
delay();
@ -225,7 +225,7 @@ public class BasicDB extends DB
System.out.println("]");
}
return 0;
return Status.OK;
}
@ -236,7 +236,7 @@ public class BasicDB extends DB
* @param key The record key of the record to delete.
* @return Zero on success, a non-zero error code on error
*/
public int delete(String table, String key)
public Status delete(String table, String key)
{
delay();
@ -245,7 +245,7 @@ public class BasicDB extends DB
System.out.println("DELETE "+table+" "+key);
}
return 0;
return Status.OK;
}
/**

Просмотреть файл

@ -295,8 +295,8 @@ public class CommandLine
}
HashMap<String,ByteIterator> result=new HashMap<String,ByteIterator>();
int ret=db.read(table,tokens[1],fields,result);
System.out.println("Return code: "+ret);
Status ret=db.read(table,tokens[1],fields,result);
System.out.println("Return code: "+ret.getName());
for (Map.Entry<String,ByteIterator> ent : result.entrySet())
{
System.out.println(ent.getKey()+"="+ent.getValue());
@ -324,8 +324,8 @@ public class CommandLine
}
Vector<HashMap<String,ByteIterator>> results=new Vector<HashMap<String,ByteIterator>>();
int ret=db.scan(table,tokens[1],Integer.parseInt(tokens[2]),fields,results);
System.out.println("Return code: "+ret);
Status ret=db.scan(table,tokens[1],Integer.parseInt(tokens[2]),fields,results);
System.out.println("Result: "+ret.getName());
int record=0;
if (results.size()==0)
{
@ -362,8 +362,8 @@ public class CommandLine
values.put(nv[0],new StringByteIterator(nv[1]));
}
int ret=db.update(table,tokens[1],values);
System.out.println("Return code: "+ret);
Status ret=db.update(table,tokens[1],values);
System.out.println("Result: "+ret.getName());
}
}
else if (tokens[0].compareTo("insert")==0)
@ -382,8 +382,8 @@ public class CommandLine
values.put(nv[0],new StringByteIterator(nv[1]));
}
int ret=db.insert(table,tokens[1],values);
System.out.println("Return code: "+ret);
Status ret=db.insert(table,tokens[1],values);
System.out.println("Result: "+ret.getName());
}
}
else if (tokens[0].compareTo("delete")==0)
@ -394,8 +394,8 @@ public class CommandLine
}
else
{
int ret=db.delete(table,tokens[1]);
System.out.println("Return code: "+ret);
Status ret=db.delete(table,tokens[1]);
System.out.println("Return result: "+ret.getName());
}
}
else

Просмотреть файл

@ -88,9 +88,9 @@ public abstract class DB
* @param key The record key of the record to read.
* @param fields The list of fields to read, or null for all of them
* @param result A HashMap of field/value pairs for the result
* @return Zero on success, a non-zero error code on error or "not found".
* @return The result of the operation.
*/
public abstract int read(String table, String key, Set<String> fields, HashMap<String,ByteIterator> result);
public abstract Status read(String table, String key, Set<String> fields, HashMap<String,ByteIterator> result);
/**
* Perform a range scan for a set of records in the database. Each field/value pair from the result will be stored in a HashMap.
@ -100,9 +100,9 @@ public abstract class DB
* @param recordcount The number of records to read
* @param fields The list of fields to read, or null for all of them
* @param result A Vector of HashMaps, where each HashMap is a set field/value pairs for one record
* @return Zero on success, a non-zero error code on error. See this class's description for a discussion of error codes.
* @return The result of the operation.
*/
public abstract int scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String,ByteIterator>> result);
public abstract Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String,ByteIterator>> result);
/**
* Update a record in the database. Any field/value pairs in the specified values HashMap will be written into the record with the specified
@ -111,9 +111,9 @@ public abstract class DB
* @param table The name of the table
* @param key The record key of the record to write.
* @param values A HashMap of field/value pairs to update in the record
* @return Zero on success, a non-zero error code on error. See this class's description for a discussion of error codes.
* @return The result of the operation.
*/
public abstract int update(String table, String key, HashMap<String,ByteIterator> values);
public abstract Status update(String table, String key, HashMap<String,ByteIterator> values);
/**
* Insert a record in the database. Any field/value pairs in the specified values HashMap will be written into the record with the specified
@ -122,16 +122,16 @@ public abstract class DB
* @param table The name of the table
* @param key The record key of the record to insert.
* @param values A HashMap of field/value pairs to insert in the record
* @return Zero on success, a non-zero error code on error. See this class's description for a discussion of error codes.
* @return The result of the operation.
*/
public abstract int insert(String table, String key, HashMap<String,ByteIterator> values);
public abstract Status insert(String table, String key, HashMap<String,ByteIterator> values);
/**
* Delete a record from the database.
*
* @param table The name of the table
* @param key The record key of the record to delete.
* @return Zero on success, a non-zero error code on error. See this class's description for a discussion of error codes.
* @return The result of the operation.
*/
public abstract int delete(String table, String key);
public abstract Status delete(String table, String key);
}

Просмотреть файл

@ -83,16 +83,16 @@ public class DBWrapper extends DB
* @param key The record key of the record to read.
* @param fields The list of fields to read, or null for all of them
* @param result A HashMap of field/value pairs for the result
* @return Zero on success, a non-zero error code on error
* @return The result of the operation.
*/
public int read(String table, String key, Set<String> fields, HashMap<String,ByteIterator> result)
public Status read(String table, String key, Set<String> fields, HashMap<String,ByteIterator> result)
{
long ist=_measurements.getIntendedtartTimeNs();
long st = System.nanoTime();
int res=_db.read(table,key,fields,result);
Status res=_db.read(table,key,fields,result);
long en=System.nanoTime();
measure("READ",ist, st, en);
_measurements.reportReturnCode("READ",res);
_measurements.reportStatus("READ",res);
return res;
}
@ -104,16 +104,16 @@ public class DBWrapper extends DB
* @param recordcount The number of records to read
* @param fields The list of fields to read, or null for all of them
* @param result A Vector of HashMaps, where each HashMap is a set field/value pairs for one record
* @return Zero on success, a non-zero error code on error
* @return The result of the operation.
*/
public int scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String,ByteIterator>> result)
public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String,ByteIterator>> result)
{
long ist=_measurements.getIntendedtartTimeNs();
long st = System.nanoTime();
int res=_db.scan(table,startkey,recordcount,fields,result);
Status res=_db.scan(table,startkey,recordcount,fields,result);
long en=System.nanoTime();
measure("SCAN",ist, st, en);
_measurements.reportReturnCode("SCAN",res);
_measurements.reportStatus("SCAN",res);
return res;
}
@ -129,16 +129,16 @@ public class DBWrapper extends DB
* @param table The name of the table
* @param key The record key of the record to write.
* @param values A HashMap of field/value pairs to update in the record
* @return Zero on success, a non-zero error code on error
* @return The result of the operation.
*/
public int update(String table, String key, HashMap<String,ByteIterator> values)
public Status update(String table, String key, HashMap<String,ByteIterator> values)
{
long ist=_measurements.getIntendedtartTimeNs();
long st = System.nanoTime();
int res=_db.update(table,key,values);
Status res=_db.update(table,key,values);
long en=System.nanoTime();
measure("UPDATE",ist, st, en);
_measurements.reportReturnCode("UPDATE",res);
_measurements.reportStatus("UPDATE",res);
return res;
}
@ -149,16 +149,16 @@ public class DBWrapper extends DB
* @param table The name of the table
* @param key The record key of the record to insert.
* @param values A HashMap of field/value pairs to insert in the record
* @return Zero on success, a non-zero error code on error
* @return The result of the operation.
*/
public int insert(String table, String key, HashMap<String,ByteIterator> values)
public Status insert(String table, String key, HashMap<String,ByteIterator> values)
{
long ist=_measurements.getIntendedtartTimeNs();
long st = System.nanoTime();
int res=_db.insert(table,key,values);
Status res=_db.insert(table,key,values);
long en=System.nanoTime();
measure("INSERT",ist, st, en);
_measurements.reportReturnCode("INSERT",res);
_measurements.reportStatus("INSERT",res);
return res;
}
@ -167,16 +167,16 @@ public class DBWrapper extends DB
*
* @param table The name of the table
* @param key The record key of the record to delete.
* @return Zero on success, a non-zero error code on error
* @return The result of the operation.
*/
public int delete(String table, String key)
public Status delete(String table, String key)
{
long ist=_measurements.getIntendedtartTimeNs();
long st = System.nanoTime();
int res=_db.delete(table,key);
Status res=_db.delete(table,key);
long en=System.nanoTime();
measure("DELETE",ist, st, en);
_measurements.reportReturnCode("DELETE",res);
_measurements.reportStatus("DELETE",res);
return res;
}
}

Просмотреть файл

@ -96,9 +96,9 @@ public class GoodBadUglyDB extends DB {
* @param result A HashMap of field/value pairs for the result
* @return Zero on success, a non-zero error code on error
*/
public int read(String table, String key, Set<String> fields, HashMap<String, ByteIterator> result) {
public Status read(String table, String key, Set<String> fields, HashMap<String, ByteIterator> result) {
delay();
return 0;
return Status.OK;
}
/**
@ -112,11 +112,11 @@ public class GoodBadUglyDB extends DB {
* @param result A Vector of HashMaps, where each HashMap is a set field/value pairs for one record
* @return Zero on success, a non-zero error code on error
*/
public int scan(String table, String startkey, int recordcount, Set<String> fields,
public Status scan(String table, String startkey, int recordcount, Set<String> fields,
Vector<HashMap<String, ByteIterator>> result) {
delay();
return 0;
return Status.OK;
}
/**
@ -128,10 +128,10 @@ public class GoodBadUglyDB extends DB {
* @param values A HashMap of field/value pairs to update in the record
* @return Zero on success, a non-zero error code on error
*/
public int update(String table, String key, HashMap<String, ByteIterator> values) {
public Status update(String table, String key, HashMap<String, ByteIterator> values) {
delay();
return 0;
return Status.OK;
}
/**
@ -143,9 +143,9 @@ public class GoodBadUglyDB extends DB {
* @param values A HashMap of field/value pairs to insert in the record
* @return Zero on success, a non-zero error code on error
*/
public int insert(String table, String key, HashMap<String, ByteIterator> values) {
public Status insert(String table, String key, HashMap<String, ByteIterator> values) {
delay();
return 0;
return Status.OK;
}
/**
@ -155,8 +155,8 @@ public class GoodBadUglyDB extends DB {
* @param key The record key of the record to delete.
* @return Zero on success, a non-zero error code on error
*/
public int delete(String table, String key) {
public Status delete(String table, String key) {
delay();
return 0;
return Status.OK;
}
}

Просмотреть файл

@ -0,0 +1,72 @@
package com.yahoo.ycsb;
/**
* The result of an operation.
*/
public class Status {
private final String name;
private final String description;
/**
* @param name A short name for the status.
* @param description A description of the status.
*/
public Status(String name, String description) {
super();
this.name = name;
this.description = description;
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
@Override
public String toString() {
return "Status [name=" + name + ", description=" + description + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Status other = (Status) obj;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
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 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.");
public static final Status UNEXPECTED_STATE = new Status("UNEXPECTED_STATE", "The operation reported success, but the result was not as expected.");
}

Просмотреть файл

@ -1,39 +0,0 @@
/**
* Copyright (c) 2010 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.
*/
package com.yahoo.ycsb;
/**
* Status codes returned by databases.
*/
public class StatusCode {
/**
* The operation completed without error.
*/
public final static int OK = 0;
/**
* The operation failed, with a generic error.
*/
public static final int ERROR = -1;
/**
* The operation failed: the requested record was not found.
*/
public static final int NOT_FOUND = -3;
}

Просмотреть файл

@ -17,12 +17,13 @@
package com.yahoo.ycsb.measurements;
import com.yahoo.ycsb.Status;
import com.yahoo.ycsb.measurements.exporter.MeasurementsExporter;
import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import com.yahoo.ycsb.measurements.exporter.MeasurementsExporter;
/**
* Collects latency measurements, and reports them when requested.
*
@ -237,12 +238,12 @@ public class Measurements
/**
* Report a return code for a single DB operation.
*/
public void reportReturnCode(String operation, int code)
public void reportStatus(final String operation, final Status status)
{
OneMeasurement m = _measurementInterval==1 ?
getOpIntendedMeasurement(operation) :
getOpMeasurement(operation);
m.reportReturnCode(code);
m.reportStatus(status);
}
/**

Просмотреть файл

@ -17,20 +17,21 @@
package com.yahoo.ycsb.measurements;
import java.io.IOException;
import java.util.concurrent.ConcurrentHashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import com.yahoo.ycsb.Status;
import com.yahoo.ycsb.measurements.exporter.MeasurementsExporter;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
/**
* A single measured metric (such as READ LATENCY)
*/
public abstract class OneMeasurement {
private final String _name;
private final ConcurrentHashMap<Integer, AtomicInteger> _returncodes;
private final ConcurrentHashMap<Status, AtomicInteger> _returncodes;
public String getName() {
return _name;
@ -41,7 +42,7 @@ public abstract class OneMeasurement {
*/
public OneMeasurement(String _name) {
this._name = _name;
this._returncodes = new ConcurrentHashMap<Integer, AtomicInteger>();
this._returncodes = new ConcurrentHashMap<Status, AtomicInteger>();
}
public abstract void measure(int latency);
@ -51,12 +52,11 @@ public abstract class OneMeasurement {
/**
* No need for synchronization, using CHM to deal with that
*/
public void reportReturnCode(int code) {
Integer Icode = code;
AtomicInteger counter = _returncodes.get(Icode);
public void reportStatus(Status status) {
AtomicInteger counter = _returncodes.get(status);
if (counter == null) {
AtomicInteger other = _returncodes.putIfAbsent(Icode, counter = new AtomicInteger());
AtomicInteger other = _returncodes.putIfAbsent(status, counter = new AtomicInteger());
if (other != null) {
counter = other;
}
@ -73,9 +73,9 @@ public abstract class OneMeasurement {
*/
public abstract void exportMeasurements(MeasurementsExporter exporter) throws IOException;
protected final void exportReturnCodes(MeasurementsExporter exporter) throws IOException {
for (Map.Entry<Integer, AtomicInteger> entry : _returncodes.entrySet()) {
exporter.write(getName(), "Return=" + entry.getKey(), entry.getValue().get());
protected final void exportStatusCounts(MeasurementsExporter exporter) throws IOException {
for (Map.Entry<Status, AtomicInteger> entry : _returncodes.entrySet()) {
exporter.write(getName(), "Return=" + entry.getKey().getName(), entry.getValue().get());
}
}
}

Просмотреть файл

@ -118,7 +118,7 @@ public class OneMeasurementHdrHistogram extends OneMeasurement {
exporter.write(getName(), ordinal(percentile) + "PercentileLatency(us)", totalHistogram.getValueAtPercentile(percentile));
}
exportReturnCodes(exporter);
exportStatusCounts(exporter);
}
/**

Просмотреть файл

@ -119,7 +119,7 @@ public class OneMeasurementHistogram extends OneMeasurement
}
}
exportReturnCodes(exporter);
exportStatusCounts(exporter);
for (int i=0; i<_buckets; i++)
{

Просмотреть файл

@ -135,7 +135,7 @@ public class OneMeasurementTimeSeries extends OneMeasurement
// TODO: 95th and 99th percentile latency
exportReturnCodes(exporter);
exportStatusCounts(exporter);
for (SeriesUnit unit : _measurements) {
exporter.write(getName(), Long.toString(unit.time), unit.average);
}

Просмотреть файл

@ -17,11 +17,12 @@
package com.yahoo.ycsb.measurements;
import java.io.IOException;
import com.yahoo.ycsb.Status;
import com.yahoo.ycsb.measurements.exporter.MeasurementsExporter;
import org.HdrHistogram.Recorder;
import com.yahoo.ycsb.measurements.exporter.MeasurementsExporter;
import java.io.IOException;
/**
* delegates to 2 measurement instances.
@ -40,10 +41,11 @@ public class TwoInOneMeasurement extends OneMeasurement {
/**
* No need for synchronization, using CHM to deal with that
*
* @see com.yahoo.ycsb.OneMeasurement#reportReturnCode(int)
* @see com.yahoo.ycsb.OneMeasurement#reportStatus(int)
*/
public void reportReturnCode(int code) {
thing1.reportReturnCode(code);
@Override
public void reportStatus(final Status status) {
thing1.reportStatus(status);
}
/**
@ -52,6 +54,7 @@ public class TwoInOneMeasurement extends OneMeasurement {
*
* @see com.yahoo.ycsb.OneMeasurement#measure(int)
*/
@Override
public void measure(int latencyInMicros) {
thing1.measure(latencyInMicros);
thing2.measure(latencyInMicros);

Просмотреть файл

@ -546,7 +546,7 @@ public class CoreWorkload extends Workload
int keynum=keysequence.nextInt();
String dbkey = buildKeyName(keynum);
HashMap<String, ByteIterator> values = buildValues(dbkey);
if (db.insert(table,dbkey,values) == 0)
if (db.insert(table,dbkey,values).equals(Status.OK))
return true;
else
return false;

Просмотреть файл

@ -25,17 +25,26 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.DB;
import com.yahoo.ycsb.DBException;
import com.yahoo.ycsb.Status;
import com.yahoo.ycsb.StringByteIterator;
import net.spy.memcached.PersistTo;
import net.spy.memcached.ReplicateTo;
import net.spy.memcached.internal.OperationFuture;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.StringWriter;
import java.io.Writer;
import java.net.URI;
import java.util.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.Vector;
/**
* A class that wraps the CouchbaseClient to allow it to be interfaced with YCSB.
@ -65,9 +74,6 @@ public class CouchbaseClient extends DB {
public static final String REPLICATE_PROPERTY = "couchbase.replicateTo";
public static final String JSON_PROPERTY = "couchbase.json";
public static final int OK = 0;
public static final int FAILURE = 1;
protected static final ObjectMapper JSON_MAPPER = new ObjectMapper();
private com.couchbase.client.CouchbaseClient client;
@ -156,7 +162,7 @@ public class CouchbaseClient extends DB {
}
@Override
public int read(final String table, final String key, final Set<String> fields,
public Status read(final String table, final String key, final Set<String> fields,
final HashMap<String, ByteIterator> result) {
String formattedKey = formatKey(table, key);
@ -164,16 +170,16 @@ public class CouchbaseClient extends DB {
Object loaded = client.get(formattedKey);
if (loaded == null) {
return FAILURE;
return Status.ERROR;
}
decode(loaded, fields, result);
return OK;
return Status.OK;
} catch (Exception e) {
if (log.isErrorEnabled()) {
log.error("Could not read value for key " + formattedKey, e);
}
return FAILURE;
return Status.ERROR;
}
}
@ -185,16 +191,16 @@ public class CouchbaseClient extends DB {
* @param recordcount The number of records to read
* @param fields The list of fields to read, or null for all of them
* @param result A Vector of HashMaps, where each HashMap is a set field/value pairs for one record
* @return FAILURE, because not implemented yet.
* @return Status.ERROR, because not implemented yet.
*/
@Override
public int scan(final String table, final String startkey, final int recordcount,
public Status scan(final String table, final String startkey, final int recordcount,
final Set<String> fields, final Vector<HashMap<String, ByteIterator>> result) {
return FAILURE;
return Status.ERROR;
}
@Override
public int update(final String table, final String key, final HashMap<String, ByteIterator> values) {
public Status update(final String table, final String key, final HashMap<String, ByteIterator> values) {
String formattedKey = formatKey(table, key);
try {
@ -209,12 +215,12 @@ public class CouchbaseClient extends DB {
if (log.isErrorEnabled()) {
log.error("Could not update value for key " + formattedKey, e);
}
return FAILURE;
return Status.ERROR;
}
}
@Override
public int insert(final String table, final String key, final HashMap<String, ByteIterator> values) {
public Status insert(final String table, final String key, final HashMap<String, ByteIterator> values) {
String formattedKey = formatKey(table, key);
try {
@ -229,12 +235,12 @@ public class CouchbaseClient extends DB {
if (log.isErrorEnabled()) {
log.error("Could not insert value for key " + formattedKey, e);
}
return FAILURE;
return Status.ERROR;
}
}
@Override
public int delete(final String table, final String key) {
public Status delete(final String table, final String key) {
String formattedKey = formatKey(table, key);
try {
@ -244,7 +250,7 @@ public class CouchbaseClient extends DB {
if (log.isErrorEnabled()) {
log.error("Could not delete value for key " + formattedKey, e);
}
return FAILURE;
return Status.ERROR;
}
}
@ -265,11 +271,11 @@ public class CouchbaseClient extends DB {
* @param future the future to potentially verify.
* @return the status of the future result.
*/
private int checkFutureStatus(final OperationFuture<?> future) {
private Status checkFutureStatus(final OperationFuture<?> future) {
if (checkFutures) {
return future.getStatus().isSuccess() ? OK : FAILURE;
return future.getStatus().isSuccess() ? Status.OK : Status.ERROR;
} else {
return OK;
return Status.OK;
}
}

Просмотреть файл

@ -16,24 +16,12 @@
package com.yahoo.ycsb.db;
import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import java.util.Vector;
import java.io.File;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.PropertiesCredentials;
import com.amazonaws.ClientConfiguration;
import com.amazonaws.services.dynamodb.AmazonDynamoDBClient;
import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.ClientConfiguration;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.PropertiesCredentials;
import com.amazonaws.services.dynamodb.AmazonDynamoDBClient;
import com.amazonaws.services.dynamodb.model.AttributeValue;
import com.amazonaws.services.dynamodb.model.AttributeValueUpdate;
import com.amazonaws.services.dynamodb.model.DeleteItemRequest;
@ -49,17 +37,25 @@ import com.amazonaws.services.dynamodb.model.UpdateItemRequest;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.DB;
import com.yahoo.ycsb.DBException;
import com.yahoo.ycsb.Status;
import com.yahoo.ycsb.StringByteIterator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Vector;
/**
* DynamoDB v1.3.14 client for YCSB
*/
public class DynamoDBClient extends DB {
private static final int OK = 0;
private static final int SERVER_ERROR = 1;
private static final int CLIENT_ERROR = 2;
private AmazonDynamoDBClient dynamoDB;
private String primaryKeyName;
private boolean debug = false;
@ -119,7 +115,7 @@ public class DynamoDBClient extends DB {
}
@Override
public int read(String table, String key, Set<String> fields,
public Status read(String table, String key, Set<String> fields,
HashMap<String, ByteIterator> result) {
logger.debug("readkey: " + key + " from table: " + table);
@ -132,7 +128,7 @@ public class DynamoDBClient extends DB {
res = dynamoDB.getItem(req);
}catch (AmazonServiceException ex) {
logger.error(ex.getMessage());
return SERVER_ERROR;
return Status.ERROR;
}catch (AmazonClientException ex){
logger.error(ex.getMessage());
return CLIENT_ERROR;
@ -143,11 +139,11 @@ public class DynamoDBClient extends DB {
result.putAll(extractResult(res.getItem()));
logger.debug("Result: " + res.toString());
}
return OK;
return Status.OK;
}
@Override
public int scan(String table, String startkey, int recordcount,
public Status scan(String table, String startkey, int recordcount,
Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
logger.debug("scan " + recordcount + " records from key: " + startkey + " on table: " + table);
/*
@ -163,7 +159,7 @@ public class DynamoDBClient extends DB {
gres = dynamoDB.getItem(greq);
}catch (AmazonServiceException ex) {
logger.error(ex.getMessage());
return SERVER_ERROR;
return Status.ERROR;
}catch (AmazonClientException ex){
logger.error(ex.getMessage());
return CLIENT_ERROR;
@ -187,7 +183,7 @@ public class DynamoDBClient extends DB {
}catch (AmazonServiceException ex) {
logger.error(ex.getMessage());
ex.printStackTrace();
return SERVER_ERROR;
return Status.ERROR;
}catch (AmazonClientException ex){
logger.error(ex.getMessage());
ex.printStackTrace();
@ -202,11 +198,11 @@ public class DynamoDBClient extends DB {
}
return OK;
return Status.OK;
}
@Override
public int update(String table, String key, HashMap<String, ByteIterator> values) {
public Status update(String table, String key, HashMap<String, ByteIterator> values) {
logger.debug("updatekey: " + key + " from table: " + table);
Map<String, AttributeValueUpdate> attributes = new HashMap<String, AttributeValueUpdate>(
@ -223,16 +219,16 @@ public class DynamoDBClient extends DB {
dynamoDB.updateItem(req);
}catch (AmazonServiceException ex) {
logger.error(ex.getMessage());
return SERVER_ERROR;
return Status.ERROR;
}catch (AmazonClientException ex){
logger.error(ex.getMessage());
return CLIENT_ERROR;
}
return OK;
return Status.OK;
}
@Override
public int insert(String table, String key,HashMap<String, ByteIterator> values) {
public Status insert(String table, String key,HashMap<String, ByteIterator> values) {
logger.debug("insertkey: " + primaryKeyName + "-" + key + " from table: " + table);
Map<String, AttributeValue> attributes = createAttributes(values);
// adding primary key
@ -244,16 +240,16 @@ public class DynamoDBClient extends DB {
res = dynamoDB.putItem(putItemRequest);
}catch (AmazonServiceException ex) {
logger.error(ex.getMessage());
return SERVER_ERROR;
return Status.ERROR;
}catch (AmazonClientException ex){
logger.error(ex.getMessage());
return CLIENT_ERROR;
}
return OK;
return Status.OK;
}
@Override
public int delete(String table, String key) {
public Status delete(String table, String key) {
logger.debug("deletekey: " + key + " from table: " + table);
DeleteItemRequest req = new DeleteItemRequest(table, createPrimaryKey(key));
DeleteItemResult res = null;
@ -262,12 +258,12 @@ public class DynamoDBClient extends DB {
res = dynamoDB.deleteItem(req);
}catch (AmazonServiceException ex) {
logger.error(ex.getMessage());
return SERVER_ERROR;
return Status.ERROR;
}catch (AmazonClientException ex){
logger.error(ex.getMessage());
return CLIENT_ERROR;
}
return OK;
return Status.OK;
}
private static Map<String, AttributeValue> createAttributes(
@ -297,4 +293,6 @@ public class DynamoDBClient extends DB {
Key k = new Key().withHashKeyElement(new AttributeValue().withS(key));
return k;
}
private final static Status CLIENT_ERROR = new Status("CLIENT_ERROR", "An error occurred on the client.");
}

Просмотреть файл

@ -17,32 +17,35 @@
package com.yahoo.ycsb.db;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.index.query.FilterBuilders.rangeFilter;
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
import static org.elasticsearch.node.NodeBuilder.nodeBuilder;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.DB;
import com.yahoo.ycsb.DBException;
import com.yahoo.ycsb.Status;
import com.yahoo.ycsb.StringByteIterator;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.Requests;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.ImmutableSettings.Builder;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.query.RangeFilterBuilder;
import org.elasticsearch.node.Node;
import org.elasticsearch.search.SearchHit;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import java.util.Vector;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.Requests;
import static org.elasticsearch.common.settings.ImmutableSettings.*;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.ImmutableSettings.Builder;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.common.xcontent.XContentBuilder;
import static org.elasticsearch.common.xcontent.XContentFactory.*;
import static org.elasticsearch.index.query.FilterBuilders.*;
import static org.elasticsearch.index.query.QueryBuilders.*;
import org.elasticsearch.index.query.RangeFilterBuilder;
import org.elasticsearch.node.Node;
import static org.elasticsearch.node.NodeBuilder.*;
import org.elasticsearch.search.SearchHit;
/**
* ElasticSearch client for YCSB framework.
@ -152,7 +155,7 @@ public class ElasticSearchClient extends DB {
* description for a discussion of error codes.
*/
@Override
public int insert(String table, String key, HashMap<String, ByteIterator> values) {
public Status insert(String table, String key, HashMap<String, ByteIterator> values) {
try {
final XContentBuilder doc = jsonBuilder().startObject();
@ -167,11 +170,11 @@ public class ElasticSearchClient extends DB {
.execute()
.actionGet();
return 0;
return Status.OK;
} catch (Exception e) {
e.printStackTrace();
}
return 1;
return Status.ERROR;
}
/**
@ -183,16 +186,16 @@ public class ElasticSearchClient extends DB {
* description for a discussion of error codes.
*/
@Override
public int delete(String table, String key) {
public Status delete(String table, String key) {
try {
client.prepareDelete(indexKey, table, key)
.execute()
.actionGet();
return 0;
return Status.OK;
} catch (Exception e) {
e.printStackTrace();
}
return 1;
return Status.ERROR;
}
/**
@ -206,7 +209,7 @@ public class ElasticSearchClient extends DB {
* @return Zero on success, a non-zero error code on error or "not found".
*/
@Override
public int read(String table, String key, Set<String> fields, HashMap<String, ByteIterator> result) {
public Status read(String table, String key, Set<String> fields, HashMap<String, ByteIterator> result) {
try {
final GetResponse response = client.prepareGet(indexKey, table, key)
.execute()
@ -222,12 +225,12 @@ public class ElasticSearchClient extends DB {
result.put(field, new StringByteIterator((String) response.getSource().get(field)));
}
}
return 0;
return Status.OK;
}
} catch (Exception e) {
e.printStackTrace();
}
return 1;
return Status.ERROR;
}
/**
@ -242,7 +245,7 @@ public class ElasticSearchClient extends DB {
* description for a discussion of error codes.
*/
@Override
public int update(String table, String key, HashMap<String, ByteIterator> values) {
public Status update(String table, String key, HashMap<String, ByteIterator> values) {
try {
final GetResponse response = client.prepareGet(indexKey, table, key)
.execute()
@ -258,13 +261,13 @@ public class ElasticSearchClient extends DB {
.execute()
.actionGet();
return 0;
return Status.OK;
}
} catch (Exception e) {
e.printStackTrace();
}
return 1;
return Status.ERROR;
}
/**
@ -281,7 +284,7 @@ public class ElasticSearchClient extends DB {
* description for a discussion of error codes.
*/
@Override
public int scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
try {
final RangeFilterBuilder filter = rangeFilter("_id").gte(startkey);
final SearchResponse response = client.prepareSearch(indexKey)
@ -304,10 +307,10 @@ public class ElasticSearchClient extends DB {
result.add(entry);
}
return 0;
return Status.OK;
} catch (Exception e) {
e.printStackTrace();
}
return 1;
return Status.ERROR;
}
}

Просмотреть файл

@ -21,19 +21,23 @@
*/
package com.yahoo.ycsb.db;
import static org.testng.AssertJUnit.assertEquals;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.DBException;
import com.yahoo.ycsb.Status;
import com.yahoo.ycsb.StringByteIterator;
import java.util.HashMap;
import java.util.Set;
import java.util.Vector;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.util.HashMap;
import java.util.Set;
import java.util.Vector;
/**
*
* @author saden
@ -82,9 +86,8 @@ public class ElasticSearchClientTest {
@Test
public void testInsert() {
System.out.println("insert");
int expResult = 0;
int result = instance.insert(MOCK_TABLE, MOCK_KEY0, MOCK_DATA);
assertEquals(expResult, result);
Status result = instance.insert(MOCK_TABLE, MOCK_KEY0, MOCK_DATA);
assertEquals(Status.OK, result);
}
/**
@ -93,9 +96,8 @@ public class ElasticSearchClientTest {
@Test
public void testDelete() {
System.out.println("delete");
int expResult = 0;
int result = instance.delete(MOCK_TABLE, MOCK_KEY1);
assertEquals(expResult, result);
Status result = instance.delete(MOCK_TABLE, MOCK_KEY1);
assertEquals(Status.OK, result);
}
/**
@ -106,9 +108,8 @@ public class ElasticSearchClientTest {
System.out.println("read");
Set<String> fields = MOCK_DATA.keySet();
HashMap<String, ByteIterator> resultParam = new HashMap<String, ByteIterator>(10);
int expResult = 0;
int result = instance.read(MOCK_TABLE, MOCK_KEY1, fields, resultParam);
assertEquals(expResult, result);
Status result = instance.read(MOCK_TABLE, MOCK_KEY1, fields, resultParam);
assertEquals(Status.OK, result);
}
/**
@ -124,9 +125,8 @@ public class ElasticSearchClientTest {
newValues.put("field" + i, new StringByteIterator("newvalue" + i));
}
int expResult = 0;
int result = instance.update(MOCK_TABLE, MOCK_KEY1, newValues);
assertEquals(expResult, result);
Status result = instance.update(MOCK_TABLE, MOCK_KEY1, newValues);
assertEquals(Status.OK, result);
//validate that the values changed
HashMap<String, ByteIterator> resultParam = new HashMap<String, ByteIterator>(10);
@ -147,8 +147,7 @@ public class ElasticSearchClientTest {
int recordcount = 10;
Set<String> fields = MOCK_DATA.keySet();
Vector<HashMap<String, ByteIterator>> resultParam = new Vector<HashMap<String, ByteIterator>>(10);
int expResult = 0;
int result = instance.scan(MOCK_TABLE, MOCK_KEY1, recordcount, fields, resultParam);
assertEquals(expResult, result);
Status result = instance.scan(MOCK_TABLE, MOCK_KEY1, recordcount, fields, resultParam);
assertEquals(Status.OK, result);
}
}

Просмотреть файл

@ -17,12 +17,6 @@
package com.yahoo.ycsb.db;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.Vector;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CacheFactory;
import com.gemstone.gemfire.cache.GemFireCache;
@ -39,7 +33,13 @@ import com.yahoo.ycsb.ByteArrayByteIterator;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.DB;
import com.yahoo.ycsb.DBException;
import com.yahoo.ycsb.StringByteIterator;
import com.yahoo.ycsb.Status;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.Vector;
/**
* VMware vFabric GemFire client for the YCSB benchmark.<br />
@ -66,12 +66,6 @@ import com.yahoo.ycsb.StringByteIterator;
*/
public class GemFireClient extends DB {
/** Return code when operation succeeded */
private static final int SUCCESS = 0;
/** Return code when operation did not succeed */
private static final int ERROR = -1;
/** property name of the port where GemFire server is listening for connections */
private static final String SERVERPORT_PROPERTY_NAME = "gemfire.serverport";
@ -143,7 +137,7 @@ public class GemFireClient extends DB {
}
@Override
public int read(String table, String key, Set<String> fields,
public Status read(String table, String key, Set<String> fields,
HashMap<String, ByteIterator> result) {
Region<String, Map<String, byte[]>> r = getRegion(table);
Map<String, byte[]> val = r.get(key);
@ -157,34 +151,34 @@ public class GemFireClient extends DB {
result.put(field, new ByteArrayByteIterator(val.get(field)));
}
}
return SUCCESS;
return Status.OK;
}
return ERROR;
return Status.ERROR;
}
@Override
public int scan(String table, String startkey, int recordcount,
public Status scan(String table, String startkey, int recordcount,
Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
// GemFire does not support scan
return ERROR;
return Status.ERROR;
}
@Override
public int update(String table, String key, HashMap<String, ByteIterator> values) {
public Status update(String table, String key, HashMap<String, ByteIterator> values) {
getRegion(table).put(key, convertToBytearrayMap(values));
return 0;
return Status.OK;
}
@Override
public int insert(String table, String key, HashMap<String, ByteIterator> values) {
public Status insert(String table, String key, HashMap<String, ByteIterator> values) {
getRegion(table).put(key, convertToBytearrayMap(values));
return 0;
return Status.OK;
}
@Override
public int delete(String table, String key) {
public Status delete(String table, String key) {
getRegion(table).destroy(key);
return 0;
return Status.OK;
}
private Map<String, byte[]> convertToBytearrayMap(Map<String,ByteIterator> values) {

Просмотреть файл

@ -20,7 +20,7 @@ package com.yahoo.ycsb.db;
import com.yahoo.ycsb.ByteArrayByteIterator;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.DBException;
import com.yahoo.ycsb.StatusCode;
import com.yahoo.ycsb.Status;
import com.yahoo.ycsb.measurements.Measurements;
import org.apache.hadoop.conf.Configuration;
@ -160,7 +160,7 @@ public class HBaseClient extends com.yahoo.ycsb.DB
* @param result A HashMap of field/value pairs for the result
* @return Zero on success, a non-zero error code on error
*/
public int read(String table, String key, Set<String> fields, HashMap<String,ByteIterator> result)
public Status read(String table, String key, Set<String> fields, HashMap<String,ByteIterator> result)
{
//if this is a "new" table, init HTable object. Else, use existing one
if (!_table.equals(table)) {
@ -173,7 +173,7 @@ public class HBaseClient extends com.yahoo.ycsb.DB
catch (IOException e)
{
System.err.println("Error accessing HBase table: "+e);
return StatusCode.ERROR;
return Status.ERROR;
}
}
@ -197,12 +197,12 @@ public class HBaseClient extends com.yahoo.ycsb.DB
catch (IOException e)
{
System.err.println("Error doing get: "+e);
return StatusCode.ERROR;
return Status.ERROR;
}
catch (ConcurrentModificationException e)
{
//do nothing for now...need to understand HBase concurrency model better
return StatusCode.ERROR;
return Status.ERROR;
}
for (KeyValue kv : r.raw()) {
@ -215,7 +215,7 @@ public class HBaseClient extends com.yahoo.ycsb.DB
}
}
return StatusCode.OK;
return Status.OK;
}
/**
@ -228,7 +228,7 @@ public class HBaseClient extends com.yahoo.ycsb.DB
* @param result A Vector of HashMaps, where each HashMap is a set field/value pairs for one record
* @return Zero on success, a non-zero error code on error
*/
public int scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String,ByteIterator>> result)
public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String,ByteIterator>> result)
{
//if this is a "new" table, init HTable object. Else, use existing one
if (!_table.equals(table)) {
@ -241,7 +241,7 @@ public class HBaseClient extends com.yahoo.ycsb.DB
catch (IOException e)
{
System.err.println("Error accessing HBase table: "+e);
return StatusCode.ERROR;
return Status.ERROR;
}
}
@ -306,14 +306,14 @@ public class HBaseClient extends com.yahoo.ycsb.DB
{
System.out.println("Error in getting/parsing scan result: "+e);
}
return StatusCode.ERROR;
return Status.ERROR;
}
finally {
scanner.close();
}
return StatusCode.OK;
return Status.OK;
}
/**
@ -325,7 +325,7 @@ public class HBaseClient extends com.yahoo.ycsb.DB
* @param values A HashMap of field/value pairs to update in the record
* @return Zero on success, a non-zero error code on error
*/
public int update(String table, String key, HashMap<String,ByteIterator> values)
public Status update(String table, String key, HashMap<String,ByteIterator> values)
{
//if this is a "new" table, init HTable object. Else, use existing one
if (!_table.equals(table)) {
@ -338,7 +338,7 @@ public class HBaseClient extends com.yahoo.ycsb.DB
catch (IOException e)
{
System.err.println("Error accessing HBase table: "+e);
return StatusCode.ERROR;
return Status.ERROR;
}
}
@ -366,15 +366,15 @@ public class HBaseClient extends com.yahoo.ycsb.DB
if (_debug) {
System.err.println("Error doing put: "+e);
}
return StatusCode.ERROR;
return Status.ERROR;
}
catch (ConcurrentModificationException e)
{
//do nothing for now...hope this is rare
return StatusCode.ERROR;
return Status.ERROR;
}
return StatusCode.OK;
return Status.OK;
}
/**
@ -386,7 +386,7 @@ public class HBaseClient extends com.yahoo.ycsb.DB
* @param values A HashMap of field/value pairs to insert in the record
* @return Zero on success, a non-zero error code on error
*/
public int insert(String table, String key, HashMap<String,ByteIterator> values)
public Status insert(String table, String key, HashMap<String,ByteIterator> values)
{
return update(table,key,values);
}
@ -398,7 +398,7 @@ public class HBaseClient extends com.yahoo.ycsb.DB
* @param key The record key of the record to delete.
* @return Zero on success, a non-zero error code on error
*/
public int delete(String table, String key)
public Status delete(String table, String key)
{
//if this is a "new" table, init HTable object. Else, use existing one
if (!_table.equals(table)) {
@ -411,7 +411,7 @@ public class HBaseClient extends com.yahoo.ycsb.DB
catch (IOException e)
{
System.err.println("Error accessing HBase table: "+e);
return StatusCode.ERROR;
return Status.ERROR;
}
}
@ -429,10 +429,10 @@ public class HBaseClient extends com.yahoo.ycsb.DB
if (_debug) {
System.err.println("Error doing delete: "+e);
}
return StatusCode.ERROR;
return Status.ERROR;
}
return StatusCode.OK;
return Status.OK;
}
public static void main(String[] args)
@ -482,7 +482,7 @@ public class HBaseClient extends com.yahoo.ycsb.DB
int keynum=random.nextInt(keyspace);
String key="user"+keynum;
long st=System.currentTimeMillis();
int rescode;
Status result;
/*
HashMap hm = new HashMap();
hm.put("field1","value1");
@ -501,15 +501,15 @@ public class HBaseClient extends com.yahoo.ycsb.DB
scanFields.add("field1");
scanFields.add("field3");
Vector<HashMap<String,ByteIterator>> scanResults = new Vector<HashMap<String,ByteIterator>>();
rescode = cli.scan("table1","user2",20,null,scanResults);
result = cli.scan("table1","user2",20,null,scanResults);
long en=System.currentTimeMillis();
accum+=(en-st);
if (rescode!=StatusCode.OK)
if (!result.equals(Status.OK))
{
System.out.println("Error "+rescode+" for "+key);
System.out.println("Error "+result+" for "+key);
}
if (i%1==0)

Просмотреть файл

@ -22,7 +22,7 @@ import com.google.common.base.Preconditions;
import com.yahoo.ycsb.ByteArrayByteIterator;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.DBException;
import com.yahoo.ycsb.StatusCode;
import com.yahoo.ycsb.Status;
import com.yahoo.ycsb.measurements.Measurements;
import org.apache.hadoop.conf.Configuration;
@ -202,7 +202,7 @@ public class HBaseClient10 extends com.yahoo.ycsb.DB
* @param result A HashMap of field/value pairs for the result
* @return Zero on success, a non-zero error code on error
*/
public int read(String table, String key, Set<String> fields, HashMap<String,ByteIterator> result)
public Status read(String table, String key, Set<String> fields, HashMap<String,ByteIterator> result)
{
//if this is a "new" table, init HTable object. Else, use existing one
if (!_tableName.equals(table)) {
@ -215,7 +215,7 @@ public class HBaseClient10 extends com.yahoo.ycsb.DB
catch (IOException e)
{
System.err.println("Error accessing HBase table: " + e);
return StatusCode.ERROR;
return Status.ERROR;
}
}
@ -241,16 +241,16 @@ public class HBaseClient10 extends com.yahoo.ycsb.DB
if (_debug) {
System.err.println("Error doing get: "+e);
}
return StatusCode.ERROR;
return Status.ERROR;
}
catch (ConcurrentModificationException e)
{
//do nothing for now...need to understand HBase concurrency model better
return StatusCode.ERROR;
return Status.ERROR;
}
if (r.isEmpty()) {
return StatusCode.NOT_FOUND;
return Status.NOT_FOUND;
}
while (r.advance()) {
@ -262,7 +262,7 @@ public class HBaseClient10 extends com.yahoo.ycsb.DB
" is: "+Bytes.toString(CellUtil.cloneValue(c)));
}
}
return StatusCode.OK;
return Status.OK;
}
/**
@ -276,7 +276,7 @@ public class HBaseClient10 extends com.yahoo.ycsb.DB
* @return Zero on success, a non-zero error code on error
*/
@Override
public int scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String,ByteIterator>> result)
public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String,ByteIterator>> result)
{
//if this is a "new" table, init HTable object. Else, use existing one
if (!_tableName.equals(table)) {
@ -289,7 +289,7 @@ public class HBaseClient10 extends com.yahoo.ycsb.DB
catch (IOException e)
{
System.err.println("Error accessing HBase table: "+e);
return StatusCode.ERROR;
return Status.ERROR;
}
}
@ -357,7 +357,7 @@ public class HBaseClient10 extends com.yahoo.ycsb.DB
{
System.out.println("Error in getting/parsing scan result: "+e);
}
return StatusCode.ERROR;
return Status.ERROR;
}
finally {
@ -367,7 +367,7 @@ public class HBaseClient10 extends com.yahoo.ycsb.DB
}
}
return StatusCode.OK;
return Status.OK;
}
/**
@ -380,7 +380,7 @@ public class HBaseClient10 extends com.yahoo.ycsb.DB
* @return Zero on success, a non-zero error code on error
*/
@Override
public int update(String table, String key, HashMap<String,ByteIterator> values)
public Status update(String table, String key, HashMap<String,ByteIterator> values)
{
//if this is a "new" table, init HTable object. Else, use existing one
if (!_tableName.equals(table)) {
@ -393,7 +393,7 @@ public class HBaseClient10 extends com.yahoo.ycsb.DB
catch (IOException e)
{
System.err.println("Error accessing HBase table: "+e);
return StatusCode.ERROR;
return Status.ERROR;
}
}
@ -427,15 +427,15 @@ public class HBaseClient10 extends com.yahoo.ycsb.DB
if (_debug) {
System.err.println("Error doing put: "+e);
}
return StatusCode.ERROR;
return Status.ERROR;
}
catch (ConcurrentModificationException e)
{
//do nothing for now...hope this is rare
return StatusCode.ERROR;
return Status.ERROR;
}
return StatusCode.OK;
return Status.OK;
}
/**
@ -448,7 +448,7 @@ public class HBaseClient10 extends com.yahoo.ycsb.DB
* @return Zero on success, a non-zero error code on error
*/
@Override
public int insert(String table, String key, HashMap<String,ByteIterator> values)
public Status insert(String table, String key, HashMap<String,ByteIterator> values)
{
return update(table,key,values);
}
@ -461,7 +461,7 @@ public class HBaseClient10 extends com.yahoo.ycsb.DB
* @return Zero on success, a non-zero error code on error
*/
@Override
public int delete(String table, String key)
public Status delete(String table, String key)
{
//if this is a "new" table, init HTable object. Else, use existing one
if (!_tableName.equals(table)) {
@ -474,7 +474,7 @@ public class HBaseClient10 extends com.yahoo.ycsb.DB
catch (IOException e)
{
System.err.println("Error accessing HBase table: "+e);
return StatusCode.ERROR;
return Status.ERROR;
}
}
@ -498,10 +498,10 @@ public class HBaseClient10 extends com.yahoo.ycsb.DB
if (_debug) {
System.err.println("Error doing delete: "+e);
}
return StatusCode.ERROR;
return Status.ERROR;
}
return StatusCode.OK;
return Status.OK;
}
@VisibleForTesting

Просмотреть файл

@ -15,10 +15,14 @@
package com.yahoo.ycsb.db;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
import static org.junit.Assert.*;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.Status;
import com.yahoo.ycsb.StringByteIterator;
import com.yahoo.ycsb.measurements.Measurements;
import com.yahoo.ycsb.workloads.CoreWorkload;
@ -31,7 +35,6 @@ import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
@ -126,8 +129,8 @@ public class HBaseClient10Test {
table.put(p);
final HashMap<String, ByteIterator> result = new HashMap<String, ByteIterator>();
final int status = client.read(CoreWorkload.table, rowKey, null, result);
assertEquals(HBaseClient10.Ok, status);
final Status status = client.read(CoreWorkload.table, rowKey, null, result);
assertEquals(Status.OK, status);
assertEquals(2, result.size());
assertEquals("value1", result.get("column1").toString());
assertEquals("value2", result.get("column2").toString());
@ -136,8 +139,8 @@ public class HBaseClient10Test {
@Test
public void testReadMissingRow() throws Exception {
final HashMap<String, ByteIterator> result = new HashMap<String, ByteIterator>();
final int status = client.read(CoreWorkload.table, "Missing row", null, result);
assertEquals(HBaseClient10.NoMatchingRecord, status);
final Status status = client.read(CoreWorkload.table, "Missing row", null, result);
assertEquals(Status.NOT_FOUND, status);
assertEquals(0, result.size());
}
@ -182,8 +185,8 @@ public class HBaseClient10Test {
final HashMap<String, String> input = new HashMap<String, String>();
input.put("column1", "value1");
input.put("column2", "value2");
final int status = client.insert(CoreWorkload.table, key, StringByteIterator.getByteIteratorMap(input));
assertEquals(HBaseClient10.Ok, status);
final Status status = client.insert(CoreWorkload.table, key, StringByteIterator.getByteIteratorMap(input));
assertEquals(Status.OK, status);
// Verify result
final Get get = new Get(Bytes.toBytes(key));

Просмотреть файл

@ -16,14 +16,14 @@
package com.yahoo.ycsb.db;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.Vector;
import com.yahoo.ycsb.ByteArrayByteIterator;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.DBException;
import com.yahoo.ycsb.Status;
import org.apache.thrift.TException;
import org.hypertable.thrift.SerializedCellsFlag;
import org.hypertable.thrift.SerializedCellsReader;
import org.hypertable.thrift.SerializedCellsWriter;
import org.hypertable.thrift.ThriftClient;
import org.hypertable.thriftgen.Cell;
@ -32,11 +32,12 @@ import org.hypertable.thriftgen.Key;
import org.hypertable.thriftgen.KeyFlag;
import org.hypertable.thriftgen.RowInterval;
import org.hypertable.thriftgen.ScanSpec;
import org.hypertable.thrift.SerializedCellsReader;
import com.yahoo.ycsb.ByteArrayByteIterator;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.DBException;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.Vector;
/**
* Hypertable client for YCSB framework
@ -49,9 +50,6 @@ public class HypertableClient extends com.yahoo.ycsb.DB
private long ns;
private String _columnFamily = "";
public static final int OK = 0;
public static final int SERVERERROR = -1;
public static final String NAMESPACE = "/ycsb";
public static final int THRIFTBROKER_PORT = 38080;
@ -122,7 +120,7 @@ public class HypertableClient extends com.yahoo.ycsb.DB
* @return Zero on success, a non-zero error code on error
*/
@Override
public int read(String table, String key, Set<String> fields,
public Status read(String table, String key, Set<String> fields,
HashMap<String, ByteIterator> result)
{
//SELECT _column_family:field[i]
@ -138,8 +136,8 @@ public class HypertableClient extends com.yahoo.ycsb.DB
if (null != fields) {
Vector<HashMap<String, ByteIterator>> resMap =
new Vector<HashMap<String, ByteIterator>>();
if (0 != scan(table, key, 1, fields, resMap)) {
return SERVERERROR;
if (!scan(table, key, 1, fields, resMap).equals(Status.OK)) {
return Status.ERROR;
}
if (!resMap.isEmpty())
result.putAll(resMap.firstElement());
@ -155,14 +153,14 @@ public class HypertableClient extends com.yahoo.ycsb.DB
if (_debug) {
System.err.println("Error doing read: " + e.message);
}
return SERVERERROR;
return Status.ERROR;
} catch (TException e) {
if (_debug)
System.err.println("Error doing read");
return SERVERERROR;
return Status.ERROR;
}
return OK;
return Status.OK;
}
/**
@ -178,7 +176,7 @@ public class HypertableClient extends com.yahoo.ycsb.DB
* @return Zero on success, a non-zero error code on error
*/
@Override
public int scan(String table, String startkey, int recordcount,
public Status scan(String table, String startkey, int recordcount,
Set<String> fields,
Vector<HashMap<String, ByteIterator>> result)
{
@ -230,14 +228,14 @@ public class HypertableClient extends com.yahoo.ycsb.DB
if (_debug) {
System.err.println("Error doing scan: " + e.message);
}
return SERVERERROR;
return Status.ERROR;
} catch (TException e) {
if (_debug)
System.err.println("Error doing scan");
return SERVERERROR;
return Status.ERROR;
}
return OK;
return Status.OK;
}
/**
@ -251,7 +249,7 @@ public class HypertableClient extends com.yahoo.ycsb.DB
* @return Zero on success, a non-zero error code on error
*/
@Override
public int update(String table, String key,
public Status update(String table, String key,
HashMap<String, ByteIterator> values)
{
return insert(table, key, values);
@ -268,7 +266,7 @@ public class HypertableClient extends com.yahoo.ycsb.DB
* @return Zero on success, a non-zero error code on error
*/
@Override
public int insert(String table, String key,
public Status insert(String table, String key,
HashMap<String, ByteIterator> values)
{
//INSERT INTO table VALUES
@ -294,14 +292,14 @@ public class HypertableClient extends com.yahoo.ycsb.DB
if (_debug) {
System.err.println("Error doing set: " + e.message);
}
return SERVERERROR;
return Status.ERROR;
} catch (TException e) {
if (_debug)
System.err.println("Error doing set");
return SERVERERROR;
return Status.ERROR;
}
return OK;
return Status.OK;
}
/**
@ -312,7 +310,7 @@ public class HypertableClient extends com.yahoo.ycsb.DB
* @return Zero on success, a non-zero error code on error
*/
@Override
public int delete(String table, String key)
public Status delete(String table, String key)
{
//DELETE * FROM table WHERE ROW=key;
@ -331,14 +329,14 @@ public class HypertableClient extends com.yahoo.ycsb.DB
if (_debug) {
System.err.println("Error doing delete: " + e.message);
}
return SERVERERROR;
return Status.ERROR;
} catch (TException e) {
if (_debug)
System.err.println("Error doing delete");
return SERVERERROR;
return Status.ERROR;
}
return OK;
return Status.OK;
}
}

Просмотреть файл

@ -17,9 +17,10 @@
package com.yahoo.ycsb.db;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.DB;
import com.yahoo.ycsb.DBException;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.Status;
import com.yahoo.ycsb.StringByteIterator;
import org.infinispan.Cache;
@ -45,10 +46,6 @@ import java.util.Vector;
*/
public class InfinispanClient extends DB {
private static final int OK = 0;
private static final int ERROR = -1;
private static final int NOT_FOUND = -2;
// An optimisation for clustered mode
private final boolean clustered;
@ -73,7 +70,7 @@ public class InfinispanClient extends DB {
infinispanManager = null;
}
public int read(String table, String key, Set<String> fields, HashMap<String, ByteIterator> result) {
public Status read(String table, String key, Set<String> fields, HashMap<String, ByteIterator> result) {
try {
Map<String, String> row;
if (clustered) {
@ -90,18 +87,18 @@ public class InfinispanClient extends DB {
for (String field : fields) result.put(field, new StringByteIterator(row.get(field)));
}
}
return OK;
return Status.OK;
} catch (Exception e) {
return ERROR;
return Status.ERROR;
}
}
public int scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
logger.warn("Infinispan does not support scan semantics");
return OK;
return Status.OK;
}
public int update(String table, String key, HashMap<String, ByteIterator> values) {
public Status update(String table, String key, HashMap<String, ByteIterator> values) {
try {
if (clustered) {
AtomicMap<String, String> row = AtomicMapLookup.getAtomicMap(infinispanManager.getCache(table), key);
@ -117,13 +114,13 @@ public class InfinispanClient extends DB {
}
}
return OK;
return Status.OK;
} catch (Exception e) {
return ERROR;
return Status.ERROR;
}
}
public int insert(String table, String key, HashMap<String, ByteIterator> values) {
public Status insert(String table, String key, HashMap<String, ByteIterator> values) {
try {
if (clustered) {
AtomicMap<String, String> row = AtomicMapLookup.getAtomicMap(infinispanManager.getCache(table), key);
@ -133,21 +130,21 @@ public class InfinispanClient extends DB {
infinispanManager.getCache(table).put(key, values);
}
return OK;
return Status.OK;
} catch (Exception e) {
return ERROR;
return Status.ERROR;
}
}
public int delete(String table, String key) {
public Status delete(String table, String key) {
try {
if (clustered)
AtomicMapLookup.removeAtomicMap(infinispanManager.getCache(table), key);
else
infinispanManager.getCache(table).remove(key);
return OK;
return Status.OK;
} catch (Exception e) {
return ERROR;
return Status.ERROR;
}
}
}

Просмотреть файл

@ -17,20 +17,21 @@
package com.yahoo.ycsb.db;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.Vector;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.DB;
import com.yahoo.ycsb.DBException;
import com.yahoo.ycsb.Status;
import com.yahoo.ycsb.StringByteIterator;
import org.infinispan.client.hotrod.RemoteCache;
import org.infinispan.client.hotrod.RemoteCacheManager;
import org.infinispan.util.logging.Log;
import org.infinispan.util.logging.LogFactory;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.DB;
import com.yahoo.ycsb.DBException;
import com.yahoo.ycsb.StringByteIterator;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.Vector;
/**
* This is a client implementation for Infinispan 5.x in client-server mode.
@ -63,7 +64,7 @@ public class InfinispanRemoteClient extends DB {
}
@Override
public int insert(String table, String recordKey, HashMap<String, ByteIterator> values) {
public Status insert(String table, String recordKey, HashMap<String, ByteIterator> values) {
String compositKey = createKey(table, recordKey);
Map<String, String> stringValues = new HashMap<String,String>();
StringByteIterator.putAllAsStrings(stringValues, values);
@ -76,7 +77,7 @@ public class InfinispanRemoteClient extends DB {
}
@Override
public int read(String table, String recordKey, Set<String> fields, HashMap<String, ByteIterator> result) {
public Status read(String table, String recordKey, Set<String> fields, HashMap<String, ByteIterator> result) {
String compositKey = createKey(table, recordKey);
try {
Map<String, String> values = cache().get(compositKey);
@ -103,13 +104,13 @@ public class InfinispanRemoteClient extends DB {
}
@Override
public int scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
logger.warn("Infinispan does not support scan semantics");
return Status.NOT_SUPPORT;
return Status.NOT_IMPLEMENTED;
}
@Override
public int update(String table, String recordKey, HashMap<String, ByteIterator> values) {
public Status update(String table, String recordKey, HashMap<String, ByteIterator> values) {
String compositKey = createKey(table, recordKey);
try {
Map<String, String> stringValues = new HashMap<String, String>();
@ -121,7 +122,7 @@ public class InfinispanRemoteClient extends DB {
}
}
@Override
public int delete(String table, String recordKey) {
public Status delete(String table, String recordKey) {
String compositKey = createKey(table, recordKey);
try {
cache().remove(compositKey);

Просмотреть файл

@ -1,26 +0,0 @@
/**
* Copyright (c) 2015 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.
*/
package com.yahoo.ycsb.db;
public class Status {
public static final int OK = 0;
public static final int ERROR = 1;
public static final int NOT_FOUND = 2;
public static final int CONFLICT = 3;
public static final int NOT_SUPPORT = 4;
}

Просмотреть файл

@ -20,6 +20,7 @@ package com.yahoo.ycsb.db;
import com.yahoo.ycsb.DB;
import com.yahoo.ycsb.DBException;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.Status;
import com.yahoo.ycsb.StringByteIterator;
import java.sql.*;
@ -316,14 +317,8 @@ public class JdbcDBClient extends DB implements JdbcDBClientConstants {
}
@Override
public int read(String tableName, String key, Set<String> fields,
public Status read(String tableName, String key, Set<String> fields,
HashMap<String, ByteIterator> result) {
if (tableName == null) {
return -1;
}
if (key == null) {
return -1;
}
try {
StatementType type = new StatementType(StatementType.Type.READ, tableName, 1, getShardIndexByKey(key));
PreparedStatement readStatement = cachedStatements.get(type);
@ -334,7 +329,7 @@ public class JdbcDBClient extends DB implements JdbcDBClientConstants {
ResultSet resultSet = readStatement.executeQuery();
if (!resultSet.next()) {
resultSet.close();
return 1;
return Status.NOT_FOUND;
}
if (result != null && fields != null) {
for (String field : fields) {
@ -343,22 +338,16 @@ public class JdbcDBClient extends DB implements JdbcDBClientConstants {
}
}
resultSet.close();
return SUCCESS;
return Status.OK;
} catch (SQLException e) {
System.err.println("Error in processing read of table " + tableName + ": "+e);
return -2;
return Status.ERROR;
}
}
@Override
public int scan(String tableName, String startKey, int recordcount,
public Status scan(String tableName, String startKey, int recordcount,
Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
if (tableName == null) {
return -1;
}
if (startKey == null) {
return -1;
}
try {
StatementType type = new StatementType(StatementType.Type.SCAN, tableName, 1, getShardIndexByKey(startKey));
PreparedStatement scanStatement = cachedStatements.get(type);
@ -379,21 +368,15 @@ public class JdbcDBClient extends DB implements JdbcDBClientConstants {
}
}
resultSet.close();
return SUCCESS;
return Status.OK;
} catch (SQLException e) {
System.err.println("Error in processing scan of table: " + tableName + e);
return -2;
return Status.ERROR;
}
}
@Override
public int update(String tableName, String key, HashMap<String, ByteIterator> values) {
if (tableName == null) {
return -1;
}
if (key == null) {
return -1;
}
public Status update(String tableName, String key, HashMap<String, ByteIterator> values) {
try {
int numFields = values.size();
StatementType type = new StatementType(StatementType.Type.UPDATE, tableName, numFields, getShardIndexByKey(key));
@ -407,22 +390,16 @@ public class JdbcDBClient extends DB implements JdbcDBClientConstants {
}
updateStatement.setString(index, key);
int result = updateStatement.executeUpdate();
if (result == 1) return SUCCESS;
else return 1;
if (result == 1) return Status.OK;
else return Status.UNEXPECTED_STATE;
} catch (SQLException e) {
System.err.println("Error in processing update to table: " + tableName + e);
return -1;
return Status.ERROR;
}
}
@Override
public int insert(String tableName, String key, HashMap<String, ByteIterator> values) {
if (tableName == null) {
return -1;
}
if (key == null) {
return -1;
}
public Status insert(String tableName, String key, HashMap<String, ByteIterator> values) {
try {
int numFields = values.size();
StatementType type = new StatementType(StatementType.Type.INSERT, tableName, numFields, getShardIndexByKey(key));
@ -437,22 +414,16 @@ public class JdbcDBClient extends DB implements JdbcDBClientConstants {
insertStatement.setString(index++, field);
}
int result = insertStatement.executeUpdate();
if (result == 1) return SUCCESS;
else return 1;
if (result == 1) return Status.OK;
else return Status.UNEXPECTED_STATE;
} catch (SQLException e) {
System.err.println("Error in processing insert to table: " + tableName + e);
return -1;
return Status.ERROR;
}
}
@Override
public int delete(String tableName, String key) {
if (tableName == null) {
return -1;
}
if (key == null) {
return -1;
}
public Status delete(String tableName, String key) {
try {
StatementType type = new StatementType(StatementType.Type.DELETE, tableName, 1, getShardIndexByKey(key));
PreparedStatement deleteStatement = cachedStatements.get(type);
@ -461,11 +432,11 @@ public class JdbcDBClient extends DB implements JdbcDBClientConstants {
}
deleteStatement.setString(1, key);
int result = deleteStatement.executeUpdate();
if (result == 1) return SUCCESS;
else return 1;
if (result == 1) return Status.OK;
else return Status.UNEXPECTED_STATE;
} catch (SQLException e) {
System.err.println("Error in processing delete to table: " + tableName + e);
return -1;
return Status.ERROR;
}
}
}

Просмотреть файл

@ -16,7 +16,6 @@
*/
package com.yahoo.ycsb.db;
import com.yahoo.ycsb.StatusCode;
/**
* Constants used by the JDBC client.
@ -53,9 +52,6 @@ public interface JdbcDBClientConstants {
/** Representing a NULL value. */
public static final String NULL_VALUE = "NULL";
/** The code to return when the call succeeds. */
public static final int SUCCESS = StatusCode.OK;
/** The primary key in the user table.*/
public static String PRIMARY_KEY = "YCSB_KEY";

Просмотреть файл

@ -20,6 +20,7 @@ package com.yahoo.ycsb.db;
import com.stumbleupon.async.TimeoutException;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.DBException;
import com.yahoo.ycsb.Status;
import com.yahoo.ycsb.StringByteIterator;
import com.yahoo.ycsb.workloads.CoreWorkload;
import org.kududb.ColumnSchema;
@ -45,10 +46,7 @@ import static org.kududb.Type.STRING;
*/
public class KuduYCSBClient extends com.yahoo.ycsb.DB {
public static final String KEY = "key";
public static final int OK = 0;
public static final int SERVER_ERROR = -1;
public static final int NO_MATCHING_RECORD = -2;
public static final int TIMEOUT = -3;
public static final Status TIMEOUT = new Status("TIMEOUT", "The operation timed out.");
public static final int MAX_TABLETS = 9000;
public static final long DEFAULT_SLEEP = 60000;
private static final String SYNC_OPS_OPT = "kudu_sync_ops";
@ -190,18 +188,18 @@ public class KuduYCSBClient extends com.yahoo.ycsb.DB {
}
@Override
public int read(String table, String key, Set<String> fields,
public Status read(String table, String key, Set<String> fields,
HashMap<String,ByteIterator> result) {
Vector<HashMap<String, ByteIterator>> results = new Vector<HashMap<String, ByteIterator>>();
int ret = scan(table, key, 1, fields, results);
if (ret != OK) return ret;
if (results.size() != 1) return NO_MATCHING_RECORD;
final Status status = scan(table, key, 1, fields, results);
if (!status.equals(Status.OK)) return status;
if (results.size() != 1) return Status.NOT_FOUND;
result.putAll(results.firstElement());
return OK;
return Status.OK;
}
@Override
public int scan(String table, String startkey, int recordcount, Set<String> fields,
public Status scan(String table, String startkey, int recordcount, Set<String> fields,
Vector<HashMap<String, ByteIterator>> result) {
try {
KuduScanner.KuduScannerBuilder scannerBuilder = client.newScannerBuilder(this.table);
@ -243,9 +241,9 @@ public class KuduYCSBClient extends com.yahoo.ycsb.DB {
} catch (Exception e) {
System.err.println("Unexpected exception " + e);
e.printStackTrace();
return SERVER_ERROR;
return Status.ERROR;
}
return OK;
return Status.OK;
}
private void addAllRowsToResult(RowResultIterator it, int recordcount,
@ -268,7 +266,7 @@ public class KuduYCSBClient extends com.yahoo.ycsb.DB {
}
@Override
public int update(String table, String key, HashMap<String, ByteIterator> values) {
public Status update(String table, String key, HashMap<String, ByteIterator> values) {
Update update = this.table.newUpdate();
PartialRow row = update.getRow();
row.addString(KEY, key);
@ -280,11 +278,11 @@ public class KuduYCSBClient extends com.yahoo.ycsb.DB {
}
}
apply(update);
return OK;
return Status.OK;
}
@Override
public int insert(String table, String key, HashMap<String, ByteIterator> values) {
public Status insert(String table, String key, HashMap<String, ByteIterator> values) {
Insert insert = this.table.newInsert();
PartialRow row = insert.getRow();
row.addString(KEY, key);
@ -292,16 +290,16 @@ public class KuduYCSBClient extends com.yahoo.ycsb.DB {
row.addString(i, new String(values.get(schema.getColumnByIndex(i).getName()).toArray()));
}
apply(insert);
return OK;
return Status.OK;
}
@Override
public int delete(String table, String key) {
public Status delete(String table, String key) {
Delete delete = this.table.newDelete();
PartialRow row = delete.getRow();
row.addString(KEY, key);
apply(delete);
return OK;
return Status.OK;
}
private void apply(Operation op) {

Просмотреть файл

@ -41,7 +41,7 @@ import com.allanbank.mongodb.builder.Sort;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.DB;
import com.yahoo.ycsb.DBException;
import com.yahoo.ycsb.StatusCode;
import com.yahoo.ycsb.Status;
import java.util.HashMap;
import java.util.Iterator;
@ -140,19 +140,19 @@ public class AsyncMongoDbClient extends DB {
* description for a discussion of error codes.
*/
@Override
public final int delete(final String table, final String key) {
public final Status delete(final String table, final String key) {
try {
final MongoCollection collection = database.getCollection(table);
final Document q = BuilderFactory.start().add("_id", key).build();
final long res = collection.delete(q, writeConcern);
if (res == 0) {
System.err.println("Nothing deleted for key " + key);
return StatusCode.ERROR;
return Status.NOT_FOUND;
}
return StatusCode.OK;
return Status.OK;
} catch (final Exception e) {
System.err.println(e.toString());
return StatusCode.ERROR;
return Status.ERROR;
}
}
@ -250,7 +250,7 @@ public class AsyncMongoDbClient extends DB {
* class's description for a discussion of error codes.
*/
@Override
public final int insert(final String table, final String key,
public final Status insert(final String table, final String key,
final HashMap<String, ByteIterator> values) {
try {
final MongoCollection collection = database.getCollection(table);
@ -272,7 +272,7 @@ public class AsyncMongoDbClient extends DB {
collection.insert(writeConcern, toInsert);
result = 1;
}
return result == 1 ? StatusCode.OK : StatusCode.ERROR;
return result == 1 ? Status.OK : Status.NOT_FOUND;
}
// Use a bulk insert.
@ -286,30 +286,30 @@ public class AsyncMongoDbClient extends DB {
batchedWriteCount += 1;
if (batchedWriteCount < batchSize) {
return StatusCode.OK;
return Status.OK;
}
long count = collection.write(batchedWrite);
if (count == batchedWriteCount) {
batchedWrite.reset().mode(BatchedWriteMode.REORDERED);
batchedWriteCount = 0;
return StatusCode.OK;
return Status.OK;
}
System.err.println("Number of inserted documents doesn't match the "
+ "number sent, " + count + " inserted, sent " + batchedWriteCount);
batchedWrite.reset().mode(BatchedWriteMode.REORDERED);
batchedWriteCount = 0;
return StatusCode.ERROR;
return Status.ERROR;
} catch (Exception e) {
System.err.println("Exception while trying bulk insert with "
+ batchedWriteCount);
e.printStackTrace();
return StatusCode.ERROR;
return Status.ERROR;
}
} catch (final Exception e) {
e.printStackTrace();
return StatusCode.ERROR;
return Status.ERROR;
}
}
@ -328,7 +328,7 @@ public class AsyncMongoDbClient extends DB {
* @return Zero on success, a non-zero error code on error or "not found".
*/
@Override
public final int read(final String table, final String key,
public final Status read(final String table, final String key,
final Set<String> fields, final HashMap<String, ByteIterator> result) {
try {
final MongoCollection collection = database.getCollection(table);
@ -361,10 +361,10 @@ public class AsyncMongoDbClient extends DB {
if (queryResult != null) {
fillMap(result, queryResult);
}
return queryResult != null ? StatusCode.OK : StatusCode.ERROR;
return queryResult != null ? Status.OK : Status.NOT_FOUND;
} catch (final Exception e) {
System.err.println(e.toString());
return StatusCode.ERROR;
return Status.ERROR;
}
}
@ -388,7 +388,7 @@ public class AsyncMongoDbClient extends DB {
* class's description for a discussion of error codes.
*/
@Override
public final int scan(final String table, final String startkey,
public final Status scan(final String table, final String startkey,
final int recordcount, final Set<String> fields,
final Vector<HashMap<String, ByteIterator>> result) {
try {
@ -413,7 +413,7 @@ public class AsyncMongoDbClient extends DB {
final MongoIterator<Document> cursor = collection.find(find);
if (!cursor.hasNext()) {
System.err.println("Nothing found in scan for key " + startkey);
return StatusCode.ERROR;
return Status.NOT_FOUND;
}
while (cursor.hasNext()) {
// toMap() returns a Map but result.add() expects a
@ -427,10 +427,10 @@ public class AsyncMongoDbClient extends DB {
result.add(docAsMap);
}
return StatusCode.OK;
return Status.OK;
} catch (final Exception e) {
System.err.println(e.toString());
return StatusCode.ERROR;
return Status.ERROR;
}
}
@ -449,7 +449,7 @@ public class AsyncMongoDbClient extends DB {
* class's description for a discussion of error codes.
*/
@Override
public final int update(final String table, final String key,
public final Status update(final String table, final String key,
final HashMap<String, ByteIterator> values) {
try {
final MongoCollection collection = database.getCollection(table);
@ -462,10 +462,10 @@ public class AsyncMongoDbClient extends DB {
}
final long res =
collection.update(query, update, false, false, writeConcern);
return res == 1 ? StatusCode.OK : StatusCode.ERROR;
return res == 1 ? Status.OK : Status.NOT_FOUND;
} catch (final Exception e) {
System.err.println(e.toString());
return StatusCode.ERROR;
return Status.ERROR;
}
}

Просмотреть файл

@ -41,7 +41,7 @@ import com.yahoo.ycsb.ByteArrayByteIterator;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.DB;
import com.yahoo.ycsb.DBException;
import com.yahoo.ycsb.StatusCode;
import com.yahoo.ycsb.Status;
import org.bson.Document;
import org.bson.types.Binary;
@ -143,7 +143,7 @@ public class MongoDbClient extends DB {
* class's description for a discussion of error codes.
*/
@Override
public int delete(String table, String key) {
public Status delete(String table, String key) {
try {
MongoCollection<Document> collection = database.getCollection(table);
@ -152,12 +152,12 @@ public class MongoDbClient extends DB {
collection.withWriteConcern(writeConcern).deleteOne(query);
if (result.wasAcknowledged() && result.getDeletedCount() == 0) {
System.err.println("Nothing deleted for key " + key);
return StatusCode.ERROR;
return Status.NOT_FOUND;
}
return StatusCode.OK;
return Status.OK;
} catch (Exception e) {
System.err.println(e.toString());
return StatusCode.ERROR;
return Status.ERROR;
}
}
@ -250,7 +250,7 @@ public class MongoDbClient extends DB {
* class's description for a discussion of error codes.
*/
@Override
public int insert(String table, String key,
public Status insert(String table, String key,
HashMap<String, ByteIterator> values) {
try {
MongoCollection<Document> collection = database.getCollection(table);
@ -287,12 +287,12 @@ public class MongoDbClient extends DB {
bulkInserts.clear();
}
}
return StatusCode.OK;
return Status.OK;
} catch (Exception e) {
System.err.println("Exception while trying bulk insert with "
+ bulkInserts.size());
e.printStackTrace();
return StatusCode.ERROR;
return Status.ERROR;
}
}
@ -312,7 +312,7 @@ public class MongoDbClient extends DB {
* @return Zero on success, a non-zero error code on error or "not found".
*/
@Override
public int read(String table, String key, Set<String> fields,
public Status read(String table, String key, Set<String> fields,
HashMap<String, ByteIterator> result) {
try {
MongoCollection<Document> collection = database.getCollection(table);
@ -333,10 +333,10 @@ public class MongoDbClient extends DB {
if (queryResult != null) {
fillMap(result, queryResult);
}
return queryResult != null ? StatusCode.OK : StatusCode.ERROR;
return queryResult != null ? Status.OK : Status.NOT_FOUND;
} catch (Exception e) {
System.err.println(e.toString());
return StatusCode.ERROR;
return Status.ERROR;
}
}
@ -359,7 +359,7 @@ public class MongoDbClient extends DB {
* class's description for a discussion of error codes.
*/
@Override
public int scan(String table, String startkey, int recordcount,
public Status scan(String table, String startkey, int recordcount,
Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
MongoCursor<Document> cursor = null;
try {
@ -384,7 +384,7 @@ public class MongoDbClient extends DB {
if (!cursor.hasNext()) {
System.err.println("Nothing found in scan for key " + startkey);
return StatusCode.ERROR;
return Status.ERROR;
}
result.ensureCapacity(recordcount);
@ -399,10 +399,10 @@ public class MongoDbClient extends DB {
result.add(resultMap);
}
return StatusCode.OK;
return Status.OK;
} catch (Exception e) {
System.err.println(e.toString());
return StatusCode.ERROR;
return Status.ERROR;
} finally {
if (cursor != null) {
cursor.close();
@ -425,7 +425,7 @@ public class MongoDbClient extends DB {
* description for a discussion of error codes.
*/
@Override
public int update(String table, String key,
public Status update(String table, String key,
HashMap<String, ByteIterator> values) {
try {
MongoCollection<Document> collection = database.getCollection(table);
@ -440,12 +440,12 @@ public class MongoDbClient extends DB {
UpdateResult result = collection.updateOne(query, update);
if (result.wasAcknowledged() && result.getMatchedCount() == 0) {
System.err.println("Nothing updated for key " + key);
return StatusCode.ERROR;
return Status.NOT_FOUND;
}
return StatusCode.OK;
return Status.OK;
} catch (Exception e) {
System.err.println(e.toString());
return StatusCode.ERROR;
return Status.ERROR;
}
}

Просмотреть файл

@ -24,6 +24,14 @@ import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeNoException;
import com.yahoo.ycsb.ByteArrayByteIterator;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.DB;
import com.yahoo.ycsb.Status;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
@ -33,13 +41,6 @@ import java.util.Properties;
import java.util.Set;
import java.util.Vector;
import org.junit.BeforeClass;
import org.junit.Test;
import com.yahoo.ycsb.ByteArrayByteIterator;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.DB;
/**
* MongoDbClientTest provides runs the basic DB test cases.
* <p>
@ -93,13 +94,13 @@ public abstract class AbstractDBTestCases {
HashMap<String, ByteIterator> inserted =
new HashMap<String, ByteIterator>();
inserted.put("a", new ByteArrayByteIterator(new byte[] { 1, 2, 3, 4 }));
int result = client.insert(table, id, inserted);
assertThat("Insert did not return success (0).", result, is(0));
Status result = client.insert(table, id, inserted);
assertThat("Insert did not return success (0).", result, is(Status.OK));
HashMap<String, ByteIterator> read = new HashMap<String, ByteIterator>();
Set<String> keys = Collections.singleton("a");
result = client.read(table, id, keys, read);
assertThat("Read did not return success (0).", result, is(0));
assertThat("Read did not return success (0).", result, is(Status.OK));
for (String key : keys) {
ByteIterator iter = read.get(key);
@ -117,16 +118,16 @@ public abstract class AbstractDBTestCases {
}
result = client.delete(table, id);
assertThat("Delete did not return success (0).", result, is(0));
assertThat("Delete did not return success (0).", result, is(Status.OK));
read.clear();
result = client.read(table, id, null, read);
assertThat("Read, after delete, did not return not found (1).", result,
is(1));
is(Status.NOT_FOUND));
assertThat("Found the deleted fields.", read.size(), is(0));
result = client.delete(table, id);
assertThat("Delete did not return not found (1).", result, is(1));
assertThat("Delete did not return not found (1).", result, is(Status.NOT_FOUND));
}
/**
@ -142,13 +143,13 @@ public abstract class AbstractDBTestCases {
HashMap<String, ByteIterator> inserted =
new HashMap<String, ByteIterator>();
inserted.put("a", new ByteArrayByteIterator(new byte[] { 1, 2, 3, 4 }));
int result = client.insert(table, id, inserted);
assertThat("Insert did not return success (0).", result, is(0));
Status result = client.insert(table, id, inserted);
assertThat("Insert did not return success (0).", result, is(Status.OK));
HashMap<String, ByteIterator> read = new HashMap<String, ByteIterator>();
Set<String> keys = Collections.singleton("a");
result = client.read(table, id, keys, read);
assertThat("Read did not return success (0).", result, is(0));
assertThat("Read did not return success (0).", result, is(Status.OK));
for (String key : keys) {
ByteIterator iter = read.get(key);
@ -168,11 +169,11 @@ public abstract class AbstractDBTestCases {
HashMap<String, ByteIterator> updated = new HashMap<String, ByteIterator>();
updated.put("a", new ByteArrayByteIterator(new byte[] { 5, 6, 7, 8 }));
result = client.update(table, id, updated);
assertThat("Update did not return success (0).", result, is(0));
assertThat("Update did not return success (0).", result, is(Status.OK));
read.clear();
result = client.read(table, id, null, read);
assertThat("Read, after update, did not return success (0).", result, is(0));
assertThat("Read, after update, did not return success (0).", result, is(Status.OK));
for (String key : keys) {
ByteIterator iter = read.get(key);
@ -205,13 +206,13 @@ public abstract class AbstractDBTestCases {
HashMap<String, ByteIterator> inserted =
new HashMap<String, ByteIterator>();
inserted.put("a", new ByteArrayByteIterator(new byte[] { 1, 2, 3, 4 }));
int result = client.insert(table, id, inserted);
assertThat("Insert did not return success (0).", result, is(0));
Status result = client.insert(table, id, inserted);
assertThat("Insert did not return success (0).", result, is(Status.OK));
HashMap<String, ByteIterator> read = new HashMap<String, ByteIterator>();
Set<String> keys = Collections.singleton("a");
result = client.read(table, id, keys, read);
assertThat("Read did not return success (0).", result, is(0));
assertThat("Read did not return success (0).", result, is(Status.OK));
for (String key : keys) {
ByteIterator iter = read.get(key);
@ -231,11 +232,11 @@ public abstract class AbstractDBTestCases {
HashMap<String, ByteIterator> updated = new HashMap<String, ByteIterator>();
updated.put("a", new ByteArrayByteIterator(new byte[] { 5, 6, 7, 8 }));
result = client.update(table, id, updated);
assertThat("Update did not return success (0).", result, is(0));
assertThat("Update did not return success (0).", result, is(Status.OK));
read.clear();
result = client.read(table, id, null, read);
assertThat("Read, after update, did not return success (0).", result, is(0));
assertThat("Read, after update, did not return success (0).", result, is(Status.OK));
for (String key : keys) {
ByteIterator iter = read.get(key);
@ -269,15 +270,15 @@ public abstract class AbstractDBTestCases {
inserted.put("a", new ByteArrayByteIterator(new byte[] {
(byte) (i & 0xFF), (byte) (i >> 8 & 0xFF), (byte) (i >> 16 & 0xFF),
(byte) (i >> 24 & 0xFF) }));
int result = client.insert(table, padded(i), inserted);
assertThat("Insert did not return success (0).", result, is(0));
Status result = client.insert(table, padded(i), inserted);
assertThat("Insert did not return success (0).", result, is(Status.OK));
}
Set<String> keys = Collections.singleton("a");
Vector<HashMap<String, ByteIterator>> results =
new Vector<HashMap<String, ByteIterator>>();
int result = client.scan(table, "00050", 5, null, results);
assertThat("Read did not return success (0).", result, is(0));
Status result = client.scan(table, "00050", 5, null, results);
assertThat("Read did not return success (0).", result, is(Status.OK));
assertThat(results.size(), is(5));
for (int i = 0; i < 5; ++i) {
HashMap<String, ByteIterator> read = results.get(i);

Просмотреть файл

@ -35,6 +35,7 @@ import com.orientechnologies.orient.core.record.impl.ODocument;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.DB;
import com.yahoo.ycsb.DBException;
import com.yahoo.ycsb.Status;
import com.yahoo.ycsb.StringByteIterator;
import java.util.HashMap;
@ -130,7 +131,7 @@ public class OrientDBClient extends DB {
* @param values A HashMap of field/value pairs to insert in the record
* @return Zero on success, a non-zero error code on error. See this class's description for a discussion of error codes.
*/
public int insert(String table, String key, HashMap<String, ByteIterator> values) {
public Status insert(String table, String key, HashMap<String, ByteIterator> values) {
try {
final ODocument document = new ODocument(CLASS);
for (Entry<String, String> entry : StringByteIterator.getStringMap(values).entrySet())
@ -138,11 +139,11 @@ public class OrientDBClient extends DB {
document.save();
dictionary.put(key, document);
return 0;
return Status.OK;
} catch (Exception e) {
e.printStackTrace();
}
return 1;
return Status.ERROR;
}
@Override
@ -153,14 +154,14 @@ public class OrientDBClient extends DB {
* @param key The record key of the record to delete.
* @return Zero on success, a non-zero error code on error. See this class's description for a discussion of error codes.
*/
public int delete(String table, String key) {
public Status delete(String table, String key) {
try {
dictionary.remove(key);
return 0;
return Status.OK;
} catch (Exception e) {
e.printStackTrace();
}
return 1;
return Status.ERROR;
}
@Override
@ -173,7 +174,7 @@ public class OrientDBClient extends DB {
* @param result A HashMap of field/value pairs for the result
* @return Zero on success, a non-zero error code on error or "not found".
*/
public int read(String table, String key, Set<String> fields, HashMap<String, ByteIterator> result) {
public Status read(String table, String key, Set<String> fields, HashMap<String, ByteIterator> result) {
try {
final ODocument document = dictionary.get(key);
if (document != null) {
@ -183,12 +184,12 @@ public class OrientDBClient extends DB {
else
for (String field : document.fieldNames())
result.put(field, new StringByteIterator((String) document.field(field)));
return 0;
return Status.OK;
}
} catch (Exception e) {
e.printStackTrace();
}
return 1;
return Status.ERROR;
}
@Override
@ -201,19 +202,19 @@ public class OrientDBClient extends DB {
* @param values A HashMap of field/value pairs to update in the record
* @return Zero on success, a non-zero error code on error. See this class's description for a discussion of error codes.
*/
public int update(String table, String key, HashMap<String, ByteIterator> values) {
public Status update(String table, String key, HashMap<String, ByteIterator> values) {
try {
final ODocument document = dictionary.get(key);
if (document != null) {
for (Entry<String, String> entry : StringByteIterator.getStringMap(values).entrySet())
document.field(entry.getKey(), entry.getValue());
document.save();
return 0;
return Status.OK;
}
} catch (Exception e) {
e.printStackTrace();
}
return 1;
return Status.ERROR;
}
@Override
@ -227,7 +228,7 @@ public class OrientDBClient extends DB {
* @param result A Vector of HashMaps, where each HashMap is a set field/value pairs for one record
* @return Zero on success, a non-zero error code on error. See this class's description for a discussion of error codes.
*/
public int scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
try {
final OIndexCursor entries = dictionary.getIndex().iterateEntriesMajor(startkey, true, true);
while (entries.hasNext()) {
@ -241,10 +242,10 @@ public class OrientDBClient extends DB {
map.put(field, new StringByteIterator((String) document.field(field)));
}
return 0;
return Status.OK;
} catch (Exception e) {
e.printStackTrace();
}
return 1;
return Status.ERROR;
}
}

Просмотреть файл

@ -23,12 +23,15 @@
*/
package com.yahoo.ycsb.db;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.DB;
import com.yahoo.ycsb.DBException;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.Status;
import com.yahoo.ycsb.StringByteIterator;
import java.util.Map;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Protocol;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@ -36,9 +39,6 @@ import java.util.Properties;
import java.util.Set;
import java.util.Vector;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Protocol;
public class RedisClient extends DB {
private Jedis jedis;
@ -87,7 +87,7 @@ public class RedisClient extends DB {
//XXX jedis.select(int index) to switch to `table`
@Override
public int read(String table, String key, Set<String> fields,
public Status read(String table, String key, Set<String> fields,
HashMap<String, ByteIterator> result) {
if (fields == null) {
StringByteIterator.putAllAsByteIterators(result, jedis.hgetAll(key));
@ -105,32 +105,33 @@ public class RedisClient extends DB {
}
assert !fieldIterator.hasNext() && !valueIterator.hasNext();
}
return result.isEmpty() ? 1 : 0;
return result.isEmpty() ? Status.ERROR : Status.OK;
}
@Override
public int insert(String table, String key, HashMap<String, ByteIterator> values) {
public Status insert(String table, String key, HashMap<String, ByteIterator> values) {
if (jedis.hmset(key, StringByteIterator.getStringMap(values)).equals("OK")) {
jedis.zadd(INDEX_KEY, hash(key), key);
return 0;
return Status.OK;
}
return 1;
return Status.ERROR;
}
@Override
public int delete(String table, String key) {
public Status delete(String table, String key) {
return jedis.del(key) == 0
&& jedis.zrem(INDEX_KEY, key) == 0
? 1 : 0;
? Status.ERROR : Status.OK;
}
@Override
public int update(String table, String key, HashMap<String, ByteIterator> values) {
return jedis.hmset(key, StringByteIterator.getStringMap(values)).equals("OK") ? 0 : 1;
public Status update(String table, String key, HashMap<String, ByteIterator> values) {
return jedis.hmset(key, StringByteIterator.getStringMap(values)).equals("OK") ?
Status.OK : Status.ERROR;
}
@Override
public int scan(String table, String startkey, int recordcount,
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),
Double.POSITIVE_INFINITY, 0, recordcount);
@ -142,7 +143,7 @@ public class RedisClient extends DB {
result.add(values);
}
return 0;
return Status.OK;
}
}

Просмотреть файл

@ -16,24 +16,25 @@
*/
package com.yahoo.ycsb.db;
import java.util.Map;
import java.util.Set;
import java.util.List;
import java.util.Arrays;
import java.util.Vector;
import java.util.HashMap;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.DB;
import com.yahoo.ycsb.DBException;
import com.yahoo.ycsb.Status;
import com.yahoo.ycsb.StringByteIterator;
import org.tarantool.TarantoolConnection16;
import org.tarantool.TarantoolConnection16Impl;
import org.tarantool.TarantoolException;
import com.yahoo.ycsb.DB;
import com.yahoo.ycsb.DBException;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.StringByteIterator;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
public class TarantoolClient extends DB {
@ -82,7 +83,7 @@ public class TarantoolClient extends DB {
}
@Override
public int insert(String table, String key, HashMap<String, ByteIterator> values) {
public Status insert(String table, String key, HashMap<String, ByteIterator> values) {
int j = 0;
String[] tuple = new String[1 + 2 * values.size()];
tuple[0] = key;
@ -95,9 +96,9 @@ public class TarantoolClient extends DB {
this.connection.replace(this.spaceNo, tuple);
} catch (TarantoolException exc) {
logger.log(Level.SEVERE,"Can't insert element", exc);
return 1;
return Status.ERROR;
}
return 0;
return Status.OK;
}
private HashMap<String, ByteIterator> tuple_convert_filter (List<String> input,
@ -112,23 +113,23 @@ public class TarantoolClient extends DB {
}
@Override
public int read(String table, String key, Set<String> fields,
public Status read(String table, String key, Set<String> fields,
HashMap<String, ByteIterator> result) {
try {
List<String> response;
response = this.connection.select(this.spaceNo, 0, Arrays.asList(key), 0, 1, 0);
result = tuple_convert_filter(response, fields);
return 0;
return Status.OK;
} catch (TarantoolException exc) {
logger.log(Level.SEVERE,"Can't select element", exc);
return 1;
return Status.ERROR;
} catch (NullPointerException exc) {
return 1;
return Status.ERROR;
}
}
@Override
public int scan(String table, String startkey,
public Status scan(String table, String startkey,
int recordcount, Set<String> fields,
Vector<HashMap<String, ByteIterator>> result) {
List<List<String>> response;
@ -136,32 +137,32 @@ public class TarantoolClient extends DB {
response = this.connection.select(this.spaceNo, 0, Arrays.asList(startkey), 0, recordcount, 6);
} catch (TarantoolException exc) {
logger.log(Level.SEVERE,"Can't select range elements", exc);
return 1;
return Status.ERROR;
} catch (NullPointerException exc) {
return 1;
return Status.ERROR;
}
for(List<String> i: response) {
HashMap<String, ByteIterator> temp = tuple_convert_filter(i, fields);
if (!temp.isEmpty())
result.add((HashMap<String, ByteIterator>) temp.clone());
}
return 0;
return Status.OK;
}
@Override
public int delete(String table, String key) {
public Status delete(String table, String key) {
try {
this.connection.delete(this.spaceNo, Arrays.asList(key));
} catch (TarantoolException exc) {
logger.log(Level.SEVERE,"Can't delete element", exc);
return 1;
return Status.ERROR;
} catch (NullPointerException e) {
return 1;
return Status.ERROR;
}
return 0;
return Status.OK;
}
@Override
public int update(String table, String key,
public Status update(String table, String key,
HashMap<String, ByteIterator> values) {
int j = 0;
String[] tuple = new String[1 + 2 * values.size()];
@ -175,9 +176,9 @@ public class TarantoolClient extends DB {
this.connection.replace(this.spaceNo, tuple);
} catch (TarantoolException exc) {
logger.log(Level.SEVERE,"Can't replace element", exc);
return 1;
return Status.ERROR;
}
return 0;
return Status.OK;
}
}