Permalink
Browse files

Update HyperClientYCSB as com.yahoo.ycsb.DB changes the interfaces

Summary:
Basically, com.yahoo.ycsb.DB changes HashMap<String, String> to
HashMap<String, ByteIterator>.
This diff also enable convert_to_java() in read(). Will it affect the
YCSB benchmark?
Two more questions:
1. Why NOTFOUND is returned as 0 in read(). It seems YCSB wants a
non-zero value for not found.
2. under which condition, interres.has_key(key) is false in
convert_to_java().
  • Loading branch information...
1 parent 9955851 commit eb2d803deab8220826d2ef1f5b49da60ea90cd45 byzhang committed Feb 21, 2012
Showing with 22 additions and 16 deletions.
  1. +22 −16 ycsb/hyperclient/HyperClientYCSB.java
View
38 ycsb/hyperclient/HyperClientYCSB.java
@@ -40,6 +40,8 @@
import com.yahoo.ycsb.DB;
import com.yahoo.ycsb.DBException;
+import com.yahoo.ycsb.ByteIterator;
+import com.yahoo.ycsb.StringByteIterator;
import hyperclient.HyperClient;
import hyperclient.ReturnCode;
@@ -86,7 +88,7 @@ public void cleanup() throws DBException
* @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,String> result)
+ public int read(String table, String key, Set<String> fields, HashMap<String,ByteIterator> result)
{
ssmap r = new ssmap();
ReturnCode ret = m_client.get(table, key, r);
@@ -98,12 +100,7 @@ public int read(String table, String key, Set<String> fields, HashMap<String,Str
if (ret == ReturnCode.SUCCESS)
{
- //convert_to_java(fields, r, result);
- return 0;
- }
-
- if (ret == ReturnCode.NOTFOUND)
- {
+ convert_to_java(fields, r, result);
return 0;
}
@@ -120,7 +117,7 @@ public int read(String table, String key, Set<String> fields, HashMap<String,Str
* @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,String>> result)
+ public int scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String,ByteIterator>> result)
{
// XXX I'm going to be lazy and not support "fields" for now. Patches
// welcome.
@@ -153,6 +150,13 @@ public int scan(String table, String startkey, int recordcount, Set<String> fiel
if (ret == ReturnCode.SUCCESS)
{
+ for (int i = 0; i < res.size(); ++i)
+ {
+ ssmap e = res.get(i);
+ HashMap<String, ByteIterator> e2 = new HashMap<String, ByteIterator>();
+ convert_to_java(fields, e, e2);
+ result.add(e2);
+ }
return 0;
}
@@ -168,7 +172,7 @@ public int scan(String table, String startkey, int recordcount, Set<String> fiel
* @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,String> values)
+ public int update(String table, String key, HashMap<String,ByteIterator> values)
{
ssmap res = new ssmap();
snmap nums = new snmap();
@@ -182,7 +186,7 @@ public int update(String table, String key, HashMap<String,String> values)
{
return -1;
}
-
+
BigInteger bi = new BigInteger(m_mat.group(2));
bi = bi.shiftLeft(32);
nums.set("recno", bi);
@@ -212,7 +216,7 @@ public int update(String table, String key, HashMap<String,String> values)
* @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,String> values)
+ public int insert(String table, String key, HashMap<String,ByteIterator> values)
{
return update(table, key, values);
}
@@ -241,22 +245,24 @@ public int delete(String table, String key)
return ret.swigValue();
}
- private void convert_to_java(Set<String> fields, ssmap interres, Map<String,String> result)
+ private void convert_to_java(Set<String> fields, ssmap interres, HashMap<String,ByteIterator> result)
{
for (String key : fields)
{
+ // Q: under which condition, interres.has_key(key) is false?
if (interres.has_key(key))
{
- result.put(key, interres.get(key));
+ result.put(key, new StringByteIterator(interres.get(key)));
}
}
}
- private void convert_from_java(Map<String,String> result, ssmap interres)
+ private void convert_from_java(HashMap<String,ByteIterator> result, ssmap interres)
{
- for (Map.Entry<String, String> entry : result.entrySet())
+ Map<String, ByteIterator> r = result;
+ for (Map.Entry<String, ByteIterator> entry : r.entrySet())
{
- interres.set(entry.getKey(), entry.getValue());
+ interres.set(entry.getKey(), entry.getValue().toString());
}
}
}

1 comment on commit eb2d803

@rescrv

This patch looks good. I'm going to test and merge, but wanted to answer your questions now.

  1. Why NOTFOUND is returned as 0 in read(). It seems YCSB wants a non-zero value for not found?

This is just an artifact of my thinking about "SUCCESS/NOTFOUND" as common cases for a GET, while other values are actual errors. I don't think YCSB ever triggers a NOTFOUND, so this fix should not break anything.

  1. Under which condition, interres.has_key(key) is false in convert_to_java()?

This is just a safety net to get things quickly working. YCSB's core workloads have username and field[1-10] as attributes. My tests create this space, but I wanted things to be robust. Perhaps we should error out and abort the test. This is yet another case of being over-cautious without ever triggering the condition being tested.

The diff which enables "convert_to_java" will not affect the flow of operations in the benchmark. It's just going to copy an extra 1KB of data per row, which should be lost in the noise.

Please sign in to comment.