All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.nosqlbench.engine.api.activityimpl.uniform.BaseDriverAdapter Maven / Gradle / Ivy

Go to download

The DriverAdapter API for nosqlbench; Provides the interfaces needed to build drivers that can be loaded by nosqlbench core, using a minimal and direct API for op mapping.

There is a newer version: 5.17.0
Show newest version
/*
 * Copyright (c) 2022 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.uniform;

import io.nosqlbench.api.config.standard.*;
import io.nosqlbench.engine.api.activityimpl.uniform.fieldmappers.FieldDestructuringMapper;
import io.nosqlbench.engine.api.activityimpl.uniform.flowtypes.Op;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;

public abstract class BaseDriverAdapter implements DriverAdapter, NBConfigurable, NBReconfigurable {

    private DriverSpaceCache spaceCache;
    private NBConfiguration cfg;

    /**
     * BaseDriverAdapter will take any provided functions from {@link #getOpStmtRemappers()}
     * and {@link #getOpFieldRemappers()} and construct a preprocessor list. These are applied
     * successively to the op template fields so long as remapping occurs.
     * @return a list of preprocessors for op template fields
     */
    @Override
    public final Function, Map> getPreprocessor() {
        List,Map>> mappers = new ArrayList<>();
        List,Map>> stmtRemappers =
            getOpStmtRemappers().stream()
                .map(m -> new FieldDestructuringMapper("stmt",m))
                .collect(Collectors.toList());
        mappers.addAll(stmtRemappers);
        mappers.addAll(getOpFieldRemappers());

        if (mappers.size()==0) {
            return (i) -> i;
        }

        Function,Map> remapper = null;
        for (int i = 0; i < mappers.size(); i++) {
            if (i==0) {
                remapper=mappers.get(i);
            } else {
                remapper = remapper.andThen(mappers.get(i));
            }
        }

        return remapper;
    }

    /**
     * 

Provide a list of field remappers which operate exclusively on the 'stmt' field * in the op template. These are useful, for example, for taking the 'stmt' field * and parsing it into component fields which might otherwise be specified by the user. * This allows users to specify String-form op templates which are automatically * parsed and destructured into the canonical field-wise form for a given type of * operation.

* *
* *

Each function in this list is applied in order. If the function returns a value, * then the 'stmt' field is removed and the resulting map is added to the other * fields in the op template.

* *
* *

If a driver adapter is meant to support the {@code stmt} field, then this * must be provided. The use of the stmt field should be documented in * the driver adapter user docs with examples for any supported formats. A default * implementation does nothing, as it must be decided per-driver whether or not * the stmt field will be used directly or whether it is short-hand for a more * canonical form. * *
* *

If you want to automatically destructure stmt values into a map and inject * its entries into the op template fields, simply provide an implementation * like this:

     * {@code
     *     return List.of(stmt -> Optional.of(NBParams.one(stmt).getMap()));
     * }
     * 

* * @return A list of optionally applied remapping functions. */ public List>>> getOpStmtRemappers() { return List.of(); } /** *

Provide a list of field remappers which operate on arbitrary fields. * Each function is applied to the op template fields.

* @return */ @Override public List,Map>> getOpFieldRemappers() { return List.of(); } @Override public synchronized final DriverSpaceCache getSpaceCache() { if (spaceCache==null) { spaceCache=new DriverSpaceCache<>(getSpaceInitializer(getConfiguration())); } return spaceCache; } @Override public NBConfiguration getConfiguration() { return cfg; } @Override public void applyConfig(NBConfiguration cfg) { this.cfg = cfg; } @Override public void applyReconfig(NBConfiguration reconf) { this.cfg = getReconfigModel().apply(reconf.getMap()); } /** * In order to be provided with config information, it is required * that the driver adapter specify the valid configuration options, * their types, and so on. */ @Override public NBConfigModel getConfigModel() { return ConfigModel.of(BaseDriverAdapter.class) .add(Param.optional("alias")) .add(Param.defaultTo("strict",true,"strict op field mode, which requires that provided op fields are recognized and used")) .add(Param.optional(List.of("op", "stmt", "statement"), String.class, "op template in statement form")) .add(Param.optional("tags", String.class, "tags to be used to filter operations")) .add(Param.defaultTo("errors", "stop", "error handler configuration")) .add(Param.optional("threads").setRegex("\\d+|\\d+x|auto").setDescription("number of concurrent operations, controlled by threadpool")) .add(Param.optional("stride").setRegex("\\d+")) .add(Param.optional("striderate", String.class, "rate limit for strides per second")) .add(Param.optional("cycles").setRegex("\\d+[KMBGTPE]?|\\d+[KMBGTPE]?\\.\\.\\d+[KMBGTPE]?").setDescription("cycle interval to use")) .add(Param.optional(List.of("cyclerate", "targetrate", "rate"), String.class, "rate limit for cycles per second")) .add(Param.optional("phaserate", String.class, "rate limit for phases per second")) .add(Param.optional("seq", String.class, "sequencing algorithm")) .add(Param.optional("instrument", Boolean.class)) .add(Param.optional(List.of("workload", "yaml"), String.class, "location of workload yaml file")) .add(Param.optional("driver",String.class)) .asReadOnly(); } @Override public NBConfigModel getReconfigModel() { return ConfigModel.of(BaseDriverAdapter.class) .add(Param.optional("threads").setRegex("\\d+|\\d+x|auto").setDescription("number of concurrent operations, controlled by threadpool")) .add(Param.optional("striderate", String.class, "rate limit for strides per second")) .add(Param.optional(List.of("cyclerate", "targetrate", "rate"), String.class, "rate limit for cycles per second")) .asReadOnly(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy