mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
partial mongodb updates
This commit is contained in:
@@ -1,2 +1,56 @@
|
|||||||
package io.nosqlbench.adapter.mongodb.core;public class MongoDBOpTypes {
|
/*
|
||||||
|
* 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.adapter.mongodb.core;
|
||||||
|
|
||||||
|
public enum MongoDBOpTypes {
|
||||||
|
/**
|
||||||
|
* Use direct command structure....
|
||||||
|
* @see <a href="https://docs.mongodb.com/manual/reference/method/db.runCommand/#command-response">command-response</a>
|
||||||
|
*/
|
||||||
|
command,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see <a href="https://www.mongodb.com/docs/manual/reference/command/update/#mongodb-dbcommand-dbcmd.update">update</a>
|
||||||
|
*/
|
||||||
|
update,
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * @see <a href="https://www.mongodb.com/docs/manual/reference/command/insert/">insert</a>
|
||||||
|
// */
|
||||||
|
// insert,
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * @see <a href="https://www.mongodb.com/docs/manual/reference/command/delete/">delete</a>
|
||||||
|
// */
|
||||||
|
// delete,
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * @see <a href="https://www.mongodb.com/docs/manual/reference/command/find/">find</a>
|
||||||
|
// */
|
||||||
|
// find,
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * @see <a href="https://www.mongodb.com/docs/manual/reference/command/findAndModify/">findAndModify</a>
|
||||||
|
// */
|
||||||
|
// findAndModify,
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * @see <a href="https://www.mongodb.com/docs/manual/reference/command/getMore/">getMore</a>
|
||||||
|
// */
|
||||||
|
// getMore
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import org.bson.conversions.Bson;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.LongFunction;
|
import java.util.function.LongFunction;
|
||||||
|
|
||||||
public class MongoOpDispenser extends BaseOpDispenser<Op> {
|
public class MongoOpDispenser extends BaseOpDispenser<Op,MongoSpace> {
|
||||||
private final LongFunction<MongoOp> opFunc;
|
private final LongFunction<MongoOp> opFunc;
|
||||||
private final LongFunction<MongoOp> mongoOpF;
|
private final LongFunction<MongoOp> mongoOpF;
|
||||||
|
|
||||||
|
|||||||
@@ -16,15 +16,18 @@
|
|||||||
|
|
||||||
package io.nosqlbench.adapter.mongodb.core;
|
package io.nosqlbench.adapter.mongodb.core;
|
||||||
|
|
||||||
|
import io.nosqlbench.api.config.standard.NBConfigModel;
|
||||||
|
import io.nosqlbench.api.config.standard.NBConfiguration;
|
||||||
import io.nosqlbench.engine.api.activityimpl.OpMapper;
|
import io.nosqlbench.engine.api.activityimpl.OpMapper;
|
||||||
import io.nosqlbench.engine.api.activityimpl.uniform.BaseDriverAdapter;
|
import io.nosqlbench.engine.api.activityimpl.uniform.BaseDriverAdapter;
|
||||||
import io.nosqlbench.engine.api.activityimpl.uniform.DriverAdapter;
|
import io.nosqlbench.engine.api.activityimpl.uniform.DriverAdapter;
|
||||||
|
import io.nosqlbench.engine.api.activityimpl.uniform.DriverSpaceCache;
|
||||||
import io.nosqlbench.engine.api.activityimpl.uniform.flowtypes.Op;
|
import io.nosqlbench.engine.api.activityimpl.uniform.flowtypes.Op;
|
||||||
|
import io.nosqlbench.engine.api.templating.ParsedOp;
|
||||||
import io.nosqlbench.nb.annotations.Service;
|
import io.nosqlbench.nb.annotations.Service;
|
||||||
import io.nosqlbench.api.config.standard.NBConfigModel;
|
|
||||||
import io.nosqlbench.api.config.standard.NBConfiguration;
|
|
||||||
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.LongFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Special thanks to Justin Chu who authored the original NoSQLBench MongoDB ActivityType.
|
* Special thanks to Justin Chu who authored the original NoSQLBench MongoDB ActivityType.
|
||||||
@@ -34,7 +37,7 @@ public class MongodbDriverAdapter extends BaseDriverAdapter<Op, MongoSpace> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OpMapper<Op> getOpMapper() {
|
public OpMapper<Op> getOpMapper() {
|
||||||
return new MongodbOpMapper(this, getSpaceCache());
|
return new MongodbOpMapper(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -46,4 +49,5 @@ public class MongodbDriverAdapter extends BaseDriverAdapter<Op, MongoSpace> {
|
|||||||
public NBConfigModel getConfigModel() {
|
public NBConfigModel getConfigModel() {
|
||||||
return super.getConfigModel().add(MongoSpace.getConfigModel());
|
return super.getConfigModel().add(MongoSpace.getConfigModel());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,29 +16,50 @@
|
|||||||
|
|
||||||
package io.nosqlbench.adapter.mongodb.core;
|
package io.nosqlbench.adapter.mongodb.core;
|
||||||
|
|
||||||
|
import io.nosqlbench.adapter.mongodb.dispensers.MongoDbUpdateOpDispenser;
|
||||||
import io.nosqlbench.engine.api.activityimpl.OpDispenser;
|
import io.nosqlbench.engine.api.activityimpl.OpDispenser;
|
||||||
import io.nosqlbench.engine.api.activityimpl.OpMapper;
|
import io.nosqlbench.engine.api.activityimpl.OpMapper;
|
||||||
import io.nosqlbench.engine.api.activityimpl.uniform.DriverAdapter;
|
|
||||||
import io.nosqlbench.engine.api.activityimpl.uniform.DriverSpaceCache;
|
|
||||||
import io.nosqlbench.engine.api.activityimpl.uniform.flowtypes.Op;
|
import io.nosqlbench.engine.api.activityimpl.uniform.flowtypes.Op;
|
||||||
import io.nosqlbench.engine.api.templating.ParsedOp;
|
import io.nosqlbench.engine.api.templating.ParsedOp;
|
||||||
|
import io.nosqlbench.engine.api.templating.TypeAndTarget;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.function.LongFunction;
|
import java.util.function.LongFunction;
|
||||||
|
|
||||||
public class MongodbOpMapper implements OpMapper<Op> {
|
public class MongodbOpMapper implements OpMapper<Op> {
|
||||||
|
private final static Logger logger = LogManager.getLogger(MongodbOpMapper.class);
|
||||||
|
|
||||||
private final DriverSpaceCache<? extends MongoSpace> ctxcache;
|
private final MongodbDriverAdapter adapter;
|
||||||
private final DriverAdapter adapter;
|
|
||||||
|
|
||||||
public MongodbOpMapper(DriverAdapter adapter, DriverSpaceCache<? extends MongoSpace> ctxcache) {
|
public MongodbOpMapper(MongodbDriverAdapter adapter) {
|
||||||
this.ctxcache = ctxcache;
|
|
||||||
this.adapter = adapter;
|
this.adapter = adapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OpDispenser<? extends Op> apply(ParsedOp op) {
|
public OpDispenser<? extends Op> apply(ParsedOp op) {
|
||||||
LongFunction<String> ctxNamer = op.getAsFunctionOr("space","default");
|
LongFunction<String> ctxNamer = op.getAsFunctionOr("space", "default");
|
||||||
LongFunction<MongoSpace> ctxFunc = l -> ctxcache.get(ctxNamer.apply(l));
|
LongFunction<MongoSpace> spaceF = l -> adapter.getSpaceCache().get(ctxNamer.apply(l));
|
||||||
return new MongoOpDispenser(adapter,ctxFunc, op);
|
|
||||||
|
TypeAndTarget<MongoDBOpTypes, String> opTypeAndTarget =
|
||||||
|
op.getOptionalTypeAndTargetEnum(MongoDBOpTypes.class, String.class)
|
||||||
|
.orElseThrow(() -> new RuntimeException("unable to determine MongoDB op type from '" + op.toString()));
|
||||||
|
Optional<LongFunction<String>> oDatabaseF = op.getAsOptionalFunction("database");
|
||||||
|
if (oDatabaseF.isEmpty()) {
|
||||||
|
logger.warn(() -> "");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return switch (opTypeAndTarget.enumId) {
|
||||||
|
case command -> null;
|
||||||
|
case update -> new MongoDbUpdateOpDispenser(adapter, op, opTypeAndTarget.targetFunction);
|
||||||
|
// case insert -> new MongoDbInsertOpDispenser(adapter, op, opTypeAndTarget.targetFunction);
|
||||||
|
// case delete -> new MongoDbDeleteOpDispenser(adapter, op, opTypeAndTarget.targetFunction);
|
||||||
|
// case find -> new mongoDbFindOpDispenser(adapter, op, opTypeAndTarget.targetFunction);
|
||||||
|
// case findAndModify -> new MongoDbFindAndModifyOpDispenser(adapter, op, opTypeAndTarget.targetFunction);
|
||||||
|
// case getMore -> new MongoDbGetMoreOpDispenser(adapter, op, opTypeAndTarget.targetFunction);
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,14 +16,46 @@
|
|||||||
|
|
||||||
package io.nosqlbench.adapter.mongodb.dispensers;
|
package io.nosqlbench.adapter.mongodb.dispensers;
|
||||||
|
|
||||||
|
import com.mongodb.client.MongoClient;
|
||||||
|
import com.mongodb.client.MongoDatabase;
|
||||||
import io.nosqlbench.adapter.mongodb.core.MongoSpace;
|
import io.nosqlbench.adapter.mongodb.core.MongoSpace;
|
||||||
import io.nosqlbench.engine.api.activityimpl.OpDispenser;
|
import io.nosqlbench.adapter.mongodb.core.MongodbDriverAdapter;
|
||||||
|
import io.nosqlbench.engine.api.activityimpl.BaseOpDispenser;
|
||||||
import io.nosqlbench.engine.api.activityimpl.uniform.flowtypes.Op;
|
import io.nosqlbench.engine.api.activityimpl.uniform.flowtypes.Op;
|
||||||
import io.nosqlbench.engine.api.templating.ParsedOp;
|
import io.nosqlbench.engine.api.templating.ParsedOp;
|
||||||
|
|
||||||
import java.util.function.LongFunction;
|
import java.util.function.LongFunction;
|
||||||
|
|
||||||
public class MongoDbUpdateOpDispenser implements OpDispenser<? extends Op> {
|
/**
|
||||||
public MongoDbUpdateOpDispenser(LongFunction<MongoSpace> ctxFunc, ParsedOp op) {
|
* https://www.mongodb.com/docs/manual/reference/command/update/#mongodb-dbcommand-dbcmd.update
|
||||||
|
* https://www.mongodb.com/docs/drivers/java/sync/current/usage-examples/updateOne/
|
||||||
|
*/
|
||||||
|
public class MongoDbUpdateOpDispenser extends BaseOpDispenser<Op, MongoSpace> {
|
||||||
|
private final LongFunction<MongoSpace> spaceF;
|
||||||
|
private final LongFunction<Op> opF;
|
||||||
|
private LongFunction<String> collectionF;
|
||||||
|
|
||||||
|
public MongoDbUpdateOpDispenser(MongodbDriverAdapter adapter, ParsedOp pop, LongFunction<String> collectionF) {
|
||||||
|
super(adapter, pop);
|
||||||
|
this.collectionF = collectionF;
|
||||||
|
this.spaceF = adapter.getSpaceFunc(pop);
|
||||||
|
this.opF = createOpF(pop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private LongFunction<Op> createOpF(ParsedOp pop) {
|
||||||
|
LongFunction<MongoClient> clientF = cycle -> spaceF.apply(cycle).getClient();
|
||||||
|
|
||||||
|
LongFunction<MongoDatabase> docF = l -> clientF.apply(l).getDatabase(collectionF.apply(l));
|
||||||
|
// docF.apply(1).getCollection()
|
||||||
|
// LongFunctionclientF.apply(l).getDatabase()
|
||||||
|
|
||||||
|
return l -> new Op() {};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Op apply(long value) {
|
||||||
|
Op op = opF.apply(value);
|
||||||
|
return op;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user