Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
40b13429
Unverified
Commit
40b13429
authored
Jun 24, 2019
by
Ge Jun
Committed by
GitHub
Jun 24, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #819 from zyearn/adapt_protobuf_3_7
Adapt to protobuf 3.7 & 3.8
parents
ca6bd6bc
034c9a3b
Hide whitespace changes
Inline
Side-by-side
Showing
26 changed files
with
167 additions
and
917 deletions
+167
-917
CMakeLists.txt
CMakeLists.txt
+2
-1
getting_started.md
docs/cn/getting_started.md
+1
-1
callback.h
src/brpc/callback.h
+5
-0
controller.cpp
src/brpc/controller.cpp
+6
-6
controller.h
src/brpc/controller.h
+5
-5
esp_message.cpp
src/brpc/esp_message.cpp
+5
-108
esp_message.h
src/brpc/esp_message.h
+8
-20
memcache.cpp
src/brpc/memcache.cpp
+8
-147
memcache.h
src/brpc/memcache.h
+12
-32
nshead_message.cpp
src/brpc/nshead_message.cpp
+6
-105
nshead_message.h
src/brpc/nshead_message.h
+6
-26
baidu_rpc_protocol.cpp
src/brpc/policy/baidu_rpc_protocol.cpp
+10
-10
hulu_pbrpc_protocol.cpp
src/brpc/policy/hulu_pbrpc_protocol.cpp
+11
-11
sofa_pbrpc_protocol.cpp
src/brpc/policy/sofa_pbrpc_protocol.cpp
+6
-6
progressive_attachment.h
src/brpc/progressive_attachment.h
+1
-1
proto_base.proto
src/brpc/proto_base.proto
+17
-0
redis.cpp
src/brpc/redis.cpp
+20
-158
redis.h
src/brpc/redis.h
+13
-35
rpc_dump.cpp
src/brpc/rpc_dump.cpp
+2
-3
rpc_dump.h
src/brpc/rpc_dump.h
+3
-4
serialized_request.cpp
src/brpc/serialized_request.cpp
+3
-96
serialized_request.h
src/brpc/serialized_request.h
+5
-21
thrift_message.cpp
src/brpc/thrift_message.cpp
+2
-91
thrift_message.h
src/brpc/thrift_message.h
+4
-24
Makefile
test/Makefile
+1
-1
rpc_replay.cpp
tools/rpc_replay/rpc_replay.cpp
+5
-5
No files found.
CMakeLists.txt
View file @
40b13429
...
...
@@ -371,7 +371,8 @@ set(PROTO_FILES idl_options.proto
brpc/policy/sofa_pbrpc_meta.proto
brpc/policy/mongo.proto
brpc/trackme.proto
brpc/streaming_rpc_meta.proto
)
brpc/streaming_rpc_meta.proto
brpc/proto_base.proto
)
file
(
MAKE_DIRECTORY
${
PROJECT_BINARY_DIR
}
/output/include/brpc
)
set
(
PROTOC_FLAGS
${
PROTOC_FLAGS
}
-I
${
PROTOBUF_INCLUDE_DIR
}
)
compile_proto
(
PROTO_HDRS PROTO_SRCS
${
PROJECT_BINARY_DIR
}
...
...
docs/cn/getting_started.md
View file @
40b13429
...
...
@@ -350,7 +350,7 @@ no known issues.
no known issues.
## protobuf: 2.4
-3.4
## protobuf: 2.4
+
Be compatible with pb 3.x and pb 2.x with the same file:
Don't use new types in proto3 and start the proto file with
`syntax="proto2";`
...
...
src/brpc/callback.h
View file @
40b13429
...
...
@@ -10,6 +10,11 @@
#define BRPC_CALLBACK_H
#include <google/protobuf/stubs/common.h> // Closure
#if GOOGLE_PROTOBUF_VERSION >= 3007000
// After protobuf 3.7.0, callback.h is removed from common.h, we need to explicitly
// include this file.
#include <google/protobuf/stubs/callback.h>
#endif
namespace
brpc
{
...
...
src/brpc/controller.cpp
View file @
40b13429
...
...
@@ -44,7 +44,7 @@
#include "brpc/retry_policy.h"
#include "brpc/stream_impl.h"
#include "brpc/policy/streaming_rpc_protocol.h" // FIXME
#include "brpc/rpc_dump.
pb.
h"
#include "brpc/rpc_dump.h"
#include "brpc/details/usercode_backup_pool.h" // RunUserCode
#include "brpc/mongo_service_adaptor.h"
...
...
@@ -162,7 +162,7 @@ void Controller::ResetNonPods() {
_server
->
_session_local_data_pool
->
Return
(
_session_local_data
);
}
_mongo_session_data
.
reset
();
delete
_
rpc_dump_meta
;
delete
_
sampled_request
;
if
(
!
is_used_by_rpc
()
&&
_correlation_id
!=
INVALID_BTHREAD_ID
)
{
CHECK_NE
(
EPERM
,
bthread_id_cancel
(
_correlation_id
));
...
...
@@ -216,7 +216,7 @@ void Controller::ResetPods() {
_server
=
NULL
;
_oncancel_id
=
INVALID_BTHREAD_ID
;
_auth_context
=
NULL
;
_
rpc_dump_meta
=
NULL
;
_
sampled_request
=
NULL
;
_request_protocol
=
PROTOCOL_UNKNOWN
;
_max_retry
=
UNSET_MAGIC_NUM
;
_retry_policy
=
NULL
;
...
...
@@ -1334,9 +1334,9 @@ void WebEscape(const std::string& source, std::string* output) {
}
}
void
Controller
::
reset_
rpc_dump_meta
(
RpcDumpMeta
*
meta
)
{
delete
_
rpc_dump_meta
;
_
rpc_dump_meta
=
meta
;
void
Controller
::
reset_
sampled_request
(
SampledRequest
*
req
)
{
delete
_
sampled_request
;
_
sampled_request
=
req
;
}
void
Controller
::
set_stream_creator
(
StreamCreator
*
sc
)
{
...
...
src/brpc/controller.h
View file @
40b13429
...
...
@@ -66,7 +66,7 @@ class SharedLoadBalancer;
class
ExcludedServers
;
class
RPCSender
;
class
StreamSettings
;
class
RpcDumpMeta
;
class
SampledRequest
;
class
MongoContext
;
class
RetryPolicy
;
class
InputMessageBase
;
...
...
@@ -261,10 +261,10 @@ public:
int
sub_count
()
const
;
const
Controller
*
sub
(
int
index
)
const
;
// Get/own
RpcDumpMeta
for sending dumped requests.
// Get/own
SampledRequest
for sending dumped requests.
// Deleted along with controller.
void
reset_
rpc_dump_meta
(
RpcDumpMeta
*
meta
);
const
RpcDumpMeta
*
rpc_dump_meta
()
{
return
_rpc_dump_meta
;
}
void
reset_
sampled_request
(
SampledRequest
*
req
);
const
SampledRequest
*
sampled_request
()
{
return
_sampled_request
;
}
// Attach a StreamCreator to this RPC. Notice that the ownership of sc has
// been transferred to cntl, and sc->DestroyStreamCreator() would be called
...
...
@@ -675,7 +675,7 @@ private:
bthread_id_t
_oncancel_id
;
const
AuthContext
*
_auth_context
;
// Authentication result
butil
::
intrusive_ptr
<
MongoContext
>
_mongo_session_data
;
RpcDumpMeta
*
_rpc_dump_meta
;
SampledRequest
*
_sampled_request
;
ProtocolType
_request_protocol
;
// Some of them are copied from `Channel' which might be destroyed
...
...
src/brpc/esp_message.cpp
View file @
40b13429
...
...
@@ -15,99 +15,18 @@
// specific language governing permissions and limitations
// under the License.
// Generated by the protocol buffer compiler. DO NOT EDIT!
#define INTERNAL_SUPPRESS_PROTOBUF_FIELD_DEPRECATION
#include "esp_message.h"
#include <algorithm>
#include <google/protobuf/stubs/once.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/wire_format_lite_inl.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/reflection_ops.h>
#include <google/protobuf/wire_format.h>
// @@protoc_insertion_point(includes)
#include <google/protobuf/reflection_ops.h> // ReflectionOps::Merge
#include <google/protobuf/wire_format.h> // WireFormatLite::GetTagWireType
namespace
brpc
{
namespace
{
const
::
google
::
protobuf
::
Descriptor
*
EspMessage_descriptor_
=
NULL
;
}
// namespace
void
protobuf_AssignDesc_esp_5fmessage_2eproto
()
{
protobuf_AddDesc_esp_5fmessage_2eproto
();
const
::
google
::
protobuf
::
FileDescriptor
*
file
=
::
google
::
protobuf
::
DescriptorPool
::
generated_pool
()
->
FindFileByName
(
"esp_message.proto"
);
GOOGLE_CHECK
(
file
!=
NULL
);
EspMessage_descriptor_
=
file
->
message_type
(
0
);
}
namespace
{
GOOGLE_PROTOBUF_DECLARE_ONCE
(
protobuf_AssignDescriptors_once_
);
inline
void
protobuf_AssignDescriptorsOnce
()
{
::
google
::
protobuf
::
GoogleOnceInit
(
&
protobuf_AssignDescriptors_once_
,
&
protobuf_AssignDesc_esp_5fmessage_2eproto
);
}
void
protobuf_RegisterTypes
(
const
::
std
::
string
&
)
{
protobuf_AssignDescriptorsOnce
();
::
google
::
protobuf
::
MessageFactory
::
InternalRegisterGeneratedMessage
(
EspMessage_descriptor_
,
&
EspMessage
::
default_instance
());
}
}
// namespace
void
protobuf_ShutdownFile_esp_5fmessage_2eproto
()
{
delete
EspMessage
::
default_instance_
;
}
void
protobuf_AddDesc_esp_5fmessage_2eproto
()
{
static
bool
already_here
=
false
;
if
(
already_here
)
{
return
;
}
already_here
=
true
;
GOOGLE_PROTOBUF_VERIFY_VERSION
;
::
google
::
protobuf
::
DescriptorPool
::
InternalAddGeneratedFile
(
"
\n\021
esp_message.proto
\022\t
baidu.rpc
\"\014\n\n
EspMessage"
,
44
);
::
google
::
protobuf
::
MessageFactory
::
InternalRegisterGeneratedFile
(
"esp_message.proto"
,
&
protobuf_RegisterTypes
);
EspMessage
::
default_instance_
=
new
EspMessage
();
EspMessage
::
default_instance_
->
InitAsDefaultInstance
();
::
google
::
protobuf
::
internal
::
OnShutdown
(
&
protobuf_ShutdownFile_esp_5fmessage_2eproto
);
}
// Force AddDescriptors() to be called at static initialization time.
struct
StaticDescriptorInitializer_esp_5fmessage_2eproto
{
StaticDescriptorInitializer_esp_5fmessage_2eproto
()
{
protobuf_AddDesc_esp_5fmessage_2eproto
();
}
}
static_descriptor_initializer_esp_5fmessage_2eproto_
;
// ===================================================================
#ifndef _MSC_VER
#endif // !_MSC_VER
EspMessage
::
EspMessage
()
:
::
google
::
protobuf
::
Message
()
{
SharedCtor
();
}
void
EspMessage
::
InitAsDefaultInstance
()
{
}
EspMessage
::
EspMessage
(
const
EspMessage
&
from
)
:
::
google
::
protobuf
::
Message
()
{
SharedCtor
();
...
...
@@ -123,25 +42,12 @@ EspMessage::~EspMessage() {
}
void
EspMessage
::
SharedDtor
()
{
if
(
this
!=
default_instance_
)
{
}
}
const
::
google
::
protobuf
::
Descriptor
*
EspMessage
::
descriptor
()
{
protobuf_AssignDescriptorsOnce
();
return
EspMessage_descriptor_
;
}
const
EspMessage
&
EspMessage
::
default_instance
()
{
if
(
default_instance_
==
NULL
)
{
protobuf_AddDesc_esp_5fmessage_2eproto
();
}
return
*
default_instance_
;
return
EspMessageBase
::
descriptor
();
}
EspMessage
*
EspMessage
::
default_instance_
=
NULL
;
EspMessage
*
EspMessage
::
New
()
const
{
return
new
EspMessage
;
}
...
...
@@ -181,10 +87,7 @@ int EspMessage::ByteSize() const {
void
EspMessage
::
MergeFrom
(
const
::
google
::
protobuf
::
Message
&
from
)
{
GOOGLE_CHECK_NE
(
&
from
,
this
);
const
EspMessage
*
source
=
::
google
::
protobuf
::
internal
::
dynamic_cast_if_available
<
const
EspMessage
*>
(
&
from
);
const
EspMessage
*
source
=
dynamic_cast
<
const
EspMessage
*>
(
&
from
);
if
(
source
==
NULL
)
{
::
google
::
protobuf
::
internal
::
ReflectionOps
::
Merge
(
from
,
this
);
}
else
{
...
...
@@ -230,16 +133,10 @@ void EspMessage::Swap(EspMessage* other) {
}
::
google
::
protobuf
::
Metadata
EspMessage
::
GetMetadata
()
const
{
protobuf_AssignDescriptorsOnce
();
::
google
::
protobuf
::
Metadata
metadata
;
metadata
.
descriptor
=
EspMessage
_descriptor_
;
metadata
.
descriptor
=
EspMessage
::
descriptor
()
;
metadata
.
reflection
=
NULL
;
return
metadata
;
}
// @@protoc_insertion_point(namespace_scope)
}
// namespace brpc
// @@protoc_insertion_point(global_scope)
src/brpc/esp_message.h
View file @
40b13429
...
...
@@ -20,23 +20,16 @@
#include <string>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/repeated_field.h>
#include <google/protobuf/extension_set.h>
#include <google/protobuf/generated_message_reflection.h>
#include <google/protobuf/message.h>
#include <google/protobuf/generated_message_reflection.h> // dynamic_cast_if_available
#include <google/protobuf/reflection_ops.h> // ReflectionOps::Merge
#include "brpc/esp_head.h"
#include "butil/iobuf.h"
#include "brpc/proto_base.pb.h"
namespace
brpc
{
// Internal implementation detail -- do not call these.
void
protobuf_AddDesc_esp_5fmessage_2eproto
();
void
protobuf_AssignDesc_esp_5fmessage_2eproto
();
void
protobuf_ShutdownFile_esp_5fmessage_2eproto
();
class
EspMessage
:
public
::
google
::
protobuf
::
Message
{
public
:
EspHead
head
;
...
...
@@ -76,20 +69,15 @@ public:
::
google
::
protobuf
::
uint8
*
SerializeWithCachedSizesToArray
(
::
google
::
protobuf
::
uint8
*
output
)
const
;
int
GetCachedSize
()
const
{
return
ByteSize
();
}
::
google
::
protobuf
::
Metadata
GetMetadata
()
const
;
protected
:
::
google
::
protobuf
::
Metadata
GetMetadata
()
const
override
;
private
:
void
SharedCtor
();
void
SharedDtor
();
friend
void
protobuf_AddDesc_esp_5fmessage_2eproto
();
friend
void
protobuf_AssignDesc_esp_5fmessage_2eproto
();
friend
void
protobuf_ShutdownFile_esp_5fmessage_2eproto
();
void
InitAsDefaultInstance
();
static
EspMessage
*
default_instance_
;
};
}
// namespace brpc
#endif // PROTOBUF_esp_5fmessage_2eproto__INCLUDED
#endif // BRPC_ESP_MESSAGE_H
src/brpc/memcache.cpp
View file @
40b13429
...
...
@@ -17,119 +17,23 @@
// Authors: Ge,Jun (gejun@baidu.com)
#define INTERNAL_SUPPRESS_PROTOBUF_FIELD_DEPRECATION
#include <algorithm>
#include <google/protobuf/stubs/once.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/wire_format_lite_inl.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/reflection_ops.h>
#include <google/protobuf/wire_format.h>
#include "butil/string_printf.h"
#include "butil/macros.h"
#include "butil/sys_byteorder.h"
#include "b
rpc/controller
.h"
#include "b
util/logging
.h"
#include "brpc/memcache.h"
#include "brpc/policy/memcache_binary_header.h"
namespace
brpc
{
// Internal implementation detail -- do not call these.
void
protobuf_AddDesc_baidu_2frpc_2fmemcache_5fbase_2eproto_impl
();
void
protobuf_AddDesc_baidu_2frpc_2fmemcache_5fbase_2eproto
();
void
protobuf_AssignDesc_baidu_2frpc_2fmemcache_5fbase_2eproto
();
void
protobuf_ShutdownFile_baidu_2frpc_2fmemcache_5fbase_2eproto
();
namespace
{
const
::
google
::
protobuf
::
Descriptor
*
MemcacheRequest_descriptor_
=
NULL
;
const
::
google
::
protobuf
::
Descriptor
*
MemcacheResponse_descriptor_
=
NULL
;
}
// namespace
void
protobuf_AssignDesc_baidu_2frpc_2fmemcache_5fbase_2eproto
()
{
protobuf_AddDesc_baidu_2frpc_2fmemcache_5fbase_2eproto
();
const
::
google
::
protobuf
::
FileDescriptor
*
file
=
::
google
::
protobuf
::
DescriptorPool
::
generated_pool
()
->
FindFileByName
(
"baidu/rpc/memcache_base.proto"
);
GOOGLE_CHECK
(
file
!=
NULL
);
MemcacheRequest_descriptor_
=
file
->
message_type
(
0
);
MemcacheResponse_descriptor_
=
file
->
message_type
(
1
);
}
namespace
{
GOOGLE_PROTOBUF_DECLARE_ONCE
(
protobuf_AssignDescriptors_once_
);
inline
void
protobuf_AssignDescriptorsOnce
()
{
::
google
::
protobuf
::
GoogleOnceInit
(
&
protobuf_AssignDescriptors_once_
,
&
protobuf_AssignDesc_baidu_2frpc_2fmemcache_5fbase_2eproto
);
}
void
protobuf_RegisterTypes
(
const
::
std
::
string
&
)
{
protobuf_AssignDescriptorsOnce
();
::
google
::
protobuf
::
MessageFactory
::
InternalRegisterGeneratedMessage
(
MemcacheRequest_descriptor_
,
&
MemcacheRequest
::
default_instance
());
::
google
::
protobuf
::
MessageFactory
::
InternalRegisterGeneratedMessage
(
MemcacheResponse_descriptor_
,
&
MemcacheResponse
::
default_instance
());
}
}
// namespace
void
protobuf_ShutdownFile_baidu_2frpc_2fmemcache_5fbase_2eproto
()
{
delete
MemcacheRequest
::
default_instance_
;
delete
MemcacheResponse
::
default_instance_
;
}
void
protobuf_AddDesc_baidu_2frpc_2fmemcache_5fbase_2eproto_impl
()
{
GOOGLE_PROTOBUF_VERIFY_VERSION
;
#if GOOGLE_PROTOBUF_VERSION >= 3002000
::
google
::
protobuf
::
internal
::
InitProtobufDefaults
();
#else
::
google
::
protobuf
::
protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto
();
#endif
::
google
::
protobuf
::
DescriptorPool
::
InternalAddGeneratedFile
(
"
\n\035
baidu/rpc/memcache_base.proto
\022\t
baidu.r"
"pc
\032
google/protobuf/descriptor.proto
\"\021\n\017
"
"MemcacheRequest
\"\022\n\020
MemcacheResponseB
\003\200\001\001
"
,
120
);
::
google
::
protobuf
::
MessageFactory
::
InternalRegisterGeneratedFile
(
"baidu/rpc/memcache_base.proto"
,
&
protobuf_RegisterTypes
);
MemcacheRequest
::
default_instance_
=
new
MemcacheRequest
();
MemcacheResponse
::
default_instance_
=
new
MemcacheResponse
();
MemcacheRequest
::
default_instance_
->
InitAsDefaultInstance
();
MemcacheResponse
::
default_instance_
->
InitAsDefaultInstance
();
::
google
::
protobuf
::
internal
::
OnShutdown
(
&
protobuf_ShutdownFile_baidu_2frpc_2fmemcache_5fbase_2eproto
);
}
GOOGLE_PROTOBUF_DECLARE_ONCE
(
protobuf_AddDesc_baidu_2frpc_2fmemcache_5fbase_2eproto_once
);
void
protobuf_AddDesc_baidu_2frpc_2fmemcache_5fbase_2eproto
()
{
::
google
::
protobuf
::
GoogleOnceInit
(
&
protobuf_AddDesc_baidu_2frpc_2fmemcache_5fbase_2eproto_once
,
&
protobuf_AddDesc_baidu_2frpc_2fmemcache_5fbase_2eproto_impl
);
}
// Force AddDescriptors() to be called at static initialization time.
struct
StaticDescriptorInitializer_baidu_2frpc_2fmemcache_5fbase_2eproto
{
StaticDescriptorInitializer_baidu_2frpc_2fmemcache_5fbase_2eproto
()
{
protobuf_AddDesc_baidu_2frpc_2fmemcache_5fbase_2eproto
();
}
}
static_descriptor_initializer_baidu_2frpc_2fmemcache_5fbase_2eproto_
;
// ===================================================================
#ifndef _MSC_VER
#endif // !_MSC_VER
MemcacheRequest
::
MemcacheRequest
()
:
::
google
::
protobuf
::
Message
()
{
SharedCtor
();
}
void
MemcacheRequest
::
InitAsDefaultInstance
()
{
}
MemcacheRequest
::
MemcacheRequest
(
const
MemcacheRequest
&
from
)
:
::
google
::
protobuf
::
Message
()
{
SharedCtor
();
...
...
@@ -146,29 +50,16 @@ MemcacheRequest::~MemcacheRequest() {
}
void
MemcacheRequest
::
SharedDtor
()
{
if
(
this
!=
default_instance_
)
{
}
}
void
MemcacheRequest
::
SetCachedSize
(
int
size
)
const
{
GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN
();
_cached_size_
=
size
;
GOOGLE_SAFE_CONCURRENT_WRITES_END
();
}
const
::
google
::
protobuf
::
Descriptor
*
MemcacheRequest
::
descriptor
()
{
protobuf_AssignDescriptorsOnce
();
return
MemcacheRequest_descriptor_
;
}
const
MemcacheRequest
&
MemcacheRequest
::
default_instance
()
{
if
(
default_instance_
==
NULL
)
{
protobuf_AddDesc_baidu_2frpc_2fmemcache_5fbase_2eproto
();
}
return
*
default_instance_
;
const
::
google
::
protobuf
::
Descriptor
*
MemcacheRequest
::
descriptor
()
{
return
MemcacheRequestBase
::
descriptor
();
}
MemcacheRequest
*
MemcacheRequest
::
default_instance_
=
NULL
;
MemcacheRequest
*
MemcacheRequest
::
New
()
const
{
return
new
MemcacheRequest
;
}
...
...
@@ -233,16 +124,13 @@ void MemcacheRequest::SerializeWithCachedSizes(
int
MemcacheRequest
::
ByteSize
()
const
{
int
total_size
=
_buf
.
size
();
GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN
();
_cached_size_
=
total_size
;
GOOGLE_SAFE_CONCURRENT_WRITES_END
();
return
total_size
;
}
void
MemcacheRequest
::
MergeFrom
(
const
::
google
::
protobuf
::
Message
&
from
)
{
GOOGLE_CHECK_NE
(
&
from
,
this
);
const
MemcacheRequest
*
source
=
::
google
::
protobuf
::
internal
::
dynamic_cast_if_available
<
const
MemcacheRequest
*>
(
&
from
);
const
MemcacheRequest
*
source
=
dynamic_cast
<
const
MemcacheRequest
*>
(
&
from
);
if
(
source
==
NULL
)
{
::
google
::
protobuf
::
internal
::
ReflectionOps
::
Merge
(
from
,
this
);
}
else
{
...
...
@@ -281,26 +169,17 @@ void MemcacheRequest::Swap(MemcacheRequest* other) {
}
::
google
::
protobuf
::
Metadata
MemcacheRequest
::
GetMetadata
()
const
{
protobuf_AssignDescriptorsOnce
();
::
google
::
protobuf
::
Metadata
metadata
;
metadata
.
descriptor
=
MemcacheRequest
_descriptor_
;
metadata
.
descriptor
=
MemcacheRequest
::
descriptor
()
;
metadata
.
reflection
=
NULL
;
return
metadata
;
}
// ===================================================================
#ifndef _MSC_VER
#endif // !_MSC_VER
MemcacheResponse
::
MemcacheResponse
()
:
::
google
::
protobuf
::
Message
()
{
SharedCtor
();
}
void
MemcacheResponse
::
InitAsDefaultInstance
()
{
}
MemcacheResponse
::
MemcacheResponse
(
const
MemcacheResponse
&
from
)
:
::
google
::
protobuf
::
Message
()
{
SharedCtor
();
...
...
@@ -316,29 +195,15 @@ MemcacheResponse::~MemcacheResponse() {
}
void
MemcacheResponse
::
SharedDtor
()
{
if
(
this
!=
default_instance_
)
{
}
}
void
MemcacheResponse
::
SetCachedSize
(
int
size
)
const
{
GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN
();
_cached_size_
=
size
;
GOOGLE_SAFE_CONCURRENT_WRITES_END
();
}
const
::
google
::
protobuf
::
Descriptor
*
MemcacheResponse
::
descriptor
()
{
protobuf_AssignDescriptorsOnce
();
return
MemcacheResponse_descriptor_
;
return
MemcacheResponseBase
::
descriptor
();
}
const
MemcacheResponse
&
MemcacheResponse
::
default_instance
()
{
if
(
default_instance_
==
NULL
)
{
protobuf_AddDesc_baidu_2frpc_2fmemcache_5fbase_2eproto
();
}
return
*
default_instance_
;
}
MemcacheResponse
*
MemcacheResponse
::
default_instance_
=
NULL
;
MemcacheResponse
*
MemcacheResponse
::
New
()
const
{
return
new
MemcacheResponse
;
}
...
...
@@ -380,16 +245,13 @@ void MemcacheResponse::SerializeWithCachedSizes(
int
MemcacheResponse
::
ByteSize
()
const
{
int
total_size
=
_buf
.
size
();
GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN
();
_cached_size_
=
total_size
;
GOOGLE_SAFE_CONCURRENT_WRITES_END
();
return
total_size
;
}
void
MemcacheResponse
::
MergeFrom
(
const
::
google
::
protobuf
::
Message
&
from
)
{
GOOGLE_CHECK_NE
(
&
from
,
this
);
const
MemcacheResponse
*
source
=
::
google
::
protobuf
::
internal
::
dynamic_cast_if_available
<
const
MemcacheResponse
*>
(
&
from
);
const
MemcacheResponse
*
source
=
dynamic_cast
<
const
MemcacheResponse
*>
(
&
from
);
if
(
source
==
NULL
)
{
::
google
::
protobuf
::
internal
::
ReflectionOps
::
Merge
(
from
,
this
);
}
else
{
...
...
@@ -429,9 +291,8 @@ void MemcacheResponse::Swap(MemcacheResponse* other) {
}
::
google
::
protobuf
::
Metadata
MemcacheResponse
::
GetMetadata
()
const
{
protobuf_AssignDescriptorsOnce
();
::
google
::
protobuf
::
Metadata
metadata
;
metadata
.
descriptor
=
MemcacheResponse
_descriptor_
;
metadata
.
descriptor
=
MemcacheResponse
::
descriptor
()
;
metadata
.
reflection
=
NULL
;
return
metadata
;
}
...
...
src/brpc/memcache.h
View file @
40b13429
...
...
@@ -21,15 +21,11 @@
#define BRPC_MEMCACHE_H
#include <string>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/repeated_field.h>
#include <google/protobuf/extension_set.h>
#include <google/protobuf/generated_message_reflection.h>
#include "google/protobuf/descriptor.pb.h"
#include <google/protobuf/message.h>
#include "butil/iobuf.h"
#include "butil/strings/string_piece.h"
#include "brpc/proto_base.pb.h"
namespace
brpc
{
...
...
@@ -90,6 +86,9 @@ public:
int
pipelined_count
()
const
{
return
_pipelined_count
;
}
butil
::
IOBuf
&
raw_buffer
()
{
return
_buf
;
}
const
butil
::
IOBuf
&
raw_buffer
()
const
{
return
_buf
;
}
// Protobuf methods.
MemcacheRequest
*
New
()
const
;
void
CopyFrom
(
const
::
google
::
protobuf
::
Message
&
from
);
...
...
@@ -108,11 +107,9 @@ public:
int
GetCachedSize
()
const
{
return
_cached_size_
;
}
static
const
::
google
::
protobuf
::
Descriptor
*
descriptor
();
static
const
MemcacheRequest
&
default_instance
();
::
google
::
protobuf
::
Metadata
GetMetadata
()
const
;
butil
::
IOBuf
&
raw_buffer
()
{
return
_buf
;
}
const
butil
::
IOBuf
&
raw_buffer
()
const
{
return
_buf
;
}
protected
:
::
google
::
protobuf
::
Metadata
GetMetadata
()
const
override
;
private
:
bool
GetOrDelete
(
uint8_t
command
,
const
butil
::
StringPiece
&
key
);
...
...
@@ -130,14 +127,6 @@ private:
int
_pipelined_count
;
butil
::
IOBuf
_buf
;
mutable
int
_cached_size_
;
friend
void
protobuf_AddDesc_baidu_2frpc_2fmemcache_5fbase_2eproto_impl
();
friend
void
protobuf_AddDesc_baidu_2frpc_2fmemcache_5fbase_2eproto
();
friend
void
protobuf_AssignDesc_baidu_2frpc_2fmemcache_5fbase_2eproto
();
friend
void
protobuf_ShutdownFile_baidu_2frpc_2fmemcache_5fbase_2eproto
();
void
InitAsDefaultInstance
();
static
MemcacheRequest
*
default_instance_
;
};
// Response from Memcache.
...
...
@@ -205,6 +194,9 @@ public:
bool
PopDecrement
(
uint64_t
*
new_value
,
uint64_t
*
cas_value
);
bool
PopTouch
();
bool
PopVersion
(
std
::
string
*
version
);
butil
::
IOBuf
&
raw_buffer
()
{
return
_buf
;
}
const
butil
::
IOBuf
&
raw_buffer
()
const
{
return
_buf
;
}
static
const
char
*
status_str
(
Status
);
// implements Message ----------------------------------------------
...
...
@@ -225,13 +217,9 @@ public:
int
GetCachedSize
()
const
{
return
_cached_size_
;
}
static
const
::
google
::
protobuf
::
Descriptor
*
descriptor
();
static
const
MemcacheResponse
&
default_instance
();
::
google
::
protobuf
::
Metadata
GetMetadata
()
const
;
butil
::
IOBuf
&
raw_buffer
()
{
return
_buf
;
}
const
butil
::
IOBuf
&
raw_buffer
()
const
{
return
_buf
;
}
static
const
char
*
status_str
(
Status
);
protected
:
::
google
::
protobuf
::
Metadata
GetMetadata
()
const
;
private
:
bool
PopCounter
(
uint8_t
command
,
uint64_t
*
new_value
,
uint64_t
*
cas_value
);
...
...
@@ -244,14 +232,6 @@ private:
std
::
string
_err
;
butil
::
IOBuf
_buf
;
mutable
int
_cached_size_
;
friend
void
protobuf_AddDesc_baidu_2frpc_2fmemcache_5fbase_2eproto_impl
();
friend
void
protobuf_AddDesc_baidu_2frpc_2fmemcache_5fbase_2eproto
();
friend
void
protobuf_AssignDesc_baidu_2frpc_2fmemcache_5fbase_2eproto
();
friend
void
protobuf_ShutdownFile_baidu_2frpc_2fmemcache_5fbase_2eproto
();
void
InitAsDefaultInstance
();
static
MemcacheResponse
*
default_instance_
;
};
}
// namespace brpc
...
...
src/brpc/nshead_message.cpp
View file @
40b13429
...
...
@@ -17,104 +17,19 @@
// Authors: Ge,Jun (gejun@baidu.com)
#define INTERNAL_SUPPRESS_PROTOBUF_FIELD_DEPRECATION
#include "brpc/nshead_message.h"
#include <algorithm>
#include "butil/logging.h"
#include <google/protobuf/stubs/once.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/wire_format_lite_inl.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/reflection_ops.h>
#include <google/protobuf/reflection_ops.h> // ReflectionOps::Merge
#include <google/protobuf/wire_format.h>
#include "brpc/nshead_message.h"
#include "butil/logging.h"
namespace
brpc
{
namespace
{
const
::
google
::
protobuf
::
Descriptor
*
NsheadMessage_descriptor_
=
NULL
;
}
// namespace
void
protobuf_AssignDesc_baidu_2frpc_2fnshead_5fmessage_2eproto
()
{
protobuf_AddDesc_baidu_2frpc_2fnshead_5fmessage_2eproto
();
const
::
google
::
protobuf
::
FileDescriptor
*
file
=
::
google
::
protobuf
::
DescriptorPool
::
generated_pool
()
->
FindFileByName
(
"baidu/rpc/nshead_message.proto"
);
GOOGLE_CHECK
(
file
!=
NULL
);
NsheadMessage_descriptor_
=
file
->
message_type
(
0
);
}
namespace
{
GOOGLE_PROTOBUF_DECLARE_ONCE
(
protobuf_AssignDescriptors_once_
);
inline
void
protobuf_AssignDescriptorsOnce
()
{
::
google
::
protobuf
::
GoogleOnceInit
(
&
protobuf_AssignDescriptors_once_
,
&
protobuf_AssignDesc_baidu_2frpc_2fnshead_5fmessage_2eproto
);
}
void
protobuf_RegisterTypes
(
const
::
std
::
string
&
)
{
protobuf_AssignDescriptorsOnce
();
::
google
::
protobuf
::
MessageFactory
::
InternalRegisterGeneratedMessage
(
NsheadMessage_descriptor_
,
&
NsheadMessage
::
default_instance
());
}
}
// namespace
void
protobuf_ShutdownFile_baidu_2frpc_2fnshead_5fmessage_2eproto
()
{
delete
NsheadMessage
::
default_instance_
;
}
void
protobuf_AddDesc_baidu_2frpc_2fnshead_5fmessage_2eproto_impl
()
{
GOOGLE_PROTOBUF_VERIFY_VERSION
;
#if GOOGLE_PROTOBUF_VERSION >= 3002000
::
google
::
protobuf
::
internal
::
InitProtobufDefaults
();
#else
::
google
::
protobuf
::
protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto
();
#endif
::
google
::
protobuf
::
DescriptorPool
::
InternalAddGeneratedFile
(
"
\n\036
baidu/rpc/nshead_message.proto
\022\t
baidu."
"rpc
\032
google/protobuf/descriptor.proto
\"\017\n
"
"
\r
NsheadMessageB
\003\200\001\001
"
,
99
);
::
google
::
protobuf
::
MessageFactory
::
InternalRegisterGeneratedFile
(
"baidu/rpc/nshead_message.proto"
,
&
protobuf_RegisterTypes
);
NsheadMessage
::
default_instance_
=
new
NsheadMessage
();
NsheadMessage
::
default_instance_
->
InitAsDefaultInstance
();
::
google
::
protobuf
::
internal
::
OnShutdown
(
&
protobuf_ShutdownFile_baidu_2frpc_2fnshead_5fmessage_2eproto
);
}
GOOGLE_PROTOBUF_DECLARE_ONCE
(
protobuf_AddDesc_baidu_2frpc_2fnshead_5fmessage_2eproto_once
);
void
protobuf_AddDesc_baidu_2frpc_2fnshead_5fmessage_2eproto
()
{
::
google
::
protobuf
::
GoogleOnceInit
(
&
protobuf_AddDesc_baidu_2frpc_2fnshead_5fmessage_2eproto_once
,
&
protobuf_AddDesc_baidu_2frpc_2fnshead_5fmessage_2eproto_impl
);
}
// Force AddDescriptors() to be called at static initialization time.
struct
StaticDescriptorInitializer_baidu_2frpc_2fnshead_5fmessage_2eproto
{
StaticDescriptorInitializer_baidu_2frpc_2fnshead_5fmessage_2eproto
()
{
protobuf_AddDesc_baidu_2frpc_2fnshead_5fmessage_2eproto
();
}
}
static_descriptor_initializer_baidu_2frpc_2fnshead_5fmessage_2eproto_
;
// ===================================================================
#ifndef _MSC_VER
#endif // !_MSC_VER
NsheadMessage
::
NsheadMessage
()
:
::
google
::
protobuf
::
Message
()
{
SharedCtor
();
}
void
NsheadMessage
::
InitAsDefaultInstance
()
{
}
NsheadMessage
::
NsheadMessage
(
const
NsheadMessage
&
from
)
:
::
google
::
protobuf
::
Message
()
{
SharedCtor
();
...
...
@@ -130,23 +45,12 @@ NsheadMessage::~NsheadMessage() {
}
void
NsheadMessage
::
SharedDtor
()
{
if
(
this
!=
default_instance_
)
{
}
}
const
::
google
::
protobuf
::
Descriptor
*
NsheadMessage
::
descriptor
()
{
protobuf_AssignDescriptorsOnce
();
return
NsheadMessage_descriptor_
;
}
const
NsheadMessage
&
NsheadMessage
::
default_instance
()
{
if
(
default_instance_
==
NULL
)
protobuf_AddDesc_baidu_2frpc_2fnshead_5fmessage_2eproto
();
return
*
default_instance_
;
return
NsheadMessageBase
::
descriptor
();
}
NsheadMessage
*
NsheadMessage
::
default_instance_
=
NULL
;
NsheadMessage
*
NsheadMessage
::
New
()
const
{
return
new
NsheadMessage
;
}
...
...
@@ -185,9 +89,7 @@ int NsheadMessage::ByteSize() const {
void
NsheadMessage
::
MergeFrom
(
const
::
google
::
protobuf
::
Message
&
from
)
{
GOOGLE_CHECK_NE
(
&
from
,
this
);
const
NsheadMessage
*
source
=
::
google
::
protobuf
::
internal
::
dynamic_cast_if_available
<
const
NsheadMessage
*>
(
&
from
);
const
NsheadMessage
*
source
=
dynamic_cast
<
const
NsheadMessage
*>
(
&
from
);
if
(
source
==
NULL
)
{
LOG
(
ERROR
)
<<
"Can only merge from NsheadMessage"
;
return
;
...
...
@@ -229,9 +131,8 @@ void NsheadMessage::Swap(NsheadMessage* other) {
}
::
google
::
protobuf
::
Metadata
NsheadMessage
::
GetMetadata
()
const
{
protobuf_AssignDescriptorsOnce
();
::
google
::
protobuf
::
Metadata
metadata
;
metadata
.
descriptor
=
NsheadMessage
_descriptor_
;
metadata
.
descriptor
=
NsheadMessage
::
descriptor
()
;
metadata
.
reflection
=
NULL
;
return
metadata
;
}
...
...
src/brpc/nshead_message.h
View file @
40b13429
...
...
@@ -20,26 +20,13 @@
#ifndef BRPC_NSHEAD_MESSAGE_H
#define BRPC_NSHEAD_MESSAGE_H
#include <string>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/repeated_field.h>
#include <google/protobuf/extension_set.h>
#include <google/protobuf/generated_message_reflection.h>
#include "google/protobuf/descriptor.pb.h"
#include <google/protobuf/message.h>
#include "brpc/nshead.h" // nshead_t
#include "butil/iobuf.h"
// IOBuf
#include "butil/iobuf.h" // IOBuf
#include "brpc/proto_base.pb.h"
namespace
brpc
{
// Internal implementation detail -- do not call these.
void
protobuf_AddDesc_baidu_2frpc_2fnshead_5fmessage_2eproto
();
void
protobuf_AssignDesc_baidu_2frpc_2fnshead_5fmessage_2eproto
();
void
protobuf_ShutdownFile_baidu_2frpc_2fnshead_5fmessage_2eproto
();
// Representing a nshead request or response.
class
NsheadMessage
:
public
::
google
::
protobuf
::
Message
{
public
:
...
...
@@ -58,7 +45,6 @@ public:
}
static
const
::
google
::
protobuf
::
Descriptor
*
descriptor
();
static
const
NsheadMessage
&
default_instance
();
void
Swap
(
NsheadMessage
*
other
);
...
...
@@ -79,19 +65,13 @@ public:
::
google
::
protobuf
::
io
::
CodedOutputStream
*
output
)
const
;
::
google
::
protobuf
::
uint8
*
SerializeWithCachedSizesToArray
(
::
google
::
protobuf
::
uint8
*
output
)
const
;
int
GetCachedSize
()
const
{
return
ByteSize
();
}
::
google
::
protobuf
::
Metadata
GetMetadata
()
const
;
protected
:
::
google
::
protobuf
::
Metadata
GetMetadata
()
const
override
;
private
:
void
SharedCtor
();
void
SharedDtor
();
private
:
friend
void
protobuf_AddDesc_baidu_2frpc_2fnshead_5fmessage_2eproto_impl
();
friend
void
protobuf_AddDesc_baidu_2frpc_2fnshead_5fmessage_2eproto
();
friend
void
protobuf_AssignDesc_baidu_2frpc_2fnshead_5fmessage_2eproto
();
friend
void
protobuf_ShutdownFile_baidu_2frpc_2fnshead_5fmessage_2eproto
();
void
InitAsDefaultInstance
();
static
NsheadMessage
*
default_instance_
;
};
}
// namespace brpc
...
...
src/brpc/policy/baidu_rpc_protocol.cpp
View file @
40b13429
...
...
@@ -320,12 +320,12 @@ void ProcessRpcRequest(InputMessageBase* msg_base) {
SampledRequest
*
sample
=
AskToBeSampled
();
if
(
sample
)
{
sample
->
set_service_name
(
request_meta
.
service_name
());
sample
->
set_method_name
(
request_meta
.
method_name
());
sample
->
set_compress_type
((
CompressType
)
meta
.
compress_type
());
sample
->
set_protocol_type
(
PROTOCOL_BAIDU_STD
);
sample
->
set_attachment_size
(
meta
.
attachment_size
());
sample
->
set_authentication_data
(
meta
.
authentication_data
());
sample
->
meta
.
set_service_name
(
request_meta
.
service_name
());
sample
->
meta
.
set_method_name
(
request_meta
.
method_name
());
sample
->
meta
.
set_compress_type
((
CompressType
)
meta
.
compress_type
());
sample
->
meta
.
set_protocol_type
(
PROTOCOL_BAIDU_STD
);
sample
->
meta
.
set_attachment_size
(
meta
.
attachment_size
());
sample
->
meta
.
set_authentication_data
(
meta
.
authentication_data
());
sample
->
request
=
msg
->
payload
;
sample
->
submit
(
start_parse_us
);
}
...
...
@@ -639,11 +639,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
->
rpc_dump_meta
())
{
}
else
if
(
cntl
->
sampled_request
())
{
// Replaying. Keep service-name as the one seen by server.
request_meta
->
set_service_name
(
cntl
->
rpc_dump_meta
()
->
service_name
());
request_meta
->
set_method_name
(
cntl
->
rpc_dump_meta
()
->
method_name
());
meta
.
set_compress_type
(
cntl
->
rpc_dump_meta
()
->
compress_type
());
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
());
}
else
{
return
cntl
->
SetFailed
(
ENOMETHOD
,
"%s.method is NULL"
,
__FUNCTION__
);
}
...
...
src/brpc/policy/hulu_pbrpc_protocol.cpp
View file @
40b13429
...
...
@@ -348,15 +348,15 @@ void ProcessHuluRequest(InputMessageBase* msg_base) {
const
CompressType
req_cmp_type
=
Hulu2CompressType
((
HuluCompressType
)
meta
.
compress_type
());
SampledRequest
*
sample
=
AskToBeSampled
();
if
(
sample
)
{
sample
->
set_service_name
(
meta
.
service_name
());
sample
->
set_method_index
(
meta
.
method_index
());
sample
->
set_compress_type
(
req_cmp_type
);
sample
->
set_protocol_type
(
PROTOCOL_HULU_PBRPC
);
sample
->
set_user_data
(
meta
.
user_data
());
sample
->
meta
.
set_service_name
(
meta
.
service_name
());
sample
->
meta
.
set_method_index
(
meta
.
method_index
());
sample
->
meta
.
set_compress_type
(
req_cmp_type
);
sample
->
meta
.
set_protocol_type
(
PROTOCOL_HULU_PBRPC
);
sample
->
meta
.
set_user_data
(
meta
.
user_data
());
if
(
meta
.
has_user_message_size
()
&&
static_cast
<
size_t
>
(
meta
.
user_message_size
())
<
msg
->
payload
.
size
())
{
size_t
attachment_size
=
msg
->
payload
.
size
()
-
meta
.
user_message_size
();
sample
->
set_attachment_size
(
attachment_size
);
sample
->
meta
.
set_attachment_size
(
attachment_size
);
}
sample
->
request
=
msg
->
payload
;
sample
->
submit
(
start_parse_us
);
...
...
@@ -642,13 +642,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
->
rpc_dump_meta
())
{
}
else
if
(
cntl
->
sampled_request
())
{
// Replaying. Keep service-name as the one seen by server.
meta
.
set_service_name
(
cntl
->
rpc_dump_meta
()
->
service_name
());
meta
.
set_method_index
(
cntl
->
rpc_dump_meta
()
->
method_index
());
meta
.
set_service_name
(
cntl
->
sampled_request
()
->
meta
.
service_name
());
meta
.
set_method_index
(
cntl
->
sampled_request
()
->
meta
.
method_index
());
meta
.
set_compress_type
(
CompressType2Hulu
(
cntl
->
rpc_dump_meta
()
->
compress_type
()));
meta
.
set_user_data
(
cntl
->
rpc_dump_meta
()
->
user_data
());
CompressType2Hulu
(
cntl
->
sampled_request
()
->
meta
.
compress_type
()));
meta
.
set_user_data
(
cntl
->
sampled_request
()
->
meta
.
user_data
());
}
else
{
return
cntl
->
SetFailed
(
ENOMETHOD
,
"method is NULL"
);
}
...
...
src/brpc/policy/sofa_pbrpc_protocol.cpp
View file @
40b13429
...
...
@@ -325,9 +325,9 @@ void ProcessSofaRequest(InputMessageBase* msg_base) {
SampledRequest
*
sample
=
AskToBeSampled
();
if
(
sample
)
{
sample
->
set_method_name
(
meta
.
method
());
sample
->
set_compress_type
(
req_cmp_type
);
sample
->
set_protocol_type
(
PROTOCOL_SOFA_PBRPC
);
sample
->
meta
.
set_method_name
(
meta
.
method
());
sample
->
meta
.
set_compress_type
(
req_cmp_type
);
sample
->
meta
.
set_protocol_type
(
PROTOCOL_SOFA_PBRPC
);
sample
->
request
=
msg
->
payload
;
sample
->
submit
(
start_parse_us
);
}
...
...
@@ -548,11 +548,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
->
rpc_dump_meta
())
{
}
else
if
(
cntl
->
sampled_request
())
{
// Replaying.
meta
.
set_method
(
cntl
->
rpc_dump_meta
()
->
method_name
());
meta
.
set_method
(
cntl
->
sampled_request
()
->
meta
.
method_name
());
meta
.
set_compress_type
(
CompressType2Sofa
(
cntl
->
rpc_dump_meta
()
->
compress_type
()));
CompressType2Sofa
(
cntl
->
sampled_request
()
->
meta
.
compress_type
()));
}
else
{
return
cntl
->
SetFailed
(
ENOMETHOD
,
"method is NULL"
);
}
...
...
src/brpc/progressive_attachment.h
View file @
40b13429
...
...
@@ -20,6 +20,7 @@
#ifndef BRPC_PROGRESSIVE_ATTACHMENT_H
#define BRPC_PROGRESSIVE_ATTACHMENT_H
#include "brpc/callback.h"
#include "butil/atomicops.h"
#include "butil/iobuf.h"
#include "butil/endpoint.h" // butil::EndPoint
...
...
@@ -27,7 +28,6 @@
#include "brpc/socket_id.h" // SocketUniquePtr
#include "brpc/shared_object.h" // SharedObject
namespace
brpc
{
class
ProgressiveAttachment
:
public
SharedObject
{
...
...
src/brpc/proto_base.proto
0 → 100644
View file @
40b13429
syntax
=
"proto2"
;
package
brpc
;
message
RedisRequestBase
{}
message
RedisResponseBase
{}
message
EspMessageBase
{}
message
MemcacheRequestBase
{}
message
MemcacheResponseBase
{}
message
NsheadMessageBase
{}
message
SerializedRequestBase
{}
message
ThriftFramedMessageBase
{}
src/brpc/redis.cpp
View file @
40b13429
...
...
@@ -17,121 +17,21 @@
// Authors: Ge,Jun (gejun@baidu.com)
#define INTERNAL_SUPPRESS_PROTOBUF_FIELD_DEPRECATION
#include <algorithm>
#include <google/protobuf/reflection_ops.h> // ReflectionOps::Merge
#include <gflags/gflags.h>
#include <google/protobuf/stubs/once.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/wire_format_lite_inl.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/reflection_ops.h>
#include <google/protobuf/wire_format.h>
#include "butil/string_printf.h"
#include "butil/macros.h"
#include "brpc/controller.h"
#include "butil/status.h"
#include "brpc/redis.h"
#include "brpc/redis_command.h"
namespace
brpc
{
DEFINE_bool
(
redis_verbose_crlf2space
,
false
,
"[DEBUG] Show
\\
r
\\
n as a space"
);
// Internal implementation detail -- do not call these.
void
protobuf_AddDesc_baidu_2frpc_2fredis_5fbase_2eproto_impl
();
void
protobuf_AddDesc_baidu_2frpc_2fredis_5fbase_2eproto
();
void
protobuf_AssignDesc_baidu_2frpc_2fredis_5fbase_2eproto
();
void
protobuf_ShutdownFile_baidu_2frpc_2fredis_5fbase_2eproto
();
namespace
{
const
::
google
::
protobuf
::
Descriptor
*
RedisRequest_descriptor_
=
NULL
;
const
::
google
::
protobuf
::
Descriptor
*
RedisResponse_descriptor_
=
NULL
;
}
// namespace
void
protobuf_AssignDesc_baidu_2frpc_2fredis_5fbase_2eproto
()
{
protobuf_AddDesc_baidu_2frpc_2fredis_5fbase_2eproto
();
const
::
google
::
protobuf
::
FileDescriptor
*
file
=
::
google
::
protobuf
::
DescriptorPool
::
generated_pool
()
->
FindFileByName
(
"baidu/rpc/redis_base.proto"
);
GOOGLE_CHECK
(
file
!=
NULL
);
RedisRequest_descriptor_
=
file
->
message_type
(
0
);
RedisResponse_descriptor_
=
file
->
message_type
(
1
);
}
namespace
{
GOOGLE_PROTOBUF_DECLARE_ONCE
(
protobuf_AssignDescriptors_once_
);
inline
void
protobuf_AssignDescriptorsOnce
()
{
::
google
::
protobuf
::
GoogleOnceInit
(
&
protobuf_AssignDescriptors_once_
,
&
protobuf_AssignDesc_baidu_2frpc_2fredis_5fbase_2eproto
);
}
void
protobuf_RegisterTypes
(
const
::
std
::
string
&
)
{
protobuf_AssignDescriptorsOnce
();
::
google
::
protobuf
::
MessageFactory
::
InternalRegisterGeneratedMessage
(
RedisRequest_descriptor_
,
&
RedisRequest
::
default_instance
());
::
google
::
protobuf
::
MessageFactory
::
InternalRegisterGeneratedMessage
(
RedisResponse_descriptor_
,
&
RedisResponse
::
default_instance
());
}
}
// namespace
void
protobuf_ShutdownFile_baidu_2frpc_2fredis_5fbase_2eproto
()
{
delete
RedisRequest
::
default_instance_
;
delete
RedisResponse
::
default_instance_
;
}
void
protobuf_AddDesc_baidu_2frpc_2fredis_5fbase_2eproto_impl
()
{
GOOGLE_PROTOBUF_VERIFY_VERSION
;
#if GOOGLE_PROTOBUF_VERSION >= 3002000
::
google
::
protobuf
::
internal
::
InitProtobufDefaults
();
#else
::
google
::
protobuf
::
protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto
();
#endif
::
google
::
protobuf
::
DescriptorPool
::
InternalAddGeneratedFile
(
"
\n\032
baidu/rpc/redis_base.proto
\022\t
baidu.rpc
\032
"
" google/protobuf/descriptor.proto
\"\016\n\014
Red"
"isRequest
\"\017\n\r
RedisResponseB
\003\200\001\001
"
,
111
);
::
google
::
protobuf
::
MessageFactory
::
InternalRegisterGeneratedFile
(
"baidu/rpc/redis_base.proto"
,
&
protobuf_RegisterTypes
);
RedisRequest
::
default_instance_
=
new
RedisRequest
();
RedisResponse
::
default_instance_
=
new
RedisResponse
();
RedisRequest
::
default_instance_
->
InitAsDefaultInstance
();
RedisResponse
::
default_instance_
->
InitAsDefaultInstance
();
::
google
::
protobuf
::
internal
::
OnShutdown
(
&
protobuf_ShutdownFile_baidu_2frpc_2fredis_5fbase_2eproto
);
}
GOOGLE_PROTOBUF_DECLARE_ONCE
(
protobuf_AddDesc_baidu_2frpc_2fredis_5fbase_2eproto_once
);
void
protobuf_AddDesc_baidu_2frpc_2fredis_5fbase_2eproto
()
{
::
google
::
protobuf
::
GoogleOnceInit
(
&
protobuf_AddDesc_baidu_2frpc_2fredis_5fbase_2eproto_once
,
&
protobuf_AddDesc_baidu_2frpc_2fredis_5fbase_2eproto_impl
);
}
// Force AddDescriptors() to be called at static initialization time.
struct
StaticDescriptorInitializer_baidu_2frpc_2fredis_5fbase_2eproto
{
StaticDescriptorInitializer_baidu_2frpc_2fredis_5fbase_2eproto
()
{
protobuf_AddDesc_baidu_2frpc_2fredis_5fbase_2eproto
();
}
}
static_descriptor_initializer_baidu_2frpc_2fredis_5fbase_2eproto_
;
// ===================================================================
#ifndef _MSC_VER
#endif // !_MSC_VER
RedisRequest
::
RedisRequest
()
:
::
google
::
protobuf
::
Message
()
{
SharedCtor
();
}
void
RedisRequest
::
InitAsDefaultInstance
()
{
}
RedisRequest
::
RedisRequest
(
const
RedisRequest
&
from
)
:
::
google
::
protobuf
::
Message
()
{
SharedCtor
();
...
...
@@ -149,29 +49,12 @@ RedisRequest::~RedisRequest() {
}
void
RedisRequest
::
SharedDtor
()
{
if
(
this
!=
default_instance_
)
{
}
}
void
RedisRequest
::
SetCachedSize
(
int
size
)
const
{
GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN
();
_cached_size_
=
size
;
GOOGLE_SAFE_CONCURRENT_WRITES_END
();
}
const
::
google
::
protobuf
::
Descriptor
*
RedisRequest
::
descriptor
()
{
protobuf_AssignDescriptorsOnce
();
return
RedisRequest_descriptor_
;
}
const
RedisRequest
&
RedisRequest
::
default_instance
()
{
if
(
default_instance_
==
NULL
)
{
protobuf_AddDesc_baidu_2frpc_2fredis_5fbase_2eproto
();
}
return
*
default_instance_
;
}
RedisRequest
*
RedisRequest
::
default_instance_
=
NULL
;
RedisRequest
*
RedisRequest
::
New
()
const
{
return
new
RedisRequest
;
}
...
...
@@ -200,16 +83,13 @@ void RedisRequest::SerializeWithCachedSizes(
int
RedisRequest
::
ByteSize
()
const
{
int
total_size
=
_buf
.
size
();
GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN
();
_cached_size_
=
total_size
;
GOOGLE_SAFE_CONCURRENT_WRITES_END
();
return
total_size
;
}
void
RedisRequest
::
MergeFrom
(
const
::
google
::
protobuf
::
Message
&
from
)
{
GOOGLE_CHECK_NE
(
&
from
,
this
);
const
RedisRequest
*
source
=
::
google
::
protobuf
::
internal
::
dynamic_cast_if_available
<
const
RedisRequest
*>
(
&
from
);
const
RedisRequest
*
source
=
dynamic_cast
<
const
RedisRequest
*>
(
&
from
);
if
(
source
==
NULL
)
{
::
google
::
protobuf
::
internal
::
ReflectionOps
::
Merge
(
from
,
this
);
}
else
{
...
...
@@ -249,14 +129,6 @@ void RedisRequest::Swap(RedisRequest* other) {
}
}
::
google
::
protobuf
::
Metadata
RedisRequest
::
GetMetadata
()
const
{
protobuf_AssignDescriptorsOnce
();
::
google
::
protobuf
::
Metadata
metadata
;
metadata
.
descriptor
=
RedisRequest_descriptor_
;
metadata
.
reflection
=
NULL
;
return
metadata
;
}
bool
RedisRequest
::
AddCommand
(
const
butil
::
StringPiece
&
command
)
{
if
(
_has_error
)
{
return
false
;
...
...
@@ -330,6 +202,17 @@ bool RedisRequest::SerializeTo(butil::IOBuf* buf) const {
return
true
;
}
const
::
google
::
protobuf
::
Descriptor
*
RedisRequest
::
descriptor
()
{
return
RedisRequestBase
::
descriptor
();
}
::
google
::
protobuf
::
Metadata
RedisRequest
::
GetMetadata
()
const
{
::
google
::
protobuf
::
Metadata
metadata
;
metadata
.
descriptor
=
RedisRequest
::
descriptor
();
metadata
.
reflection
=
NULL
;
return
metadata
;
}
void
RedisRequest
::
Print
(
std
::
ostream
&
os
)
const
{
butil
::
IOBuf
cp
=
_buf
;
butil
::
IOBuf
seg
;
...
...
@@ -355,19 +238,11 @@ std::ostream& operator<<(std::ostream& os, const RedisRequest& r) {
return
os
;
}
// ===================================================================
#ifndef _MSC_VER
#endif // !_MSC_VER
RedisResponse
::
RedisResponse
()
:
::
google
::
protobuf
::
Message
()
{
SharedCtor
();
}
void
RedisResponse
::
InitAsDefaultInstance
()
{
}
RedisResponse
::
RedisResponse
(
const
RedisResponse
&
from
)
:
::
google
::
protobuf
::
Message
()
{
SharedCtor
();
...
...
@@ -385,26 +260,11 @@ RedisResponse::~RedisResponse() {
}
void
RedisResponse
::
SharedDtor
()
{
if
(
this
!=
default_instance_
)
{
}
}
void
RedisResponse
::
SetCachedSize
(
int
size
)
const
{
_cached_size_
=
size
;
}
const
::
google
::
protobuf
::
Descriptor
*
RedisResponse
::
descriptor
()
{
protobuf_AssignDescriptorsOnce
();
return
RedisResponse_descriptor_
;
}
const
RedisResponse
&
RedisResponse
::
default_instance
()
{
if
(
default_instance_
==
NULL
)
{
protobuf_AddDesc_baidu_2frpc_2fredis_5fbase_2eproto
();
}
return
*
default_instance_
;
}
RedisResponse
*
RedisResponse
::
default_instance_
=
NULL
;
RedisResponse
*
RedisResponse
::
New
()
const
{
return
new
RedisResponse
;
...
...
@@ -440,8 +300,7 @@ int RedisResponse::ByteSize() const {
void
RedisResponse
::
MergeFrom
(
const
::
google
::
protobuf
::
Message
&
from
)
{
GOOGLE_CHECK_NE
(
&
from
,
this
);
const
RedisResponse
*
source
=
::
google
::
protobuf
::
internal
::
dynamic_cast_if_available
<
const
RedisResponse
*>
(
&
from
);
const
RedisResponse
*
source
=
dynamic_cast
<
const
RedisResponse
*>
(
&
from
);
if
(
source
==
NULL
)
{
::
google
::
protobuf
::
internal
::
ReflectionOps
::
Merge
(
from
,
this
);
}
else
{
...
...
@@ -508,10 +367,13 @@ void RedisResponse::Swap(RedisResponse* other) {
}
}
const
::
google
::
protobuf
::
Descriptor
*
RedisResponse
::
descriptor
()
{
return
RedisResponseBase
::
descriptor
();
}
::
google
::
protobuf
::
Metadata
RedisResponse
::
GetMetadata
()
const
{
protobuf_AssignDescriptorsOnce
();
::
google
::
protobuf
::
Metadata
metadata
;
metadata
.
descriptor
=
RedisResponse
_descriptor_
;
metadata
.
descriptor
=
RedisResponse
::
descriptor
()
;
metadata
.
reflection
=
NULL
;
return
metadata
;
}
...
...
src/brpc/redis.h
View file @
40b13429
...
...
@@ -20,21 +20,13 @@
#ifndef BRPC_REDIS_H
#define BRPC_REDIS_H
#include <string>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/repeated_field.h>
#include <google/protobuf/extension_set.h>
#include <google/protobuf/generated_message_reflection.h>
#include "google/protobuf/descriptor.pb.h"
#include <google/protobuf/message.h>
#include "butil/iobuf.h"
#include "butil/strings/string_piece.h"
#include "butil/arena.h"
#include "
redis_reply
.h"
#include "
parse_result
.h"
#include "
brpc/proto_base.pb
.h"
#include "
brpc/redis_reply
.h"
#include "brpc/parse_result.h"
namespace
brpc
{
...
...
@@ -126,13 +118,14 @@ public:
::
google
::
protobuf
::
io
::
CodedOutputStream
*
output
)
const
;
::
google
::
protobuf
::
uint8
*
SerializeWithCachedSizesToArray
(
::
google
::
protobuf
::
uint8
*
output
)
const
;
int
GetCachedSize
()
const
{
return
_cached_size_
;
}
static
const
::
google
::
protobuf
::
Descriptor
*
descriptor
();
static
const
RedisRequest
&
default_instance
();
::
google
::
protobuf
::
Metadata
GetMetadata
()
const
;
static
const
::
google
::
protobuf
::
Descriptor
*
descriptor
();
void
Print
(
std
::
ostream
&
)
const
;
protected
:
::
google
::
protobuf
::
Metadata
GetMetadata
()
const
override
;
private
:
void
SharedCtor
();
void
SharedDtor
();
...
...
@@ -143,14 +136,6 @@ private:
bool
_has_error
;
// previous AddCommand had error
butil
::
IOBuf
_buf
;
// the serialized request.
mutable
int
_cached_size_
;
// ByteSize
friend
void
protobuf_AddDesc_baidu_2frpc_2fredis_5fbase_2eproto_impl
();
friend
void
protobuf_AddDesc_baidu_2frpc_2fredis_5fbase_2eproto
();
friend
void
protobuf_AssignDesc_baidu_2frpc_2fredis_5fbase_2eproto
();
friend
void
protobuf_ShutdownFile_baidu_2frpc_2fredis_5fbase_2eproto
();
void
InitAsDefaultInstance
();
static
RedisRequest
*
default_instance_
;
};
// Response from Redis.
...
...
@@ -205,9 +190,10 @@ public:
int
GetCachedSize
()
const
{
return
_cached_size_
;
}
static
const
::
google
::
protobuf
::
Descriptor
*
descriptor
();
static
const
RedisResponse
&
default_instance
();
::
google
::
protobuf
::
Metadata
GetMetadata
()
const
;
protected
:
::
google
::
protobuf
::
Metadata
GetMetadata
()
const
override
;
private
:
void
SharedCtor
();
void
SharedDtor
();
...
...
@@ -218,14 +204,6 @@ private:
butil
::
Arena
_arena
;
int
_nreply
;
mutable
int
_cached_size_
;
friend
void
protobuf_AddDesc_baidu_2frpc_2fredis_5fbase_2eproto_impl
();
friend
void
protobuf_AddDesc_baidu_2frpc_2fredis_5fbase_2eproto
();
friend
void
protobuf_AssignDesc_baidu_2frpc_2fredis_5fbase_2eproto
();
friend
void
protobuf_ShutdownFile_baidu_2frpc_2fredis_5fbase_2eproto
();
void
InitAsDefaultInstance
();
static
RedisResponse
*
default_instance_
;
};
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
RedisRequest
&
);
...
...
src/brpc/rpc_dump.cpp
View file @
40b13429
...
...
@@ -34,7 +34,6 @@ namespace bvar {
std
::
string
read_command_name
();
}
namespace
brpc
{
DECLARE_uint64
(
max_body_size
);
...
...
@@ -243,7 +242,7 @@ bool RpcDumpContext::Serialize(butil::IOBuf& buf, SampledRequest* sample) {
const
size_t
starting_size
=
buf
.
size
();
butil
::
IOBufAsZeroCopyOutputStream
buf_stream
(
&
buf
);
if
(
!
sample
->
SerializeToZeroCopyStream
(
&
buf_stream
))
{
if
(
!
sample
->
meta
.
SerializeToZeroCopyStream
(
&
buf_stream
))
{
LOG
(
ERROR
)
<<
"Fail to serialize"
;
return
false
;
}
...
...
@@ -352,7 +351,7 @@ SampledRequest* SampleIterator::Pop(butil::IOBuf& buf, bool* format_error) {
butil
::
IOBuf
meta_buf
;
buf
.
cutn
(
&
meta_buf
,
meta_size
);
std
::
unique_ptr
<
SampledRequest
>
req
(
new
SampledRequest
);
if
(
!
ParsePbFromIOBuf
(
req
.
get
()
,
meta_buf
))
{
if
(
!
ParsePbFromIOBuf
(
&
req
->
meta
,
meta_buf
))
{
LOG
(
ERROR
)
<<
"Fail to parse RpcDumpMeta"
;
*
format_error
=
true
;
return
NULL
;
...
...
src/brpc/rpc_dump.h
View file @
40b13429
...
...
@@ -24,13 +24,12 @@
#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"
// RpcDumpMeta
namespace
butil
{
class
FileEnumerator
;
}
namespace
brpc
{
DECLARE_bool
(
rpc_dump
);
...
...
@@ -49,9 +48,9 @@ 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
,
public
RpcDumpMeta
{
struct
SampledRequest
:
public
bvar
::
Collected
{
butil
::
IOBuf
request
;
RpcDumpMeta
meta
;
// Implement methods of Sampled.
void
dump_and_destroy
(
size_t
round
)
override
;
...
...
src/brpc/serialized_request.cpp
View file @
40b13429
...
...
@@ -17,95 +17,16 @@
// Authors: Ge,Jun (gejun@baidu.com)
#define INTERNAL_SUPPRESS_PROTOBUF_FIELD_DEPRECATION
#include "brpc/serialized_request.h"
#include <algorithm>
#include <google/protobuf/stubs/once.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/wire_format_lite_inl.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/reflection_ops.h>
#include <google/protobuf/wire_format.h>
#include "butil/logging.h"
namespace
brpc
{
namespace
{
const
::
google
::
protobuf
::
Descriptor
*
SerializedRequest_descriptor_
=
NULL
;
}
// namespace
void
protobuf_AssignDesc_baidu_2frpc_2fserialized_5frequest_2eproto
()
{
protobuf_AddDesc_baidu_2frpc_2fserialized_5frequest_2eproto
();
const
::
google
::
protobuf
::
FileDescriptor
*
file
=
::
google
::
protobuf
::
DescriptorPool
::
generated_pool
()
->
FindFileByName
(
"baidu/rpc/serialized_request.proto"
);
GOOGLE_CHECK
(
file
!=
NULL
);
SerializedRequest_descriptor_
=
file
->
message_type
(
0
);
}
namespace
{
GOOGLE_PROTOBUF_DECLARE_ONCE
(
protobuf_AssignDescriptors_once_
);
inline
void
protobuf_AssignDescriptorsOnce
()
{
::
google
::
protobuf
::
GoogleOnceInit
(
&
protobuf_AssignDescriptors_once_
,
&
protobuf_AssignDesc_baidu_2frpc_2fserialized_5frequest_2eproto
);
}
void
protobuf_RegisterTypes
(
const
::
std
::
string
&
)
{
protobuf_AssignDescriptorsOnce
();
::
google
::
protobuf
::
MessageFactory
::
InternalRegisterGeneratedMessage
(
SerializedRequest_descriptor_
,
&
SerializedRequest
::
default_instance
());
}
}
// namespace
void
protobuf_ShutdownFile_baidu_2frpc_2fserialized_5frequest_2eproto
()
{
delete
SerializedRequest
::
default_instance_
;
}
void
protobuf_AddDesc_baidu_2frpc_2fserialized_5frequest_2eproto
()
{
static
bool
already_here
=
false
;
if
(
already_here
)
return
;
already_here
=
true
;
GOOGLE_PROTOBUF_VERIFY_VERSION
;
::
google
::
protobuf
::
DescriptorPool
::
InternalAddGeneratedFile
(
"
\n\"
baidu/rpc/serialized_request.proto
\022\t
ba"
"idu.rpc
\"\023\n\021
SerializedRequest"
,
68
);
::
google
::
protobuf
::
MessageFactory
::
InternalRegisterGeneratedFile
(
"baidu/rpc/serialized_request.proto"
,
&
protobuf_RegisterTypes
);
SerializedRequest
::
default_instance_
=
new
SerializedRequest
();
SerializedRequest
::
default_instance_
->
InitAsDefaultInstance
();
::
google
::
protobuf
::
internal
::
OnShutdown
(
&
protobuf_ShutdownFile_baidu_2frpc_2fserialized_5frequest_2eproto
);
}
// Force AddDescriptors() to be called at static initialization time.
struct
StaticDescriptorInitializer_baidu_2frpc_2fserialized_5frequest_2eproto
{
StaticDescriptorInitializer_baidu_2frpc_2fserialized_5frequest_2eproto
()
{
protobuf_AddDesc_baidu_2frpc_2fserialized_5frequest_2eproto
();
}
}
static_descriptor_initializer_baidu_2frpc_2fserialized_5frequest_2eproto_
;
// ===================================================================
#ifndef _MSC_VER
#endif // !_MSC_VER
SerializedRequest
::
SerializedRequest
()
:
::
google
::
protobuf
::
Message
()
{
SharedCtor
();
}
void
SerializedRequest
::
InitAsDefaultInstance
()
{
}
SerializedRequest
::
SerializedRequest
(
const
SerializedRequest
&
from
)
:
::
google
::
protobuf
::
Message
()
{
SharedCtor
();
...
...
@@ -120,26 +41,15 @@ SerializedRequest::~SerializedRequest() {
}
void
SerializedRequest
::
SharedDtor
()
{
if
(
this
!=
default_instance_
)
{
}
}
void
SerializedRequest
::
SetCachedSize
(
int
/*size*/
)
const
{
CHECK
(
false
)
<<
"You're not supposed to call "
<<
__FUNCTION__
;
}
const
::
google
::
protobuf
::
Descriptor
*
SerializedRequest
::
descriptor
()
{
protobuf_AssignDescriptorsOnce
();
return
SerializedRequest_descriptor_
;
return
SerializedRequestBase
::
descriptor
();
}
const
SerializedRequest
&
SerializedRequest
::
default_instance
()
{
if
(
default_instance_
==
NULL
)
protobuf_AddDesc_baidu_2frpc_2fserialized_5frequest_2eproto
();
return
*
default_instance_
;
}
SerializedRequest
*
SerializedRequest
::
default_instance_
=
NULL
;
SerializedRequest
*
SerializedRequest
::
New
()
const
{
return
new
SerializedRequest
;
}
...
...
@@ -179,9 +89,7 @@ void SerializedRequest::MergeFrom(const SerializedRequest&) {
void
SerializedRequest
::
CopyFrom
(
const
::
google
::
protobuf
::
Message
&
from
)
{
if
(
&
from
==
this
)
return
;
const
SerializedRequest
*
source
=
::
google
::
protobuf
::
internal
::
dynamic_cast_if_available
<
const
SerializedRequest
*>
(
&
from
);
const
SerializedRequest
*
source
=
dynamic_cast
<
const
SerializedRequest
*>
(
&
from
);
if
(
source
==
NULL
)
{
CHECK
(
false
)
<<
"SerializedRequest can only CopyFrom SerializedRequest"
;
}
else
{
...
...
@@ -206,9 +114,8 @@ void SerializedRequest::Swap(SerializedRequest* other) {
}
::
google
::
protobuf
::
Metadata
SerializedRequest
::
GetMetadata
()
const
{
protobuf_AssignDescriptorsOnce
();
::
google
::
protobuf
::
Metadata
metadata
;
metadata
.
descriptor
=
SerializedRequest
_descriptor_
;
metadata
.
descriptor
=
SerializedRequest
::
descriptor
()
;
metadata
.
reflection
=
NULL
;
return
metadata
;
}
...
...
src/brpc/serialized_request.h
View file @
40b13429
...
...
@@ -20,22 +20,12 @@
#ifndef BRPC_SERIALIZED_REQUEST_H
#define BRPC_SERIALIZED_REQUEST_H
#include <string>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/repeated_field.h>
#include <google/protobuf/extension_set.h>
#include <google/protobuf/generated_message_reflection.h>
#include <google/protobuf/message.h>
#include "butil/iobuf.h"
#include "brpc/proto_base.pb.h"
namespace
brpc
{
// Internal implementation detail -- do not call these.
void
protobuf_AddDesc_baidu_2frpc_2fserialized_5frequest_2eproto
();
void
protobuf_AssignDesc_baidu_2frpc_2fserialized_5frequest_2eproto
();
void
protobuf_ShutdownFile_baidu_2frpc_2fserialized_5frequest_2eproto
();
class
SerializedRequest
:
public
::
google
::
protobuf
::
Message
{
public
:
SerializedRequest
();
...
...
@@ -49,7 +39,6 @@ public:
}
static
const
::
google
::
protobuf
::
Descriptor
*
descriptor
();
static
const
SerializedRequest
&
default_instance
();
void
Swap
(
SerializedRequest
*
other
);
...
...
@@ -62,9 +51,11 @@ public:
bool
IsInitialized
()
const
;
int
ByteSize
()
const
;
int
GetCachedSize
()
const
{
return
(
int
)
_serialized
.
size
();
}
::
google
::
protobuf
::
Metadata
GetMetadata
()
const
;
butil
::
IOBuf
&
serialized_data
()
{
return
_serialized
;
}
const
butil
::
IOBuf
&
serialized_data
()
const
{
return
_serialized
;
}
protected
:
::
google
::
protobuf
::
Metadata
GetMetadata
()
const
;
private
:
bool
MergePartialFromCodedStream
(
...
...
@@ -81,13 +72,6 @@ private:
private
:
butil
::
IOBuf
_serialized
;
friend
void
protobuf_AddDesc_baidu_2frpc_2fserialized_5frequest_2eproto
();
friend
void
protobuf_AssignDesc_baidu_2frpc_2fserialized_5frequest_2eproto
();
friend
void
protobuf_ShutdownFile_baidu_2frpc_2fserialized_5frequest_2eproto
();
void
InitAsDefaultInstance
();
static
SerializedRequest
*
default_instance_
;
};
}
// namespace brpc
...
...
src/brpc/thrift_message.cpp
View file @
40b13429
...
...
@@ -22,7 +22,6 @@
#include <algorithm>
#include "butil/logging.h"
#include "brpc/details/controller_private_accessor.h"
#include <google/protobuf/stubs/once.h>
#include <google/protobuf/io/coded_stream.h>
...
...
@@ -33,86 +32,11 @@
namespace
brpc
{
namespace
{
const
::
google
::
protobuf
::
Descriptor
*
ThriftFramedMessage_descriptor_
=
NULL
;
}
// namespace
void
protobuf_AssignDesc_baidu_2frpc_2fthrift_framed_5fmessage_2eproto
()
{
protobuf_AddDesc_baidu_2frpc_2fthrift_framed_5fmessage_2eproto
();
const
::
google
::
protobuf
::
FileDescriptor
*
file
=
::
google
::
protobuf
::
DescriptorPool
::
generated_pool
()
->
FindFileByName
(
"thrift_framed_message.proto"
);
GOOGLE_CHECK
(
file
!=
NULL
);
ThriftFramedMessage_descriptor_
=
file
->
message_type
(
0
);
}
namespace
{
GOOGLE_PROTOBUF_DECLARE_ONCE
(
protobuf_AssignDescriptors_once_
);
inline
void
protobuf_AssignDescriptorsOnce
()
{
::
google
::
protobuf
::
GoogleOnceInit
(
&
protobuf_AssignDescriptors_once_
,
&
protobuf_AssignDesc_baidu_2frpc_2fthrift_framed_5fmessage_2eproto
);
}
void
protobuf_RegisterTypes
(
const
::
std
::
string
&
)
{
protobuf_AssignDescriptorsOnce
();
::
google
::
protobuf
::
MessageFactory
::
InternalRegisterGeneratedMessage
(
ThriftFramedMessage_descriptor_
,
&
ThriftFramedMessage
::
default_instance
());
}
}
// namespace
void
protobuf_ShutdownFile_baidu_2frpc_2fthrift_framed_5fmessage_2eproto
()
{
delete
ThriftFramedMessage
::
default_instance_
;
}
void
protobuf_AddDesc_baidu_2frpc_2fthrift_framed_5fmessage_2eproto_impl
()
{
GOOGLE_PROTOBUF_VERIFY_VERSION
;
#if GOOGLE_PROTOBUF_VERSION >= 3002000
::
google
::
protobuf
::
internal
::
InitProtobufDefaults
();
#else
::
google
::
protobuf
::
protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto
();
#endif
::
google
::
protobuf
::
DescriptorPool
::
InternalAddGeneratedFile
(
"
\n\033
thrift_framed_message.proto
\022\004
brpc
\"\025\n\023
ThriftFramedMessage"
,
58
);
::
google
::
protobuf
::
MessageFactory
::
InternalRegisterGeneratedFile
(
"thrift_framed_message.proto"
,
&
protobuf_RegisterTypes
);
ThriftFramedMessage
::
default_instance_
=
new
ThriftFramedMessage
();
ThriftFramedMessage
::
default_instance_
->
InitAsDefaultInstance
();
::
google
::
protobuf
::
internal
::
OnShutdown
(
&
protobuf_ShutdownFile_baidu_2frpc_2fthrift_framed_5fmessage_2eproto
);
}
GOOGLE_PROTOBUF_DECLARE_ONCE
(
protobuf_AddDesc_baidu_2frpc_2fthrift_framed_5fmessage_2eproto_once
);
void
protobuf_AddDesc_baidu_2frpc_2fthrift_framed_5fmessage_2eproto
()
{
::
google
::
protobuf
::
GoogleOnceInit
(
&
protobuf_AddDesc_baidu_2frpc_2fthrift_framed_5fmessage_2eproto_once
,
&
protobuf_AddDesc_baidu_2frpc_2fthrift_framed_5fmessage_2eproto_impl
);
}
// Force AddDescriptors() to be called at static initialization time.
struct
StaticDescriptorInitializer_baidu_2frpc_2fthrift_framed_5fmessage_2eproto
{
StaticDescriptorInitializer_baidu_2frpc_2fthrift_framed_5fmessage_2eproto
()
{
protobuf_AddDesc_baidu_2frpc_2fthrift_framed_5fmessage_2eproto
();
}
}
static_descriptor_initializer_baidu_2frpc_2fthrift_framed_5fmessage_2eproto_
;
// ===================================================================
#ifndef _MSC_VER
#endif // !_MSC_VER
ThriftFramedMessage
::
ThriftFramedMessage
()
:
::
google
::
protobuf
::
Message
()
{
SharedCtor
();
}
void
ThriftFramedMessage
::
InitAsDefaultInstance
()
{
}
void
ThriftFramedMessage
::
SharedCtor
()
{
field_id
=
THRIFT_INVALID_FID
;
_own_raw_instance
=
false
;
...
...
@@ -127,23 +51,12 @@ ThriftFramedMessage::~ThriftFramedMessage() {
}
void
ThriftFramedMessage
::
SharedDtor
()
{
if
(
this
!=
default_instance_
)
{
}
}
const
::
google
::
protobuf
::
Descriptor
*
ThriftFramedMessage
::
descriptor
()
{
protobuf_AssignDescriptorsOnce
();
return
ThriftFramedMessage_descriptor_
;
return
ThriftFramedMessageBase
::
descriptor
();
}
const
ThriftFramedMessage
&
ThriftFramedMessage
::
default_instance
()
{
if
(
default_instance_
==
NULL
)
protobuf_AddDesc_baidu_2frpc_2fthrift_framed_5fmessage_2eproto
();
return
*
default_instance_
;
}
ThriftFramedMessage
*
ThriftFramedMessage
::
default_instance_
=
NULL
;
ThriftFramedMessage
*
ThriftFramedMessage
::
New
()
const
{
return
new
ThriftFramedMessage
;
}
...
...
@@ -222,9 +135,8 @@ void ThriftFramedMessage::Swap(ThriftFramedMessage* other) {
}
::
google
::
protobuf
::
Metadata
ThriftFramedMessage
::
GetMetadata
()
const
{
protobuf_AssignDescriptorsOnce
();
::
google
::
protobuf
::
Metadata
metadata
;
metadata
.
descriptor
=
ThriftFramedMessage
_descriptor_
;
metadata
.
descriptor
=
ThriftFramedMessage
::
descriptor
()
;
metadata
.
reflection
=
NULL
;
return
metadata
;
}
...
...
@@ -239,4 +151,3 @@ void ThriftStub::CallMethod(const char* method_name,
}
}
// namespace brpc
src/brpc/thrift_message.h
View file @
40b13429
...
...
@@ -20,20 +20,12 @@
#ifndef BRPC_THRIFT_MESSAGE_H
#define BRPC_THRIFT_MESSAGE_H
#include <functional>
#include <string>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/repeated_field.h>
#include <google/protobuf/extension_set.h>
#include <google/protobuf/generated_message_reflection.h>
#include "google/protobuf/descriptor.pb.h"
#include <google/protobuf/message.h>
#include "butil/iobuf.h"
#include "butil/class_name.h"
#include "brpc/channel_base.h"
#include "brpc/controller.h"
#include "brpc/proto_base.pb.h"
namespace
apache
{
namespace
thrift
{
...
...
@@ -46,11 +38,6 @@ class TProtocol;
namespace
brpc
{
// Internal implementation detail -- do not call these.
void
protobuf_AddDesc_baidu_2frpc_2fthrift_framed_5fmessage_2eproto
();
void
protobuf_AssignDesc_baidu_2frpc_2fthrift_framed_5fmessage_2eproto
();
void
protobuf_ShutdownFile_baidu_2frpc_2fthrift_framed_5fmessage_2eproto
();
class
ThriftStub
;
static
const
int16_t
THRIFT_INVALID_FID
=
-
1
;
...
...
@@ -92,7 +79,6 @@ public:
ThriftFramedMessage
&
operator
=
(
const
ThriftFramedMessage
&
from
)
=
delete
;
static
const
::
google
::
protobuf
::
Descriptor
*
descriptor
();
static
const
ThriftFramedMessage
&
default_instance
();
void
Swap
(
ThriftFramedMessage
*
other
);
...
...
@@ -113,19 +99,13 @@ public:
::
google
::
protobuf
::
io
::
CodedOutputStream
*
output
)
const
;
::
google
::
protobuf
::
uint8
*
SerializeWithCachedSizesToArray
(
::
google
::
protobuf
::
uint8
*
output
)
const
;
int
GetCachedSize
()
const
{
return
ByteSize
();
}
protected
:
::
google
::
protobuf
::
Metadata
GetMetadata
()
const
;
private
:
void
SharedCtor
();
void
SharedDtor
();
private
:
friend
void
protobuf_AddDesc_baidu_2frpc_2fthrift_framed_5fmessage_2eproto_impl
();
friend
void
protobuf_AddDesc_baidu_2frpc_2fthrift_framed_5fmessage_2eproto
();
friend
void
protobuf_AssignDesc_baidu_2frpc_2fthrift_framed_5fmessage_2eproto
();
friend
void
protobuf_ShutdownFile_baidu_2frpc_2fthrift_framed_5fmessage_2eproto
();
void
InitAsDefaultInstance
();
static
ThriftFramedMessage
*
default_instance_
;
};
class
ThriftStub
{
...
...
test/Makefile
View file @
40b13429
...
...
@@ -162,7 +162,7 @@ all: $(TEST_BINS)
.PHONY
:
clean
clean
:
clean_bins
@
echo
"Cleaning"
@
rm
-rf
$(TEST_BUTIL_OBJS)
$(TEST_BVAR_OBJS)
$(TEST_BTHREAD_OBJS)
$(TEST_BRPC_OBJS)
$(TEST_PROTO_OBJS)
@
rm
-rf
$(TEST_BUTIL_OBJS)
$(TEST_BVAR_OBJS)
$(TEST_BTHREAD_OBJS)
$(TEST_BRPC_OBJS)
$(TEST_PROTO_OBJS)
$
(
TEST_PROTO_SOURCES:.proto
=
.pb.h
)
$
(
TEST_PROTO_SOURCES:.proto
=
.pb.cc
)
@
$(MAKE)
-C
.. clean_debug
.PHONY
:
clean_bins
...
...
tools/rpc_replay/rpc_replay.cpp
View file @
40b13429
...
...
@@ -150,21 +150,21 @@ static void* replay_thread(void* arg) {
continue
;
}
brpc
::
Channel
*
chan
=
chan_group
->
channel
(
sample
->
protocol_type
());
chan_group
->
channel
(
sample
->
meta
.
protocol_type
());
if
(
chan
==
NULL
)
{
LOG
(
ERROR
)
<<
"No channel on protocol="
<<
sample
->
protocol_type
();
<<
sample
->
meta
.
protocol_type
();
continue
;
}
brpc
::
Controller
*
cntl
=
new
brpc
::
Controller
;
req
.
Clear
();
cntl
->
reset_
rpc_dump_meta
(
sample_guard
.
release
());
if
(
sample
->
attachment_size
()
>
0
)
{
cntl
->
reset_
sampled_request
(
sample_guard
.
release
());
if
(
sample
->
meta
.
attachment_size
()
>
0
)
{
sample
->
request
.
cutn
(
&
req
.
serialized_data
(),
sample
->
request
.
size
()
-
sample
->
attachment_size
());
sample
->
request
.
size
()
-
sample
->
meta
.
attachment_size
());
cntl
->
request_attachment
()
=
sample
->
request
.
movable
();
}
else
{
req
.
serialized_data
()
=
sample
->
request
.
movable
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment