Skip to content
Snippets Groups Projects
Commit e1245743 authored by Thomas Lopatic's avatar Thomas Lopatic
Browse files

Don't use keys of inserted records before they have actually been written to the database.

parent 45e245e6
No related branches found
No related tags found
No related merge requests found
package com.yahoo.ycsb.generator;
import java.util.PriorityQueue;
/**
* A CounterGenerator that reports generated integers via lastInt()
* only after they have been acknowledged.
*/
public class AcknowledgedCounterGenerator extends CounterGenerator
{
private PriorityQueue<Integer> ack;
private int limit;
/**
* Create a counter that starts at countstart.
*/
public AcknowledgedCounterGenerator(int countstart)
{
super(countstart);
ack = new PriorityQueue<Integer>();
limit = countstart - 1;
}
@Override
public int lastInt()
{
return limit;
}
public synchronized void acknowledge(int value)
{
ack.add(value);
// move a contiguous sequence from the priority queue
// over to the "limit" variable
Integer min;
while ((min = ack.peek()) != null && min == limit + 1) {
limit = ack.poll();
}
}
}
......@@ -20,6 +20,7 @@ package com.yahoo.ycsb.workloads;
import java.util.Properties;
import com.yahoo.ycsb.*;
import com.yahoo.ycsb.generator.AcknowledgedCounterGenerator;
import com.yahoo.ycsb.generator.CounterGenerator;
import com.yahoo.ycsb.generator.DiscreteGenerator;
import com.yahoo.ycsb.generator.ExponentialGenerator;
......@@ -299,7 +300,7 @@ public class CoreWorkload extends Workload
Generator fieldchooser;
CounterGenerator transactioninsertkeysequence;
AcknowledgedCounterGenerator transactioninsertkeysequence;
IntegerGenerator scanlength;
......@@ -417,7 +418,7 @@ public class CoreWorkload extends Workload
operationchooser.addValue(readmodifywriteproportion,"READMODIFYWRITE");
}
transactioninsertkeysequence=new CounterGenerator(recordcount);
transactioninsertkeysequence=new AcknowledgedCounterGenerator(recordcount);
if (requestdistrib.compareTo("uniform")==0)
{
keychooser=new UniformIntegerGenerator(0,recordcount-1);
......@@ -763,5 +764,6 @@ public class CoreWorkload extends Workload
HashMap<String, ByteIterator> values = buildValues(dbkey);
db.insert(table,dbkey,values);
transactioninsertkeysequence.acknowledge(keynum);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment