Conversation
…action, not support prepare statement. issue apache#209
|
mysql的prepared statement协议的支持。 |
| @@ -0,0 +1,562 @@ | |||
| [MySQL](https://www.mysql.com/)是著名的开源的关系型数据库,为了使用户更快捷地访问mysql并充分利用bthread的并发能力,brpc直接支持mysql协议。示例程序:[example/mysql_c++](https://github.com/brpc/brpc/tree/master/example/mysql_c++/) | |||
|
|
|||
| **注意**:只支持MySQL 4.1 及之后的版本的文本协议,支持事务,不支持Prepared statement。目前支持的鉴权方式为mysql_native_password,使用事务的时候不支持single模式。 | |||
|
|
||
| - 请求类型必须为MysqlRequest,回复类型必须为MysqlResponse,否则CallMethod会失败。不需要stub,直接调用channel.CallMethod,method填NULL。 | ||
| - 调用request.Query()传入要执行的命令,可以批量执行命令,多个命令用分号隔开。 | ||
| - 依次调用response.reply(X)弹出操作结果,根据返回类型的不同,选择不同的类型接收,如:MysqlReply::Ok,MysqlReply::Error,const MysqlReply::Columnconst MysqlReply::Row等。 |
| 事务可以保证在一个事务中的多个RPC请求最终要么都成功,要么都失败。 | ||
|
|
||
| ```c++ | ||
| rpc::Channel channel; |
|
|
||
| ##### libmysqlclient实现(100线程) | ||
|
|
||
| ./mysql_press -thread_num=50 -op_type=1 -use_bthread=true |
| @@ -0,0 +1,148 @@ | |||
| cmake_minimum_required(VERSION 2.8.10) | |||
| } | ||
| const char* delim1 = "&"; | ||
| std::vector<size_t> idx; | ||
| for (size_t p = params.find(delim1); p != butil::StringPiece::npos; |
There was a problem hiding this comment.
可以使用butil::StringSplitter或butil::SplitString
|
|
||
| DEFINE_bool(mysql_verbose, false, "[DEBUG] Print EVERY mysql request/response"); | ||
|
|
||
| void MysqlParseAuthenticator(const butil::StringPiece& raw, |
There was a problem hiding this comment.
这几个函数是不是可以在mysql_authenticator.h里声明一下
| return true; | ||
| } | ||
|
|
||
| void MysqlParseAuthenticator(const butil::StringPiece& raw, |
There was a problem hiding this comment.
是不是可以实现成MysqlAuthenticator::ParseFromString 这样更对称一些
| std::string mysql_build_mysql41_authentication_response(const std::string& salt_data, | ||
| const std::string& password); | ||
|
|
||
| std::string mysql_build_sha256_authentication_response(const std::string& salt_data, |
| _type = MYSQL_RSP_UNKNOWN; | ||
| _data.padding = 0; | ||
| } | ||
| inline void MysqlReply::Swap(MysqlReply& other) { |
| return rc; | ||
| } | ||
|
|
||
| ParseError MysqlReply::Field::ParseBinaryDataTime(butil::IOBuf& buf, |
| MYSQL_SET_FLAG = 0x0800, | ||
| }; | ||
|
|
||
| enum MysqlServerStatus : uint16_t { |
| namespace brpc { | ||
|
|
||
| namespace { | ||
| const uint32_t max_allowed_packet = 67108864; |
| if (seq == 0) { | ||
| const uint32_t old_size = outbuf->size(); | ||
| outbuf->append(head); | ||
| size -= outbuf->size() - old_size; |
There was a problem hiding this comment.
为什么不直接用size -= head.size()呢
|
|
||
| } // namespace | ||
|
|
||
| butil::Status MysqlMakeCommand(butil::IOBuf* outbuf, |
There was a problem hiding this comment.
这个叫MysqlMakeCommandPacket会不会更合适
| typedef butil::FlatMap<SocketId, MysqlStatementId> MysqlStatementKVMap; | ||
| typedef butil::DoublyBufferedData<MysqlStatementKVMap> MysqlStatementDBD; | ||
|
|
||
| inline size_t my_init_kv(MysqlStatementKVMap& m) { |
There was a problem hiding this comment.
这个不用放在头文件里吧,放在mysql_statement.cpp里就行了
| // LOG(INFO) << response.reply(0); | ||
| // } | ||
|
|
||
| class MysqlStatementStub { |
There was a problem hiding this comment.
这个类是不是放在mysql_statment.h里更合适
| return MakePacket(outbuf, head, func, edata); | ||
| } | ||
|
|
||
| butil::Status MysqlMakeExecuteData(MysqlStatementStub* stmt, |
There was a problem hiding this comment.
这个作为MysqlStatementStub的成员函数会不会更合适
|
|
||
| const int32_t UNSET_MAGIC_NUM = -123456789; | ||
|
|
||
| // if controller want to reserve a sock after RPC, set BIND_SOCK_ACTIVE |
There was a problem hiding this comment.
这个ACTIVE不是很好理解,是不是可以叫BIND_SOCK_RESERVE
| if (!tmp_sock || (!is_health_check_call() && !tmp_sock->IsAvailable())) { | ||
| SetFailed(EHOSTDOWN, "Not connected to bind socket yet, server_id=%" PRIu64, | ||
| tmp_sock->id()); |
There was a problem hiding this comment.
tmp_sock为NULL,tmp_sock->id()会coredump吧?
|
求教, mysql协议现在是什么状态了呢 |
目前没时间开发这个,有兴趣可以贡献一下。 |
Add Mysql Protocol, support text protocol, transaction, support prepare statement.
issue #209
What problem does this PR solve?
Issue Number:
Problem Summary:
What is changed and the side effects?
Changed:
Side effects:
Performance effects(性能影响):
Breaking backward compatibility(向后兼容性):
Check List: