-
Notifications
You must be signed in to change notification settings - Fork 59
Conversation
shengofsun
commented
Apr 23, 2018
- remove c interface of register rpc handler
- remove rpc code of RPC_L2_CLIENT_READ/WRITE, replace with proper storage engine rpc code.
- move some storage engine rpc_code's properties from config file to source code: is_write_operation, allow_batch, thread_pool
include/dsn/c/api_layer1.h
Outdated
void *context, | ||
dsn::gpid gpid DEFAULT(dsn::gpid())); | ||
const char *extra_name, | ||
const dsn_rpc_request_handler_t &cb); | ||
|
||
/*! unregister callback to handle RPC request, and returns void* context upon \ref |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个注释我需要改
@@ -44,6 +44,11 @@ DEFINE_THREAD_POOL_CODE(THREAD_POOL_LOCAL_APP) | |||
DEFINE_THREAD_POOL_CODE(THREAD_POOL_REPLICATION_LONG) | |||
DEFINE_THREAD_POOL_CODE(THREAD_POOL_COMPACT) | |||
|
|||
#define STORAGE_WRITE(x, allow_batch) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加注释
include/dsn/tool-api/task_code.h
Outdated
@@ -122,7 +129,7 @@ class task_code | |||
int _internal_code{0}; | |||
}; | |||
|
|||
// you can define task_cods by the following macros | |||
// you can define task_codes by the following macros |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
task_codes -> task_code
include/dsn/tool-api/task_code.h
Outdated
#define DEFINE_STORAGE_RPC_CODE(x, pri, pool, is_write, allow_batch) \ | ||
__selectany const ::dsn::task_code x( \ | ||
#x, TASK_TYPE_RPC_REQUEST, pri, pool, is_write, allow_batch); \ | ||
__selectany const ::dsn::task_code x##_ACK( \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么Reponse用THREAD_POOL_DEFAULT?说明原因并加注释
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
用THREAD_POOL_DEFAULT没问题,不过这里还是用注释解释清楚,免得以后再看又要想
src/core/core/rpc_engine.h
Outdated
dsn_rpc_request_handler_t h; | ||
}; | ||
|
||
typedef std::unordered_map<std::string, handler_entry *> rpc_handlers; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是否用 std::unordered_map<std::string, std::unique_ptr<handler_entry>> 更好?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
handler_entry是两个地方都共享,用uniq_ptr没有让代码更简单。要用就用shared_ptr, 或者用我找找有没有ref counted thread unsafe的公共类
src/core/core/rpc_engine.h
Outdated
rpc_handlers _handlers; | ||
mutable utils::rw_lock_nr _handlers_lock; | ||
|
||
std::vector<std::pair<rpc_handler_info *, utils::rw_lock_nr> *> _vhandlers; | ||
std::vector<std::pair<handler_entry *, utils::rw_lock_nr> *> _vhandlers; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里为何用pair*来着?可以直接用 std::vector<std::pair<handler_entry *, utils::rw_lock_nr>> 吗?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在vector里面初始化utils::rw_lock_nr比较麻烦,各种编译不过……
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
那么pair里面的handler_entry *至少可以改为 std::unique<handler_entry>吧?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个改了也不好,因为hander_entry是被_handlers这个map指向了两次,然后又被_vhandler指向了一次。有三个reference
dsn_rpc_request_handler_t cb = [](dsn_message_t request, void *param) { | ||
auto hc2 = (hc_type1 *)param; | ||
|
||
dsn_rpc_request_handler_t cb = [this, handler](dsn_message_t request) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是不是可以不赋值,而是直接放到函数参数里面?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对下层来说太麻烦了,一下要支持好多种类型的handler, rpc_engine的register接口就是一个std::function<void (dsn_message_t)> 来说会清晰非常多。性能问题应该还好,this和handler都是个单纯的指针
@@ -140,8 +148,10 @@ class rpc_engine | |||
// | |||
// rpc registrations | |||
// | |||
bool register_rpc_handler(rpc_handler_info *handler); | |||
rpc_handler_info *unregister_rpc_handler(dsn::task_code rpc_code); | |||
bool register_rpc_handler(dsn::task_code code, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是不是可以增加参数为 dsn_rpc_request_handler_t &&h 的重载函数?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
反正注册就是个一锤子买卖,就算拷贝也就拷贝一次。
include/dsn/c/api_layer1.h
Outdated
void *context, | ||
dsn::gpid gpid DEFAULT(dsn::gpid())); | ||
const char *extra_name, | ||
const dsn_rpc_request_handler_t &cb); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是不是可以增加 dsn_rpc_request_handler_t &&h 的重载函数?
public: | ||
// not configurable [ | ||
dsn::task_code code; | ||
dsn_task_type_t type; | ||
std::string name; | ||
dsn::task_code rpc_paired_code; | ||
shared_exp_delay rpc_request_delayer; | ||
|
||
bool rpc_request_for_storage; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没有初始化?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
待会加一下
src/core/core/rpc_engine.cpp
Outdated
{ | ||
std::string name(handler->code.to_string()); | ||
handler_entry *ctx = new handler_entry{code, extra_name, h}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
handler_entry在哪里delete的?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在unregister_rpc_handler的时候delete的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果没有调用 unregister_rpc_handler,析构函数也没有delete?
src/core/core/rpc_engine.h
Outdated
rpc_handlers _handlers; | ||
mutable utils::rw_lock_nr _handlers_lock; | ||
|
||
std::vector<std::pair<rpc_handler_info *, utils::rw_lock_nr> *> _vhandlers; | ||
std::vector<std::pair<handler_entry *, utils::rw_lock_nr> *> _vhandlers; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
那么pair里面的handler_entry *至少可以改为 std::unique<handler_entry>吧?
include/dsn/tool-api/task_code.h
Outdated
#define DEFINE_STORAGE_RPC_CODE(x, pri, pool, is_write, allow_batch) \ | ||
__selectany const ::dsn::task_code x( \ | ||
#x, TASK_TYPE_RPC_REQUEST, pri, pool, is_write, allow_batch); \ | ||
__selectany const ::dsn::task_code x##_ACK( \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
用THREAD_POOL_DEFAULT没问题,不过这里还是用注释解释清楚,免得以后再看又要想