Commit fd34cbd6 authored by zhujiashun's avatar zhujiashun

revert changes related to SampleRequest

parent 0a7432f0
......@@ -159,7 +159,7 @@ void Controller::ResetNonPods() {
_server->_session_local_data_pool->Return(_session_local_data);
}
_mongo_session_data.reset();
delete _sampled_request;
delete _rpc_dump_meta;
if (!is_used_by_rpc() && _correlation_id != INVALID_BTHREAD_ID) {
CHECK_NE(EPERM, bthread_id_cancel(_correlation_id));
......@@ -213,7 +213,7 @@ void Controller::ResetPods() {
_server = NULL;
_oncancel_id = INVALID_BTHREAD_ID;
_auth_context = NULL;
_sampled_request = NULL;
_rpc_dump_meta = NULL;
_request_protocol = PROTOCOL_UNKNOWN;
_max_retry = UNSET_MAGIC_NUM;
_retry_policy = NULL;
......@@ -1331,9 +1331,9 @@ void WebEscape(const std::string& source, std::string* output) {
}
}
void Controller::reset_sampled_request(SampledRequest* req) {
delete _sampled_request;
_sampled_request = req;
void Controller::reset_rpc_dump_meta(RpcDumpMeta* meta) {
delete _rpc_dump_meta;
_rpc_dump_meta = meta;
}
void Controller::set_stream_creator(StreamCreator* sc) {
......
......@@ -63,7 +63,7 @@ class SharedLoadBalancer;
class ExcludedServers;
class RPCSender;
class StreamSettings;
class SampledRequest;
class RpcDumpMeta;
class MongoContext;
class RetryPolicy;
class InputMessageBase;
......@@ -258,10 +258,10 @@ public:
int sub_count() const;
const Controller* sub(int index) const;
// Get/own SampledRquest for sending dumped requests.
// Get/own RpcDumpMeta for sending dumped requests.
// Deleted along with controller.
void reset_sampled_request(SampledRequest* req);
const SampledRequest* sampled_request() { return _sampled_request; }
void reset_rpc_dump_meta(RpcDumpMeta* meta);
const RpcDumpMeta* rpc_dump_meta() { return _rpc_dump_meta; }
// Attach a StreamCreator to this RPC. Notice that the ownership of sc has
// been transferred to cntl, and sc->DestroyStreamCreator() would be called
......@@ -672,7 +672,7 @@ private:
bthread_id_t _oncancel_id;
const AuthContext* _auth_context; // Authentication result
butil::intrusive_ptr<MongoContext> _mongo_session_data;
SampledRequest* _sampled_request;
RpcDumpMeta* _rpc_dump_meta;
ProtocolType _request_protocol;
// Some of them are copied from `Channel' which might be destroyed
......
......@@ -636,11 +636,11 @@ void PackRpcRequest(butil::IOBuf* req_buf,
method->service()->name());
request_meta->set_method_name(method->name());
meta.set_compress_type(cntl->request_compress_type());
} else if (cntl->sampled_request()) {
} else if (cntl->rpc_dump_meta()) {
// Replaying. Keep service-name as the one seen by server.
request_meta->set_service_name(cntl->sampled_request()->meta.service_name());
request_meta->set_method_name(cntl->sampled_request()->meta.method_name());
meta.set_compress_type(cntl->sampled_request()->meta.compress_type());
request_meta->set_service_name(cntl->rpc_dump_meta()->meta.service_name());
request_meta->set_method_name(cntl->rpc_dump_meta()->meta.method_name());
meta.set_compress_type(cntl->rpc_dump_meta()->meta.compress_type());
} else {
return cntl->SetFailed(ENOMETHOD, "%s.method is NULL", __FUNCTION__);
}
......
......@@ -639,13 +639,13 @@ void PackHuluRequest(butil::IOBuf* req_buf,
meta.set_service_name(method->service()->name());
meta.set_method_index(method->index());
meta.set_compress_type(CompressType2Hulu(cntl->request_compress_type()));
} else if (cntl->sampled_request()) {
} else if (cntl->rpc_dump_meta()) {
// Replaying. Keep service-name as the one seen by server.
meta.set_service_name(cntl->sampled_request()->meta.service_name());
meta.set_method_index(cntl->sampled_request()->meta.method_index());
meta.set_service_name(cntl->rpc_dump_meta()->meta.service_name());
meta.set_method_index(cntl->rpc_dump_meta()->meta.method_index());
meta.set_compress_type(
CompressType2Hulu(cntl->sampled_request()->meta.compress_type()));
meta.set_user_data(cntl->sampled_request()->meta.user_data());
CompressType2Hulu(cntl->rpc_dump_meta()->meta.compress_type()));
meta.set_user_data(cntl->rpc_dump_meta()->meta.user_data());
} else {
return cntl->SetFailed(ENOMETHOD, "method is NULL");
}
......
......@@ -545,11 +545,11 @@ void PackSofaRequest(butil::IOBuf* req_buf,
if (method) {
meta.set_method(method->full_name());
meta.set_compress_type(CompressType2Sofa(cntl->request_compress_type()));
} else if (cntl->sampled_request()) {
} else if (cntl->rpc_dump_meta()) {
// Replaying.
meta.set_method(cntl->sampled_request()->meta.method_name());
meta.set_method(cntl->rpc_dump_meta()->meta.method_name());
meta.set_compress_type(
CompressType2Sofa(cntl->sampled_request()->meta.compress_type()));
CompressType2Sofa(cntl->rpc_dump_meta()->meta.compress_type()));
} else {
return cntl->SetFailed(ENOMETHOD, "method is NULL");
}
......
......@@ -21,7 +21,7 @@
#include "butil/iobuf.h" // IOBuf
#include "butil/files/file_path.h" // FilePath
#include "bvar/collector.h"
#include "brpc/rpc_dump.pb.h" // RpcDumpMeta
#include "brpc/rpc_dump.pb.h" // RpcDumpMetaProto
namespace butil {
class FileEnumerator;
......@@ -46,9 +46,17 @@ DECLARE_bool(rpc_dump);
// In practice, sampled requests are just small fraction of all requests.
// The overhead of sampling should be negligible for overall performance.
struct SampledRequest : public bvar::Collected {
// According to
// https://developers.google.com/protocol-buffers/docs/cpptutorial#parsing-and-serialization,
// we use combination instead of inheritance.
class RpcDumpMeta {
public:
RpcDumpMetaProto meta;
};
struct SampledRequest : public bvar::Collected
, public RpcDumpMeta {
butil::IOBuf request;
RpcDumpMeta meta;
// Implement methods of Sampled.
void dump_and_destroy(size_t round) override;
......
......@@ -3,7 +3,7 @@ import "brpc/options.proto";
package brpc;
message RpcDumpMeta {
message RpcDumpMetaProto {
// baidu_std, hulu_pbrpc
optional string service_name = 1;
......
......@@ -157,7 +157,7 @@ static void* replay_thread(void* arg) {
brpc::Controller* cntl = new brpc::Controller;
req.Clear();
cntl->reset_sampled_request(sample_guard.release());
cntl->reset_rpc_dump_meta(sample_guard.release());
if (sample->meta.attachment_size() > 0) {
sample->request.cutn(
&req.serialized_data(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment