Skip to content

Commit

Permalink
StatusCode -> Status
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cmccoy committed Nov 3, 2015
1 parent 28a090a commit 5113c2e
Show file tree
Hide file tree
Showing 43 changed files with 735 additions and 757 deletions.
44 changes: 22 additions & 22 deletions accumulo/src/main/java/com/yahoo/ycsb/db/AccumuloClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
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;
Expand Down Expand Up @@ -199,14 +199,14 @@ private Scanner getRow(Text row, Set<String> fields) {
}

@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 {
Expand All @@ -219,20 +219,20 @@ 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 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
Expand Down Expand Up @@ -283,17 +283,17 @@ public int scan(String t, String startkey, int recordcount,
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));
Expand All @@ -315,44 +315,44 @@ public int update(String t, String key,
} 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 {
deleteRow(new Text(key));
} 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:
Expand Down Expand Up @@ -412,7 +412,7 @@ private void keyNotification(String key) throws KeeperException {
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.
Expand All @@ -438,15 +438,15 @@ private void keyNotification(String key) throws KeeperException {

}

public int presplit(String t, String[] keys)
public Status presplit(String t, String[] keys)
throws TableNotFoundException, AccumuloException,
AccumuloSecurityException {
TreeSet<Text> splits = new TreeSet<Text>();
for (int i = 0; i < keys.length; i++) {
splits.add(new Text(keys[i]));
}
connector.tableOperations().addSplits(t, splits);
return StatusCode.OK;
return Status.OK;
}

}
32 changes: 16 additions & 16 deletions aerospike/src/main/java/com/yahoo/ycsb/db/AerospikeClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
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;
Expand Down Expand Up @@ -97,7 +97,7 @@ public void cleanup() throws DBException {
}

@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;
Expand All @@ -111,29 +111,29 @@ record = client.get(readPolicy, new Key(namespace, table, key));

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()) {
result.put(entry.getKey(),
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;
Expand All @@ -147,37 +147,37 @@ private int write(String table, String key, WritePolicy writePolicy,

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;
}
}
}
28 changes: 14 additions & 14 deletions cassandra/src/main/java/com/yahoo/ycsb/db/CassandraCQLClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public void cleanup() throws DBException {
* @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 {
Expand Down Expand Up @@ -229,12 +229,12 @@ public int read(String table, String key, Set<String> fields,

}

return StatusCode.OK;
return Status.OK;

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

}
Expand All @@ -260,7 +260,7 @@ public int read(String table, String key, Set<String> fields,
* @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 {
Expand Down Expand Up @@ -320,12 +320,12 @@ public int scan(String table, String startkey, int recordcount,
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;
}

}
Expand All @@ -344,7 +344,7 @@ public int scan(String table, String startkey, int recordcount,
* @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);
Expand All @@ -364,7 +364,7 @@ public int update(String table, String key,
* @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 {
Expand All @@ -390,12 +390,12 @@ public int insert(String table, String key,

ResultSet rs = session.execute(insertStmt);

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

return StatusCode.ERROR;
return Status.ERROR;
}

/**
Expand All @@ -408,7 +408,7 @@ public int insert(String table, String key,
* @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;
Expand All @@ -421,15 +421,15 @@ public int delete(String table, String key) {
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;
}

}
Loading

0 comments on commit 5113c2e

Please sign in to comment.