Skip to content

Commit

Permalink
Add single definition of status codes
Browse files Browse the repository at this point in the history
  • Loading branch information
cmccoy committed Nov 3, 2015
1 parent 65bedc0 commit 28a090a
Show file tree
Hide file tree
Showing 10 changed files with 209 additions and 177 deletions.
64 changes: 30 additions & 34 deletions accumulo/src/main/java/com/yahoo/ycsb/db/AccumuloClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,11 @@

package com.yahoo.ycsb.db;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import java.util.Set;
import java.util.TreeSet;
import java.util.Vector;
import java.util.concurrent.TimeUnit;
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 org.apache.accumulo.core.client.AccumuloException;
import org.apache.accumulo.core.client.AccumuloSecurityException;
Expand All @@ -49,20 +44,21 @@
import org.apache.hadoop.io.Text;
import org.apache.zookeeper.KeeperException;

import com.yahoo.ycsb.ByteArrayByteIterator;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.DB;
import com.yahoo.ycsb.DBException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import java.util.Set;
import java.util.TreeSet;
import java.util.Vector;
import java.util.concurrent.TimeUnit;

/**
* <a href="https://accumulo.apache.org/">Accumulo</a> binding for YCSB.
*/
public class AccumuloClient extends DB {
// Error code constants.
public static final int OK = 0;
public static final int SERVER_ERROR = -1;
public static final int HTTP_ERROR = -2;
public static final int NO_MATCHING_RECORD = -3;

private ZooKeeperInstance inst;
private Connector connector;
Expand Down Expand Up @@ -210,7 +206,7 @@ public int read(String t, String key, Set<String> fields,
checkTable(t);
} catch (TableNotFoundException e) {
System.err.println("Error trying to connect to Accumulo table." + e);
return SERVER_ERROR;
return StatusCode.ERROR;
}

try {
Expand All @@ -223,9 +219,9 @@ public int read(String t, String key, Set<String> fields,
}
} catch (Exception e) {
System.err.println("Error trying to reading Accumulo table" + key + e);
return SERVER_ERROR;
return StatusCode.ERROR;
}
return OK;
return StatusCode.OK;

}

Expand All @@ -236,7 +232,7 @@ public int scan(String t, String startkey, int recordcount,
checkTable(t);
} catch (TableNotFoundException e) {
System.err.println("Error trying to connect to Accumulo table." + e);
return SERVER_ERROR;
return StatusCode.ERROR;
}

// There doesn't appear to be a way to create a range for a given
Expand Down Expand Up @@ -287,7 +283,7 @@ public int scan(String t, String startkey, int recordcount,
new ByteArrayByteIterator(buf));
}

return OK;
return StatusCode.OK;
}

@Override
Expand All @@ -297,7 +293,7 @@ public int update(String t, String key,
checkTable(t);
} catch (TableNotFoundException e) {
System.err.println("Error trying to connect to Accumulo table." + e);
return SERVER_ERROR;
return StatusCode.ERROR;
}

Mutation mutInsert = new Mutation(new Text(key));
Expand All @@ -319,14 +315,14 @@ public int update(String t, String key,
} catch (MutationsRejectedException e) {
System.err.println("Error performing update.");
e.printStackTrace();
return SERVER_ERROR;
return StatusCode.ERROR;
} catch (KeeperException e) {
System.err.println("Error notifying the Zookeeper Queue.");
e.printStackTrace();
return SERVER_ERROR;
return StatusCode.ERROR;
}

return OK;
return StatusCode.OK;
}

@Override
Expand All @@ -341,22 +337,22 @@ public int delete(String t, String key) {
checkTable(t);
} catch (TableNotFoundException e) {
System.err.println("Error trying to connect to Accumulo table." + e);
return SERVER_ERROR;
return StatusCode.ERROR;
}

try {
deleteRow(new Text(key));
} catch (MutationsRejectedException e) {
System.err.println("Error performing delete.");
e.printStackTrace();
return SERVER_ERROR;
return StatusCode.ERROR;
} catch (RuntimeException e) {
System.err.println("Error performing delete.");
e.printStackTrace();
return SERVER_ERROR;
return StatusCode.ERROR;
}

return OK;
return StatusCode.OK;
}

// These functions are adapted from RowOperations.java:
Expand Down Expand Up @@ -449,8 +445,8 @@ public int presplit(String t, String[] keys)
for (int i = 0; i < keys.length; i++) {
splits.add(new Text(keys[i]));
}
connector.tableOperations().addSplits(t, splits);
return OK;
connector.tableOperations().addSplits(t, splits);
return StatusCode.OK;
}

}
35 changes: 16 additions & 19 deletions aerospike/src/main/java/com/yahoo/ycsb/db/AerospikeClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.aerospike.client.AerospikeException;
import com.aerospike.client.Bin;
import com.aerospike.client.Key;
Expand All @@ -31,10 +25,16 @@
import com.aerospike.client.policy.Policy;
import com.aerospike.client.policy.RecordExistsAction;
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 java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.Vector;

/**
* YCSB binding for <a href="http://www.aerospike.com/">Areospike</a>.
Expand All @@ -45,9 +45,6 @@ public class AerospikeClient extends com.yahoo.ycsb.DB {
private static final String DEFAULT_TIMEOUT = "10000";
private static final String DEFAULT_NAMESPACE = "ycsb";

private static final int RESULT_OK = 0;
private static final int RESULT_ERROR = -1;

private String namespace = null;

private com.aerospike.client.AerospikeClient client = null;
Expand Down Expand Up @@ -114,26 +111,26 @@ record = client.get(readPolicy, new Key(namespace, table, key));

if (record == null) {
System.err.println("Record key " + key + " not found (read)");
return RESULT_ERROR;
return StatusCode.ERROR;
}

for (Map.Entry<String, Object> entry: record.bins.entrySet()) {
result.put(entry.getKey(),
new ByteArrayByteIterator((byte[])entry.getValue()));
}

return RESULT_OK;
return StatusCode.OK;
} catch (AerospikeException e) {
System.err.println("Error while reading key " + key + ": " + e);
return RESULT_ERROR;
return StatusCode.ERROR;
}
}

@Override
public int scan(String table, String start, int count, Set<String> fields,
Vector<HashMap<String, ByteIterator>> result) {
System.err.println("Scan not implemented");
return RESULT_ERROR;
return StatusCode.ERROR;
}

private int write(String table, String key, WritePolicy writePolicy,
Expand All @@ -150,10 +147,10 @@ private int write(String table, String key, WritePolicy writePolicy,

try {
client.put(writePolicy, keyObj, bins);
return RESULT_OK;
return StatusCode.OK;
} catch (AerospikeException e) {
System.err.println("Error while writing key " + key + ": " + e);
return RESULT_ERROR;
return StatusCode.ERROR;
}
}

Expand All @@ -174,13 +171,13 @@ public int 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 RESULT_ERROR;
return StatusCode.ERROR;
}

return RESULT_OK;
return StatusCode.OK;
} catch (AerospikeException e) {
System.err.println("Error while deleting key " + key + ": " + e);
return RESULT_ERROR;
return StatusCode.ERROR;
}
}
}
19 changes: 8 additions & 11 deletions cassandra/src/main/java/com/yahoo/ycsb/db/CassandraCQLClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ public class CassandraCQLClient extends DB {
private static ConsistencyLevel readConsistencyLevel = ConsistencyLevel.ONE;
private static ConsistencyLevel writeConsistencyLevel = ConsistencyLevel.ONE;

public static final int OK = 0;
public static final int ERR = -1;

public static final String YCSB_KEY = "y_id";
public static final String KEYSPACE_PROPERTY = "cassandra.keyspace";
public static final String KEYSPACE_PROPERTY_DEFAULT = "ycsb";
Expand Down Expand Up @@ -232,12 +229,12 @@ public int read(String table, String key, Set<String> fields,

}

return OK;
return StatusCode.OK;

} catch (Exception e) {
e.printStackTrace();
System.out.println("Error reading key: " + key);
return ERR;
return StatusCode.ERROR;
}

}
Expand Down Expand Up @@ -323,12 +320,12 @@ public int scan(String table, String startkey, int recordcount,
result.add(tuple);
}

return OK;
return StatusCode.OK;

} catch (Exception e) {
e.printStackTrace();
System.out.println("Error scanning with startkey: " + startkey);
return ERR;
return StatusCode.ERROR;
}

}
Expand Down Expand Up @@ -393,12 +390,12 @@ public int insert(String table, String key,

ResultSet rs = session.execute(insertStmt);

return OK;
return StatusCode.OK;
} catch (Exception e) {
e.printStackTrace();
}

return ERR;
return StatusCode.ERROR;
}

/**
Expand Down Expand Up @@ -426,13 +423,13 @@ public int delete(String table, String key) {

ResultSet rs = session.execute(stmt);

return OK;
return StatusCode.OK;
} catch (Exception e) {
e.printStackTrace();
System.out.println("Error deleting key: " + key);
}

return ERR;
return StatusCode.ERROR;
}

}
Loading

0 comments on commit 28a090a

Please sign in to comment.