From 28cab783cf426758b4f878fcc523fddfef52eb6d Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Mon, 24 Jul 2017 14:57:51 +0000 Subject: make_vespa_string -> make_string. --- messagebus/src/vespa/messagebus/error.cpp | 4 ++-- .../src/vespa/messagebus/network/rpcnetwork.cpp | 19 +++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/messagebus/src/vespa/messagebus/error.cpp b/messagebus/src/vespa/messagebus/error.cpp index 5e5aed85f29..7a7785a853f 100644 --- a/messagebus/src/vespa/messagebus/error.cpp +++ b/messagebus/src/vespa/messagebus/error.cpp @@ -24,9 +24,9 @@ Error::toString() const { string name(ErrorCode::getName(_code)); if (name.empty()) { - name = vespalib::make_vespa_string("%u", _code); + name = vespalib::make_string("%u", _code); } - return vespalib::make_vespa_string("[%s @ %s]: %s", name.c_str(), + return vespalib::make_string("[%s @ %s]: %s", name.c_str(), _service.empty() ? "localhost" : _service.c_str(), _msg.c_str()); } diff --git a/messagebus/src/vespa/messagebus/network/rpcnetwork.cpp b/messagebus/src/vespa/messagebus/network/rpcnetwork.cpp index e5851bb3c4c..20edbd084e5 100644 --- a/messagebus/src/vespa/messagebus/network/rpcnetwork.cpp +++ b/messagebus/src/vespa/messagebus/network/rpcnetwork.cpp @@ -9,11 +9,14 @@ #include #include #include +#include #include #include LOG_SETUP(".rpcnetwork"); +using vespalib::make_string; + namespace { /** @@ -190,7 +193,7 @@ RPCNetwork::invoke(FRT_RPCRequest *req) const string RPCNetwork::getConnectionSpec() const { - return vespalib::make_vespa_string("tcp/%s:%d", _ident.getHostname().c_str(), _orb.GetListenPort()); + return make_string("tcp/%s:%d", _ident.getHostname().c_str(), _orb.GetListenPort()); } RPCSendAdapter * @@ -292,13 +295,13 @@ RPCNetwork::resolveServiceAddress(RoutingNode &recipient, const string &serviceN { if (_oosManager.isOOS(serviceName)) { return Error(ErrorCode::SERVICE_OOS, - vespalib::make_vespa_string("The service '%s' has been marked as out of service.", + make_string("The service '%s' has been marked as out of service.", serviceName.c_str())); } RPCServiceAddress::UP ret = _servicePool.resolve(serviceName); if (ret.get() == NULL) { return Error(ErrorCode::NO_ADDRESS_FOR_SERVICE, - vespalib::make_vespa_string("The address of service '%s' could not be resolved. It is not currently " + make_string("The address of service '%s' could not be resolved. It is not currently " "registered with the Vespa name server. " "The service must be having problems, or the routing configuration is wrong.", serviceName.c_str())); @@ -306,7 +309,7 @@ RPCNetwork::resolveServiceAddress(RoutingNode &recipient, const string &serviceN RPCTarget::SP target = _targetPool.getTarget(_orb, *ret); if (target.get() == NULL) { return Error(ErrorCode::CONNECTION_ERROR, - vespalib::make_vespa_string("Failed to connect to service '%s'.", + make_string("Failed to connect to service '%s'.", serviceName.c_str())); } ret->setTarget(target); // free by freeServiceAddress() @@ -348,17 +351,13 @@ RPCNetwork::send(RPCNetwork::SendContext &ctx) RPCSendAdapter *adapter = getSendAdapter(ctx._version); if (adapter == NULL) { replyError(ctx, ErrorCode::INCOMPATIBLE_VERSION, - vespalib::make_vespa_string( - "Can not send to version '%s' recipient.", - ctx._version.toString().c_str())); + make_string("Can not send to version '%s' recipient.", ctx._version.toString().c_str())); } else if (timeRemaining == 0) { replyError(ctx, ErrorCode::TIMEOUT, "Aborting transmission because zero time remains."); } else if (payload.size() == 0) { replyError(ctx, ErrorCode::ENCODE_ERROR, - vespalib::make_vespa_string( - "Protocol '%s' failed to encode message.", - ctx._msg.getProtocol().c_str())); + make_string("Protocol '%s' failed to encode message.", ctx._msg.getProtocol().c_str())); } else if (ctx._recipients.size() == 1) { adapter->sendByHandover(*ctx._recipients.front(), ctx._version, std::move(payload), timeRemaining); } else { -- cgit v1.2.3 From 17f9f8870efd698d1f82508d582a0dc9026453cd Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Mon, 24 Jul 2017 14:59:54 +0000 Subject: make_vespa_string -> make_string. --- .../src/vespa/messagebus/routing/hopspec.cpp | 6 +- .../vespa/messagebus/routing/policydirective.cpp | 9 +-- .../src/vespa/messagebus/routing/resender.cpp | 3 +- .../vespa/messagebus/routing/routedirective.cpp | 5 +- .../src/vespa/messagebus/routing/routespec.cpp | 4 +- .../src/vespa/messagebus/routing/routingnode.cpp | 64 +++++++++------------- .../src/vespa/messagebus/routing/routingspec.cpp | 4 +- .../vespa/messagebus/routing/routingtablespec.cpp | 10 ++-- .../vespa/messagebus/routing/verbatimdirective.cpp | 3 +- 9 files changed, 48 insertions(+), 60 deletions(-) diff --git a/messagebus/src/vespa/messagebus/routing/hopspec.cpp b/messagebus/src/vespa/messagebus/routing/hopspec.cpp index 4e05c5c7b90..ba18c24c92d 100644 --- a/messagebus/src/vespa/messagebus/routing/hopspec.cpp +++ b/messagebus/src/vespa/messagebus/routing/hopspec.cpp @@ -3,6 +3,8 @@ #include "routingspec.h" #include +using vespalib::make_string; + namespace mbus { HopSpec::HopSpec(const string &name, const string &selector) : @@ -46,9 +48,9 @@ HopSpec::toConfig(string &cfg, const string &prefix) const } uint32_t numRecipients = _recipients.size(); if (numRecipients > 0) { - cfg.append(prefix).append("recipient[").append(vespalib::make_vespa_string("%d", numRecipients)).append("]\n"); + cfg.append(prefix).append("recipient[").append(make_string("%d", numRecipients)).append("]\n"); for (uint32_t i = 0; i < numRecipients; ++i) { - cfg.append(prefix).append("recipient[").append(vespalib::make_vespa_string("%d", i)).append("] "); + cfg.append(prefix).append("recipient[").append(make_string("%d", i)).append("] "); cfg.append(RoutingSpec::toConfigString(_recipients[i])).append("\n"); } } diff --git a/messagebus/src/vespa/messagebus/routing/policydirective.cpp b/messagebus/src/vespa/messagebus/routing/policydirective.cpp index 2c03cbfac03..3a95520a18b 100644 --- a/messagebus/src/vespa/messagebus/routing/policydirective.cpp +++ b/messagebus/src/vespa/messagebus/routing/policydirective.cpp @@ -2,6 +2,8 @@ #include "policydirective.h" #include +using vespalib::make_string; + namespace mbus { PolicyDirective::PolicyDirective(const vespalib::stringref &name, const vespalib::stringref ¶m) : @@ -15,16 +17,15 @@ string PolicyDirective::toString() const { if (_param.empty()) { - return vespalib::make_vespa_string("[%s]", _name.c_str()); + return make_string("[%s]", _name.c_str()); } - return vespalib::make_vespa_string("[%s:%s]", _name.c_str(), _param.c_str()); + return make_string("[%s:%s]", _name.c_str(), _param.c_str()); } string PolicyDirective::toDebugString() const { - return vespalib::make_vespa_string("PolicyDirective(name = '%s', param = '%s')", - _name.c_str(), _param.c_str()); + return make_string("PolicyDirective(name = '%s', param = '%s')", _name.c_str(), _param.c_str()); } } // mbus diff --git a/messagebus/src/vespa/messagebus/routing/resender.cpp b/messagebus/src/vespa/messagebus/routing/resender.cpp index 6608ef7012c..048d81b697e 100644 --- a/messagebus/src/vespa/messagebus/routing/resender.cpp +++ b/messagebus/src/vespa/messagebus/routing/resender.cpp @@ -85,8 +85,7 @@ Resender::scheduleRetry(RoutingNode &node) node.prepareForRetry(); // consumes the reply node.getTrace().trace( TraceLevel::COMPONENT, - vespalib::make_vespa_string("Message scheduled for retry %u in %.2f seconds.", - retry, delay)); + vespalib::make_string("Message scheduled for retry %u in %.2f seconds.", retry, delay)); msg.setRetry(retry); _queue.push(Entry((uint64_t)(_time.MilliSecsToNow() + delay * 1000), &node)); return true; diff --git a/messagebus/src/vespa/messagebus/routing/routedirective.cpp b/messagebus/src/vespa/messagebus/routing/routedirective.cpp index a54ce78bea2..c926c20fb1c 100644 --- a/messagebus/src/vespa/messagebus/routing/routedirective.cpp +++ b/messagebus/src/vespa/messagebus/routing/routedirective.cpp @@ -22,14 +22,13 @@ RouteDirective::matches(const IHopDirective &dir) const string RouteDirective::toString() const { - return vespalib::make_vespa_string("route:%s", _name.c_str()); + return vespalib::make_string("route:%s", _name.c_str()); } string RouteDirective::toDebugString() const { - return vespalib::make_vespa_string("RouteDirective(name = '%s')", - _name.c_str()); + return vespalib::make_string("RouteDirective(name = '%s')", _name.c_str()); } } // mbus diff --git a/messagebus/src/vespa/messagebus/routing/routespec.cpp b/messagebus/src/vespa/messagebus/routing/routespec.cpp index 1f3ed380bee..4762dd4a394 100644 --- a/messagebus/src/vespa/messagebus/routing/routespec.cpp +++ b/messagebus/src/vespa/messagebus/routing/routespec.cpp @@ -36,9 +36,9 @@ RouteSpec::toConfig(string &cfg, const string &prefix) const cfg.append(prefix).append("name ").append(RoutingSpec::toConfigString(_name)).append("\n"); uint32_t numHops = _hops.size(); if (numHops > 0) { - cfg.append(prefix).append("hop[").append(vespalib::make_vespa_string("%d", numHops)).append("]\n"); + cfg.append(prefix).append("hop[").append(vespalib::make_string("%d", numHops)).append("]\n"); for (uint32_t i = 0; i < numHops; ++i) { - cfg.append(prefix).append("hop[").append(vespalib::make_vespa_string("%d", i)).append("] "); + cfg.append(prefix).append("hop[").append(vespalib::make_string("%d", i)).append("] "); cfg.append(RoutingSpec::toConfigString(_hops[i])).append("\n"); } } diff --git a/messagebus/src/vespa/messagebus/routing/routingnode.cpp b/messagebus/src/vespa/messagebus/routing/routingnode.cpp index a3a9936b7d2..0f24b47cb94 100644 --- a/messagebus/src/vespa/messagebus/routing/routingnode.cpp +++ b/messagebus/src/vespa/messagebus/routing/routingnode.cpp @@ -8,9 +8,12 @@ #include #include #include +#include #include #include +using vespalib::make_string; + namespace mbus { RoutingNode::RoutingNode(MessageBus &mbus, INetwork &net, Resender *resender, @@ -287,20 +290,16 @@ RoutingNode::notifyMerge() // Execute the {@link RoutingPolicy#merge(RoutingContext)} method of the current routing policy. If a // policy fails to produce a reply, this attaches an error reply to this node. const PolicyDirective &dir = _routingContext->getDirective(); - _trace.trace(TraceLevel::SPLIT_MERGE, vespalib::make_vespa_string( - "Routing policy '%s' merging replies.", - dir.getName().c_str())); + _trace.trace(TraceLevel::SPLIT_MERGE, make_string("Routing policy '%s' merging replies.", dir.getName().c_str())); try { _policy->merge(*_routingContext); } catch (const std::exception &e) { - setError(ErrorCode::POLICY_ERROR, vespalib::make_vespa_string( - "Policy '%s' threw an exception; %s", - dir.getName().c_str(), e.what())); + setError(ErrorCode::POLICY_ERROR, make_string("Policy '%s' threw an exception; %s", + dir.getName().c_str(), e.what())); } if (_reply.get() == NULL) { - setError(ErrorCode::APP_FATAL_ERROR, vespalib::make_vespa_string( - "Routing policy '%s' failed to merge replies.", - dir.getName().c_str())); + setError(ErrorCode::APP_FATAL_ERROR, make_string("Routing policy '%s' failed to merge replies.", + dir.getName().c_str())); } // Notifies the parent node. @@ -392,8 +391,7 @@ RoutingNode::lookupHop() const HopBlueprint *hop = table->getHop(name); configureFromBlueprint(*hop); _trace.trace(TraceLevel::SPLIT_MERGE, - vespalib::make_vespa_string("Recognized '%s' as %s.", - name.c_str(), hop->toString().c_str())); + make_string("Recognized '%s' as %s.", name.c_str(), hop->toString().c_str())); return true; } } @@ -409,14 +407,13 @@ RoutingNode::lookupRoute() RouteDirective &dir = static_cast(*hop.getDirective(0)); if (table.get() == NULL || !table->hasRoute(dir.getName())) { setError(ErrorCode::ILLEGAL_ROUTE, - vespalib::make_vespa_string("Route '%s' does not exist.", - dir.getName().c_str())); + make_string("Route '%s' does not exist.", dir.getName().c_str())); return false; } insertRoute(*table->getRoute(dir.getName())); _trace.trace(TraceLevel::SPLIT_MERGE, - vespalib::make_vespa_string("Route '%s' retrieved by directive; new route is '%s'.", - dir.getName().c_str(), _route.toString().c_str())); + make_string("Route '%s' retrieved by directive; new route is '%s'.", + dir.getName().c_str(), _route.toString().c_str())); return true; } if (table.get() != NULL) { @@ -424,8 +421,7 @@ RoutingNode::lookupRoute() if (table->hasRoute(name)) { insertRoute(*table->getRoute(name)); _trace.trace(TraceLevel::SPLIT_MERGE, - vespalib::make_vespa_string("Recognized '%s' as route '%s'.", - name.c_str(), _route.toString().c_str())); + make_string("Recognized '%s' as route '%s'.", name.c_str(), _route.toString().c_str())); return true; } } @@ -480,36 +476,27 @@ RoutingNode::executePolicySelect() const PolicyDirective &dir = _routingContext->getDirective(); _policy = _mbus.getRoutingPolicy(_msg.getProtocol(), dir.getName(), dir.getParam()); if (_policy.get() == NULL) { - setError(ErrorCode::UNKNOWN_POLICY, vespalib::make_vespa_string( - "Protocol '%s' could not create routing policy " - "'%s' with parameter '%s'.", - _msg.getProtocol().c_str(), dir.getName().c_str(), - dir.getParam().c_str())); + 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())); return false; } - _trace.trace(TraceLevel::SPLIT_MERGE, vespalib::make_vespa_string( - "Running routing policy '%s'.", - dir.getName().c_str())); + _trace.trace(TraceLevel::SPLIT_MERGE, make_string("Running routing policy '%s'.", dir.getName().c_str())); try { _policy->select(*_routingContext); } catch (const std::exception &e) { - setError(ErrorCode::POLICY_ERROR, vespalib::make_vespa_string( - "Policy '%s' threw an exception; %s", - dir.getName().c_str(), e.what())); + setError(ErrorCode::POLICY_ERROR, make_string("Policy '%s' threw an exception; %s", + dir.getName().c_str(), e.what())); return false; } if (_children.empty()) { if (_reply.get() == NULL) { setError(ErrorCode::NO_SERVICES_FOR_ROUTE, - vespalib::make_vespa_string( - "Policy '%s' selected no recipients for " - "route '%s'.", - dir.getName().c_str(), _route.toString().c_str())); + make_string("Policy '%s' selected no recipients for route '%s'.", + dir.getName().c_str(), _route.toString().c_str())); } else { _trace.trace(TraceLevel::SPLIT_MERGE, - vespalib::make_vespa_string( - "Policy '%s' assigned a reply to this branch.", - dir.getName().c_str())); + make_string("Policy '%s' assigned a reply to this branch.", dir.getName().c_str())); } return false; } @@ -519,8 +506,8 @@ RoutingNode::executePolicySelect() RoutingNode *child = *it; Hop &hop = child->_route.getHop(0); child->_trace.trace(TraceLevel::SPLIT_MERGE, - vespalib::make_vespa_string("Component '%s' selected by policy '%s'.", - hop.toString().c_str(), dir.getName().c_str())); + make_string("Component '%s' selected by policy '%s'.", + hop.toString().c_str(), dir.getName().c_str())); } return true; } @@ -535,7 +522,7 @@ RoutingNode::resolveChildren(uint32_t childDepth) { RoutingNode *child = *it; child->_trace.trace(TraceLevel::SPLIT_MERGE, - vespalib::make_vespa_string("Resolving '%s'.", child->_route.toString().c_str())); + make_string("Resolving '%s'.", child->_route.toString().c_str())); child->_isActive = (child->_reply.get() == NULL); if (child->_isActive) { ++numActiveChildren; @@ -591,4 +578,3 @@ RoutingNode::shouldIgnoreResult() } } // namespace mbus - diff --git a/messagebus/src/vespa/messagebus/routing/routingspec.cpp b/messagebus/src/vespa/messagebus/routing/routingspec.cpp index 8079bb5c83e..55cde6c6d82 100644 --- a/messagebus/src/vespa/messagebus/routing/routingspec.cpp +++ b/messagebus/src/vespa/messagebus/routing/routingspec.cpp @@ -45,9 +45,9 @@ RoutingSpec::toConfig(string &cfg, const string &prefix) const { uint32_t numTables = _tables.size(); if (numTables > 0) { - cfg.append(prefix).append("routingtable[").append(vespalib::make_vespa_string("%d", numTables)).append("]\n"); + cfg.append(prefix).append("routingtable[").append(vespalib::make_string("%d", numTables)).append("]\n"); for (uint32_t i = 0; i < numTables; ++i) { - _tables[i].toConfig(cfg, vespalib::make_vespa_string("%sroutingtable[%d].", prefix.c_str(), i)); + _tables[i].toConfig(cfg, vespalib::make_string("%sroutingtable[%d].", prefix.c_str(), i)); } } } diff --git a/messagebus/src/vespa/messagebus/routing/routingtablespec.cpp b/messagebus/src/vespa/messagebus/routing/routingtablespec.cpp index 08ebdc4ec0c..40e99bf3ef7 100644 --- a/messagebus/src/vespa/messagebus/routing/routingtablespec.cpp +++ b/messagebus/src/vespa/messagebus/routing/routingtablespec.cpp @@ -2,6 +2,8 @@ #include "routingspec.h" #include +using vespalib::make_string; + namespace mbus { RoutingTableSpec::RoutingTableSpec(const string &protocol) : @@ -34,16 +36,16 @@ RoutingTableSpec::toConfig(string &cfg, const string &prefix) const cfg.append(prefix).append("protocol ").append(RoutingSpec::toConfigString(_protocol)).append("\n"); uint32_t numHops = _hops.size(); if (numHops > 0) { - cfg.append(prefix).append("hop[").append(vespalib::make_vespa_string("%d", numHops)).append("]\n"); + cfg.append(prefix).append("hop[").append(make_string("%d", numHops)).append("]\n"); for (uint32_t i = 0; i < numHops; ++i) { - _hops[i].toConfig(cfg, vespalib::make_vespa_string("%shop[%d].", prefix.c_str(), i)); + _hops[i].toConfig(cfg, make_string("%shop[%d].", prefix.c_str(), i)); } } uint32_t numRoutes = _routes.size(); if (numRoutes > 0) { - cfg.append(prefix).append("route[").append(vespalib::make_vespa_string("%d", numRoutes)).append("]\n"); + cfg.append(prefix).append("route[").append(make_string("%d", numRoutes)).append("]\n"); for (uint32_t i = 0; i < numRoutes; ++i) { - _routes[i].toConfig(cfg, vespalib::make_vespa_string("%sroute[%d].", prefix.c_str(), i)); + _routes[i].toConfig(cfg, make_string("%sroute[%d].", prefix.c_str(), i)); } } } diff --git a/messagebus/src/vespa/messagebus/routing/verbatimdirective.cpp b/messagebus/src/vespa/messagebus/routing/verbatimdirective.cpp index d1c0f4c9986..86f50d897a5 100644 --- a/messagebus/src/vespa/messagebus/routing/verbatimdirective.cpp +++ b/messagebus/src/vespa/messagebus/routing/verbatimdirective.cpp @@ -28,8 +28,7 @@ VerbatimDirective::toString() const string VerbatimDirective::toDebugString() const { - return vespalib::make_vespa_string("VerbatimDirective(image = '%s')", - _image.c_str()); + return vespalib::make_string("VerbatimDirective(image = '%s')", _image.c_str()); } } // mbus -- cgit v1.2.3 From 87b1d3270af371f6dc7c53bd4d60a77308217223 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Mon, 24 Jul 2017 15:01:50 +0000 Subject: make_vespa_string -> make_string. --- messagebus/src/vespa/messagebus/sequencer.cpp | 10 ++++---- messagebus/src/vespa/messagebus/sourcesession.cpp | 29 ++++++++--------------- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/messagebus/src/vespa/messagebus/sequencer.cpp b/messagebus/src/vespa/messagebus/sequencer.cpp index 0aa715729fe..79fbd346c16 100644 --- a/messagebus/src/vespa/messagebus/sequencer.cpp +++ b/messagebus/src/vespa/messagebus/sequencer.cpp @@ -3,6 +3,8 @@ #include "tracelevel.h" #include +using vespalib::make_string; + namespace mbus { Sequencer::Sequencer(IMessageHandler &sender) : @@ -42,7 +44,7 @@ Sequencer::filter(Message::UP msg) it->second = new MessageQueue(); } msg->getTrace().trace(TraceLevel::COMPONENT, - vespalib::make_vespa_string("Sequencer queued message with sequence id '%" PRIu64 "'.", seqId)); + make_string("Sequencer queued message with sequence id '%" PRIu64 "'.", seqId)); it->second->push(msg.get()); msg.release(); return Message::UP(); @@ -56,8 +58,8 @@ void Sequencer::sequencedSend(Message::UP msg) { msg->getTrace().trace(TraceLevel::COMPONENT, - vespalib::make_vespa_string("Sequencer sending message with sequence id '%" PRIu64 "'.", - msg->getContext().value.UINT64)); + make_string("Sequencer sending message with sequence id '%" PRIu64 "'.", + msg->getContext().value.UINT64)); msg->pushHandler(*this); _sender.handleMessage(std::move(msg)); } @@ -80,7 +82,7 @@ Sequencer::handleReply(Reply::UP reply) { uint64_t seq = reply->getContext().value.UINT64; reply->getTrace().trace(TraceLevel::COMPONENT, - vespalib::make_vespa_string("Sequencer received reply with sequence id '%" PRIu64 "'.", seq)); + make_string("Sequencer received reply with sequence id '%" PRIu64 "'.", seq)); Message::UP msg; { vespalib::LockGuard guard(_lock); diff --git a/messagebus/src/vespa/messagebus/sourcesession.cpp b/messagebus/src/vespa/messagebus/sourcesession.cpp index 1daf6ccee99..9a93a4aedf1 100644 --- a/messagebus/src/vespa/messagebus/sourcesession.cpp +++ b/messagebus/src/vespa/messagebus/sourcesession.cpp @@ -1,15 +1,14 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "sourcesession.h" -#include "sourcesessionparams.h" -#include "error.h" #include "errorcode.h" #include "messagebus.h" #include "replygate.h" #include "tracelevel.h" -#include #include #include +using vespalib::make_string; + namespace mbus { SourceSession::SourceSession(MessageBus &mbus, const SourceSessionParams ¶ms) @@ -48,15 +47,11 @@ SourceSession::send(Message::UP msg, const string &routeName, bool parseIfNotFou msg->setRoute(*route); found = true; } else if (!parseIfNotFound) { - string str = vespalib::make_vespa_string( - "Route '%s' not found.", - routeName.c_str()); + string str = make_string("Route '%s' not found.", routeName.c_str()); return Result(Error(ErrorCode::ILLEGAL_ROUTE, str), std::move(msg)); } } else if (!parseIfNotFound) { - string str = vespalib::make_vespa_string( - "No routing table available for protocol '%s'.", - msg->getProtocol().c_str()); + string str = make_string("No routing table available for protocol '%s'.", msg->getProtocol().c_str()); return Result(Error(ErrorCode::ILLEGAL_ROUTE, str), std::move(msg)); } if (!found) { @@ -82,13 +77,12 @@ SourceSession::send(Message::UP msg) { vespalib::MonitorGuard guard(_monitor); if (_closed) { - return Result(Error(ErrorCode::SEND_QUEUE_CLOSED, - "Source session is closed."), std::move(msg)); + return Result(Error(ErrorCode::SEND_QUEUE_CLOSED, "Source session is closed."), std::move(msg)); } if (_throttlePolicy.get() != NULL && !_throttlePolicy->canSend(*msg, _pendingCount)) { return Result(Error(ErrorCode::SEND_QUEUE_FULL, - vespalib::make_vespa_string("Too much pending data (%d messages).", - _pendingCount)), std::move(msg)); + make_string("Too much pending data (%d messages).", _pendingCount)), + std::move(msg)); } msg->pushHandler(_replyHandler); if (_throttlePolicy.get() != NULL) { @@ -98,9 +92,8 @@ SourceSession::send(Message::UP msg) } if (msg->getTrace().shouldTrace(TraceLevel::COMPONENT)) { msg->getTrace().trace(TraceLevel::COMPONENT, - vespalib::make_vespa_string("Source session accepted a %d byte message. " - "%d message(s) now pending.", - msg->getApproxSize(), _pendingCount)); + make_string("Source session accepted a %d byte message. %d message(s) now pending.", + msg->getApproxSize(), _pendingCount)); } msg->pushHandler(*this); _sequencer.handleMessage(std::move(msg)); @@ -122,9 +115,7 @@ SourceSession::handleReply(Reply::UP reply) } if (reply->getTrace().shouldTrace(TraceLevel::COMPONENT)) { reply->getTrace().trace(TraceLevel::COMPONENT, - vespalib::make_vespa_string("Source session received reply. " - "%d message(s) now pending.", - _pendingCount)); + make_string("Source session received reply. %d message(s) now pending.", _pendingCount)); } IReplyHandler &handler = reply->getCallStack().pop(*reply); handler.handleReply(std::move(reply)); -- cgit v1.2.3 From 74ebe62ec310cb56da390a9310031b4b914ac85f Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Mon, 24 Jul 2017 15:13:59 +0000 Subject: make_vespa_string -> make_string. --- messagebus/src/vespa/messagebus/common.h | 1 - .../src/vespa/messagebus/network/rpcsendv1.cpp | 60 ++++++++++------------ 2 files changed, 26 insertions(+), 35 deletions(-) diff --git a/messagebus/src/vespa/messagebus/common.h b/messagebus/src/vespa/messagebus/common.h index b7ed4006f5f..0e171b9f6d0 100644 --- a/messagebus/src/vespa/messagebus/common.h +++ b/messagebus/src/vespa/messagebus/common.h @@ -2,7 +2,6 @@ #pragma once #include -#include namespace mbus { diff --git a/messagebus/src/vespa/messagebus/network/rpcsendv1.cpp b/messagebus/src/vespa/messagebus/network/rpcsendv1.cpp index 741a2fde3c1..f2922865907 100644 --- a/messagebus/src/vespa/messagebus/network/rpcsendv1.cpp +++ b/messagebus/src/vespa/messagebus/network/rpcsendv1.cpp @@ -8,6 +8,8 @@ #include #include +using vespalib::make_string; + namespace { /** @@ -75,13 +77,12 @@ RPCSendV1::attach(RPCNetwork &net) _net = &net; const string &prefix = _net->getIdentity().getServicePrefix(); if (!prefix.empty()) { - _clientIdent = vespalib::make_vespa_string("'%s'", prefix.c_str()); + _clientIdent = make_string("'%s'", prefix.c_str()); _serverIdent = _clientIdent; } FRT_ReflectionBuilder builder(&_net->getSupervisor()); - builder.DefineMethod(METHOD_NAME, METHOD_PARAMS, METHOD_RETURN, true, - FRT_METHOD(RPCSendV1::invoke), this); + builder.DefineMethod(METHOD_NAME, METHOD_PARAMS, METHOD_RETURN, true, FRT_METHOD(RPCSendV1::invoke), this); builder.MethodDesc("Send a message bus request and get a reply back."); builder.ParamDesc("version", "The version of the message."); builder.ParamDesc("route", "Names of additional hops to visit."); @@ -167,18 +168,16 @@ RPCSendV1::send(RoutingNode &recipient, const vespalib::Version &version, if (ctx->getTrace().shouldTrace(TraceLevel::SEND_RECEIVE)) { ctx->getTrace().trace(TraceLevel::SEND_RECEIVE, - vespalib::make_vespa_string( - "Sending message (version %s) from %s to '%s' with %.2f seconds timeout.", - version.toString().c_str(), _clientIdent.c_str(), - address.getServiceName().c_str(), ctx->getTimeout())); + make_string("Sending message (version %s) from %s to '%s' with %.2f seconds timeout.", + version.toString().c_str(), _clientIdent.c_str(), + address.getServiceName().c_str(), ctx->getTimeout())); } if (hop.getIgnoreResult()) { address.getTarget().getFRTTarget().InvokeVoid(req); if (ctx->getTrace().shouldTrace(TraceLevel::SEND_RECEIVE)) { ctx->getTrace().trace(TraceLevel::SEND_RECEIVE, - vespalib::make_vespa_string("Not waiting for a reply from '%s'.", - address.getServiceName().c_str())); + make_string("Not waiting for a reply from '%s'.", address.getServiceName().c_str())); } Reply::UP reply(new EmptyReply()); reply->getTrace().swap(ctx->getTrace()); @@ -203,18 +202,18 @@ RPCSendV1::RequestDone(FRT_RPCRequest *req) switch (req->GetErrorCode()) { case FRTE_RPC_TIMEOUT: error = Error(ErrorCode::TIMEOUT, - vespalib::make_vespa_string("A timeout occured while waiting for '%s' (%g seconds expired); %s", - serviceName.c_str(), ctx->getTimeout(), req->GetErrorMessage())); + make_string("A timeout occured while waiting for '%s' (%g seconds expired); %s", + serviceName.c_str(), ctx->getTimeout(), req->GetErrorMessage())); break; case FRTE_RPC_CONNECTION: error = Error(ErrorCode::CONNECTION_ERROR, - vespalib::make_vespa_string("A connection error occured for '%s'; %s", - serviceName.c_str(), req->GetErrorMessage())); + make_string("A connection error occured for '%s'; %s", + serviceName.c_str(), req->GetErrorMessage())); break; default: error = Error(ErrorCode::NETWORK_ERROR, - vespalib::make_vespa_string("A network error occured for '%s'; %s", - serviceName.c_str(), req->GetErrorMessage())); + make_string("A network error occured for '%s'; %s", + serviceName.c_str(), req->GetErrorMessage())); } } else { FRT_Values &ret = *req->GetReturn(); @@ -246,17 +245,15 @@ RPCSendV1::RequestDone(FRT_RPCRequest *req) } } else { error = Error(ErrorCode::DECODE_ERROR, - vespalib::make_vespa_string("Protocol '%s' failed to decode routable.", - protocolName)); + make_string("Protocol '%s' failed to decode routable.", protocolName)); } } else { error = Error(ErrorCode::UNKNOWN_PROTOCOL, - vespalib::make_vespa_string("Protocol '%s' is not known by %s.", - protocolName, _serverIdent.c_str())); + make_string("Protocol '%s' is not known by %s.", protocolName, _serverIdent.c_str())); } } - if (reply.get() == NULL) { + if ( ! reply ) { reply.reset(new EmptyReply()); } reply->setRetryDelay(retryDelay); @@ -269,8 +266,7 @@ RPCSendV1::RequestDone(FRT_RPCRequest *req) } if (ctx->getTrace().shouldTrace(TraceLevel::SEND_RECEIVE)) { ctx->getTrace().trace(TraceLevel::SEND_RECEIVE, - vespalib::make_vespa_string("Reply (type %d) received at %s.", - reply->getType(), _clientIdent.c_str())); + make_string("Reply (type %d) received at %s.", reply->getType(), _clientIdent.c_str())); } reply->getTrace().swap(ctx->getTrace()); if (error.getCode() != ErrorCode::NONE) { @@ -301,17 +297,15 @@ RPCSendV1::invoke(FRT_RPCRequest *req) if (protocol.get() == NULL) { replyError(req, version, traceLevel, Error(ErrorCode::UNKNOWN_PROTOCOL, - vespalib::make_vespa_string("Protocol '%s' is not known by %s.", - protocolName, _serverIdent.c_str()))); + make_string("Protocol '%s' is not known by %s.", protocolName, _serverIdent.c_str()))); return; } Routable::UP routable = protocol->decode(version, BlobRef(payload, payloadLen)); req->DiscardBlobs(); - if (routable.get() == NULL) { + if ( ! routable ) { replyError(req, version, traceLevel, Error(ErrorCode::DECODE_ERROR, - vespalib::make_vespa_string("Protocol '%s' failed to decode routable.", - protocolName))); + make_string("Protocol '%s' failed to decode routable.", protocolName))); return; } if (routable->isReply()) { @@ -333,8 +327,8 @@ RPCSendV1::invoke(FRT_RPCRequest *req) msg->getTrace().setLevel(traceLevel); if (msg->getTrace().shouldTrace(TraceLevel::SEND_RECEIVE)) { msg->getTrace().trace(TraceLevel::SEND_RECEIVE, - vespalib::make_vespa_string("Message (type %d) received at %s for session '%s'.", - msg->getType(), _serverIdent.c_str(), session)); + make_string("Message (type %d) received at %s for session '%s'.", + msg->getType(), _serverIdent.c_str(), session)); } _net->getOwner().deliverMessage(std::move(msg), session); } @@ -346,16 +340,14 @@ RPCSendV1::handleReply(Reply::UP reply) FRT_RPCRequest &req = ctx->getRequest(); string version = ctx->getVersion().toString(); if (reply->getTrace().shouldTrace(TraceLevel::SEND_RECEIVE)) { - reply->getTrace().trace(TraceLevel::SEND_RECEIVE, - vespalib::make_vespa_string("Sending reply (version %s) from %s.", - version.c_str(), _serverIdent.c_str())); + reply->getTrace().trace(TraceLevel::SEND_RECEIVE, make_string("Sending reply (version %s) from %s.", + version.c_str(), _serverIdent.c_str())); } Blob payload(0); if (reply->getType() != 0) { payload = _net->getOwner().getProtocol(reply->getProtocol())->encode(ctx->getVersion(), *reply); if (payload.size() == 0) { - reply->addError(Error(ErrorCode::ENCODE_ERROR, - "An error occured while encoding the reply, see log.")); + reply->addError(Error(ErrorCode::ENCODE_ERROR, "An error occured while encoding the reply, see log.")); } } FRT_Values &ret = *req.GetReturn(); -- cgit v1.2.3 From 3565bd357c11b7fa5c3c14ce407c765d44ad91f4 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Mon, 24 Jul 2017 15:20:02 +0000 Subject: Avoid temporaries and move string construction outside lock. --- messagebus/src/vespa/messagebus/protocolrepository.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/messagebus/src/vespa/messagebus/protocolrepository.cpp b/messagebus/src/vespa/messagebus/protocolrepository.cpp index 681af440a89..26f6b53361f 100644 --- a/messagebus/src/vespa/messagebus/protocolrepository.cpp +++ b/messagebus/src/vespa/messagebus/protocolrepository.cpp @@ -52,8 +52,9 @@ ProtocolRepository::getRoutingPolicy(const string &protocolName, const string &policyName, const string &policyParam) { + string cacheKey = protocolName; + cacheKey.append('.').append(policyName).append(".").append(policyParam); vespalib::LockGuard guard(_lock); - string cacheKey = protocolName + "." + policyName + "." + policyParam; RoutingPolicyCache::iterator cit = _routingPolicyCache.find(cacheKey); if (cit != _routingPolicyCache.end()) { return cit->second; @@ -67,12 +68,10 @@ ProtocolRepository::getRoutingPolicy(const string &protocolName, try { policy = pit->second->createPolicy(policyName, policyParam); } catch (const std::exception &e) { - LOG(error, "Protocol '%s' threw an exception; %s", - protocolName.c_str(), e.what()); + LOG(error, "Protocol '%s' threw an exception; %s", protocolName.c_str(), e.what()); } if (policy.get() == NULL) { - LOG(error, "Protocol '%s' failed to create routing policy '%s' " - "with parameter '%s'.", + LOG(error, "Protocol '%s' failed to create routing policy '%s' with parameter '%s'.", protocolName.c_str(), policyName.c_str(), policyParam.c_str()); return IRoutingPolicy::SP(); } -- cgit v1.2.3 From 90c18b1ce77f746e075137560382597eea9a5723 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Mon, 24 Jul 2017 15:29:15 +0000 Subject: using vespalib::make_string --- messagebus/src/vespa/messagebus/error.cpp | 8 ++++---- messagebus/src/vespa/messagebus/messagebus.cpp | 9 +++------ messagebus/src/vespa/messagebus/routing/errordirective.cpp | 6 ++++-- messagebus/src/vespa/messagebus/routing/routedirective.cpp | 6 ++++-- messagebus/src/vespa/messagebus/routing/routespec.cpp | 6 ++++-- messagebus/src/vespa/messagebus/routing/routingspec.cpp | 6 ++++-- 6 files changed, 23 insertions(+), 18 deletions(-) diff --git a/messagebus/src/vespa/messagebus/error.cpp b/messagebus/src/vespa/messagebus/error.cpp index 7a7785a853f..85c9b92eb19 100644 --- a/messagebus/src/vespa/messagebus/error.cpp +++ b/messagebus/src/vespa/messagebus/error.cpp @@ -3,6 +3,8 @@ #include "errorcode.h" #include +using vespalib::make_string; + namespace mbus { Error::Error() @@ -24,11 +26,9 @@ Error::toString() const { string name(ErrorCode::getName(_code)); if (name.empty()) { - name = vespalib::make_string("%u", _code); + name = make_string("%u", _code); } - return vespalib::make_string("[%s @ %s]: %s", name.c_str(), - _service.empty() ? "localhost" : _service.c_str(), - _msg.c_str()); + return make_string("[%s @ %s]: %s", name.c_str(), _service.empty() ? "localhost" : _service.c_str(), _msg.c_str()); } } // namespace mbus diff --git a/messagebus/src/vespa/messagebus/messagebus.cpp b/messagebus/src/vespa/messagebus/messagebus.cpp index b0376ba7cda..e32f5ca4137 100644 --- a/messagebus/src/vespa/messagebus/messagebus.cpp +++ b/messagebus/src/vespa/messagebus/messagebus.cpp @@ -13,6 +13,7 @@ LOG_SETUP(".messagebus"); using vespalib::LockGuard; +using vespalib::make_string; namespace { @@ -370,14 +371,10 @@ MessageBus::deliverMessage(Message::UP msg, const string &session) } if (msgHandler == NULL) { deliverError(std::move(msg), ErrorCode::UNKNOWN_SESSION, - vespalib::make_string( - "Session '%s' does not exist.", - session.c_str())); + make_string("Session '%s' does not exist.", session.c_str())); } else if (!checkPending(*msg)) { deliverError(std::move(msg), ErrorCode::SESSION_BUSY, - vespalib::make_string( - "Session '%s' is busy, try again later.", - session.c_str())); + make_string("Session '%s' is busy, try again later.", session.c_str())); } else { _msn->deliverMessage(std::move(msg), *msgHandler); } diff --git a/messagebus/src/vespa/messagebus/routing/errordirective.cpp b/messagebus/src/vespa/messagebus/routing/errordirective.cpp index 082583b9271..c26a76d10c7 100644 --- a/messagebus/src/vespa/messagebus/routing/errordirective.cpp +++ b/messagebus/src/vespa/messagebus/routing/errordirective.cpp @@ -2,6 +2,8 @@ #include "errordirective.h" #include +using vespalib::make_string; + namespace mbus { ErrorDirective::ErrorDirective(const vespalib::stringref &msg) : @@ -11,13 +13,13 @@ ErrorDirective::ErrorDirective(const vespalib::stringref &msg) : string ErrorDirective::toString() const { - return vespalib::make_string("(%s)", _msg.c_str()); + return make_string("(%s)", _msg.c_str()); } string ErrorDirective::toDebugString() const { - return vespalib::make_string("ErrorDirective(msg = '%s')", _msg.c_str()); + return make_string("ErrorDirective(msg = '%s')", _msg.c_str()); } } // mbus diff --git a/messagebus/src/vespa/messagebus/routing/routedirective.cpp b/messagebus/src/vespa/messagebus/routing/routedirective.cpp index c926c20fb1c..dc84f8c0711 100644 --- a/messagebus/src/vespa/messagebus/routing/routedirective.cpp +++ b/messagebus/src/vespa/messagebus/routing/routedirective.cpp @@ -2,6 +2,8 @@ #include "routedirective.h" #include +using vespalib::make_string; + namespace mbus { RouteDirective::RouteDirective(const vespalib::stringref & name) : @@ -22,13 +24,13 @@ RouteDirective::matches(const IHopDirective &dir) const string RouteDirective::toString() const { - return vespalib::make_string("route:%s", _name.c_str()); + return make_string("route:%s", _name.c_str()); } string RouteDirective::toDebugString() const { - return vespalib::make_string("RouteDirective(name = '%s')", _name.c_str()); + return make_string("RouteDirective(name = '%s')", _name.c_str()); } } // mbus diff --git a/messagebus/src/vespa/messagebus/routing/routespec.cpp b/messagebus/src/vespa/messagebus/routing/routespec.cpp index 4762dd4a394..0ebd6745740 100644 --- a/messagebus/src/vespa/messagebus/routing/routespec.cpp +++ b/messagebus/src/vespa/messagebus/routing/routespec.cpp @@ -3,6 +3,8 @@ #include "routingspec.h" #include +using vespalib::make_string; + namespace mbus { RouteSpec::RouteSpec(const string &name) : @@ -36,9 +38,9 @@ RouteSpec::toConfig(string &cfg, const string &prefix) const cfg.append(prefix).append("name ").append(RoutingSpec::toConfigString(_name)).append("\n"); uint32_t numHops = _hops.size(); if (numHops > 0) { - cfg.append(prefix).append("hop[").append(vespalib::make_string("%d", numHops)).append("]\n"); + cfg.append(prefix).append("hop[").append(make_string("%d", numHops)).append("]\n"); for (uint32_t i = 0; i < numHops; ++i) { - cfg.append(prefix).append("hop[").append(vespalib::make_string("%d", i)).append("] "); + cfg.append(prefix).append("hop[").append(make_string("%d", i)).append("] "); cfg.append(RoutingSpec::toConfigString(_hops[i])).append("\n"); } } diff --git a/messagebus/src/vespa/messagebus/routing/routingspec.cpp b/messagebus/src/vespa/messagebus/routing/routingspec.cpp index 55cde6c6d82..7d627366759 100644 --- a/messagebus/src/vespa/messagebus/routing/routingspec.cpp +++ b/messagebus/src/vespa/messagebus/routing/routingspec.cpp @@ -2,6 +2,8 @@ #include "routingspec.h" #include +using vespalib::make_string; + namespace mbus { RoutingSpec::RoutingSpec() : @@ -45,9 +47,9 @@ RoutingSpec::toConfig(string &cfg, const string &prefix) const { uint32_t numTables = _tables.size(); if (numTables > 0) { - cfg.append(prefix).append("routingtable[").append(vespalib::make_string("%d", numTables)).append("]\n"); + cfg.append(prefix).append("routingtable[").append(make_string("%d", numTables)).append("]\n"); for (uint32_t i = 0; i < numTables; ++i) { - _tables[i].toConfig(cfg, vespalib::make_string("%sroutingtable[%d].", prefix.c_str(), i)); + _tables[i].toConfig(cfg, make_string("%sroutingtable[%d].", prefix.c_str(), i)); } } } -- cgit v1.2.3