Skip to content
Snippets Groups Projects
Commit 08ed845b authored by danielpoltx's avatar danielpoltx
Browse files

Added SequentialGenerator.java

parent e45120b3
No related branches found
No related tags found
No related merge requests found
/**
* Copyright (c) 2010 Yahoo! Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You
* may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License. See accompanying
* LICENSE file.
*/
package com.yahoo.ycsb.generator;
import java.util.concurrent.atomic.AtomicInteger;
/**
* Generates a sequence of integers 0, 1, ...
*/
public class SequentialGenerator extends NumberGenerator
{
final AtomicInteger counter;
int _interval,_countstart;
/**
* Create a counter that starts at countstart
*/
public SequentialGenerator(int countstart, int countend)
{
counter=new AtomicInteger();
setLastValue(counter.get());
_countstart=countstart;
_interval=countend-countstart+1;
}
/**
* If the generator returns numeric (integer) values, return the next value as an int. Default is to return -1, which
* is appropriate for generators that do not return numeric values.
*/
public int nextInt()
{
int ret = _countstart + counter.getAndIncrement()%_interval;
setLastValue(ret);
return ret;
}
@Override
public Number nextValue()
{
int ret = _countstart + counter.getAndIncrement()%_interval;
setLastValue(ret);
return ret;
}
@Override
public Number lastValue()
{
return counter.get() + 1;
}
@Override
public double mean() {
throw new UnsupportedOperationException("Can't compute mean of non-stationary distribution!");
}
}
......@@ -62,16 +62,18 @@ import java.util.ArrayList;
* <LI><b>readmodifywriteproportion</b>: what proportion of operations should be read a record,
* modify it, write it back (default: 0)
* <LI><b>requestdistribution</b>: what distribution should be used to select the records to operate
* on - uniform, zipfian, hotspot, ordered, exponential or latest (default: uniform)
* on - uniform, zipfian, hotspot, sequential, exponential or latest (default: uniform)
* <LI><b>maxscanlength</b>: for scans, what is the maximum number of records to scan (default: 1000)
* <LI><b>scanlengthdistribution</b>: for scans, what distribution should be used to choose the
* number of records to scan, for each scan, between 1 and maxscanlength (default: uniform)
* <LI><b>insertstart</b>: for parallel loads and runs, defines the starting record for this
* YCSB instance (default: 0)
* <LI><b>insertcount</b>: for parallel loads and runs, defines the ending record for this
* <LI><b>insertcount</b>: for parallel loads and runs, defines the number of records for this
* YCSB instance (default: recordcount)
* <LI><b>zeropadding</b>: for generating a record sequence compatible with string sort order by
* 0 padding the record number. Controls the number of 0s to use for padding. (default: 1)
* For example for row 5, with zeropadding=1 you get 'user5' key and with zeropading=8 you get
* 'user00000005' key.
* <LI><b>insertorder</b>: should records be inserted in order by key ("ordered"), or in hashed
* order ("hashed") (default: hashed)
* </ul>
......@@ -413,9 +415,12 @@ public class CoreWorkload extends Workload {
String scanlengthdistrib =
p.getProperty(SCAN_LENGTH_DISTRIBUTION_PROPERTY, SCAN_LENGTH_DISTRIBUTION_PROPERTY_DEFAULT);
int insertstart=Integer.parseInt(p.getProperty(INSERT_START_PROPERTY,INSERT_START_PROPERTY_DEFAULT));
int insertcount=Integer.parseInt(p.getProperty(INSERT_COUNT_PROPERTY,String.valueOf(recordcount-insertstart)));
zeropadding=Integer.parseInt(p.getProperty(ZERO_PADDING_PROPERTY,ZERO_PADDING_PROPERTY_DEFAULT));
int insertstart =
Integer.parseInt(p.getProperty(INSERT_START_PROPERTY,INSERT_START_PROPERTY_DEFAULT));
int insertcount =
Integer.parseInt(p.getProperty(INSERT_COUNT_PROPERTY,String.valueOf(recordcount-insertstart)));
zeropadding =
Integer.parseInt(p.getProperty(ZERO_PADDING_PROPERTY,ZERO_PADDING_PROPERTY_DEFAULT));
readallfields = Boolean.parseBoolean(
p.getProperty(READ_ALL_FIELDS_PROPERTY, READ_ALL_FIELDS_PROPERTY_DEFAULT));
......@@ -474,7 +479,7 @@ public class CoreWorkload extends Workload {
transactioninsertkeysequence = new AcknowledgedCounterGenerator(recordcount);
if (requestdistrib.compareTo("uniform") == 0) {
keychooser=new UniformIntegerGenerator(insertstart,insertstart+insertcount-1);
} else if (requestdistrib.compareTo("ordered")==0) {
} else if (requestdistrib.compareTo("sequential")==0) {
keychooser=new SequentialGenerator(insertstart,insertstart+insertcount-1);
}else if (requestdistrib.compareTo("zipfian") == 0) {
// it does this by generating a random "next key" in part by taking the modulus over the
......@@ -525,7 +530,11 @@ public class CoreWorkload extends Workload {
if (!orderedinserts) {
keynum = Utils.hash(keynum);
}
return "user"+String.format("%0"+zeropadding+"d",keynum);
String value=Long.toString(keynum);
int fill=zeropadding - value.length();
String prekey="user";
for(int i=0; i<fill;i++) {prekey+='0';}
return prekey+value;
}
/**
......
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