progress on cqld4

This commit is contained in:
Jonathan Shook 2021-04-01 10:51:03 -05:00
parent ca7fb7b839
commit 50d9fc43ec
4 changed files with 117 additions and 22 deletions

View File

@ -4,7 +4,7 @@
<parent>
<groupId>io.nosqlbench</groupId>
<artifactId>mvn-defaults</artifactId>
<version>4.15.20-SNAPSHOT</version>
<version>4.15.31-SNAPSHOT</version>
<relativePath>../mvn-defaults</relativePath>
</parent>
@ -23,13 +23,13 @@
<dependency>
<groupId>io.nosqlbench</groupId>
<artifactId>engine-api</artifactId>
<version>4.15.20-SNAPSHOT</version>
<version>4.15.31-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.nosqlbench</groupId>
<artifactId>drivers-api</artifactId>
<version>4.15.20-SNAPSHOT</version>
<version>4.15.31-SNAPSHOT</version>
</dependency>
@ -61,7 +61,7 @@
<dependency>
<groupId>io.nosqlbench</groupId>
<artifactId>virtdata-lib-basics</artifactId>
<version>4.15.20-SNAPSHOT</version>
<version>4.15.31-SNAPSHOT</version>
<scope>compile</scope>
</dependency>

View File

@ -1,18 +0,0 @@
import io.nosqlbench.engine.api.activityapi.core.SyncAction;
public class Cqld4Action implements SyncAction {
private final Cqld4Activity activity;
public Cqld4Action(int slot, Cqld4Activity activity) {
this.activity = activity;
}
@Override
public int runCycle(long cycle) {
return 0;
}
}

View File

@ -0,0 +1,92 @@
package io.nosqlbench.driver.cqld4;
import com.codahale.metrics.Histogram;
import com.codahale.metrics.Timer;
import io.nosqlbench.engine.api.activityapi.core.ActivityDefObserver;
import io.nosqlbench.engine.api.activityapi.core.SyncAction;
import io.nosqlbench.engine.api.activityapi.errorhandling.modular.ErrorDetail;
import io.nosqlbench.engine.api.activityimpl.ActivityDef;
import io.nosqlbench.engine.api.activityimpl.OpDispenser;
import java.util.concurrent.TimeUnit;
public class Cqld4Action implements SyncAction, ActivityDefObserver {
/**
* The thread number within the activity instance
**/
private final int slot;
private final Cqld4Activity activity;
private Timer bindTimer;
private Timer executeTimer;
private Timer resultTimer;
private Timer resultSuccessTimer;
private Histogram triesHisto;
private int maxTries;
public Cqld4Action(int slot, Cqld4Activity activity) {
this.slot = slot;
this.activity = activity;
}
@Override
public void init() {
this.bindTimer = activity.getInstrumentation().getOrCreateBindTimer();
this.executeTimer = activity.getInstrumentation().getOrCreateExecuteTimer();
this.resultTimer = activity.getInstrumentation().getOrCreateResultTimer();
this.resultSuccessTimer = activity.getInstrumentation().getOrCreateResultSuccessTimer();
this.triesHisto = activity.getInstrumentation().getOrCreateTriesHistogram();
}
@Override
public int runCycle(long cycle) {
Cqld4Op cql4op;
try (Timer.Context ctx = bindTimer.time()) {
OpDispenser<Cqld4Op> opDispenser = activity.getSequence().get(cycle);
cql4op = opDispenser.apply(cycle);
}
int tries = 0;
int result = 0;
Exception error=null;
while (tries < maxTries) {
tries++;
long startat = System.nanoTime();
try {
try (Timer.Context ctx = executeTimer.time()) {
cql4op.run();
}
}
catch (Exception e) {
error=e;
} finally {
long nanos = System.nanoTime() - startat;
resultTimer.update(nanos, TimeUnit.NANOSECONDS);
if (error==null) {
resultSuccessTimer.update(nanos, TimeUnit.NANOSECONDS);
break;
} else {
ErrorDetail detail = activity.getErrorhandler().handleError(error,cycle,nanos);
result = detail.resultCode;
if (!detail.isRetryable()) {
break;
}
}
}
}
triesHisto.update(tries);
return result;
}
@Override
public void onActivityDefUpdate(ActivityDef activityDef) {
this.maxTries = activity.getActivityDef().getParams().getOptionalInteger("maxtries").orElse(10);
}
}

View File

@ -1,3 +1,6 @@
package io.nosqlbench.driver.cqld4;
import io.nosqlbench.engine.api.activityapi.errorhandling.modular.NBErrorHandler;
import io.nosqlbench.engine.api.activityapi.planning.OpSequence;
import io.nosqlbench.engine.api.activityconfig.yaml.OpTemplate;
import io.nosqlbench.engine.api.activityimpl.ActivityDef;
@ -13,6 +16,7 @@ public class Cqld4Activity extends SimpleActivity {
private final static Logger logger = LogManager.getLogger(Cqld4Activity.class);
private OpSequence<OpDispenser<Cqld4Op>> sequence;
private NBErrorHandler errorhandler;
public Cqld4Activity(ActivityDef activityDef) {
super(activityDef);
@ -23,5 +27,22 @@ public class Cqld4Activity extends SimpleActivity {
super.initActivity();
Function<OpTemplate,OpDispenser<Cqld4Op>> f = Cqld4ReadyOp::new;
sequence = createOpSequence(f);
this.errorhandler = new NBErrorHandler(
() -> activityDef.getParams().getOptionalString("errors").orElse("stop"),
this::getExceptionMetrics
);
}
public NBErrorHandler getErrorhandler() {
return errorhandler;
}
public OpSequence<OpDispenser<Cqld4Op>> getSequence() {
return sequence;
}
public int getMaxTries() {
return 0;
}
}