add refkey property to op template API

This commit is contained in:
Jonathan Shook 2024-10-30 13:08:48 -05:00
parent 5bf6a004af
commit 5a737c72ef
8 changed files with 92 additions and 4 deletions

View File

@ -43,7 +43,8 @@ public class Cqld4PreparedStmtDispenser extends Cqld4BaseOpDispenser {
private final ParsedTemplateString stmtTpl;
private final LongFunction<Object[]> fieldsF;
private PreparedStatement preparedStmt;
private CqlSession boundSession;
// This is a stable enum for the op template from the workload, bounded by cardinality of all op templates
private int refkey;
public Cqld4PreparedStmtDispenser(
Cqld4DriverAdapter adapter,
@ -66,6 +67,7 @@ public class Cqld4PreparedStmtDispenser extends Cqld4BaseOpDispenser {
private LongFunction<Object[]> getFieldsFunction(ParsedOp op) {
LongFunction<Object[]> varbinder;
varbinder = op.newArrayBinderFromBindPoints(stmtTpl.getBindPoints());
this.refkey = op.getRefKey();
return varbinder;
}

View File

@ -17,12 +17,14 @@
package io.nosqlbench.adapters.api.activityconfig.rawyaml;
import io.nosqlbench.adapters.api.util.AdaptersApiVersionInfo;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
public class RawOpsDoc extends OpsOwner {
public class RawOpsDoc extends OpsOwner implements Iterable<RawOpsBlock> {
private RawScenarios scenarios = new RawScenarios();
private final List<RawOpsBlock> blocks = new ArrayList<>();
@ -129,4 +131,8 @@ public class RawOpsDoc extends OpsOwner {
this.versionRegex = regex;
}
@Override
public @NotNull Iterator<RawOpsBlock> iterator() {
return this.blocks.iterator();
}
}

View File

@ -16,9 +16,13 @@
package io.nosqlbench.adapters.api.activityconfig.rawyaml;
import java.util.List;
import org.jetbrains.annotations.NotNull;
public class RawOpsDocList {
import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer;
public class RawOpsDocList implements Iterable<RawOpsDoc> {
private final List<RawOpsDoc> rawOpsDocList;
@ -45,4 +49,22 @@ public class RawOpsDocList {
long optemplates = rawOpsDocList.stream().flatMap(d -> d.getBlocks().stream()).flatMap(s -> s.getRawOpDefs().stream()).count();
return "docs:" + docs + " blocks:" + blocks + " optemplates:" + optemplates;
}
@Override
public @NotNull Iterator<RawOpsDoc> iterator() {
return this.rawOpsDocList.iterator();
}
public int applyModifier(Consumer<RawOpDef> modifier) {
int count = 0;
for (RawOpsDoc rawOpsDoc : rawOpsDocList) {
for (RawOpsBlock opBlock : rawOpsDoc) {
for (RawOpDef rawOpDef : opBlock.getRawOpDefs()) {
modifier.accept(rawOpDef);
count++;
}
}
}
return count;
}
}

View File

@ -29,6 +29,7 @@ public class OpData extends OpTemplate {
private Map<String, Object> params = Map.of();
private Map<String, String> bindings = Map.of();
private Map<String, String> tags = new LinkedHashMap<>();
private int refKey;
public OpData(String desc, String name, Map<String, String> tags, Map<String, String> bindings, Map<String, Object> params, Map<String, Object> op) {
this.desc = desc;
@ -141,6 +142,16 @@ public class OpData extends OpTemplate {
return this.params;
}
@Override
public int getRefKey() {
return refKey;
}
@Override
public void setRefKey(int refKey) {
this.refKey = refKey;
}
@Override
public Optional<Map<String, Object>> getOp() {
return Optional.of(this.op);

View File

@ -32,6 +32,7 @@ public class OpDef extends OpTemplate {
private final LinkedHashMap<String, Object> params;
private final LinkedHashMap<String, String> bindings;
private final LinkedHashMap<String, String> tags;
private int refKey;
public OpDef(OpsBlock block, RawOpDef rawOpDef) {
this.block = block;
@ -84,6 +85,16 @@ public class OpDef extends OpTemplate {
return params;
}
@Override
public int getRefKey() {
return this.refKey;
}
@Override
public void setRefKey(int refKey) {
this.refKey = refKey;
}
private LinkedHashMap<String, Object> composeParams() {
MultiMapLookup<Object> lookup = new MultiMapLookup<>(rawOpDef.getParams(), block.getParams());
LinkedHashMap<String, Object> params = new LinkedHashMap<>(lookup);

View File

@ -56,6 +56,7 @@ public abstract class OpTemplate implements Tagged {
public final static String FIELD_BINDINGS = "bindings";
public final static String FIELD_PARAMS = "params";
public final static String FIELD_TAGS = "tags";
public final static String FIELD_REFKEY = "refkey";
/**
* @return a description for the op template, or an empty string
@ -129,6 +130,13 @@ public abstract class OpTemplate implements Tagged {
}
}
/**
* Get an integer key for the op template for this workload template, based on enumeration of all
* active op templates. This value is stable within the current instance of the workload template only.
* @return a unique integer key for this op template within the workload template
*/
public abstract int getRefKey();
public abstract void setRefKey(int refKey);
public <V> V getParam(String name, Class<? extends V> type) {
Object object = getParams().get(name);

View File

@ -28,6 +28,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.*;
import java.util.function.Consumer;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@ -39,6 +40,7 @@ public class OpsDocList implements Iterable<OpsDoc> {
public OpsDocList(RawOpsDocList rawOpsDocList) {
this.rawOpsDocList = rawOpsDocList;
this.applyModifier(new enumerator());
}
public static OpsDocList none() {
@ -180,4 +182,26 @@ public class OpsDocList implements Iterable<OpsDoc> {
List<RawOpsDoc> stmtDocs = rawOpsDocList.getOpsDocs();
return Pattern.compile(stmtDocs.size()>0 ? stmtDocs.get(0).getVersionRegex() : ".*");
}
public int applyModifier(Consumer<OpTemplate> modifier) {
int count=0;
for (OpsDoc stmtDoc : this.getStmtDocs()) {
for (OpsBlock opTemplates : stmtDoc) {
for (OpTemplate opTemplate : opTemplates) {
modifier.accept(opTemplate);
count++;
}
}
}
return count;
}
public static class enumerator implements Consumer<OpTemplate> {
private int count=0;
@Override
public void accept(OpTemplate opTemplate) {
opTemplate.setRefKey(count++);
}
}
}

View File

@ -953,6 +953,10 @@ public class ParsedOp extends NBBaseComponent implements LongFunction<Map<String
return lfa;
}
public int getRefKey() {
return this._opTemplate.getRefKey();
}
public static enum SubOpNaming {
SubKey,