From 93b456616a62ddebde096f9764cef4301d1fd77f Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Mon, 4 Mar 2019 13:20:57 +0000 Subject: =default --- .../attribute/imported_attribute_vector.cpp | 3 +- .../attribute/imported_attribute_vector.h | 9 +-- .../imported_attribute_vector_read_guard.cpp | 7 +- .../imported_attribute_vector_read_guard.h | 77 +++++++++++----------- 4 files changed, 44 insertions(+), 52 deletions(-) (limited to 'searchlib') diff --git a/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.cpp b/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.cpp index 0ba4bc814d5..9e3b0bbde3e 100644 --- a/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.cpp +++ b/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.cpp @@ -39,8 +39,7 @@ ImportedAttributeVector::ImportedAttributeVector(vespalib::stringref name, { } -ImportedAttributeVector::~ImportedAttributeVector() { -} +ImportedAttributeVector::~ImportedAttributeVector() = default; std::unique_ptr ImportedAttributeVector::makeReadGuard(bool stableEnumGuard) const diff --git a/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.h b/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.h index e6356866ed9..33afaaf7f1e 100644 --- a/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.h +++ b/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.h @@ -6,11 +6,9 @@ #include #include -namespace search { +namespace search { struct IDocumentMetaStoreContext; } -struct IDocumentMetaStoreContext; - -namespace attribute { +namespace search::attribute { class BitVectorSearchCache; class ReadableAttributeVector; @@ -63,7 +61,7 @@ public: return _name; } - virtual std::unique_ptr makeReadGuard(bool stableEnumGuard) const override; + std::unique_ptr makeReadGuard(bool stableEnumGuard) const override; protected: vespalib::string _name; @@ -75,4 +73,3 @@ protected: }; } -} diff --git a/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector_read_guard.cpp b/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector_read_guard.cpp index 428b14671cd..50fa1ffded3 100644 --- a/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector_read_guard.cpp +++ b/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector_read_guard.cpp @@ -6,8 +6,7 @@ #include "reference_attribute.h" #include -namespace search { -namespace attribute { +namespace search::attribute { ImportedAttributeVectorReadGuard::ImportedAttributeVectorReadGuard( const ImportedAttributeVector &imported_attribute, @@ -24,8 +23,7 @@ ImportedAttributeVectorReadGuard::ImportedAttributeVectorReadGuard( _targetLids = _reference_attribute.getTargetLids(); } -ImportedAttributeVectorReadGuard::~ImportedAttributeVectorReadGuard() { -} +ImportedAttributeVectorReadGuard::~ImportedAttributeVectorReadGuard() = default; const vespalib::string& ImportedAttributeVectorReadGuard::getName() const { return _imported_attribute.getName(); @@ -169,4 +167,3 @@ long ImportedAttributeVectorReadGuard::onSerializeForDescendingSort(DocId doc, } } -} diff --git a/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector_read_guard.h b/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector_read_guard.h index 4cf4d5b64c1..f130a095006 100644 --- a/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector_read_guard.h +++ b/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector_read_guard.h @@ -45,49 +45,48 @@ protected: } public: - ImportedAttributeVectorReadGuard(const ImportedAttributeVector &imported_attribute, - bool stableEnumGuard); - ~ImportedAttributeVectorReadGuard(); + ImportedAttributeVectorReadGuard(const ImportedAttributeVector &imported_attribute, bool stableEnumGuard); + ~ImportedAttributeVectorReadGuard() override; - virtual const vespalib::string &getName() const override; - virtual uint32_t getNumDocs() const override; - virtual uint32_t getValueCount(uint32_t doc) const override; - virtual uint32_t getMaxValueCount() const override; - virtual largeint_t getInt(DocId doc) const override; - virtual double getFloat(DocId doc) const override; - virtual const char *getString(DocId doc, char *buffer, size_t sz) const override; - virtual EnumHandle getEnum(DocId doc) const override; - virtual uint32_t get(DocId docId, largeint_t *buffer, uint32_t sz) const override; - virtual uint32_t get(DocId docId, double *buffer, uint32_t sz) const override; - virtual uint32_t get(DocId docId, const char **buffer, uint32_t sz) const override; - virtual uint32_t get(DocId docId, EnumHandle *buffer, uint32_t sz) const override; - virtual uint32_t get(DocId docId, WeightedInt *buffer, uint32_t sz) const override; - virtual uint32_t get(DocId docId, WeightedFloat *buffer, uint32_t sz) const override; - virtual uint32_t get(DocId docId, WeightedString *buffer, uint32_t sz) const override; - virtual uint32_t get(DocId docId, WeightedConstChar *buffer, uint32_t sz) const override; - virtual uint32_t get(DocId docId, WeightedEnum *buffer, uint32_t sz) const override; - virtual bool findEnum(const char * value, EnumHandle & e) const override; - virtual std::vector findFoldedEnums(const char *value) const override; + const vespalib::string &getName() const override; + uint32_t getNumDocs() const override; + uint32_t getValueCount(uint32_t doc) const override; + uint32_t getMaxValueCount() const override; + largeint_t getInt(DocId doc) const override; + double getFloat(DocId doc) const override; + const char *getString(DocId doc, char *buffer, size_t sz) const override; + EnumHandle getEnum(DocId doc) const override; + uint32_t get(DocId docId, largeint_t *buffer, uint32_t sz) const override; + uint32_t get(DocId docId, double *buffer, uint32_t sz) const override; + uint32_t get(DocId docId, const char **buffer, uint32_t sz) const override; + uint32_t get(DocId docId, EnumHandle *buffer, uint32_t sz) const override; + uint32_t get(DocId docId, WeightedInt *buffer, uint32_t sz) const override; + uint32_t get(DocId docId, WeightedFloat *buffer, uint32_t sz) const override; + uint32_t get(DocId docId, WeightedString *buffer, uint32_t sz) const override; + uint32_t get(DocId docId, WeightedConstChar *buffer, uint32_t sz) const override; + uint32_t get(DocId docId, WeightedEnum *buffer, uint32_t sz) const override; + bool findEnum(const char * value, EnumHandle & e) const override; + std::vector findFoldedEnums(const char *value) const override; - virtual const char * getStringFromEnum(EnumHandle e) const override; - virtual std::unique_ptr createSearchContext(std::unique_ptr term, - const SearchContextParams ¶ms) const override; - virtual const IDocumentWeightAttribute *asDocumentWeightAttribute() const override; - virtual const tensor::ITensorAttribute *asTensorAttribute() const override; - virtual BasicType::Type getBasicType() const override; - virtual size_t getFixedWidth() const override; - virtual CollectionType::Type getCollectionType() const override; - virtual bool hasEnum() const override; - virtual bool getIsFilter() const override; - virtual bool getIsFastSearch() const override; - virtual uint32_t getCommittedDocIdLimit() const override; - virtual bool isImported() const override; + const char * getStringFromEnum(EnumHandle e) const override; + std::unique_ptr createSearchContext(std::unique_ptr term, + const SearchContextParams ¶ms) const override; + const IDocumentWeightAttribute *asDocumentWeightAttribute() const override; + const tensor::ITensorAttribute *asTensorAttribute() const override; + BasicType::Type getBasicType() const override; + size_t getFixedWidth() const override; + CollectionType::Type getCollectionType() const override; + bool hasEnum() const override; + bool getIsFilter() const override; + bool getIsFastSearch() const override; + uint32_t getCommittedDocIdLimit() const override; + bool isImported() const override; protected: - virtual long onSerializeForAscendingSort(DocId doc, void * serTo, long available, - const common::BlobConverter * bc) const override; - virtual long onSerializeForDescendingSort(DocId doc, void * serTo, long available, - const common::BlobConverter * bc) const override; + long onSerializeForAscendingSort(DocId doc, void * serTo, long available, + const common::BlobConverter * bc) const override; + long onSerializeForDescendingSort(DocId doc, void * serTo, long available, + const common::BlobConverter * bc) const override; }; } -- cgit v1.2.3 From f1c2464fd83e6623000ad6eb59272b189fffb78e Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 5 Mar 2019 06:04:04 +0000 Subject: Transform to slime. --- .../tests/queryeval/blueprint/blueprint_test.cpp | 68 ++++++++++++++++++++ .../src/vespa/searchlib/queryeval/blueprint.cpp | 11 ++++ .../src/vespa/searchlib/queryeval/blueprint.h | 7 +- .../src/vespa/vespalib/objects/CMakeLists.txt | 1 + .../src/vespa/vespalib/objects/object2slime.cpp | 75 ++++++++++++++++++++++ .../src/vespa/vespalib/objects/object2slime.h | 41 ++++++++++++ 6 files changed, 202 insertions(+), 1 deletion(-) create mode 100644 staging_vespalib/src/vespa/vespalib/objects/object2slime.cpp create mode 100644 staging_vespalib/src/vespa/vespalib/objects/object2slime.h (limited to 'searchlib') diff --git a/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp b/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp index e5ee83507ae..0d34b41d5c7 100644 --- a/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp +++ b/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -178,6 +179,7 @@ public: void testSearchCreation(); void testBlueprintMakeNew(); void requireThatAsStringWorks(); + void requireThatAsSlimeWorks(); void requireThatVisitMembersWorks(); void requireThatDocIdLimitInjectionWorks(); int Main() override; @@ -698,6 +700,59 @@ getExpectedBlueprint() "}\n"; } +vespalib::string +getExpectedSlimeBlueprint() { + return "{" + " '(anonymous namespace)::MyOr': {" + " isTermLike: true," + " fields: {" + " '[type]': 'FieldList'," + " '[0]': {" + " '[type]': 'Field'," + " fieldId: 5," + " handle: 7," + " isFilter: false" + " }" + " }," + " estimate: {" + " '[type]': 'HitEstimate'," + " empty: false," + " estHits: 9," + " tree_size: 2," + " allow_termwise_eval: 0" + " }," + " sourceId: 4294967295," + " docid_limit: 0," + " children: {" + " '[type]': 'std::vector'," + " '[0]': {" + " isTermLike: true," + " fields: {" + " '[type]': 'FieldList'," + " '[0]': {" + " '[type]': 'Field'," + " fieldId: 5," + " handle: 7," + " isFilter: false" + " }" + " }," + " '[type]': '(anonymous namespace)::MyTerm'," + " estimate: {" + " '[type]': 'HitEstimate'," + " empty: false," + " estHits: 9," + " tree_size: 1," + " allow_termwise_eval: 1" + " }," + " sourceId: 4294967295," + " docid_limit: 0" + " }" + " }" + " }" + "}"; +} + + struct BlueprintFixture { MyOr _blueprint; @@ -713,6 +768,18 @@ Test::requireThatAsStringWorks() EXPECT_EQUAL(getExpectedBlueprint(), f._blueprint.asString()); } +void +Test::requireThatAsSlimeWorks() +{ + BlueprintFixture f; + vespalib::Slime slime; + f._blueprint.asSlime(vespalib::slime::SlimeInserter(slime)); + auto s = slime.toString(); + vespalib::Slime expectedSlime; + vespalib::slime::JsonFormat::decode(getExpectedSlimeBlueprint(), expectedSlime); + EXPECT_EQUAL(expectedSlime, slime); +} + void Test::requireThatVisitMembersWorks() { @@ -749,6 +816,7 @@ Test::Main() testSearchCreation(); testBlueprintMakeNew(); requireThatAsStringWorks(); + requireThatAsSlimeWorks(); requireThatVisitMembersWorks(); requireThatDocIdLimitInjectionWorks(); TEST_DONE(); diff --git a/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp index c99e07cd355..3f3b4a2300e 100644 --- a/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp @@ -6,7 +6,9 @@ #include "equiv_blueprint.h" #include #include +#include #include +#include #include #include @@ -117,6 +119,15 @@ Blueprint::asString() const return dumper.toString(); } +vespalib::slime::Cursor & +Blueprint::asSlime(const vespalib::slime::Inserter & inserter) const +{ + vespalib::slime::Cursor & cursor = inserter.insertObject(); + vespalib::Object2Slime dumper(cursor); + visit(dumper, "", this); + return cursor; +} + vespalib::string Blueprint::getClassName() const { diff --git a/searchlib/src/vespa/searchlib/queryeval/blueprint.h b/searchlib/src/vespa/searchlib/queryeval/blueprint.h index 165f592867a..4b60e7d0d8b 100644 --- a/searchlib/src/vespa/searchlib/queryeval/blueprint.h +++ b/searchlib/src/vespa/searchlib/queryeval/blueprint.h @@ -9,7 +9,11 @@ #include #include -namespace vespalib { class ObjectVisitor; }; +namespace vespalib { class ObjectVisitor; } +namespace vespalib::slime { + class Cursor; + class Inserter; +} namespace search::queryeval { @@ -173,6 +177,7 @@ public: // for debug dumping vespalib::string asString() const; + vespalib::slime::Cursor & asSlime(const vespalib::slime::Inserter & cursor) const; virtual vespalib::string getClassName() const; virtual void visitMembers(vespalib::ObjectVisitor &visitor) const; virtual bool isEquiv() const { return false; } diff --git a/staging_vespalib/src/vespa/vespalib/objects/CMakeLists.txt b/staging_vespalib/src/vespa/vespalib/objects/CMakeLists.txt index 12970a7d39b..f3afda94fe6 100644 --- a/staging_vespalib/src/vespa/vespalib/objects/CMakeLists.txt +++ b/staging_vespalib/src/vespa/vespalib/objects/CMakeLists.txt @@ -5,6 +5,7 @@ vespa_add_library(staging_vespalib_vespalib_objects OBJECT namedobject.cpp objectvisitor.cpp objectdumper.cpp + object2slime.cpp visit.cpp objectpredicate.cpp objectoperation.cpp diff --git a/staging_vespalib/src/vespa/vespalib/objects/object2slime.cpp b/staging_vespalib/src/vespa/vespalib/objects/object2slime.cpp new file mode 100644 index 00000000000..f06060529c3 --- /dev/null +++ b/staging_vespalib/src/vespa/vespalib/objects/object2slime.cpp @@ -0,0 +1,75 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include "object2slime.h" +#include +#include + + +namespace vespalib { + +Object2Slime::Object2Slime(slime::Cursor & cursor) + : _cursor(&cursor), + _stack() +{ +} + +Object2Slime::~Object2Slime() = default; + +//----------------------------------------------------------------------------- + +void +Object2Slime::openStruct(const vespalib::string &name, const vespalib::string &type) +{ + _stack.push_back(_cursor); + + if (name.empty()) { + _cursor = & _cursor->setObject(type); + } else { + _cursor = & _cursor->setObject(name); + _cursor->setString("[type]", type); + } +} + +void +Object2Slime::closeStruct() +{ + _cursor = _stack.back(); + _stack.pop_back(); +} + +void +Object2Slime::visitBool(const vespalib::string &name, bool value) +{ + _cursor->setBool(name, value); +} + +void +Object2Slime::visitInt(const vespalib::string &name, int64_t value) +{ + _cursor->setLong(name, value); +} + +void +Object2Slime::visitFloat(const vespalib::string &name, double value) +{ + _cursor->setDouble(name, value); +} + +void +Object2Slime::visitString(const vespalib::string &name, const vespalib::string &value) +{ + _cursor->setString(name, value); +} + +void +Object2Slime::visitNull(const vespalib::string &name) +{ + _cursor->setNix(name); +} + +void +Object2Slime::visitNotImplemented() +{ + _cursor->setNix("not_implemented"); +} + +} // namespace vespalib diff --git a/staging_vespalib/src/vespa/vespalib/objects/object2slime.h b/staging_vespalib/src/vespa/vespalib/objects/object2slime.h new file mode 100644 index 00000000000..9c147047a74 --- /dev/null +++ b/staging_vespalib/src/vespa/vespalib/objects/object2slime.h @@ -0,0 +1,41 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#pragma once + +#include "objectvisitor.h" +#include + +namespace vespalib { + +namespace slime { class Cursor; } + +/** + * This is a concrete object visitor that will build up a structured + * human-readable string representation of an object. + **/ +class Object2Slime : public ObjectVisitor +{ +private: + slime::Cursor * _cursor; + std::vector _stack; + +public: + /** + * Create an object dumper with the given indent size; default is + * 4 spaces per indent level. + * + * @param indent indent size in number of spaces + **/ + Object2Slime(slime::Cursor & cursor); + ~Object2Slime(); + + void openStruct(const vespalib::string &name, const vespalib::string &type) override; + void closeStruct() override; + void visitBool(const vespalib::string &name, bool value) override; + void visitInt(const vespalib::string &name, int64_t value) override; + void visitFloat(const vespalib::string &name, double value) override; + void visitString(const vespalib::string &name, const vespalib::string &value) override; + void visitNull(const vespalib::string &name) override; + void visitNotImplemented() override; +}; + +} // namespace vespalib -- cgit v1.2.3 From 289e76ca3e334dd3efab0880c00fd7582bdf9175 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 5 Mar 2019 06:07:06 +0000 Subject: Add placeholder for trace level --- searchlib/src/vespa/searchlib/engine/request.cpp | 3 ++- searchlib/src/vespa/searchlib/engine/request.h | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'searchlib') diff --git a/searchlib/src/vespa/searchlib/engine/request.cpp b/searchlib/src/vespa/searchlib/engine/request.cpp index 8f4aa427988..28cbbae64b8 100644 --- a/searchlib/src/vespa/searchlib/engine/request.cpp +++ b/searchlib/src/vespa/searchlib/engine/request.cpp @@ -8,8 +8,9 @@ namespace search::engine { Request::Request(const fastos::TimeStamp &start_time) : _startTime(start_time), _timeOfDoom(fastos::TimeStamp(fastos::TimeStamp::FUTURE)), - ranking(), + _traceLevel(0), queryFlags(0), + ranking(), location(), propertiesMap(), stackItems(0), diff --git a/searchlib/src/vespa/searchlib/engine/request.h b/searchlib/src/vespa/searchlib/engine/request.h index 02ab75fe509..863c2db4e15 100644 --- a/searchlib/src/vespa/searchlib/engine/request.h +++ b/searchlib/src/vespa/searchlib/engine/request.h @@ -26,13 +26,17 @@ public: bool should_drop_sort_data() const; + uint32_t getTraceLevel() const { return _traceLevel; } + Request & setTraceLevel(uint32_t traceLevel) { _traceLevel = traceLevel; return *this; } + private: const fastos::TimeStamp _startTime; fastos::TimeStamp _timeOfDoom; + uint32_t _traceLevel; public: /// Everything here should move up to private section and have accessors - vespalib::string ranking; uint32_t queryFlags; + vespalib::string ranking; vespalib::string location; PropertiesMap propertiesMap; uint32_t stackItems; -- cgit v1.2.3 From d9a1b8be930da47e9c7b42ab44eecd29b385c170 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 5 Mar 2019 06:07:56 +0000 Subject: = default and NULL ->nullptr --- searchlib/src/vespa/searchlib/engine/searchrequest.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'searchlib') diff --git a/searchlib/src/vespa/searchlib/engine/searchrequest.cpp b/searchlib/src/vespa/searchlib/engine/searchrequest.cpp index 7159c83716b..b558e07480d 100644 --- a/searchlib/src/vespa/searchlib/engine/searchrequest.cpp +++ b/searchlib/src/vespa/searchlib/engine/searchrequest.cpp @@ -17,20 +17,20 @@ SearchRequest::SearchRequest(const fastos::TimeStamp &start_time) sessionId() { } -SearchRequest::~SearchRequest() {} +SearchRequest::~SearchRequest() = default; void SearchRequest::Source::lazyDecode() const { - if ((_request.get() == NULL) && (_fs4Packet != NULL)) { - _request.reset(new SearchRequest(_start)); + if (!_request && (_fs4Packet != nullptr)) { + _request = std::make_unique(_start); PacketConverter::toSearchRequest(*_fs4Packet, *_request); _fs4Packet->Free(); - _fs4Packet = NULL; + _fs4Packet = nullptr; } } SearchRequest::Source::~Source() { - if (_fs4Packet != NULL) { + if (_fs4Packet != nullptr) { _fs4Packet->Free(); } } -- cgit v1.2.3 From d138c1667dfaf921d2fea1990f7964df1a4a48f8 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 5 Mar 2019 10:32:58 +0000 Subject: Add a simple Trace Object wrapping the slime. --- .../src/tests/engine/searchapi/searchapi_test.cpp | 78 ++++++++++++++-------- .../src/vespa/searchlib/engine/CMakeLists.txt | 1 + searchlib/src/vespa/searchlib/engine/request.h | 1 + searchlib/src/vespa/searchlib/engine/trace.cpp | 33 +++++++++ searchlib/src/vespa/searchlib/engine/trace.h | 38 +++++++++++ 5 files changed, 122 insertions(+), 29 deletions(-) create mode 100644 searchlib/src/vespa/searchlib/engine/trace.cpp create mode 100644 searchlib/src/vespa/searchlib/engine/trace.h (limited to 'searchlib') diff --git a/searchlib/src/tests/engine/searchapi/searchapi_test.cpp b/searchlib/src/tests/engine/searchapi/searchapi_test.cpp index a517890620c..f06ce5c188c 100644 --- a/searchlib/src/tests/engine/searchapi/searchapi_test.cpp +++ b/searchlib/src/tests/engine/searchapi/searchapi_test.cpp @@ -1,10 +1,12 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include -LOG_SETUP("searchapi_test"); + #include #include #include #include +#include +#include +LOG_SETUP("searchapi_test"); using namespace search::engine; using namespace search::fs4transport; @@ -28,18 +30,8 @@ template void copyPacket(T &src, T &dst) { } // namespace -class Test : public vespalib::TestApp -{ -public: - void propertyNames(); - void convertToRequest(); - void convertFromReply(); - int Main() override; -}; - -void -Test::propertyNames() -{ + +TEST("propertyNames") { EXPECT_EQUAL(search::MapNames::RANK, "rank"); EXPECT_EQUAL(search::MapNames::FEATURE, "feature"); EXPECT_EQUAL(search::MapNames::HIGHLIGHTTERMS, "highlightterms"); @@ -47,9 +39,7 @@ Test::propertyNames() EXPECT_EQUAL(search::MapNames::CACHES, "caches"); } -void -Test::convertToRequest() -{ +TEST("convertToReques") { FS4Packet_QUERYX src; src._offset = 2u; src._maxhits = 3u; @@ -116,9 +106,7 @@ Test::convertToRequest() } } -void -Test::convertFromReply() -{ +TEST("convertFromReply") { SearchReply src; src.offset = 1u; src.totalHitCount = 2u; @@ -240,14 +228,46 @@ Test::convertFromReply() } } -int -Test::Main() -{ - TEST_INIT("searchapi_test"); - propertyNames(); - convertToRequest(); - convertFromReply(); - TEST_DONE(); +void verify(vespalib::stringref expected, const vespalib::Slime & slime) { + vespalib::Slime expectedSlime; + vespalib::slime::JsonFormat::decode(expected, expectedSlime); + EXPECT_EQUAL(expectedSlime, slime); +} + +TEST("verify trace") { + Trace t(7); + verify("{" + " traces: [" + " ]," + " creation_time: 7" + "}", + t.getRoot()); + + t.createCursor("tag_a"); + verify("{" + " traces: [" + " {" + " tag: 'tag_a'" + " }" + " ]," + " creation_time: 7" + "}", + t.getRoot()); + Trace::Cursor & tagB = t.createCursor("tag_b"); + tagB.setLong("long", 19); + verify("{" + " traces: [" + " {" + " tag: 'tag_a'" + " }," + " {" + " tag: 'tag_b'," + " long: 19" + " }" + " ]," + " creation_time: 7" + "}", + t.getRoot()); } -TEST_APPHOOK(Test); +TEST_MAIN() { TEST_RUN_ALL(); } \ No newline at end of file diff --git a/searchlib/src/vespa/searchlib/engine/CMakeLists.txt b/searchlib/src/vespa/searchlib/engine/CMakeLists.txt index 95b47b991af..e475d786a60 100644 --- a/searchlib/src/vespa/searchlib/engine/CMakeLists.txt +++ b/searchlib/src/vespa/searchlib/engine/CMakeLists.txt @@ -13,6 +13,7 @@ vespa_add_library(searchlib_engine OBJECT searchreply.cpp searchrequest.cpp source_description.cpp + trace.cpp transport_metrics.cpp transportserver.cpp DEPENDS diff --git a/searchlib/src/vespa/searchlib/engine/request.h b/searchlib/src/vespa/searchlib/engine/request.h index 863c2db4e15..58c71cd8458 100644 --- a/searchlib/src/vespa/searchlib/engine/request.h +++ b/searchlib/src/vespa/searchlib/engine/request.h @@ -3,6 +3,7 @@ #pragma once #include "propertiesmap.h" +#include "trace.h" #include namespace search::engine { diff --git a/searchlib/src/vespa/searchlib/engine/trace.cpp b/searchlib/src/vespa/searchlib/engine/trace.cpp new file mode 100644 index 00000000000..381c851f40b --- /dev/null +++ b/searchlib/src/vespa/searchlib/engine/trace.cpp @@ -0,0 +1,33 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "trace.h" +#include +#include + +namespace search::engine { + + +Trace::Trace(const fastos::TimeStamp &start_time) + : _trace(std::make_unique()), + _root(_trace->setObject()), + _traces(_root.setArray("traces")) +{ + _root.setLong("creation_time", start_time); +} + +Trace::~Trace() = default; + +Trace::Cursor & +Trace::createCursor(vespalib::stringref name) { + Cursor & trace = _traces.addObject(); + trace.setString("tag", name); + return trace; + +} + +vespalib::string +Trace::toString() const { + return _trace->toString(); +} + +} diff --git a/searchlib/src/vespa/searchlib/engine/trace.h b/searchlib/src/vespa/searchlib/engine/trace.h new file mode 100644 index 00000000000..4f2bea680df --- /dev/null +++ b/searchlib/src/vespa/searchlib/engine/trace.h @@ -0,0 +1,38 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include + +namespace fastos { class TimeStamp; } +namespace vespalib { class Slime; } +namespace vespalib::slime { class Cursor; } + +namespace search::engine { + + /** + * Used for adding traces to a request. Acquire a new Cursor for everytime you want to trace something. + * Note that it is not thread safe. All use of any cursor aquired must be thread safe. + */ +class Trace +{ +public: + using Cursor = vespalib::slime::Cursor; + Trace(const fastos::TimeStamp &start_time); + ~Trace(); + + /** + * Will give you a trace entry. It will also add a timestamp relative to the creation of the trace. + * @param name + * @return + */ + Cursor & createCursor(vespalib::stringref name); + vespalib::string toString() const; + vespalib::Slime & getRoot() const { return *_trace; } +private: + std::unique_ptr _trace; + Cursor & _root; + Cursor & _traces; +}; + +} -- cgit v1.2.3 From 4ca57c3bc062bda152157a9286210509f9987af4 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 5 Mar 2019 11:39:39 +0000 Subject: Cleanup --- .../src/vespa/searchlib/engine/packetconverter.cpp | 34 ++++++++++++---------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'searchlib') diff --git a/searchlib/src/vespa/searchlib/engine/packetconverter.cpp b/searchlib/src/vespa/searchlib/engine/packetconverter.cpp index e6fb37223d6..8a55af4cfb7 100644 --- a/searchlib/src/vespa/searchlib/engine/packetconverter.cpp +++ b/searchlib/src/vespa/searchlib/engine/packetconverter.cpp @@ -4,6 +4,9 @@ #include LOG_SETUP(".engine.packetconverter"); +using search::fef::Property; +using search::fef::Properties; + namespace { bool checkFeature(uint32_t features, uint32_t mask) { @@ -14,8 +17,8 @@ struct FS4PropertiesBuilder : public search::fef::IPropertiesVisitor { uint32_t idx; search::fs4transport::FS4Properties &props; FS4PropertiesBuilder(search::fs4transport::FS4Properties &p) : idx(0), props(p) {} - void visitProperty(const search::fef::Property::Value &key, - const search::fef::Property &values) override + void visitProperty(const Property::Value &key, + const Property &values) override { for (uint32_t i = 0; i < values.size(); ++i) { props.setKey(idx, key.data(), key.size()); @@ -39,7 +42,7 @@ PacketConverter::fillPacketProperties(const PropertiesMap &source, PropsVector& PropertiesMap::ITR end = source.end(); for (uint32_t i = 0; itr != end; ++itr, ++i) { const vespalib::string &name = itr->first; - const search::fef::Properties &values = itr->second; + const Properties &values = itr->second; target[i].setName(name.c_str(), name.size()); target[i].allocEntries(values.numValues()); FS4PropertiesBuilder builder(target[i]); @@ -58,9 +61,8 @@ PacketConverter::toSearchRequest(const QUERYX &packet, SearchRequest &request) request.queryFlags = packet.getQueryFlags(); request.ranking = packet._ranking; - for (uint32_t i = 0; i < packet._propsVector.size(); ++i) { - const FS4Properties &src = packet._propsVector[i]; - search::fef::Properties &dst = request.propertiesMap.lookupCreate(src.getName()); + for (const FS4Properties &src : packet._propsVector) { + Properties &dst = request.propertiesMap.lookupCreate(src.getName()); for (uint32_t e = 0; e < src.size(); ++e) { dst.add(vespalib::stringref(src.getKey(e), src.getKeyLen(e)), vespalib::stringref(src.getValue(e), src.getValueLen(e))); @@ -100,7 +102,7 @@ PacketConverter::fromSearchReply(const SearchReply &reply, QUERYRESULTX &packet) packet._totNumDocs = reply.totalHitCount; packet._maxRank = reply.maxRank; packet.setDistributionKey(reply.getDistributionKey()); - if (reply.sortIndex.size() > 0) { + if ( ! reply.sortIndex.empty()) { packet._features |= QRF_SORTDATA; uint32_t idxCnt = reply.sortIndex.size(); LOG_ASSERT(reply.sortIndex.size() == reply.hits.size()+1); @@ -112,7 +114,7 @@ PacketConverter::fromSearchReply(const SearchReply &reply, QUERYRESULTX &packet) } memcpy(packet._sortData, &(reply.sortData[0]), reply.sortData.size()); } - if (reply.groupResult.size() > 0) { + if ( ! reply.groupResult.empty()) { packet._features |= QRF_GROUPDATA; packet.AllocateGroupData(reply.groupResult.size()); memcpy(packet._groupData, &(reply.groupResult[0]), reply.groupResult.size()); @@ -123,8 +125,10 @@ PacketConverter::fromSearchReply(const SearchReply &reply, QUERYRESULTX &packet) packet._coverageDegradeReason = reply.coverage.getDegradeReason(); packet.setNodesQueried(reply.coverage.getNodesQueried()); packet.setNodesReplied(reply.coverage.getNodesReplied()); - if (reply.request && (reply.request->queryFlags & QFLAG_COVERAGE_NODES)) { - packet._features |= QRF_COVERAGE_NODES; + if (reply.request) { + if (reply.request->queryFlags & QFLAG_COVERAGE_NODES) { + packet._features |= QRF_COVERAGE_NODES; + } } if (reply.useWideHits) { packet._features |= QRF_MLD; @@ -150,9 +154,8 @@ PacketConverter::toDocsumRequest(const GETDOCSUMSX &packet, DocsumRequest &reque request.ranking = packet._ranking; request.queryFlags = packet._qflags; request.resultClassName = packet._resultClassName; - for (uint32_t i = 0; i < packet._propsVector.size(); ++i) { - const FS4Properties &src = packet._propsVector[i]; - search::fef::Properties &dst = request.propertiesMap.lookupCreate(src.getName()); + for (const FS4Properties &src : packet._propsVector) { + Properties &dst = request.propertiesMap.lookupCreate(src.getName()); for (uint32_t e = 0; e < src.size(); ++e) { dst.add(vespalib::stringref(src.getKey(e), src.getKeyLen(e)), vespalib::stringref(src.getValue(e), src.getValueLen(e))); @@ -169,8 +172,7 @@ PacketConverter::toDocsumRequest(const GETDOCSUMSX &packet, DocsumRequest &reque request.hits[i].gid = packet._docid[i]._gid; request.hits[i].path = packet._docid[i]._partid; } - search::fef::Property sessionId = - request.propertiesMap.rankProperties().lookup("sessionId"); + Property sessionId = request.propertiesMap.rankProperties().lookup("sessionId"); if (sessionId.found()) { vespalib::string id = sessionId.get(); request.sessionId.assign(id.begin(), id.end()); @@ -198,7 +200,7 @@ PacketConverter::toDocsumReplyElement(const DOCSUM &packet, DocsumReply::Docsum void PacketConverter::fromDocsumReplyElement(const DocsumReply::Docsum &docsum, DOCSUM &packet) { - if (docsum.data.get() != 0) { + if (docsum.data.get() != nullptr) { packet.SetBuf(docsum.data.c_str(), docsum.data.size()); } packet.setGid(docsum.gid); -- cgit v1.2.3 From 885a066cfdddfd8c0c1edb23c754171f0d6e0ed6 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 5 Mar 2019 11:41:12 +0000 Subject: Wire the trace object through. --- .../searchcore/proton/matchengine/matchengine.cpp | 19 +++++++++++++++---- searchlib/src/vespa/searchlib/engine/request.cpp | 3 ++- searchlib/src/vespa/searchlib/engine/request.h | 5 +++++ 3 files changed, 22 insertions(+), 5 deletions(-) (limited to 'searchlib') diff --git a/searchcore/src/vespa/searchcore/proton/matchengine/matchengine.cpp b/searchcore/src/vespa/searchcore/proton/matchengine/matchengine.cpp index 8fcb30a4143..0cb50fb00b0 100644 --- a/searchcore/src/vespa/searchcore/proton/matchengine/matchengine.cpp +++ b/searchcore/src/vespa/searchcore/proton/matchengine/matchengine.cpp @@ -2,9 +2,12 @@ #include "matchengine.h" #include #include -#include +#include +#include +#include #include + LOG_SETUP(".proton.matchengine.matchengine"); namespace { @@ -113,9 +116,9 @@ void MatchEngine::performSearch(search::engine::SearchRequest::Source req, search::engine::SearchClient &client) { - search::engine::SearchReply::UP ret(new search::engine::SearchReply); + auto ret = std::make_unique(); - if (req.get() != NULL) { + if (req.get()) { ISearchHandler::SP searchHandler; vespalib::SimpleThreadBundle::UP threadBundle = _threadBundlePool.obtain(); { // try to find the match handler corresponding to the specified search doc type @@ -123,7 +126,7 @@ MatchEngine::performSearch(search::engine::SearchRequest::Source req, DocTypeName docTypeName(*req.get()); searchHandler = _handlers.getHandler(docTypeName); } - if (searchHandler.get() != NULL) { + if (searchHandler) { ret = searchHandler->match(searchHandler, *req.get(), *threadBundle); } else { HandlerMap::Snapshot::UP snapshot; @@ -140,6 +143,14 @@ MatchEngine::performSearch(search::engine::SearchRequest::Source req, } ret->request = req.release(); ret->setDistributionKey(_distributionKey); + if (ret->request->getTraceLevel() > 0) { + vespalib::asciistream os; + os << "trace-" << _distributionKey; + search::fef::Properties & trace = ret->propertiesMap.lookupCreate(os.str()); + vespalib::SmartBuffer output(4096); + vespalib::slime::BinaryFormat::encode(ret->request->trace().getRoot(), output); + trace.add("slime", output.obtain().make_stringref()); + } client.searchDone(std::move(ret)); } diff --git a/searchlib/src/vespa/searchlib/engine/request.cpp b/searchlib/src/vespa/searchlib/engine/request.cpp index 28cbbae64b8..fd4a46ccc43 100644 --- a/searchlib/src/vespa/searchlib/engine/request.cpp +++ b/searchlib/src/vespa/searchlib/engine/request.cpp @@ -14,7 +14,8 @@ Request::Request(const fastos::TimeStamp &start_time) location(), propertiesMap(), stackItems(0), - stackDump() + stackDump(), + _trace(start_time) { } diff --git a/searchlib/src/vespa/searchlib/engine/request.h b/searchlib/src/vespa/searchlib/engine/request.h index 58c71cd8458..21087d4eff0 100644 --- a/searchlib/src/vespa/searchlib/engine/request.h +++ b/searchlib/src/vespa/searchlib/engine/request.h @@ -12,6 +12,8 @@ class Request { public: Request(const fastos::TimeStamp &start_time); + Request(const Request &) = delete; + Request & operator =(const Request &) = delete; virtual ~Request(); void setTimeout(const fastos::TimeStamp & timeout); fastos::TimeStamp getStartTime() const { return _startTime; } @@ -30,6 +32,7 @@ public: uint32_t getTraceLevel() const { return _traceLevel; } Request & setTraceLevel(uint32_t traceLevel) { _traceLevel = traceLevel; return *this; } + Trace & trace() { return _trace; } private: const fastos::TimeStamp _startTime; fastos::TimeStamp _timeOfDoom; @@ -42,6 +45,8 @@ public: PropertiesMap propertiesMap; uint32_t stackItems; std::vector stackDump; +private: + mutable Trace _trace; }; } -- cgit v1.2.3 From 4869f87c3e5e175f118a68ed24c73c1ccbb72771 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 5 Mar 2019 12:15:01 +0000 Subject: Trace the optimized blueprint. --- .../src/vespa/searchcore/proton/matching/match_tools.h | 1 + .../src/vespa/searchcore/proton/matching/matcher.cpp | 14 ++++++++++++++ searchlib/src/vespa/searchlib/engine/request.h | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) (limited to 'searchlib') diff --git a/searchcore/src/vespa/searchcore/proton/matching/match_tools.h b/searchcore/src/vespa/searchcore/proton/matching/match_tools.h index 0ecf6eb5b78..dfef51bfc5e 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/match_tools.h +++ b/searchcore/src/vespa/searchcore/proton/matching/match_tools.h @@ -132,6 +132,7 @@ public: std::unique_ptr createOnSummaryTask() const; const RequestContext & requestContext() const { return _requestContext; } + const Query & query() const { return _query; } }; } diff --git a/searchcore/src/vespa/searchcore/proton/matching/matcher.cpp b/searchcore/src/vespa/searchcore/proton/matching/matcher.cpp index 382e197c16b..4ebf74c373f 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/matcher.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/matcher.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include LOG_SETUP(".proton.matching.matcher"); @@ -203,6 +204,17 @@ Matcher::computeNumThreadsPerSearch(Blueprint::HitEstimate hits, const Propertie return threads; } +namespace { + void traceQuery(const SearchRequest &request, const Query & query) { + if (request.getTraceLevel() > 3) { + if (query.peekRoot()) { + vespalib::slime::ObjectInserter inserter(request.trace().createCursor("blueprint"), "optimized"); + query.peekRoot()->asSlime(inserter); + } + } + } +} + SearchReply::UP Matcher::match(const SearchRequest &request, vespalib::ThreadBundle &threadBundle, ISearchContext &searchContext, IAttributeContext &attrContext, SessionManager &sessionMgr, @@ -240,6 +252,7 @@ Matcher::match(const SearchRequest &request, vespalib::ThreadBundle &threadBundl if (!mtf->valid()) { reply->errorCode = ECODE_QUERY_PARSE_ERROR; reply->errorMessage = "query execution failed (invalid query)"; + traceQuery(request, mtf->query()); return reply; } @@ -274,6 +287,7 @@ Matcher::match(const SearchRequest &request, vespalib::ThreadBundle &threadBundl sessionMgr.insert(std::move(session)); } reply = std::move(result->_reply); + traceQuery(request, mtf->query()); uint32_t numActiveLids = metaStore.getNumActiveLids(); // note: this is actually totalSpace+1, since 0 is reserved diff --git a/searchlib/src/vespa/searchlib/engine/request.h b/searchlib/src/vespa/searchlib/engine/request.h index 21087d4eff0..521a5be39fc 100644 --- a/searchlib/src/vespa/searchlib/engine/request.h +++ b/searchlib/src/vespa/searchlib/engine/request.h @@ -32,7 +32,7 @@ public: uint32_t getTraceLevel() const { return _traceLevel; } Request & setTraceLevel(uint32_t traceLevel) { _traceLevel = traceLevel; return *this; } - Trace & trace() { return _trace; } + Trace & trace() const { return _trace; } private: const fastos::TimeStamp _startTime; fastos::TimeStamp _timeOfDoom; -- cgit v1.2.3 From 774a725b9d525e6e6be35ed4651d6c0b8d2358c4 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 5 Mar 2019 14:03:39 +0000 Subject: Control traceLevel --- .../src/vespa/searchlib/engine/packetconverter.cpp | 3 +++ searchlib/src/vespa/searchlib/engine/propertiesmap.cpp | 2 +- searchlib/src/vespa/searchlib/fef/indexproperties.cpp | 18 ++++++++++++++++++ searchlib/src/vespa/searchlib/fef/indexproperties.h | 14 ++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) (limited to 'searchlib') diff --git a/searchlib/src/vespa/searchlib/engine/packetconverter.cpp b/searchlib/src/vespa/searchlib/engine/packetconverter.cpp index 8a55af4cfb7..d87d9888aae 100644 --- a/searchlib/src/vespa/searchlib/engine/packetconverter.cpp +++ b/searchlib/src/vespa/searchlib/engine/packetconverter.cpp @@ -1,6 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "packetconverter.h" +#include + #include LOG_SETUP(".engine.packetconverter"); @@ -74,6 +76,7 @@ PacketConverter::toSearchRequest(const QUERYX &packet, SearchRequest &request) request.location = packet._location; request.stackItems = packet._numStackItems; request.stackDump.assign( packet._stackDump.begin(), packet._stackDump.end()); + request.setTraceLevel(search::fef::indexproperties::trace::Level::lookup(request.propertiesMap.modelOverrides())); } void diff --git a/searchlib/src/vespa/searchlib/engine/propertiesmap.cpp b/searchlib/src/vespa/searchlib/engine/propertiesmap.cpp index b09813c0258..4726a3b9c27 100644 --- a/searchlib/src/vespa/searchlib/engine/propertiesmap.cpp +++ b/searchlib/src/vespa/searchlib/engine/propertiesmap.cpp @@ -11,7 +11,7 @@ PropertiesMap::PropertiesMap() : _propertiesMap() { } -PropertiesMap::~PropertiesMap() { } +PropertiesMap::~PropertiesMap() = default; fef::Properties & PropertiesMap::lookupCreate(vespalib::stringref name) diff --git a/searchlib/src/vespa/searchlib/fef/indexproperties.cpp b/searchlib/src/vespa/searchlib/fef/indexproperties.cpp index 5cd6c479d24..fd73ce5a0f0 100644 --- a/searchlib/src/vespa/searchlib/fef/indexproperties.cpp +++ b/searchlib/src/vespa/searchlib/fef/indexproperties.cpp @@ -388,6 +388,24 @@ DiversityCutoffStrategy::lookup(const Properties &props, const vespalib::string return lookupString(props, NAME, defaultValue); } +} + +namespace trace { + +const vespalib::string Level::NAME("tracelevel"); +const uint32_t Level::DEFAULT_VALUE(0); + +uint32_t +Level::lookup(const Properties &props) +{ + return lookup(props, DEFAULT_VALUE); +} + +uint32_t +Level::lookup(const Properties &props, uint32_t defaultValue) +{ + return lookupUint32(props, NAME, defaultValue); +} } diff --git a/searchlib/src/vespa/searchlib/fef/indexproperties.h b/searchlib/src/vespa/searchlib/fef/indexproperties.h index 8b78e347a90..23efe514d68 100644 --- a/searchlib/src/vespa/searchlib/fef/indexproperties.h +++ b/searchlib/src/vespa/searchlib/fef/indexproperties.h @@ -310,6 +310,20 @@ namespace matchphase { } // namespace matchphase +namespace trace { + + /** + * Property for the heap size used in the hit collector. + **/ + struct Level { + static const vespalib::string NAME; + static const uint32_t DEFAULT_VALUE; + static uint32_t lookup(const Properties &props); + static uint32_t lookup(const Properties &props, uint32_t defaultValue); + }; + +} + namespace hitcollector { -- cgit v1.2.3 From f5003a69aa96526f721e4098c1b6dffc49d0c9dc Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Wed, 6 Mar 2019 23:57:46 +0000 Subject: Update copyrigt year. --- searchlib/src/vespa/searchlib/engine/trace.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'searchlib') diff --git a/searchlib/src/vespa/searchlib/engine/trace.h b/searchlib/src/vespa/searchlib/engine/trace.h index 4f2bea680df..68f0103a762 100644 --- a/searchlib/src/vespa/searchlib/engine/trace.h +++ b/searchlib/src/vespa/searchlib/engine/trace.h @@ -1,4 +1,4 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright 2019 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once @@ -24,7 +24,7 @@ public: /** * Will give you a trace entry. It will also add a timestamp relative to the creation of the trace. * @param name - * @return + * @return a Cursor to use for further tracing. */ Cursor & createCursor(vespalib::stringref name); vespalib::string toString() const; -- cgit v1.2.3 From c92495d103205dfebbe0b02c259e7756ae3ce738 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Wed, 6 Mar 2019 23:58:53 +0000 Subject: Update copyrigt year. --- searchlib/src/vespa/searchlib/engine/trace.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'searchlib') diff --git a/searchlib/src/vespa/searchlib/engine/trace.cpp b/searchlib/src/vespa/searchlib/engine/trace.cpp index 381c851f40b..47ccac137f5 100644 --- a/searchlib/src/vespa/searchlib/engine/trace.cpp +++ b/searchlib/src/vespa/searchlib/engine/trace.cpp @@ -1,4 +1,4 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright 2019 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "trace.h" #include @@ -6,7 +6,6 @@ namespace search::engine { - Trace::Trace(const fastos::TimeStamp &start_time) : _trace(std::make_unique()), _root(_trace->setObject()), @@ -22,7 +21,6 @@ Trace::createCursor(vespalib::stringref name) { Cursor & trace = _traces.addObject(); trace.setString("tag", name); return trace; - } vespalib::string -- cgit v1.2.3 From 85371fa5da72ab4c2724e1fd9f1aec79c472f751 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Thu, 7 Mar 2019 00:37:52 +0000 Subject: Put distribution-key in trace payload and name it 'trace'. --- .../com/yahoo/prelude/fastsearch/VespaBackEndSearcher.java | 2 +- .../src/vespa/searchcore/proton/matchengine/matchengine.cpp | 12 ++++-------- searchlib/src/tests/engine/searchapi/searchapi_test.cpp | 8 ++++---- searchlib/src/vespa/searchlib/engine/trace.h | 3 ++- 4 files changed, 11 insertions(+), 14 deletions(-) (limited to 'searchlib') diff --git a/container-search/src/main/java/com/yahoo/prelude/fastsearch/VespaBackEndSearcher.java b/container-search/src/main/java/com/yahoo/prelude/fastsearch/VespaBackEndSearcher.java index f4d98b73a0d..5f055c9ea87 100644 --- a/container-search/src/main/java/com/yahoo/prelude/fastsearch/VespaBackEndSearcher.java +++ b/container-search/src/main/java/com/yahoo/prelude/fastsearch/VespaBackEndSearcher.java @@ -421,7 +421,7 @@ public abstract class VespaBackEndSearcher extends PingableSearcher { if (resultPacket.propsArray == null) return; Value.ArrayValue traces = new Value.ArrayValue(); for (FS4Properties properties : resultPacket.propsArray) { - if ( ! properties.getName().startsWith("trace")) continue; + if ( ! properties.getName().equals("trace")) continue; for (FS4Properties.Entry entry : properties.getEntries()) { if (!entry.key.equals("slime")) continue; traces.add(new SlimeAdapter(BinaryFormat.decode(entry.getValue()).get())); diff --git a/searchcore/src/vespa/searchcore/proton/matchengine/matchengine.cpp b/searchcore/src/vespa/searchcore/proton/matchengine/matchengine.cpp index 0cb50fb00b0..3a28eeb4dfd 100644 --- a/searchcore/src/vespa/searchcore/proton/matchengine/matchengine.cpp +++ b/searchcore/src/vespa/searchcore/proton/matchengine/matchengine.cpp @@ -50,7 +50,6 @@ MatchEngine::MatchEngine(size_t numThreads, size_t threadsPerSearch, uint32_t di _threadBundlePool(std::max(size_t(1), threadsPerSearch)), _nodeUp(false) { - // empty } MatchEngine::~MatchEngine() @@ -106,9 +105,7 @@ MatchEngine::search(search::engine::SearchRequest::Source request, return ret; } - vespalib::Executor::Task::UP task; - task.reset(new SearchTask(*this, std::move(request), client)); - _executor.execute(std::move(task)); + _executor.execute(std::make_unique(*this, std::move(request), client)); return search::engine::SearchReply::UP(); } @@ -144,11 +141,10 @@ MatchEngine::performSearch(search::engine::SearchRequest::Source req, ret->request = req.release(); ret->setDistributionKey(_distributionKey); if (ret->request->getTraceLevel() > 0) { - vespalib::asciistream os; - os << "trace-" << _distributionKey; - search::fef::Properties & trace = ret->propertiesMap.lookupCreate(os.str()); + ret->request->trace().getRoot().setLong("distribution-key", _distributionKey); + search::fef::Properties & trace = ret->propertiesMap.lookupCreate("trace"); vespalib::SmartBuffer output(4096); - vespalib::slime::BinaryFormat::encode(ret->request->trace().getRoot(), output); + vespalib::slime::BinaryFormat::encode(ret->request->trace().getSlime(), output); trace.add("slime", output.obtain().make_stringref()); } client.searchDone(std::move(ret)); diff --git a/searchlib/src/tests/engine/searchapi/searchapi_test.cpp b/searchlib/src/tests/engine/searchapi/searchapi_test.cpp index f06ce5c188c..626435360a0 100644 --- a/searchlib/src/tests/engine/searchapi/searchapi_test.cpp +++ b/searchlib/src/tests/engine/searchapi/searchapi_test.cpp @@ -241,7 +241,7 @@ TEST("verify trace") { " ]," " creation_time: 7" "}", - t.getRoot()); + t.getSlime()); t.createCursor("tag_a"); verify("{" @@ -252,7 +252,7 @@ TEST("verify trace") { " ]," " creation_time: 7" "}", - t.getRoot()); + t.getSlime()); Trace::Cursor & tagB = t.createCursor("tag_b"); tagB.setLong("long", 19); verify("{" @@ -267,7 +267,7 @@ TEST("verify trace") { " ]," " creation_time: 7" "}", - t.getRoot()); + t.getSlime()); } -TEST_MAIN() { TEST_RUN_ALL(); } \ No newline at end of file +TEST_MAIN() { TEST_RUN_ALL(); } diff --git a/searchlib/src/vespa/searchlib/engine/trace.h b/searchlib/src/vespa/searchlib/engine/trace.h index 68f0103a762..5ebae8ad03b 100644 --- a/searchlib/src/vespa/searchlib/engine/trace.h +++ b/searchlib/src/vespa/searchlib/engine/trace.h @@ -28,7 +28,8 @@ public: */ Cursor & createCursor(vespalib::stringref name); vespalib::string toString() const; - vespalib::Slime & getRoot() const { return *_trace; } + Cursor & getRoot() const { return _root; } + vespalib::Slime & getSlime() const { return *_trace; } private: std::unique_ptr _trace; Cursor & _root; -- cgit v1.2.3 From b97b0e995a431bd3dc57a56ba2cc77aaced8555c Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Thu, 7 Mar 2019 11:49:21 +0000 Subject: Oath license --- searchlib/src/vespa/searchlib/engine/trace.cpp | 2 +- searchlib/src/vespa/searchlib/engine/trace.h | 2 +- staging_vespalib/src/vespa/vespalib/objects/object2slime.cpp | 3 ++- staging_vespalib/src/vespa/vespalib/objects/object2slime.h | 3 ++- 4 files changed, 6 insertions(+), 4 deletions(-) (limited to 'searchlib') diff --git a/searchlib/src/vespa/searchlib/engine/trace.cpp b/searchlib/src/vespa/searchlib/engine/trace.cpp index 47ccac137f5..e12fb9affa6 100644 --- a/searchlib/src/vespa/searchlib/engine/trace.cpp +++ b/searchlib/src/vespa/searchlib/engine/trace.cpp @@ -1,4 +1,4 @@ -// Copyright 2019 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "trace.h" #include diff --git a/searchlib/src/vespa/searchlib/engine/trace.h b/searchlib/src/vespa/searchlib/engine/trace.h index 5ebae8ad03b..09d61c0f199 100644 --- a/searchlib/src/vespa/searchlib/engine/trace.h +++ b/searchlib/src/vespa/searchlib/engine/trace.h @@ -1,4 +1,4 @@ -// Copyright 2019 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once diff --git a/staging_vespalib/src/vespa/vespalib/objects/object2slime.cpp b/staging_vespalib/src/vespa/vespalib/objects/object2slime.cpp index dc2bc3ef01c..184ae768908 100644 --- a/staging_vespalib/src/vespa/vespalib/objects/object2slime.cpp +++ b/staging_vespalib/src/vespa/vespalib/objects/object2slime.cpp @@ -1,4 +1,5 @@ -// Copyright 2019 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + #include "object2slime.h" #include #include diff --git a/staging_vespalib/src/vespa/vespalib/objects/object2slime.h b/staging_vespalib/src/vespa/vespalib/objects/object2slime.h index 50d22b29969..4c1ee660502 100644 --- a/staging_vespalib/src/vespa/vespalib/objects/object2slime.h +++ b/staging_vespalib/src/vespa/vespalib/objects/object2slime.h @@ -1,4 +1,5 @@ -// Copyright 2019 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + #pragma once #include "objectvisitor.h" -- cgit v1.2.3 From a2eb3e7243ce88153fdac4d126999141d37c33e3 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Thu, 7 Mar 2019 12:29:08 +0000 Subject: Unify root and children and drop a level --- .../tests/queryeval/blueprint/blueprint_test.cpp | 87 +++++++++++----------- .../src/vespa/vespalib/objects/object2slime.cpp | 11 +-- 2 files changed, 49 insertions(+), 49 deletions(-) (limited to 'searchlib') diff --git a/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp b/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp index 0d34b41d5c7..108b7b9d20d 100644 --- a/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp +++ b/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp @@ -703,50 +703,49 @@ getExpectedBlueprint() vespalib::string getExpectedSlimeBlueprint() { return "{" - " '(anonymous namespace)::MyOr': {" - " isTermLike: true," - " fields: {" - " '[type]': 'FieldList'," - " '[0]': {" - " '[type]': 'Field'," - " fieldId: 5," - " handle: 7," - " isFilter: false" - " }" - " }," - " estimate: {" - " '[type]': 'HitEstimate'," - " empty: false," - " estHits: 9," - " tree_size: 2," - " allow_termwise_eval: 0" - " }," - " sourceId: 4294967295," - " docid_limit: 0," - " children: {" - " '[type]': 'std::vector'," - " '[0]': {" - " isTermLike: true," - " fields: {" - " '[type]': 'FieldList'," - " '[0]': {" - " '[type]': 'Field'," - " fieldId: 5," - " handle: 7," - " isFilter: false" - " }" - " }," - " '[type]': '(anonymous namespace)::MyTerm'," - " estimate: {" - " '[type]': 'HitEstimate'," - " empty: false," - " estHits: 9," - " tree_size: 1," - " allow_termwise_eval: 1" - " }," - " sourceId: 4294967295," - " docid_limit: 0" - " }" + " '[type]': '(anonymous namespace)::MyOr'," + " isTermLike: true," + " fields: {" + " '[type]': 'FieldList'," + " '[0]': {" + " '[type]': 'Field'," + " fieldId: 5," + " handle: 7," + " isFilter: false" + " }" + " }," + " estimate: {" + " '[type]': 'HitEstimate'," + " empty: false," + " estHits: 9," + " tree_size: 2," + " allow_termwise_eval: 0" + " }," + " sourceId: 4294967295," + " docid_limit: 0," + " children: {" + " '[type]': 'std::vector'," + " '[0]': {" + " isTermLike: true," + " fields: {" + " '[type]': 'FieldList'," + " '[0]': {" + " '[type]': 'Field'," + " fieldId: 5," + " handle: 7," + " isFilter: false" + " }" + " }," + " '[type]': '(anonymous namespace)::MyTerm'," + " estimate: {" + " '[type]': 'HitEstimate'," + " empty: false," + " estHits: 9," + " tree_size: 1," + " allow_termwise_eval: 1" + " }," + " sourceId: 4294967295," + " docid_limit: 0" " }" " }" "}"; diff --git a/staging_vespalib/src/vespa/vespalib/objects/object2slime.cpp b/staging_vespalib/src/vespa/vespalib/objects/object2slime.cpp index 184ae768908..562f332fb89 100644 --- a/staging_vespalib/src/vespa/vespalib/objects/object2slime.cpp +++ b/staging_vespalib/src/vespa/vespalib/objects/object2slime.cpp @@ -19,11 +19,10 @@ Object2Slime::~Object2Slime() = default; void Object2Slime::openStruct(const vespalib::string &name, const vespalib::string &type) { - _stack.push_back(_cursor); - if (name.empty()) { - _cursor = _cursor.get().setObject(type); + _cursor.get().setString("[type]", type); } else { + _stack.push_back(_cursor); _cursor = _cursor.get().setObject(name); _cursor.get().setString("[type]", type); } @@ -32,8 +31,10 @@ Object2Slime::openStruct(const vespalib::string &name, const vespalib::string &t void Object2Slime::closeStruct() { - _cursor = _stack.back(); - _stack.pop_back(); + if ( ! _stack.empty()) { + _cursor = _stack.back(); + _stack.pop_back(); + } } void -- cgit v1.2.3