diff options
11 files changed, 50 insertions, 11 deletions
diff --git a/searchcore/src/vespa/searchcore/proton/matchengine/matchengine.cpp b/searchcore/src/vespa/searchcore/proton/matchengine/matchengine.cpp index 96ad422009c..83466cd51ad 100644 --- a/searchcore/src/vespa/searchcore/proton/matchengine/matchengine.cpp +++ b/searchcore/src/vespa/searchcore/proton/matchengine/matchengine.cpp @@ -62,7 +62,7 @@ MatchEngine::close() { LOG(debug, "Closing search interface."); { - vespalib::LockGuard guard(_lock); + std::lock_guard<std::mutex> guard(_lock); _closed = true; } @@ -74,21 +74,21 @@ ISearchHandler::SP MatchEngine::putSearchHandler(const DocTypeName &docTypeName, const ISearchHandler::SP &searchHandler) { - vespalib::LockGuard guard(_lock); + std::lock_guard<std::mutex> guard(_lock); return _handlers.putHandler(docTypeName, searchHandler); } ISearchHandler::SP MatchEngine::getSearchHandler(const DocTypeName &docTypeName) { - vespalib::LockGuard guard(_lock); + std::lock_guard<std::mutex> guard(_lock); return _handlers.getHandler(docTypeName); } ISearchHandler::SP MatchEngine::removeSearchHandler(const DocTypeName &docTypeName) { - vespalib::LockGuard guard(_lock); + std::lock_guard<std::mutex> guard(_lock); return _handlers.removeHandler(docTypeName); } @@ -121,7 +121,7 @@ MatchEngine::performSearch(search::engine::SearchRequest::Source req, ISearchHandler::SP searchHandler; vespalib::SimpleThreadBundle::UP threadBundle = _threadBundlePool.obtain(); { // try to find the match handler corresponding to the specified search doc type - vespalib::LockGuard guard(_lock); + std::lock_guard<std::mutex> guard(_lock); DocTypeName docTypeName(*req.get()); searchHandler = _handlers.getHandler(docTypeName); } @@ -130,7 +130,7 @@ MatchEngine::performSearch(search::engine::SearchRequest::Source req, } else { HandlerMap<ISearchHandler>::Snapshot::UP snapshot; { - vespalib::LockGuard guard(_lock); + std::lock_guard<std::mutex> guard(_lock); snapshot = _handlers.snapshot(); } if (snapshot->valid()) { diff --git a/searchcore/src/vespa/searchcore/proton/matchengine/matchengine.h b/searchcore/src/vespa/searchcore/proton/matchengine/matchengine.h index 3055bbfb814..e27f1789ed3 100644 --- a/searchcore/src/vespa/searchcore/proton/matchengine/matchengine.h +++ b/searchcore/src/vespa/searchcore/proton/matchengine/matchengine.h @@ -9,6 +9,7 @@ #include <vespa/vespalib/net/state_explorer.h> #include <vespa/vespalib/util/threadstackexecutor.h> #include <vespa/vespalib/util/simple_thread_bundle.h> +#include <mutex> namespace proton { @@ -16,7 +17,7 @@ class MatchEngine : public search::engine::SearchServer, public vespalib::StateExplorer { private: - vespalib::Lock _lock; + std::mutex _lock; const uint32_t _distributionKey; bool _closed; HandlerMap<ISearchHandler> _handlers; diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/DoubleCompatibleValue.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/DoubleCompatibleValue.java index dab89fe8955..0ed2bdd6331 100644 --- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/DoubleCompatibleValue.java +++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/DoubleCompatibleValue.java @@ -39,6 +39,11 @@ public abstract class DoubleCompatibleValue extends Value { } @Override + public Value modulo(Value value) { + return new DoubleValue(asDouble() % value.asDouble()); + } + + @Override public Value compare(TruthOperator operator, Value value) { return new BooleanValue(operator.evaluate(asDouble(), value.asDouble())); } diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/DoubleValue.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/DoubleValue.java index 28272e58c91..17157ab385f 100644 --- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/DoubleValue.java +++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/DoubleValue.java @@ -98,6 +98,17 @@ public final class DoubleValue extends DoubleCompatibleValue { } @Override + public Value modulo(Value value) { + try { + return mutable(this.value % value.asDouble()); + } + catch (UnsupportedOperationException e) { + throw unsupported("modulo",value); + } + } + + + @Override public Value function(Function function, Value value) { // use the tensor implementation of max and min if the argument is a tensor if ( (function.equals(Function.min) || function.equals(Function.max)) && value instanceof TensorValue) diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/StringValue.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/StringValue.java index acf301f3b80..5374a9d3ce6 100644 --- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/StringValue.java +++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/StringValue.java @@ -68,6 +68,11 @@ public class StringValue extends Value { } @Override + public Value modulo(Value value) { + throw new UnsupportedOperationException("String values ('" + value + "') does not support modulo"); + } + + @Override public Value compare(TruthOperator operator, Value value) { if (operator.equals(TruthOperator.EQUAL)) return new BooleanValue(this.equals(value)); diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/TensorValue.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/TensorValue.java index 45988ef0776..b283603e713 100644 --- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/TensorValue.java +++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/TensorValue.java @@ -81,6 +81,15 @@ public class TensorValue extends Value { return new TensorValue(value.map((value) -> value / argument.asDouble())); } + @Override + public Value modulo(Value argument) { + if (argument instanceof TensorValue) + return new TensorValue(value.fmod(((TensorValue) argument).value)); + else + return new TensorValue(value.map((value) -> value % argument.asDouble())); + } + + private Tensor asTensor(Value value, String operationName) { if ( ! (value instanceof TensorValue)) throw new UnsupportedOperationException("Could not perform " + operationName + diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/Value.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/Value.java index a63387506a0..f42082321b3 100644 --- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/Value.java +++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/Value.java @@ -41,6 +41,8 @@ public abstract class Value { public abstract Value divide(Value value); + public abstract Value modulo(Value value); + /** Perform the comparison specified by the operator between this value and the given value */ public abstract Value compare(TruthOperator operator, Value value); diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ArithmeticOperator.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ArithmeticOperator.java index 5a5237c2608..2187a96ba4d 100644 --- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ArithmeticOperator.java +++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ArithmeticOperator.java @@ -25,8 +25,11 @@ public enum ArithmeticOperator { }}, DIVIDE(3, "/") { public Value evaluate(Value x, Value y) { return x.divide(y); + }}, + MODULO(4, "%") { public Value evaluate(Value x, Value y) { + return x.modulo(y); }}; - + /** A list of all the operators in this in order of decreasing precedence */ public static final List<ArithmeticOperator> operatorsByPrecedence = operatorsByPrecedence(); @@ -52,6 +55,7 @@ public enum ArithmeticOperator { private static List<ArithmeticOperator> operatorsByPrecedence() { List<ArithmeticOperator> operators = new ArrayList<>(); + operators.add(MODULO); operators.add(DIVIDE); operators.add(MULTIPLY); operators.add(MINUS); diff --git a/searchlib/src/main/javacc/RankingExpressionParser.jj b/searchlib/src/main/javacc/RankingExpressionParser.jj index c3b9235cc93..01fed00202c 100755 --- a/searchlib/src/main/javacc/RankingExpressionParser.jj +++ b/searchlib/src/main/javacc/RankingExpressionParser.jj @@ -65,6 +65,7 @@ TOKEN : <DIV: "/"> | <MUL: "*"> | <DOT: "."> | + <MOD: "%"> | <DOLLAR: "$"> | <COMMA: ","> | @@ -202,7 +203,8 @@ ArithmeticOperator arithmetic() : { } ( <ADD> { return ArithmeticOperator.PLUS; } | <SUB> { return ArithmeticOperator.MINUS; } | <DIV> { return ArithmeticOperator.DIVIDE; } | - <MUL> { return ArithmeticOperator.MULTIPLY; } ) + <MUL> { return ArithmeticOperator.MULTIPLY; } | + <MOD> { return ArithmeticOperator.MODULO; } ) { return null; } } diff --git a/storage/src/vespa/storage/distributor/statecheckers.cpp b/storage/src/vespa/storage/distributor/statecheckers.cpp index 4c5301dd8c2..49e9ba9f1c4 100644 --- a/storage/src/vespa/storage/distributor/statecheckers.cpp +++ b/storage/src/vespa/storage/distributor/statecheckers.cpp @@ -445,7 +445,7 @@ JoinBucketsStateChecker::computeJoinBucket(const Context& c) const --level; target = candidate; } - return document::Bucket(BucketSpace::placeHolder(), target); + return document::Bucket(c.getBucket().getBucketSpace(), target); } StateChecker::Result diff --git a/storage/src/vespa/storage/persistence/filestorage/filestorhandlerimpl.cpp b/storage/src/vespa/storage/persistence/filestorage/filestorhandlerimpl.cpp index fffd559866d..31f712faea2 100644 --- a/storage/src/vespa/storage/persistence/filestorage/filestorhandlerimpl.cpp +++ b/storage/src/vespa/storage/persistence/filestorage/filestorhandlerimpl.cpp @@ -742,7 +742,7 @@ FileStorHandlerImpl::calculateTargetBasedOnDocId( std::vector<RemapInfo*>& targets) { document::DocumentId id(getDocId(msg)); - document::Bucket bucket(BucketSpace::placeHolder(), _bucketIdFactory.getBucketId(id)); + document::Bucket bucket(msg.getBucket().getBucketSpace(), _bucketIdFactory.getBucketId(id)); for (uint32_t i = 0; i < targets.size(); i++) { if (targets[i]->bucket.getBucketId().getRawId() != 0 && |