From 3b22ac90c3c55128963bf29702604549ed651549 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 24 Mar 2020 12:18:51 +0000 Subject: - Avoid adding empty traces that you need to carry on. - Avoid copying shared pointers when not necessary. - Some c++11 improvements. --- messagebus/src/tests/routeparser/routeparser.cpp | 61 +++++-------- .../src/vespa/messagebus/network/rpcsendv2.cpp | 7 +- messagebus/src/vespa/messagebus/routable.cpp | 2 +- messagebus/src/vespa/messagebus/routing/hop.cpp | 30 +------ messagebus/src/vespa/messagebus/routing/hop.h | 23 ++--- .../src/vespa/messagebus/routing/hopblueprint.cpp | 17 +--- .../src/vespa/messagebus/routing/hopblueprint.h | 8 -- .../src/vespa/messagebus/routing/routeparser.cpp | 6 +- .../vespa/messagebus/routing/routingcontext.cpp | 11 ++- .../src/vespa/messagebus/routing/routingnode.cpp | 99 +++++++++------------- messagebus/src/vespa/messagebus/trace.h | 4 +- messagebus/src/vespa/messagebus/tracenode.h | 11 --- 12 files changed, 94 insertions(+), 185 deletions(-) delete mode 100644 messagebus/src/vespa/messagebus/tracenode.h (limited to 'messagebus') diff --git a/messagebus/src/tests/routeparser/routeparser.cpp b/messagebus/src/tests/routeparser/routeparser.cpp index eb72b03e76a..12054c6c494 100644 --- a/messagebus/src/tests/routeparser/routeparser.cpp +++ b/messagebus/src/tests/routeparser/routeparser.cpp @@ -29,11 +29,11 @@ public: private: bool testError(const Route &route, const string &msg); bool testError(const Hop &hop, const string &msg); - bool testErrorDirective(IHopDirective::SP dir, const string &msg); - bool testPolicyDirective(IHopDirective::SP dir, const string &name, const string ¶m); - bool testRouteDirective(IHopDirective::SP dir, const string &name); - bool testTcpDirective(IHopDirective::SP dir, const string &host, uint32_t port, const string &session); - bool testVerbatimDirective(IHopDirective::SP dir, const string &image); + bool testErrorDirective(const IHopDirective & dir, const string &msg); + bool testPolicyDirective(const IHopDirective & dir, const string &name, const string ¶m); + bool testRouteDirective(const IHopDirective & dir, const string &name); + bool testTcpDirective(const IHopDirective & dir, const string &host, uint32_t port, const string &session); + bool testVerbatimDirective(const IHopDirective & dir, const string &image); }; TEST_APPHOOK(Test); @@ -77,84 +77,69 @@ Test::testError(const Hop &hop, const string &msg) } bool -Test::testErrorDirective(IHopDirective::SP dir, const string &msg) +Test::testErrorDirective(const IHopDirective & dir, const string &msg) { - if (!EXPECT_TRUE(dir.get() != NULL)) { + if (!EXPECT_EQUAL(IHopDirective::TYPE_ERROR, dir.getType())) { return false; } - if (!EXPECT_EQUAL(IHopDirective::TYPE_ERROR, dir->getType())) { - return false; - } - if (!EXPECT_EQUAL(msg, static_cast(*dir).getMessage())) { + if (!EXPECT_EQUAL(msg, static_cast(dir).getMessage())) { return false; } return true; } bool -Test::testPolicyDirective(IHopDirective::SP dir, const string &name, const string ¶m) +Test::testPolicyDirective(const IHopDirective & dir, const string &name, const string ¶m) { - if (!EXPECT_TRUE(dir.get() != NULL)) { + if (!EXPECT_EQUAL(IHopDirective::TYPE_POLICY, dir.getType())) { return false; } - if (!EXPECT_EQUAL(IHopDirective::TYPE_POLICY, dir->getType())) { + if (!EXPECT_EQUAL(name, static_cast(dir).getName())) { return false; } - if (!EXPECT_EQUAL(name, static_cast(*dir).getName())) { - return false; - } - if (!EXPECT_EQUAL(param, static_cast(*dir).getParam())) { + if (!EXPECT_EQUAL(param, static_cast(dir).getParam())) { return false; } return true; } bool -Test::testRouteDirective(IHopDirective::SP dir, const string &name) +Test::testRouteDirective(const IHopDirective & dir, const string &name) { - if (!EXPECT_TRUE(dir.get() != NULL)) { - return false; - } - if (!EXPECT_EQUAL(IHopDirective::TYPE_ROUTE, dir->getType())) { + if (!EXPECT_EQUAL(IHopDirective::TYPE_ROUTE, dir.getType())) { return false; } - if (!EXPECT_EQUAL(name, static_cast(*dir).getName())) { + if (!EXPECT_EQUAL(name, static_cast(dir).getName())) { return false; } return true; } bool -Test::testTcpDirective(IHopDirective::SP dir, const string &host, uint32_t port, const string &session) +Test::testTcpDirective(const IHopDirective & dir, const string &host, uint32_t port, const string &session) { - if (!EXPECT_TRUE(dir.get() != NULL)) { - return false; - } - if (!EXPECT_EQUAL(IHopDirective::TYPE_TCP, dir->getType())) { + if (!EXPECT_EQUAL(IHopDirective::TYPE_TCP, dir.getType())) { return false; } - if (!EXPECT_EQUAL(host, static_cast(*dir).getHost())) { + if (!EXPECT_EQUAL(host, static_cast(dir).getHost())) { return false; } - if (!EXPECT_EQUAL(port, static_cast(*dir).getPort())) { + if (!EXPECT_EQUAL(port, static_cast(dir).getPort())) { return false; } - if (!EXPECT_EQUAL(session, static_cast(*dir).getSession())) { + if (!EXPECT_EQUAL(session, static_cast(dir).getSession())) { return false; } return true; } bool -Test::testVerbatimDirective(IHopDirective::SP dir, const string &image) +Test::testVerbatimDirective(const IHopDirective & dir, const string &image) { - if (!EXPECT_TRUE(dir.get() != NULL)) { - return false; - } - if (!EXPECT_EQUAL(IHopDirective::TYPE_VERBATIM, dir->getType())) { + if (!EXPECT_EQUAL(IHopDirective::TYPE_VERBATIM, dir.getType())) { return false; } - if (!EXPECT_EQUAL(image, static_cast(*dir).getImage())) { + if (!EXPECT_EQUAL(image, static_cast(dir).getImage())) { return false; } return true; diff --git a/messagebus/src/vespa/messagebus/network/rpcsendv2.cpp b/messagebus/src/vespa/messagebus/network/rpcsendv2.cpp index 3b0c10500b9..6afa1528092 100644 --- a/messagebus/src/vespa/messagebus/network/rpcsendv2.cpp +++ b/messagebus/src/vespa/messagebus/network/rpcsendv2.cpp @@ -207,7 +207,7 @@ RPCSendV2::createReply(const FRT_Values & ret, const string & serviceName, reply = decode(root[PROTOCOL_F].asString().make_stringref(), version, BlobRef(payload.data, payload.size), error); } if ( ! reply ) { - reply.reset(new EmptyReply()); + reply = std::make_unique(); } reply->setRetryDelay(root[RETRYDELAY_F].asDouble()); Inspector & errors = root[ERRORS_F]; @@ -217,7 +217,10 @@ RPCSendV2::createReply(const FRT_Values & ret, const string & serviceName, reply->addError(Error(e[CODE_F].asLong(), e[MSG_F].asString().make_string(), (service.size > 0) ? service.make_string() : serviceName)); } - rootTrace.addChild(TraceNode::decode(root[TRACE_F].asString().make_string())); + Inspector & trace = root[TRACE_F]; + if (trace.valid() && (trace.asString().size > 0)) { + rootTrace.addChild(TraceNode::decode(trace.asString().make_string())); + } return reply; } diff --git a/messagebus/src/vespa/messagebus/routable.cpp b/messagebus/src/vespa/messagebus/routable.cpp index 6c62d7e75ca..801029c5bc7 100644 --- a/messagebus/src/vespa/messagebus/routable.cpp +++ b/messagebus/src/vespa/messagebus/routable.cpp @@ -11,7 +11,7 @@ Routable::Routable() : _trace() { } -Routable::~Routable() { } +Routable::~Routable() = default; void Routable::discard() diff --git a/messagebus/src/vespa/messagebus/routing/hop.cpp b/messagebus/src/vespa/messagebus/routing/hop.cpp index 232ae9f840a..76f58d57d7b 100644 --- a/messagebus/src/vespa/messagebus/routing/hop.cpp +++ b/messagebus/src/vespa/messagebus/routing/hop.cpp @@ -25,41 +25,19 @@ Hop::Hop(std::vector selector, bool ignoreResult) : Hop::Hop(const Hop &) = default; Hop & Hop::operator = (const Hop &) = default; -Hop::~Hop() { } +Hop::~Hop() = default; Hop & Hop::addDirective(IHopDirective::SP dir) { - _selector.push_back(dir); + _selector.emplace_back(std::move(dir)); return *this; } Hop & Hop::setDirective(uint32_t i, IHopDirective::SP dir) { - _selector[i] = dir; - return *this; -} - -IHopDirective::SP -Hop::removeDirective(uint32_t i) -{ - IHopDirective::SP ret = _selector[i]; - _selector.erase(_selector.begin() + i); - return ret; -} - -Hop & -Hop::clearDirectives() -{ - _selector.clear(); - return *this; -} - -Hop & -Hop::setIgnoreResult(bool ignoreResult) -{ - _ignoreResult = ignoreResult; + _selector[i] = std::move(dir); return *this; } @@ -76,7 +54,7 @@ Hop::matches(const Hop &hop) const return false; } for (uint32_t i = 0; i < hop.getNumDirectives(); ++i) { - if (!_selector[i]->matches(*hop.getDirective(i))) { + if (!_selector[i]->matches(hop.getDirective(i))) { return false; } } diff --git a/messagebus/src/vespa/messagebus/routing/hop.h b/messagebus/src/vespa/messagebus/routing/hop.h index 6e7ab94caa1..94140bdd953 100644 --- a/messagebus/src/vespa/messagebus/routing/hop.h +++ b/messagebus/src/vespa/messagebus/routing/hop.h @@ -77,7 +77,8 @@ public: * @param i The index of the directive to return. * @return The item. */ - IHopDirective::SP getDirective(uint32_t i) const { return _selector[i]; } + const IHopDirective & getDirective(uint32_t i) const { return *_selector[i]; } + IHopDirective::SP getDirectiveSP(uint32_t i) const { return _selector[i]; } /** * Sets the directive at a given index. @@ -88,21 +89,6 @@ public: */ Hop &setDirective(uint32_t i, IHopDirective::SP dir); - /** - * Removes the directive at the given index. - * - * @param i The index of the directive to remove. - * @return The removed directive. - */ - IHopDirective::SP removeDirective(uint32_t i); - - /** - * Clears all directives from this hop. - * - * @return This, to allow chaining. - */ - Hop &clearDirectives(); - /** * Returns the service name referenced by this hop. This is the concatenation of all selector primitives, * but with no ignore-result prefix. @@ -124,7 +110,10 @@ public: * @param ignoreResult Whether or not to ignore the result. * @return This, to allow chaining. */ - Hop &setIgnoreResult(bool ignoreResult); + Hop &setIgnoreResult(bool ignoreResult) { + _ignoreResult = ignoreResult; + return *this; + } /** * Parses the given string as a single hop. The {@link this#toString()} method is compatible with this parser. diff --git a/messagebus/src/vespa/messagebus/routing/hopblueprint.cpp b/messagebus/src/vespa/messagebus/routing/hopblueprint.cpp index 0bd9aaa6c50..b9d6780fd63 100644 --- a/messagebus/src/vespa/messagebus/routing/hopblueprint.cpp +++ b/messagebus/src/vespa/messagebus/routing/hopblueprint.cpp @@ -11,26 +11,17 @@ HopBlueprint::HopBlueprint(const HopSpec &spec) : { Hop hop = Hop::parse(spec.getSelector()); for (uint32_t i = 0; i < hop.getNumDirectives(); ++i) { - _selector.push_back(hop.getDirective(i)); + _selector.emplace_back(hop.getDirectiveSP(i)); } std::vector lst; for (uint32_t i = 0; i < spec.getNumRecipients(); ++i) { - lst.push_back(spec.getRecipient(i)); + lst.emplace_back(spec.getRecipient(i)); } - for (std::vector::iterator it = lst.begin(); - it != lst.end(); ++it) - { - _recipients.push_back(Hop::parse(*it)); + for (const string & recipient : lst) { + _recipients.emplace_back(Hop::parse(recipient)); } } -HopBlueprint & -HopBlueprint::setIgnoreResult(bool ignoreResult) -{ - _ignoreResult = ignoreResult; - return *this; -} - string HopBlueprint::toString() const { diff --git a/messagebus/src/vespa/messagebus/routing/hopblueprint.h b/messagebus/src/vespa/messagebus/routing/hopblueprint.h index 1ae8def398d..21b449651f1 100644 --- a/messagebus/src/vespa/messagebus/routing/hopblueprint.h +++ b/messagebus/src/vespa/messagebus/routing/hopblueprint.h @@ -83,14 +83,6 @@ public: */ bool getIgnoreResult() const { return _ignoreResult; } - /** - * Sets whether or not to ignore the result when routing through this hop. - * - * @param ignoreResult Whether or not to ignore the result. - * @return This, to allow chaining. - */ - HopBlueprint &setIgnoreResult(bool ignoreResult); - /** * Returns a string representation of this. * diff --git a/messagebus/src/vespa/messagebus/routing/routeparser.cpp b/messagebus/src/vespa/messagebus/routing/routeparser.cpp index 88d5d6e4a0f..c9c10b38014 100644 --- a/messagebus/src/vespa/messagebus/routing/routeparser.cpp +++ b/messagebus/src/vespa/messagebus/routing/routeparser.cpp @@ -85,8 +85,8 @@ RouteParser::createHop(stringref str) } if (len > 4 && str.substr(0, 4) == "tcp/") { IHopDirective::SP tcp = createTcpDirective(str.substr(4)); - if (tcp.get() != nullptr) { - return Hop().addDirective(tcp); + if (tcp) { + return Hop().addDirective(std::move(tcp)); } } if (len > 6 && str.substr(0, 6) == "route:") { @@ -128,7 +128,7 @@ RouteParser::createRoute(stringref str) if (from < at - 1) { Hop hop = createHop(str.substr(from, at - from)); if (hop.hasDirectives() && - hop.getDirective(0)->getType() == IHopDirective::TYPE_ERROR) + hop.getDirective(0).getType() == IHopDirective::TYPE_ERROR) { return std::move(Route().addHop(std::move(hop))); } diff --git a/messagebus/src/vespa/messagebus/routing/routingcontext.cpp b/messagebus/src/vespa/messagebus/routing/routingcontext.cpp index 12aaa160eab..3da0ad700a3 100644 --- a/messagebus/src/vespa/messagebus/routing/routingcontext.cpp +++ b/messagebus/src/vespa/messagebus/routing/routingcontext.cpp @@ -44,14 +44,13 @@ RoutingContext::getMatchedRecipients(std::vector &ret) const std::set done; const std::vector &recipients = _node.getRecipients(); const Hop &hop = getHop(); - for (std::vector::const_iterator it = recipients.begin(); - it != recipients.end(); ++it) + for (const Route & recipient : recipients) { - if (it->hasHops() && hop.matches(it->getHop(0))) { - IHopDirective::SP dir = it->getHop(0).getDirective(_directive); + if (recipient.hasHops() && hop.matches(recipient.getHop(0))) { + IHopDirective::SP dir = recipient.getHop(0).getDirectiveSP(_directive); string key = dir->toString(); if (done.find(key) == done.end()) { - Route add = *it; + Route add = recipient; add.setHop(0, hop); add.getHop(0).setDirective(_directive, std::move(dir)); ret.push_back(std::move(add)); @@ -95,7 +94,7 @@ RoutingContext::getDirectiveIndex() const const PolicyDirective & RoutingContext::getDirective() const { - return static_cast(*getHop().getDirective(_directive)); + return static_cast(getHop().getDirective(_directive)); } string diff --git a/messagebus/src/vespa/messagebus/routing/routingnode.cpp b/messagebus/src/vespa/messagebus/routing/routingnode.cpp index b5b99ea43c2..77a164eddf9 100644 --- a/messagebus/src/vespa/messagebus/routing/routingnode.cpp +++ b/messagebus/src/vespa/messagebus/routing/routingnode.cpp @@ -67,10 +67,8 @@ RoutingNode::~RoutingNode() void RoutingNode::clearChildren() { - for (std::vector::iterator it = _children.begin(); - it != _children.end(); ++it) - { - delete *it; + for (auto child : _children) { + delete child; } _children.clear(); } @@ -101,15 +99,12 @@ RoutingNode::prepareForRetry() { _shouldRetry = false; _reply.reset(); - if (_routingContext.get() != nullptr && _routingContext->getSelectOnRetry()) { + if (_routingContext && _routingContext->getSelectOnRetry()) { clearChildren(); } else if (!_children.empty()) { bool retryingSome = false; - for (std::vector::iterator it = _children.begin(); - it != _children.end(); ++it) - { - RoutingNode *child= *it; - if (child->_shouldRetry || child->_reply.get() == nullptr) { + for (auto child : _children) { + if (child->_shouldRetry || ! child->_reply) { child->prepareForRetry(); retryingSome = true; } @@ -159,7 +154,7 @@ RoutingNode::setError(uint32_t code, const string &msg) void RoutingNode::setError(const Error &err) { - Reply::UP reply(new EmptyReply()); + auto reply = std::make_unique(); reply->getTrace().setLevel(_trace.getLevel()); reply->addError(err); setReply(std::move(reply)); @@ -188,8 +183,10 @@ RoutingNode::setReply(Reply::UP reply) { if (reply) { _shouldRetry = _resender != nullptr && _resender->shouldRetry(*reply); - _trace.getRoot().addChild(std::move(reply->getTrace().getRoot())); - reply->getTrace().clear(); + if ( ! reply->getTrace().getRoot().isEmpty()) { + _trace.getRoot().addChild(std::move(reply->getTrace().getRoot())); + reply->getTrace().clear(); + } } _reply = std::move(reply); } @@ -211,16 +208,14 @@ RoutingNode::notifyAbort(const string &msg) mystack.pop(); if (!node->_isActive) { // reply not pending - } else if (node->_reply.get() != nullptr) { + } else if (node->_reply) { node->notifyParent(); } else if (node->_children.empty()) { node->setError(ErrorCode::SEND_ABORTED, msg); node->notifyParent(); } else { - for (std::vector::iterator it = node->_children.begin(); - it != node->_children.end(); ++it) - { - mystack.push(*it); + for (auto child : node->_children) { + mystack.push(child); } } } @@ -240,14 +235,12 @@ RoutingNode::notifyTransmit() if (node->hasReply()) { node->notifyParent(); } else { - assert(node->_serviceAddress.get() != nullptr); + assert(node->_serviceAddress); sendTo.push_back(node); } } else { - for (std::vector::iterator it = node->_children.begin(); - it != node->_children.end(); ++it) - { - mystack.push(*it); + for (auto child : node->_children) { + mystack.push(child); } } } @@ -275,10 +268,8 @@ RoutingNode::notifyMerge() // manipulating the trace in case tracing is disabled. if (_trace.getLevel() > 0) { TraceNode tail; - for (std::vector::iterator it = _children.begin(); - it != _children.end(); ++it) - { - TraceNode &root = (*it)->_trace.getRoot(); + for (auto child : _children) { + TraceNode &root = child->_trace.getRoot(); tail.addChild(root); root.clear(); } @@ -296,7 +287,7 @@ RoutingNode::notifyMerge() setError(ErrorCode::POLICY_ERROR, make_string("Policy '%s' threw an exception; %s", dir.getName().c_str(), e.what())); } - if (_reply.get() == nullptr) { + if ( ! _reply) { setError(ErrorCode::APP_FATAL_ERROR, make_string("Routing policy '%s' failed to merge replies.", dir.getName().c_str())); } @@ -315,12 +306,12 @@ RoutingNode::hasUnconsumedErrors() while (!mystack.empty()) { RoutingNode *node = mystack.top(); mystack.pop(); - if (node->_reply.get() != nullptr) { + if (node->_reply) { for (uint32_t i = 0; i < node->_reply->getNumErrors(); ++i) { int errorCode = node->_reply->getError(i).getCode(); RoutingNode *it = node; while (it != nullptr) { - if (it->_routingContext.get() != nullptr && + if (it->_routingContext && it->_routingContext->isConsumableError(errorCode)) { errorCode = ErrorCode::NONE; @@ -337,10 +328,8 @@ RoutingNode::hasUnconsumedErrors() } } } else { - for (std::vector::iterator it = node->_children.begin(); - it != node->_children.end(); ++it) - { - mystack.push(*it); + for (auto child : node->_children) { + mystack.push(child); } } } @@ -374,17 +363,17 @@ RoutingNode::resolve(uint32_t depth) if (executePolicySelect()) { return resolveChildren(depth + 1); } - return _reply.get() != nullptr; + return bool(_reply); } _net.allocServiceAddress(*this); - return _serviceAddress.get() != nullptr || _reply.get() != nullptr; + return _serviceAddress || _reply; } bool RoutingNode::lookupHop() { RoutingTable::SP table = _mbus.getRoutingTable(_msg.getProtocol()); - if (table.get() != nullptr) { + if (table) { string name = _route.getHop(0).getServiceName(); if (table->hasHop(name)) { const HopBlueprint *hop = table->getHop(name); @@ -402,8 +391,9 @@ RoutingNode::lookupRoute() { RoutingTable::SP table = _mbus.getRoutingTable(_msg.getProtocol()); Hop &hop = _route.getHop(0); - if (hop.getDirective(0)->getType() == IHopDirective::TYPE_ROUTE) { - RouteDirective &dir = static_cast(*hop.getDirective(0)); + const RouteDirective &dir = static_cast(hop.getDirective(0)); + if (dir.getType() == IHopDirective::TYPE_ROUTE) { + if (!table || !table->hasRoute(dir.getName())) { setError(ErrorCode::ILLEGAL_ROUTE, make_string("Route '%s' does not exist.", dir.getName().c_str())); return false; @@ -443,10 +433,10 @@ RoutingNode::findErrorDirective() { Hop &hop = _route.getHop(0); for (uint32_t i = 0; i < hop.getNumDirectives(); ++i) { - IHopDirective::SP dir = hop.getDirective(i); - if (dir->getType() == IHopDirective::TYPE_ERROR) { + const IHopDirective & dir = hop.getDirective(i); + if (dir.getType() == IHopDirective::TYPE_ERROR) { setError(ErrorCode::ILLEGAL_ROUTE, - static_cast(*dir).getMessage()); + static_cast(dir).getMessage()); return true; } } @@ -458,9 +448,8 @@ RoutingNode::findPolicyDirective() { Hop &hop = _route.getHop(0); for (uint32_t i = 0; i < hop.getNumDirectives(); ++i) { - IHopDirective::SP dir = hop.getDirective(i); - if (dir->getType() == IHopDirective::TYPE_POLICY) { - _routingContext.reset(new RoutingContext(*this, i)); + if (hop.getDirective(i).getType() == IHopDirective::TYPE_POLICY) { + _routingContext = std::make_unique(*this, i); return true; } } @@ -472,7 +461,7 @@ RoutingNode::executePolicySelect() { const PolicyDirective &dir = _routingContext->getDirective(); _policy = _mbus.getRoutingPolicy(_msg.getProtocol(), dir.getName(), dir.getParam()); - if (_policy.get() == nullptr) { + if ( ! _policy) { setError(ErrorCode::UNKNOWN_POLICY, make_string( "Protocol '%s' could not create routing policy '%s' with parameter '%s'.", _msg.getProtocol().c_str(), dir.getName().c_str(), dir.getParam().c_str())); @@ -487,7 +476,7 @@ RoutingNode::executePolicySelect() return false; } if (_children.empty()) { - if (_reply.get() == nullptr) { + if ( ! _reply) { setError(ErrorCode::NO_SERVICES_FOR_ROUTE, make_string("Policy '%s' selected no recipients for route '%s'.", dir.getName().c_str(), _route.toString().c_str())); @@ -497,10 +486,7 @@ RoutingNode::executePolicySelect() } return false; } - for (std::vector::iterator it = _children.begin(); - it != _children.end(); ++it) - { - RoutingNode *child = *it; + for (auto child : _children) { Hop &hop = child->_route.getHop(0); child->_trace.trace(TraceLevel::SPLIT_MERGE, make_string("Component '%s' selected by policy '%s'.", @@ -514,13 +500,10 @@ RoutingNode::resolveChildren(uint32_t childDepth) { int numActiveChildren = 0; bool ret = true; - for (std::vector::iterator it = _children.begin(); - it != _children.end(); ++it) - { - RoutingNode *child = *it; + for (auto child : _children) { child->_trace.trace(TraceLevel::SPLIT_MERGE, make_string("Resolving '%s'.", child->_route.toString().c_str())); - child->_isActive = (child->_reply.get() == nullptr); + child->_isActive = ! child->_reply; if (child->_isActive) { ++numActiveChildren; if (!child->resolve(childDepth)) { @@ -560,10 +543,10 @@ RoutingNode::tryIgnoreResult() if (!shouldIgnoreResult()) { return false; } - if (_reply.get() == nullptr || !_reply->hasErrors()) { + if ( ! _reply || !_reply->hasErrors()) { return false; } - setReply(Reply::UP(new EmptyReply())); + setReply(std::make_unique()); _trace.trace(TraceLevel::SPLIT_MERGE, "Ignoring errors in reply."); return true; } diff --git a/messagebus/src/vespa/messagebus/trace.h b/messagebus/src/vespa/messagebus/trace.h index a5f02ea2fa4..5a26cb68e46 100644 --- a/messagebus/src/vespa/messagebus/trace.h +++ b/messagebus/src/vespa/messagebus/trace.h @@ -3,11 +3,11 @@ #pragma once #include -#include namespace mbus { - typedef vespalib::Trace Trace; + using Trace = vespalib::Trace; + using TraceNode = vespalib::TraceNode; #define MBUS_TRACE2(ttrace, level, note, addTime) \ VESPALIB_TRACE2(ttrace, level, note, addTime) diff --git a/messagebus/src/vespa/messagebus/tracenode.h b/messagebus/src/vespa/messagebus/tracenode.h deleted file mode 100644 index f582a70a151..00000000000 --- a/messagebus/src/vespa/messagebus/tracenode.h +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#pragma once - -#include - -namespace mbus { - - using TraceNode = vespalib::TraceNode; - -} // namespace mbus - -- cgit v1.2.3