diff --git a/src/com/yahoo/ycsb/Utils.java b/src/com/yahoo/ycsb/Utils.java index f94ebc0d2d84d63d5122b5567d9b94ba617189de..57dd141a066bd0145d1f2f617d4c9045e71ec36a 100644 --- a/src/com/yahoo/ycsb/Utils.java +++ b/src/com/yahoo/ycsb/Utils.java @@ -48,9 +48,9 @@ public class Utils /** * Hash an integer value. */ - public static int hash(int val) + public static long hash(long val) { - return FNVhash32(val); + return FNVhash64(val); } public static final int FNV_offset_basis_32=0x811c9dc5; diff --git a/src/com/yahoo/ycsb/workloads/CoreWorkload.java b/src/com/yahoo/ycsb/workloads/CoreWorkload.java index 3e75b6fda891eaab2e7ab25de37d916d08ebfb22..4c95bb662f983046abdce86abc4654a50f2addf2 100644 --- a/src/com/yahoo/ycsb/workloads/CoreWorkload.java +++ b/src/com/yahoo/ycsb/workloads/CoreWorkload.java @@ -411,6 +411,33 @@ public class CoreWorkload extends Workload } } + public String buildKeyName(long keynum) { + if (!orderedinserts) + { + keynum=Utils.hash(keynum); + } + return "user"+keynum; + } + HashMap<String, ByteIterator> buildValues() { + HashMap<String,ByteIterator> values=new HashMap<String,ByteIterator>(); + + for (int i=0; i<fieldcount; i++) + { + String fieldkey="field"+i; + ByteIterator data= new RandomByteIterator(fieldlengthgenerator.nextInt()); + values.put(fieldkey,data); + } + return values; + } + HashMap<String, ByteIterator> buildUpdate() { + //update a random field + HashMap<String, ByteIterator> values=new HashMap<String,ByteIterator>(); + String fieldname="field"+fieldchooser.nextString(); + ByteIterator data = new RandomByteIterator(fieldlengthgenerator.nextInt()); + values.put(fieldname,data); + return values; + } + /** * Do one insert operation. Because it will be called concurrently from multiple client threads, this * function must be thread safe. However, avoid synchronized, or the threads will block waiting for each @@ -420,19 +447,8 @@ public class CoreWorkload extends Workload public boolean doInsert(DB db, Object threadstate) { int keynum=keysequence.nextInt(); - if (!orderedinserts) - { - keynum=Utils.hash(keynum); - } - String dbkey="user"+keynum; - HashMap<String,ByteIterator> values=new HashMap<String,ByteIterator>(); - - for (int i=0; i<fieldcount; i++) - { - String fieldkey="field"+i; - ByteIterator data= new RandomByteIterator(fieldlengthgenerator.nextInt()); - values.put(fieldkey,data); - } + String dbkey = buildKeyName(keynum); + HashMap<String, ByteIterator> values = buildValues(); if (db.insert(table,dbkey,values) == 0) return true; else @@ -483,12 +499,8 @@ public class CoreWorkload extends Workload } while (keynum>transactioninsertkeysequence.lastInt()); - if (!orderedinserts) - { - keynum=Utils.hash(keynum); - } - String keyname="user"+keynum; - + String keyname = buildKeyName(keynum); + HashSet<String> fields=null; if (!readallfields) @@ -513,11 +525,7 @@ public class CoreWorkload extends Workload } while (keynum>transactioninsertkeysequence.lastInt()); - if (!orderedinserts) - { - keynum=Utils.hash(keynum); - } - String keyname="user"+keynum; + String keyname = buildKeyName(keynum); HashSet<String> fields=null; @@ -530,24 +538,17 @@ public class CoreWorkload extends Workload fields.add(fieldname); } - HashMap<String,ByteIterator> values=new HashMap<String,ByteIterator>(); + HashMap<String,ByteIterator> values; if (writeallfields) { //new data for all the fields - for (int i=0; i<fieldcount; i++) - { - String fieldname="field"+i; - ByteIterator data = new RandomByteIterator(fieldlengthgenerator.nextInt()); - values.put(fieldname,data); - } + values = buildValues(); } else { //update a random field - String fieldname="field"+fieldchooser.nextString(); - ByteIterator data = new RandomByteIterator(fieldlengthgenerator.nextInt()); - values.put(fieldname,data); + values = buildUpdate(); } //do the transaction @@ -573,11 +574,7 @@ public class CoreWorkload extends Workload } while (keynum>transactioninsertkeysequence.lastInt()); - if (!orderedinserts) - { - keynum=Utils.hash(keynum); - } - String startkeyname="user"+keynum; + String startkeyname = buildKeyName(keynum); //choose a random scan length int len=scanlength.nextInt(); @@ -606,30 +603,19 @@ public class CoreWorkload extends Workload } while (keynum>transactioninsertkeysequence.lastInt()); - if (!orderedinserts) - { - keynum=Utils.hash(keynum); - } - String keyname="user"+keynum; + String keyname=buildKeyName(keynum); - HashMap<String,ByteIterator> values=new HashMap<String,ByteIterator>(); + HashMap<String,ByteIterator> values; if (writeallfields) { //new data for all the fields - for (int i=0; i<fieldcount; i++) - { - String fieldname="field"+i; - ByteIterator data = new RandomByteIterator(fieldlengthgenerator.nextInt()); - values.put(fieldname,data); - } + values = buildValues(); } else { //update a random field - String fieldname="field"+fieldchooser.nextString(); - ByteIterator data = new RandomByteIterator(fieldlengthgenerator.nextInt()); - values.put(fieldname,data); + values = buildUpdate(); } db.update(table,keyname,values); @@ -639,19 +625,10 @@ public class CoreWorkload extends Workload { //choose the next key int keynum=transactioninsertkeysequence.nextInt(); - if (!orderedinserts) - { - keynum=Utils.hash(keynum); - } - String dbkey="user"+keynum; - - HashMap<String,ByteIterator> values=new HashMap<String,ByteIterator>(); - for (int i=0; i<fieldcount; i++) - { - String fieldkey="field"+i; - ByteIterator data = new RandomByteIterator(fieldlengthgenerator.nextInt()); - values.put(fieldkey,data); - } + + String dbkey = buildKeyName(keynum); + + HashMap<String, ByteIterator> values = buildValues(); db.insert(table,dbkey,values); } }