Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add delete operation to core workflow #1724

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions core/src/main/java/site/ycsb/workloads/CoreWorkload.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
* <LI><b>readproportion</b>: what proportion of operations should be reads (default: 0.95)
* <LI><b>updateproportion</b>: what proportion of operations should be updates (default: 0.05)
* <LI><b>insertproportion</b>: what proportion of operations should be inserts (default: 0)
* <LI><b>deleteproportion</b>: what proportion of operations should be deletes (default: 0)
* <LI><b>scanproportion</b>: what proportion of operations should be scans (default: 0)
* <LI><b>readmodifywriteproportion</b>: what proportion of operations should be read a record,
* modify it, write it back (default: 0)
Expand Down Expand Up @@ -240,6 +241,16 @@ public class CoreWorkload extends Workload {
*/
public static final String SCAN_PROPORTION_PROPERTY_DEFAULT = "0.0";

/**
* The name of the property for the proportion of transactions that are deletes.
*/
public static final String DELETE_PROPORTION_PROPERTY = "deleteproportion";

/**
* The default proportion of transactions that are delete.
*/
public static final String DELETE_PROPORTION_PROPERTY_DEFAULT = "0.0";

/**
* The name of the property for the proportion of transactions that are read-modify-write.
*/
Expand Down Expand Up @@ -488,7 +499,7 @@ public void init(Properties p) throws WorkloadException {
keysequence = new CounterGenerator(insertstart);
operationchooser = createOperationGenerator(p);

transactioninsertkeysequence = new AcknowledgedCounterGenerator(recordcount);
transactioninsertkeysequence = new AcknowledgedCounterGenerator(insertstart);
if (requestdistrib.compareTo("uniform") == 0) {
keychooser = new UniformLongGenerator(insertstart, insertstart + insertcount - 1);
} else if (requestdistrib.compareTo("exponential") == 0) {
Expand All @@ -500,7 +511,7 @@ public void init(Properties p) throws WorkloadException {
ExponentialGenerator.EXPONENTIAL_FRAC_DEFAULT));
keychooser = new ExponentialGenerator(percentile, recordcount * frac);
} else if (requestdistrib.compareTo("sequential") == 0) {
keychooser = new SequentialGenerator(insertstart, insertstart + insertcount - 1);
keychooser = new SequentialGenerator(insertstart, insertstart + recordcount - 1);
} else if (requestdistrib.compareTo("zipfian") == 0) {
// it does this by generating a random "next key" in part by taking the modulus over the
// number of keys.
Expand Down Expand Up @@ -669,6 +680,9 @@ public boolean doTransaction(DB db, Object threadstate) {
case "INSERT":
doTransactionInsert(db);
break;
case "DELETE":
doTransactionDelete(db);
break;
case "SCAN":
doTransactionScan(db);
break;
Expand Down Expand Up @@ -711,6 +725,8 @@ long nextKeynum() {
do {
keynum = transactioninsertkeysequence.lastValue() - keychooser.nextValue().intValue();
} while (keynum < 0);
} else if (keychooser instanceof SequentialGenerator) {
keynum = keychooser.nextValue().intValue();
} else {
do {
keynum = keychooser.nextValue().intValue();
Expand All @@ -720,7 +736,6 @@ long nextKeynum() {
}

public void doTransactionRead(DB db) {
// choose a random key
long keynum = nextKeynum();

String keyname = CoreWorkload.buildKeyName(keynum, zeropadding, orderedinserts);
Expand All @@ -747,7 +762,6 @@ public void doTransactionRead(DB db) {
}

public void doTransactionReadModifyWrite(DB db) {
// choose a random key
minhokang242 marked this conversation as resolved.
Show resolved Hide resolved
long keynum = nextKeynum();

String keyname = CoreWorkload.buildKeyName(keynum, zeropadding, orderedinserts);
Expand Down Expand Up @@ -794,7 +808,6 @@ public void doTransactionReadModifyWrite(DB db) {
}

public void doTransactionScan(DB db) {
// choose a random key
long keynum = nextKeynum();

String startkeyname = CoreWorkload.buildKeyName(keynum, zeropadding, orderedinserts);
Expand All @@ -816,7 +829,6 @@ public void doTransactionScan(DB db) {
}

public void doTransactionUpdate(DB db) {
// choose a random key
long keynum = nextKeynum();

String keyname = CoreWorkload.buildKeyName(keynum, zeropadding, orderedinserts);
Expand Down Expand Up @@ -848,11 +860,19 @@ public void doTransactionInsert(DB db) {
}
}

public void doTransactionDelete(DB db) {
long keynum = nextKeynum();

String keyname = CoreWorkload.buildKeyName(keynum, zeropadding, orderedinserts);

db.delete(table, keyname);
}

/**
* Creates a weighted discrete values with database operations for a workload to perform.
* Weights/proportions are read from the properties list and defaults are used
* when values are not configured.
* Current operations are "READ", "UPDATE", "INSERT", "SCAN" and "READMODIFYWRITE".
* Current operations are "READ", "UPDATE", "INSERT", "SCAN", "READMODIFYWRITE", "DELETE".
*
* @param p The properties list to pull weights from.
* @return A generator that can be used to determine the next operation to perform.
Expand All @@ -868,6 +888,8 @@ protected static DiscreteGenerator createOperationGenerator(final Properties p)
p.getProperty(UPDATE_PROPORTION_PROPERTY, UPDATE_PROPORTION_PROPERTY_DEFAULT));
final double insertproportion = Double.parseDouble(
p.getProperty(INSERT_PROPORTION_PROPERTY, INSERT_PROPORTION_PROPERTY_DEFAULT));
final double deleteproportion = Double.parseDouble(
p.getProperty(DELETE_PROPORTION_PROPERTY, DELETE_PROPORTION_PROPERTY_DEFAULT));
final double scanproportion = Double.parseDouble(
p.getProperty(SCAN_PROPORTION_PROPERTY, SCAN_PROPORTION_PROPERTY_DEFAULT));
final double readmodifywriteproportion = Double.parseDouble(p.getProperty(
Expand All @@ -886,6 +908,10 @@ protected static DiscreteGenerator createOperationGenerator(final Properties p)
operationchooser.addValue(insertproportion, "INSERT");
}

if (deleteproportion > 0) {
operationchooser.addValue(deleteproportion, "DELETE");
}

if (scanproportion > 0) {
operationchooser.addValue(scanproportion, "SCAN");
}
Expand Down
40 changes: 40 additions & 0 deletions workloads/workloadg
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 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.


# Yahoo! Cloud System Benchmark
# Workload A: Update heavy workload
# Application example: Session store recording recent actions
#
# Read/update ratio: 50/50
# Default data size: 1 KB records (10 fields, 100 bytes each, plus key)
# Request distribution: zipfian

recordcount=1000
operationcount=1000
workload=site.ycsb.workloads.CoreWorkload

readallfields=true
insertorder=ordered
insertstart=0

readproportion=0
updateproportion=0
scanproportion=0
insertproportion=0.8
deleteproportion=0.2

requestdistribution=sequential