refactor dryrun for type clarity

This commit is contained in:
Jonathan Shook 2024-10-23 13:40:09 -05:00
parent d5ec597152
commit 05c6b82bba
12 changed files with 339 additions and 34 deletions

View File

@ -0,0 +1,34 @@
/*
* Copyright (c) 2022-2024 nosqlbench
*
* 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.
*/
package io.nosqlbench.adapters.api.activityimpl.uniform.opwrappers;
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.CycleOp;
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.RunnableOp;
public class DryCycleOp<T> implements CycleOp<T> {
private final CycleOp<T> op;
public DryCycleOp(CycleOp<T> op) {
this.op = op;
}
@Override
public T apply(long value) {
return null;
}
}

View File

@ -0,0 +1,45 @@
/*
* Copyright (c) 2022-2024 nosqlbench
*
* 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.
*/
package io.nosqlbench.adapters.api.activityimpl.uniform.opwrappers;
import io.nosqlbench.adapters.api.activityimpl.BaseOpDispenser;
import io.nosqlbench.adapters.api.activityimpl.OpDispenser;
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverAdapter;
import io.nosqlbench.adapters.api.activityimpl.uniform.Space;
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.CycleOp;
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.RunnableOp;
import io.nosqlbench.adapters.api.templating.ParsedOp;
public class DryCycleOpDispenserWrapper<S extends Space, RESULT> extends BaseOpDispenser<CycleOp<RESULT>, S> {
private final OpDispenser<CycleOp<RESULT>> realDispenser;
public DryCycleOpDispenserWrapper(
DriverAdapter<CycleOp<RESULT>, S> adapter,
ParsedOp pop,
OpDispenser<CycleOp<RESULT>> realDispenser
) {
super(adapter, pop);
this.realDispenser = realDispenser;
}
@Override
public CycleOp<RESULT> getOp(long cycle) {
CycleOp<RESULT> op = realDispenser.getOp(cycle);
return new DryCycleOp<>(op);
}
}

View File

@ -16,16 +16,16 @@
package io.nosqlbench.adapters.api.activityimpl.uniform.opwrappers;
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.Op;
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.RunnableOp;
public class DryRunOp implements RunnableOp {
public class DryRunableOp implements RunnableOp {
private final Op op;
private final RunnableOp op;
public DryRunOp(Op op) {
public DryRunableOp(RunnableOp op) {
this.op = op;
}
@Override
public void run() {
}

View File

@ -19,20 +19,26 @@ package io.nosqlbench.adapters.api.activityimpl.uniform.opwrappers;
import io.nosqlbench.adapters.api.activityimpl.BaseOpDispenser;
import io.nosqlbench.adapters.api.activityimpl.OpDispenser;
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverAdapter;
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.Op;
import io.nosqlbench.adapters.api.activityimpl.uniform.Space;
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.RunnableOp;
import io.nosqlbench.adapters.api.templating.ParsedOp;
public class DryRunOpDispenserWrapper extends BaseOpDispenser<Op, Object> {
public class DryRunnableOpDispenserWrapper<S extends Space> extends BaseOpDispenser<RunnableOp, S> {
private final OpDispenser<? extends Op> realDispenser;
private final OpDispenser<RunnableOp> realDispenser;
public DryRunOpDispenserWrapper(DriverAdapter<Op,Object> adapter, ParsedOp pop, OpDispenser<? extends Op> realDispenser) {
public DryRunnableOpDispenserWrapper(
DriverAdapter<RunnableOp, S> adapter,
ParsedOp pop,
OpDispenser<RunnableOp> realDispenser
) {
super(adapter, pop);
this.realDispenser = realDispenser;
}
@Override
public DryRunOp getOp(long cycle) {
Op op = realDispenser.getOp(cycle);
return new DryRunOp(op);
public DryRunableOp getOp(long cycle) {
RunnableOp op = realDispenser.getOp(cycle);
return new DryRunableOp(op);
}
}

View File

@ -0,0 +1,34 @@
/*
* Copyright (c) 2022-2024 nosqlbench
*
* 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.
*/
package io.nosqlbench.adapters.api.activityimpl.uniform.opwrappers;
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.CycleOp;
public class EmitterCycleOp<T> implements CycleOp<T> {
private final CycleOp<T> cycleOp;
public EmitterCycleOp(CycleOp<T> cycleOp) {
this.cycleOp = cycleOp;
}
@Override
public T apply(long value) {
T result = cycleOp.apply(value);
System.out.println("result from cycle " + value + ":\n"+result);
return result;
}
}

View File

@ -0,0 +1,45 @@
/*
* Copyright (c) 2022-2024 nosqlbench
*
* 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.
*/
package io.nosqlbench.adapters.api.activityimpl.uniform.opwrappers;
import io.nosqlbench.adapters.api.activityimpl.BaseOpDispenser;
import io.nosqlbench.adapters.api.activityimpl.OpDispenser;
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverAdapter;
import io.nosqlbench.adapters.api.activityimpl.uniform.Space;
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.CycleOp;
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.RunnableOp;
import io.nosqlbench.adapters.api.templating.ParsedOp;
public class EmitterCycleOpDispenserWrapper<O,S extends Space,R> extends BaseOpDispenser<CycleOp<R>, S> {
private final OpDispenser<CycleOp<R>> realDispenser;
public EmitterCycleOpDispenserWrapper(
DriverAdapter<? extends CycleOp<R>, S> adapter,
ParsedOp pop,
OpDispenser<CycleOp<R>> realDispenser
) {
super(adapter, pop);
this.realDispenser = realDispenser;
}
@Override
public EmitterCycleOp<R> getOp(long cycle) {
CycleOp<R> cycleOp = realDispenser.getOp(cycle);
return new EmitterCycleOp(cycleOp);
}
}

View File

@ -18,16 +18,16 @@ package io.nosqlbench.adapters.api.activityimpl.uniform.opwrappers;
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.CycleOp;
public class EmitterOp implements CycleOp<Object> {
public class EmitterOp<T> implements CycleOp<T> {
private final CycleOp<?> cycleOp;
public EmitterOp(CycleOp<?> cycleOp) {
private final CycleOp<T> cycleOp;
public EmitterOp(CycleOp<T> cycleOp) {
this.cycleOp = cycleOp;
}
@Override
public Object apply(long value) {
Object result = cycleOp.apply(value);
public T apply(long value) {
T result = cycleOp.apply(value);
System.out.println("result from cycle " + value + ":\n"+result);
return result;
}

View File

@ -19,15 +19,16 @@ package io.nosqlbench.adapters.api.activityimpl.uniform.opwrappers;
import io.nosqlbench.adapters.api.activityimpl.BaseOpDispenser;
import io.nosqlbench.adapters.api.activityimpl.OpDispenser;
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverAdapter;
import io.nosqlbench.adapters.api.activityimpl.uniform.Space;
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.CycleOp;
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.Op;
import io.nosqlbench.adapters.api.templating.ParsedOp;
public class EmitterOpDispenserWrapper extends BaseOpDispenser<Op, Object> {
public class EmitterOpDispenserWrapper extends BaseOpDispenser<Op, Space> {
private final OpDispenser<? extends CycleOp<?>> realDispenser;
public EmitterOpDispenserWrapper(DriverAdapter<Op,Object> adapter, ParsedOp pop, OpDispenser<? extends CycleOp<?>> realDispenser) {
public EmitterOpDispenserWrapper(DriverAdapter<Op,Space> adapter, ParsedOp pop, OpDispenser<? extends CycleOp<?>> realDispenser) {
super(adapter, pop);
this.realDispenser = realDispenser;
}

View File

@ -0,0 +1,32 @@
/*
* Copyright (c) 2022-2024 nosqlbench
*
* 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.
*/
package io.nosqlbench.adapters.api.activityimpl.uniform.opwrappers;
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.RunnableOp;
public class EmitterRunnableOp implements RunnableOp {
private final RunnableOp runnableOp;
public EmitterRunnableOp(RunnableOp runnableOp) {
this.runnableOp = runnableOp;
}
@Override
public void run() {
runnableOp.run();
}
}

View File

@ -0,0 +1,45 @@
/*
* Copyright (c) 2022-2024 nosqlbench
*
* 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.
*/
package io.nosqlbench.adapters.api.activityimpl.uniform.opwrappers;
import io.nosqlbench.adapters.api.activityimpl.BaseOpDispenser;
import io.nosqlbench.adapters.api.activityimpl.OpDispenser;
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverAdapter;
import io.nosqlbench.adapters.api.activityimpl.uniform.Space;
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.Op;
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.RunnableOp;
import io.nosqlbench.adapters.api.templating.ParsedOp;
public class EmitterRunnableOpDispenserWrapper<O,S> extends BaseOpDispenser<RunnableOp, Space> {
private final OpDispenser<RunnableOp> realDispenser;
public EmitterRunnableOpDispenserWrapper(
DriverAdapter<? extends RunnableOp, ? extends Space> adapter,
ParsedOp pop,
OpDispenser<RunnableOp> realDispenser
) {
super(adapter, pop);
this.realDispenser = realDispenser;
}
@Override
public EmitterRunnableOp getOp(long cycle) {
RunnableOp cycleOp = realDispenser.getOp(cycle);
return new EmitterRunnableOp(cycleOp);
}
}

View File

@ -0,0 +1,73 @@
package io.nosqlbench.engine.api.activityimpl;
import io.nosqlbench.adapters.api.activityimpl.OpDispenser;
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverAdapter;
import io.nosqlbench.adapters.api.activityimpl.uniform.Space;
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.CycleOp;
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.Op;
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.RunnableOp;
import io.nosqlbench.adapters.api.activityimpl.uniform.opwrappers.DryCycleOpDispenserWrapper;
import io.nosqlbench.adapters.api.activityimpl.uniform.opwrappers.DryRunnableOpDispenserWrapper;
import io.nosqlbench.adapters.api.activityimpl.uniform.opwrappers.EmitterCycleOpDispenserWrapper;
import io.nosqlbench.adapters.api.activityimpl.uniform.opwrappers.EmitterRunnableOpDispenserWrapper;
import io.nosqlbench.adapters.api.templating.ParsedOp;
import io.nosqlbench.nb.api.errors.OpConfigError;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class OpWrappers {
public final static Logger logger = LogManager.getLogger(OpWrappers.class);
public static <OP extends Op, SPACE extends Space> OpDispenser<OP> wrapOptionally(
DriverAdapter<OP, SPACE> adapter,
OpDispenser<OP> dispenser,
ParsedOp pop,
String dryrunSpec
) {
if (dryrunSpec.isEmpty() || "none".equals(dryrunSpec)) {
return dispenser;
}
if ("op".equalsIgnoreCase(dryrunSpec)) {
Op exampleOp = dispenser.getOp(0L);
if (exampleOp instanceof RunnableOp runnableOp) {
dispenser = new DryRunnableOpDispenserWrapper(adapter, pop, dispenser);
} else if (exampleOp instanceof CycleOp<?> cycleOp) {
dispenser = new DryCycleOpDispenserWrapper(adapter, pop, dispenser);
} else {
throw new OpConfigError("Unable to wrap op named '" + pop.getDefinedNames() + "' for dry run, since" +
"only RunnableOp and CycleOp<Result> types are supported");
}
logger.warn(
"initialized {} for dry run only. " +
"This op will be synthesized for each cycle, but will not be executed.",
pop.getName()
);
} else if ("emit".equalsIgnoreCase(dryrunSpec)) {
Op exampleOp = dispenser.getOp(0L);
if (exampleOp instanceof RunnableOp runnableOp) {
dispenser = new EmitterRunnableOpDispenserWrapper(adapter, pop, dispenser);
} else if (exampleOp instanceof CycleOp<?> cycleOp) {
dispenser = new EmitterCycleOpDispenserWrapper(adapter, pop, dispenser);
} else {
throw new OpConfigError("Unable to make op named '" + pop.getName() + "' emit a value, " +
"since only RunnableOp and CycleOp<Result> types are supported");
}
dispenser = new EmitterRunnableOpDispenserWrapper(
(DriverAdapter<Op, Space>) adapter,
pop,
(OpDispenser<? extends Op>) dispenser
);
logger.warn(
"initialized {} for to emit the result type to stdout. ",
pop.getName()
);
}
return dispenser;
}
}

View File

@ -27,8 +27,10 @@ import io.nosqlbench.adapters.api.activityimpl.uniform.Space;
import io.nosqlbench.adapters.api.activityimpl.uniform.decorators.SyntheticOpTemplateProvider;
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.CycleOp;
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.Op;
import io.nosqlbench.adapters.api.activityimpl.uniform.opwrappers.DryRunOpDispenserWrapper;
import io.nosqlbench.adapters.api.activityimpl.uniform.opwrappers.EmitterOpDispenserWrapper;
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.RunnableOp;
import io.nosqlbench.adapters.api.activityimpl.uniform.opwrappers.DryRunnableOpDispenserWrapper;
import io.nosqlbench.adapters.api.activityimpl.uniform.opwrappers.EmitterCycleOpDispenserWrapper;
import io.nosqlbench.adapters.api.activityimpl.uniform.opwrappers.EmitterRunnableOpDispenserWrapper;
import io.nosqlbench.adapters.api.templating.ParsedOp;
import io.nosqlbench.engine.api.activityapi.core.*;
import io.nosqlbench.engine.api.activityapi.core.progress.ActivityMetricProgressMeter;
@ -415,7 +417,6 @@ public class SimpleActivity extends NBStatusComponent implements Activity, Invok
.orElse(SequencerType.bucket);
SequencePlanner<OpDispenser<? extends O>> planner = new SequencePlanner<>(sequencerType);
int dryrunCount = 0;
for (int i = 0; i < pops.size(); i++) {
long ratio = ratios.get(i);
ParsedOp pop = pops.get(i);
@ -431,16 +432,7 @@ public class SimpleActivity extends NBStatusComponent implements Activity, Invok
LongFunction<Space> spaceFunc = adapter.getSpaceFunc(pop);
OpDispenser<Op> dispenser = opMapper.apply(pop, spaceFunc);
String dryrunSpec = pop.takeStaticConfigOr("dryrun", "none");
if ("op".equalsIgnoreCase(dryrunSpec)) {
dispenser = new DryRunOpDispenserWrapper((DriverAdapter<Op, Object>) adapter, pop, dispenser);
dryrunCount++;
} else if ("emit".equalsIgnoreCase(dryrunSpec)) {
dispenser = new EmitterOpDispenserWrapper(
(DriverAdapter<Op, Object>) adapter,
pop,
(OpDispenser<? extends CycleOp<?>>) dispenser
);
}
dispenser = OpWrappers.wrapOptionally(adapter, dispenser, pop, dryrunSpec);
// if (strict) {
// optemplate.assertConsumed();
@ -450,9 +442,7 @@ public class SimpleActivity extends NBStatusComponent implements Activity, Invok
throw new OpConfigError("Error while mapping op from template named '" + pop.getName() + "': " + e.getMessage(), e);
}
}
if (0 < dryrunCount) {
logger.warn("initialized {} op templates for dry run only. These ops will be synthesized for each cycle, but will not be executed.", dryrunCount);
}
return planner.resolve();