diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-11-18 10:46:55 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2020-11-18 18:22:16 +0000 |
commit | 37822a5c2ecf566bac41ea8a8c94226115ac370f (patch) | |
tree | 2266cd8bdbc8675892c74dafeab2c7317142dd77 /messagebus | |
parent | b2d2d0053d16ca15c9298f3e8312b494e246c5e9 (diff) |
Hide the modifiable TraceNode root inside the Trace object
Diffstat (limited to 'messagebus')
9 files changed, 26 insertions, 27 deletions
diff --git a/messagebus/src/tests/simpleprotocol/simpleprotocol.cpp b/messagebus/src/tests/simpleprotocol/simpleprotocol.cpp index 715ef597767..091c7b668a1 100644 --- a/messagebus/src/tests/simpleprotocol/simpleprotocol.cpp +++ b/messagebus/src/tests/simpleprotocol/simpleprotocol.cpp @@ -6,9 +6,7 @@ #include <vespa/messagebus/testlib/simplereply.h> #include <vespa/messagebus/testlib/slobrok.h> #include <vespa/messagebus/testlib/testserver.h> -#include <vespa/messagebus/errorcode.h> #include <vespa/messagebus/ireplyhandler.h> -#include <vespa/messagebus/network/identity.h> #include <vespa/messagebus/routing/routingcontext.h> #include <vespa/vespalib/testkit/testapp.h> #include <vespa/vespalib/component/vtag.h> @@ -29,12 +27,15 @@ Test::Main() { // test protocol IRoutingPolicy::UP bogus = protocol.createPolicy("bogus", ""); - EXPECT_TRUE(bogus.get() == 0); + EXPECT_FALSE(bogus); } TEST_FLUSH(); { // test SimpleMessage - Message::UP msg(new SimpleMessage("test")); + EXPECT_EQUAL(160u, sizeof(Routable)); + EXPECT_EQUAL(208u, sizeof(Message)); + EXPECT_EQUAL(288u, sizeof(SimpleMessage)); + auto msg = std::make_unique<SimpleMessage>("test"); EXPECT_TRUE(!msg->isReply()); EXPECT_TRUE(msg->getProtocol() == SimpleProtocol::NAME); EXPECT_TRUE(msg->getType() == SimpleProtocol::MESSAGE); @@ -42,7 +43,7 @@ Test::Main() Blob b = protocol.encode(version, *msg); EXPECT_TRUE(b.size() > 0); Routable::UP tmp = protocol.decode(version, BlobRef(b)); - ASSERT_TRUE(tmp.get() != 0); + ASSERT_TRUE(tmp); EXPECT_TRUE(!tmp->isReply()); EXPECT_TRUE(tmp->getProtocol() == SimpleProtocol::NAME); EXPECT_TRUE(tmp->getType() == SimpleProtocol::MESSAGE); @@ -51,7 +52,10 @@ Test::Main() TEST_FLUSH(); { // test SimpleReply - Reply::UP reply(new SimpleReply("reply")); + EXPECT_EQUAL(160u, sizeof(Routable)); + EXPECT_EQUAL(200u, sizeof(Reply)); + EXPECT_EQUAL(264u, sizeof(SimpleReply)); + auto reply = std::make_unique<SimpleReply>("reply"); EXPECT_TRUE(reply->isReply()); EXPECT_TRUE(reply->getProtocol() == SimpleProtocol::NAME); EXPECT_TRUE(reply->getType() == SimpleProtocol::REPLY); @@ -59,7 +63,7 @@ Test::Main() Blob b = protocol.encode(version, *reply); EXPECT_TRUE(b.size() > 0); Routable::UP tmp = protocol.decode(version, BlobRef(b)); - ASSERT_TRUE(tmp.get() != 0); + ASSERT_TRUE(tmp); EXPECT_TRUE(tmp->isReply()); EXPECT_TRUE(tmp->getProtocol() == SimpleProtocol::NAME); EXPECT_TRUE(tmp->getType() == SimpleProtocol::REPLY); diff --git a/messagebus/src/vespa/messagebus/network/rpcsend.cpp b/messagebus/src/vespa/messagebus/network/rpcsend.cpp index dca7f0c997f..86c9b139f1a 100644 --- a/messagebus/src/vespa/messagebus/network/rpcsend.cpp +++ b/messagebus/src/vespa/messagebus/network/rpcsend.cpp @@ -178,7 +178,7 @@ RPCSend::doRequestDone(FRT_RPCRequest *req) { } } else { FRT_Values &ret = *req->GetReturn(); - reply = createReply(ret, serviceName, error, trace.getRoot()); + reply = createReply(ret, serviceName, error, trace); } if (trace.shouldTrace(TraceLevel::SEND_RECEIVE)) { trace.trace(TraceLevel::SEND_RECEIVE, diff --git a/messagebus/src/vespa/messagebus/network/rpcsend.h b/messagebus/src/vespa/messagebus/network/rpcsend.h index f3a9177d236..1ccdea6fbc5 100644 --- a/messagebus/src/vespa/messagebus/network/rpcsend.h +++ b/messagebus/src/vespa/messagebus/network/rpcsend.h @@ -12,7 +12,7 @@ class FRT_ReflectionBuilder; namespace vespalib::slime { struct Cursor; } namespace vespalib { struct Memory; } -namespace vespalib { class TraceNode; } +namespace vespalib { class Trace; } namespace mbus { class Error; @@ -56,7 +56,7 @@ protected: virtual void build(FRT_ReflectionBuilder & builder) = 0; virtual std::unique_ptr<Reply> createReply(const FRT_Values & response, const string & serviceName, - Error & error, vespalib::TraceNode & rootTrace) const = 0; + Error & error, vespalib::Trace & trace) const = 0; virtual void encodeRequest(FRT_RPCRequest &req, const vespalib::Version &version, const Route & route, const RPCServiceAddress & address, const Message & msg, uint32_t traceLevel, const PayLoadFiller &filler, duration timeRemaining) const = 0; diff --git a/messagebus/src/vespa/messagebus/network/rpcsendv1.cpp b/messagebus/src/vespa/messagebus/network/rpcsendv1.cpp index 388ab3309c4..f87a8d9638a 100644 --- a/messagebus/src/vespa/messagebus/network/rpcsendv1.cpp +++ b/messagebus/src/vespa/messagebus/network/rpcsendv1.cpp @@ -115,7 +115,7 @@ RPCSendV1::toParams(const FRT_Values &args) const std::unique_ptr<Reply> -RPCSendV1::createReply(const FRT_Values & ret, const string & serviceName, Error & error, vespalib::TraceNode & rootTrace) const +RPCSendV1::createReply(const FRT_Values & ret, const string & serviceName, Error & error, vespalib::Trace & trace) const { vespalib::Version version = vespalib::Version(ret[0]._string._str); double retryDelay = ret[1]._double; @@ -127,7 +127,7 @@ RPCSendV1::createReply(const FRT_Values & ret, const string & serviceName, Error uint32_t errorServicesLen = ret[4]._string_array._len; const char *protocolName = ret[5]._string._str; BlobRef payload(ret[6]._data._buf, ret[6]._data._len); - const char *trace = ret[7]._string._str; + const char *traceStr = ret[7]._string._str; Reply::UP reply; if (payload.size() > 0) { @@ -141,7 +141,7 @@ RPCSendV1::createReply(const FRT_Values & ret, const string & serviceName, Error reply->addError(Error(errorCodes[i], errorMessages[i]._str, errorServices[i]._len > 0 ? errorServices[i]._str : serviceName.c_str())); } - rootTrace.addChild(TraceNode::decode(trace)); + trace.addChild(TraceNode::decode(traceStr)); return reply; } diff --git a/messagebus/src/vespa/messagebus/network/rpcsendv1.h b/messagebus/src/vespa/messagebus/network/rpcsendv1.h index 249acc50e0c..f9b4b0bdfe8 100644 --- a/messagebus/src/vespa/messagebus/network/rpcsendv1.h +++ b/messagebus/src/vespa/messagebus/network/rpcsendv1.h @@ -17,7 +17,7 @@ private: const PayLoadFiller &filler, duration timeRemaining) const override; std::unique_ptr<Reply> createReply(const FRT_Values & response, const string & serviceName, - Error & error, vespalib::TraceNode & rootTrace) const override; + Error & error, vespalib::Trace & trace) const override; void createResponse(FRT_Values & ret, const string & version, Reply & reply, Blob payload) const override; }; diff --git a/messagebus/src/vespa/messagebus/network/rpcsendv2.cpp b/messagebus/src/vespa/messagebus/network/rpcsendv2.cpp index f7303ece20f..9f5aad920b4 100644 --- a/messagebus/src/vespa/messagebus/network/rpcsendv2.cpp +++ b/messagebus/src/vespa/messagebus/network/rpcsendv2.cpp @@ -188,7 +188,7 @@ RPCSendV2::toParams(const FRT_Values &args) const std::unique_ptr<Reply> RPCSendV2::createReply(const FRT_Values & ret, const string & serviceName, - Error & error, vespalib::TraceNode & rootTrace) const + Error & error, vespalib::Trace & rootTrace) const { uint8_t encoding = ret[3]._intval8; uint32_t uncompressedSize = ret[4]._intval32; diff --git a/messagebus/src/vespa/messagebus/network/rpcsendv2.h b/messagebus/src/vespa/messagebus/network/rpcsendv2.h index c48aa90a9fb..da4154e70a8 100644 --- a/messagebus/src/vespa/messagebus/network/rpcsendv2.h +++ b/messagebus/src/vespa/messagebus/network/rpcsendv2.h @@ -17,7 +17,7 @@ private: const PayLoadFiller &filler, duration timeRemaining) const override; std::unique_ptr<Reply> createReply(const FRT_Values & response, const string & serviceName, - Error & error, vespalib::TraceNode & rootTrace) const override; + Error & error, vespalib::Trace & trace) const override; void createResponse(FRT_Values & ret, const string & version, Reply & reply, Blob payload) const override; }; diff --git a/messagebus/src/vespa/messagebus/routing/routingnode.cpp b/messagebus/src/vespa/messagebus/routing/routingnode.cpp index 3a433b05bc5..cc8dd236428 100644 --- a/messagebus/src/vespa/messagebus/routing/routingnode.cpp +++ b/messagebus/src/vespa/messagebus/routing/routingnode.cpp @@ -184,10 +184,7 @@ RoutingNode::setReply(Reply::UP reply) { if (reply) { _shouldRetry = _resender != nullptr && _resender->shouldRetry(*reply); - if ( ! reply->getTrace().isEmpty()) { - _trace.getRoot().addChild(std::move(reply->getTrace().getRoot())); - reply->getTrace().clear(); - } + _trace.addChild(std::move(reply->getTrace())); } _reply = std::move(reply); } @@ -268,14 +265,12 @@ RoutingNode::notifyMerge() // Merges the trace information from all children into this. This method takes care not to spend cycles // manipulating the trace in case tracing is disabled. if (_trace.getLevel() > 0) { - TraceNode tail; + Trace tail; for (auto * child : _children) { - TraceNode &root = child->_trace.getRoot(); - tail.addChild(root); - root.clear(); + tail.addChild(std::move(child->_trace)); } tail.setStrict(false); - _trace.getRoot().addChild(tail); + _trace.addChild(std::move(tail)); } // Execute the {@link RoutingPolicy#merge(RoutingContext)} method of the current routing policy. If a diff --git a/messagebus/src/vespa/messagebus/sendproxy.cpp b/messagebus/src/vespa/messagebus/sendproxy.cpp index fa485e19bb8..bec000b56e2 100644 --- a/messagebus/src/vespa/messagebus/sendproxy.cpp +++ b/messagebus/src/vespa/messagebus/sendproxy.cpp @@ -55,8 +55,8 @@ SendProxy::handleReply(Reply::UP reply) } trace.clear(); } else if (trace.getLevel() > 0) { - trace.getRoot().addChild(reply->getTrace().getRoot()); - trace.getRoot().normalize(); + trace.addChild(reply->getTrace().getRoot()); + trace.normalize(); } reply->swapState(*_msg); reply->setMessage(std::move(_msg)); |