From 3ab18635bb9b32451a906bb377794e4399d263a4 Mon Sep 17 00:00:00 2001 From: Jonathan Shook Date: Thu, 2 Jan 2025 12:15:06 -0600 Subject: [PATCH] removing vestigial code --- .../api/activityapi/core/AsyncAction.java | 3 +- .../api/activityapi/core/BaseAsyncAction.java | 74 ------- .../core/ops/fluent/OpTrackerImpl.java | 187 ------------------ .../api/activityimpl/ActivityDispenser.java | 24 --- .../scenario/container/ActivityBindings.java | 137 ------------- .../core/ops/fluent/OpTrackerImplTest.java | 38 ---- 6 files changed, 1 insertion(+), 462 deletions(-) delete mode 100644 nb-engine/nb-engine-core/src/main/java/io/nosqlbench/engine/api/activityapi/core/BaseAsyncAction.java delete mode 100644 nb-engine/nb-engine-core/src/main/java/io/nosqlbench/engine/api/activityapi/core/ops/fluent/OpTrackerImpl.java delete mode 100644 nb-engine/nb-engine-core/src/main/java/io/nosqlbench/engine/api/activityimpl/ActivityDispenser.java delete mode 100644 nb-engine/nb-engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/container/ActivityBindings.java delete mode 100644 nb-engine/nb-engine-core/src/test/java/io/nosqlbench/engine/api/activityapi/core/ops/fluent/OpTrackerImplTest.java diff --git a/nb-engine/nb-engine-core/src/main/java/io/nosqlbench/engine/api/activityapi/core/AsyncAction.java b/nb-engine/nb-engine-core/src/main/java/io/nosqlbench/engine/api/activityapi/core/AsyncAction.java index 76ac9e9a1..984984fef 100644 --- a/nb-engine/nb-engine-core/src/main/java/io/nosqlbench/engine/api/activityapi/core/AsyncAction.java +++ b/nb-engine/nb-engine-core/src/main/java/io/nosqlbench/engine/api/activityapi/core/AsyncAction.java @@ -49,8 +49,7 @@ public interface AsyncAction extends Action { * concurrency limits for the new cycle. * * Each action implementation is responsible for tracking and controlling - * its own limits of concurrency. The {@link BaseAsyncAction} base class is a - * convenient starting point for such implementations. + * its own limits of concurrency. * * If the action is known to have additional open slots for an operations to * be started (according to the configured concurrency limits), diff --git a/nb-engine/nb-engine-core/src/main/java/io/nosqlbench/engine/api/activityapi/core/BaseAsyncAction.java b/nb-engine/nb-engine-core/src/main/java/io/nosqlbench/engine/api/activityapi/core/BaseAsyncAction.java deleted file mode 100644 index 7d0726ee7..000000000 --- a/nb-engine/nb-engine-core/src/main/java/io/nosqlbench/engine/api/activityapi/core/BaseAsyncAction.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2022-2023 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.engine.api.activityapi.core; - -import io.nosqlbench.engine.api.activityapi.core.ops.fluent.opfacets.TrackedOp; -import io.nosqlbench.engine.api.activityimpl.uniform.Activity; -import io.nosqlbench.nb.api.engine.activityimpl.ActivityDef; -import io.nosqlbench.nb.api.engine.activityimpl.ParameterMap; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; - -/** - * - * @param An type of state holder for an operation, holding everything unique to that cycle and operation - * @param An type of of an Activity, a state holder for a runtime instance of an StandardActivity - */ -public abstract class BaseAsyncAction implements AsyncAction, - Stoppable, ActivityDefObserver { - private final static Logger logger = LogManager.getLogger("BaseAsyncAction"); - - protected final A activity; - - protected int slot; - protected boolean running = true; - - public BaseAsyncAction(A activity, int slot) { - this.activity = activity; - this.slot = slot; - - onActivityDefUpdate(activity.getActivityDef()); - } - - @Override - public void onActivityDefUpdate(ActivityDef activityDef) { - ParameterMap params = activityDef.getParams(); - params.getOptionalInteger("async").orElseThrow( - () -> new RuntimeException("the async parameter is required to activate async actions")); - } - - public boolean enqueue(TrackedOp opc) { - startOpCycle(opc); - return (running); - } - - /** - * Implementations that extend this base class can call this method in order to put - * an operation in flight. Implementations should call either {@link TrackedOp#skip(int)} - * or {@link TrackedOp#start()}}. - * - * @param opc A tracked operation with state of parameterized type D - */ - public abstract void startOpCycle(TrackedOp opc); - - @Override - public void requestStop() { - logger.info(() -> this + " requested to stop."); - this.running = false; - } - -} diff --git a/nb-engine/nb-engine-core/src/main/java/io/nosqlbench/engine/api/activityapi/core/ops/fluent/OpTrackerImpl.java b/nb-engine/nb-engine-core/src/main/java/io/nosqlbench/engine/api/activityapi/core/ops/fluent/OpTrackerImpl.java deleted file mode 100644 index c99a33d67..000000000 --- a/nb-engine/nb-engine-core/src/main/java/io/nosqlbench/engine/api/activityapi/core/ops/fluent/OpTrackerImpl.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright (c) 2022-2023 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.engine.api.activityapi.core.ops.fluent; - -import com.codahale.metrics.Counter; -import com.codahale.metrics.Timer; -import io.nosqlbench.engine.api.activityimpl.uniform.Activity; -import io.nosqlbench.nb.api.engine.activityimpl.ActivityDef; -import io.nosqlbench.engine.api.activityapi.core.ActivityDefObserver; -import io.nosqlbench.engine.api.activityapi.core.ops.fluent.opfacets.*; - -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.LongFunction; - -/** - This tracker keeps track of the state of operations associated with it. - @param - The payload data type of the associated Op, based on OpImpl */ -public class OpTrackerImpl implements OpTracker, ActivityDefObserver { - private final AtomicInteger pendingOps = new AtomicInteger(0); - private final String label; - private final long slot; - private final Counter pendingOpsCounter; - private final Timer cycleServiceTimer; - private final Timer cycleResponseTimer; - - private int maxPendingOps = 1; - private LongFunction cycleOpFunction; - - - public OpTrackerImpl(Activity activity, long slot) { - this.slot = slot; - this.label = "tracker-" + slot + "_" + activity.getAlias(); - - this.pendingOpsCounter = activity.metrics.pendingOpsCounter; - this.cycleServiceTimer = activity.metrics.cycleServiceTimer; - this.cycleResponseTimer = activity.metrics.cycleResponseTimer; - } - - // for testing - public OpTrackerImpl( - String name, int slot, Timer cycleServiceTimer, Timer cycleResponseTimer, - Counter pendingOpsCounter - ) { - this.label = name; - this.slot = slot; - this.cycleResponseTimer = cycleResponseTimer; - this.cycleServiceTimer = cycleServiceTimer; - this.pendingOpsCounter = pendingOpsCounter; - } - - @Override - public void onOpStarted(StartedOp op) { - pendingOps.incrementAndGet(); - pendingOpsCounter.inc(); - } - - @Override - public void onOpSuccess(SucceededOp op) { - pendingOpsCounter.dec(); - int pending = this.pendingOps.decrementAndGet(); - - cycleServiceTimer.update(op.getServiceTimeNanos(), TimeUnit.NANOSECONDS); - if (cycleResponseTimer != null) { - cycleResponseTimer.update(op.getResponseTimeNanos(), TimeUnit.NANOSECONDS); - } - - if (pending < maxPendingOps) { - synchronized (this) { - notify(); - } - } - } - - @Override - public void onOpSkipped(SkippedOp op) { - pendingOpsCounter.dec(); - int pending = this.pendingOps.decrementAndGet(); - - if (pending < maxPendingOps) { - synchronized (this) { - notify(); - } - } - - } - - - @Override - public void onOpFailure(FailedOp op) { - pendingOpsCounter.dec(); - int pending = this.pendingOps.decrementAndGet(); - - cycleServiceTimer.update(op.getServiceTimeNanos(), TimeUnit.NANOSECONDS); - if (cycleResponseTimer != null) { - cycleResponseTimer.update(op.getResponseTimeNanos(), TimeUnit.NANOSECONDS); - } - - if (pending < maxPendingOps) { - synchronized (this) { - notify(); - } - } - } - - @Override - public void setMaxPendingOps(int maxPendingOps) { - this.maxPendingOps = maxPendingOps; - synchronized (this) { - notifyAll(); - } - } - - @Override - public boolean isFull() { - return this.pendingOps.intValue() >= maxPendingOps; - } - - @Override - public int getPendingOps() { - return pendingOps.intValue(); - } - - @Override - public void setCycleOpFunction(LongFunction newOpFunction) { - this.cycleOpFunction = newOpFunction; - } - - @Override - public TrackedOp newOp(long cycle, OpEvents strideTracker) { - D opstate = cycleOpFunction.apply(cycle); - OpImpl op = new EventedOpImpl<>(this, strideTracker); - op.setCycle(cycle); - op.setData(opstate); - return op; - } - - public int getMaxPendingOps() { - return maxPendingOps; - } - - @Override - public synchronized boolean awaitCompletion(long timeout) { - long endAt = System.currentTimeMillis() + timeout; - while (getPendingOps() > 0 && System.currentTimeMillis() < endAt) { - try { - long waitfor = Math.max(0, endAt - System.currentTimeMillis()); - wait(waitfor); - } catch (InterruptedException ignored) { - } - } - return getPendingOps() == 0; - } - - @Override - public String toString() { - return "OpTracker-" + label + ":" + this.slot + " " + this.pendingOps.get() + "/" + maxPendingOps + " ops "; - } - - @Override - public void onActivityDefUpdate(ActivityDef activityDef) { - this.maxPendingOps = getMaxPendingOpsForThisThread(activityDef); - } - - private int getMaxPendingOpsForThisThread(ActivityDef def) { - int maxTotalOpsInFlight = def.getParams().getOptionalInteger("async").orElse(1); - int threads = def.getThreads(); - return (maxTotalOpsInFlight / threads) + (slot < (maxTotalOpsInFlight % threads) ? 1 : 0); - } - - -} diff --git a/nb-engine/nb-engine-core/src/main/java/io/nosqlbench/engine/api/activityimpl/ActivityDispenser.java b/nb-engine/nb-engine-core/src/main/java/io/nosqlbench/engine/api/activityimpl/ActivityDispenser.java deleted file mode 100644 index 6efcc35d4..000000000 --- a/nb-engine/nb-engine-core/src/main/java/io/nosqlbench/engine/api/activityimpl/ActivityDispenser.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2022-2023 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.engine.api.activityimpl; - -import io.nosqlbench.engine.api.activityimpl.uniform.Activity; -import io.nosqlbench.nb.api.engine.activityimpl.ActivityDef; - -public interface ActivityDispenser { - Activity getActivity(ActivityDef activityDef); -} diff --git a/nb-engine/nb-engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/container/ActivityBindings.java b/nb-engine/nb-engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/container/ActivityBindings.java deleted file mode 100644 index c0d447076..000000000 --- a/nb-engine/nb-engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/container/ActivityBindings.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright (c) 2022-2023 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.engine.core.lifecycle.scenario.container; - -import io.nosqlbench.nb.api.engine.activityimpl.ActivityDef; -import org.graalvm.polyglot.Value; -import org.graalvm.polyglot.proxy.ProxyObject; - -import javax.script.Bindings; -import java.util.*; -import java.util.stream.Collectors; - -/** - * Provide a bindings wrapper around a ScenarioController, - */ -public class ActivityBindings implements Bindings, ProxyObject { - - private final ContainerActivitiesController scenario; - private final Map elementMap = new HashMap(); - - public ActivityBindings(ContainerActivitiesController containerActivitiesController) { - this.scenario = containerActivitiesController; - } - - @Override - public Object put(String name, Object value) { - throw new RuntimeException("ScenarioBindings do not allow put(...)"); - } - - @Override - public void putAll(Map toMerge) { - throw new RuntimeException("ScenarioBindings do not allow putAll(...)"); - } - - @Override - public void clear() { - throw new RuntimeException("ScenarioBindings do not allow clear(...)"); - } - - @Override - public Set keySet() { - return scenario.getAliases(); - } - - @Override - public Collection values() { - return wrap(scenario.getActivityDefs()); - } - - private Collection wrap(List activityDefs) { - return activityDefs - .stream() - .map(s -> (Bindings) s) - .collect(Collectors.toList()); - } - - @Override - public Set> entrySet() { - Set> newset = new HashSet<>(); - for (ActivityDef activityDef : scenario.getActivityDefs()) { - newset.add(new AbstractMap.SimpleImmutableEntry(activityDef.getAlias(),activityDef)); - } - return newset; - } - - @Override - public int size() { - return scenario.getActivityDefs().size(); - } - - @Override - public boolean isEmpty() { - return scenario.getActivityDefs().isEmpty(); - } - - @Override - public boolean containsKey(Object key) { - return scenario.getAliases().contains(String.valueOf(key)); - } - - @Override - public boolean containsValue(Object value) { - throw new RuntimeException("Should this be used?"); - } - - @Override - public Bindings get(Object key) { - Bindings activityParams = scenario.getActivityDef(String.valueOf(key)).getParams(); - return activityParams; - } - - @Override - public Object remove(Object key) { - throw new RuntimeException("this is not the advised way to forceStopMotors an activity"); -// scenario.forceStopMotors(String.valueOf(key)); - } - - @Override - public Object getMember(String key) { - Bindings bindings = get(key); - return bindings; - } - - @Override - public Object getMemberKeys() { - ArrayList keys = new ArrayList<>(keySet()); - return keys; - } - - @Override - public boolean hasMember(String key) { - boolean b = containsKey(key); - return b; - } - - @Override - public void putMember(String key, Value value) { - if (value.isHostObject()) { - put(key,value.asHostObject()); - } else { - throw new RuntimeException("Unable to put a non-host object into the activities bindings layer:" + value); - } - } -} diff --git a/nb-engine/nb-engine-core/src/test/java/io/nosqlbench/engine/api/activityapi/core/ops/fluent/OpTrackerImplTest.java b/nb-engine/nb-engine-core/src/test/java/io/nosqlbench/engine/api/activityapi/core/ops/fluent/OpTrackerImplTest.java deleted file mode 100644 index 62af54520..000000000 --- a/nb-engine/nb-engine-core/src/test/java/io/nosqlbench/engine/api/activityapi/core/ops/fluent/OpTrackerImplTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2022-2023 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.engine.api.activityapi.core.ops.fluent; - -import com.codahale.metrics.Counter; -import com.codahale.metrics.Timer; -import io.nosqlbench.engine.api.activityapi.core.ops.fluent.opfacets.SucceededOp; -import io.nosqlbench.engine.api.activityapi.core.ops.fluent.opfacets.EventedOpImpl; -import io.nosqlbench.engine.api.activityapi.core.ops.fluent.opfacets.StartedOp; -import io.nosqlbench.engine.api.activityapi.core.ops.fluent.opfacets.TrackedOp; -import org.junit.jupiter.api.Test; - -public class OpTrackerImplTest { - - @Test - public void testLifeCycle() { - OpTrackerImpl tracker = new OpTrackerImpl("test", 0, new Timer(), new Timer(), new Counter()); - TrackedOp tracked = new EventedOpImpl<>(tracker); - StartedOp started = tracked.start(); - tracker.onOpStarted(started); - SucceededOp stop = started.succeed(23); - } - -}