You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brpc.apache.org by GitBox <gi...@apache.org> on 2019/04/05 02:41:54 UTC

[GitHub] [incubator-brpc] jamesge edited a comment on issue #692: Add Mysql Protocol, only support text protocol now, not support trans…

jamesge edited a comment on issue #692: Add Mysql Protocol, only support text protocol now, not support trans…
URL: https://github.com/apache/incubator-brpc/pull/692#issuecomment-480129822
 
 
   > @jamesge 最近在考虑prepared statement 和 transaction的实现问题。这两个功能的特点是,需要在一个连接上面进行多次回话,在多次回话过程中连接需要独占。
   > 调用接口的伪代码:
   > // begin transaction
   > brpc::MysqlRequest txReq;
   > brpc::MysqlResponse txRsp;
   > brpc::Controller txCntl;
   > txCntl.txState = BEGIN_TX;
   > txReq.BeginTx();
   > channel.CallMethod(NULL, &txCntl, &txReq, &txRsp, NULL);
   > 
   > const brpc::MysqlReply::Tx& tx = txRsp.reply(0).tx();
   > 
   > //txRsp keep a connection
   > // begin crud operation
   > brpc::MysqlRequest crudReq1;
   > brpc::MysqlResponse curdRsp1;
   > brpc::Controller crudCntl1;
   > crudCntl1.tx = tx;
   > txReq1.Query("sql statement1");
   > channel.CallMethod(NULL, &crudCntl1, &crudReq1, &crudRsp1, NULL);
   > 
   > brpc::MysqlRequest crudReq2;
   > brpc::MysqlResponse curdRsp2;
   > brpc::Controller crudCntl2;
   > crudCntl2.tx = tx;
   > txReq1.Query("sql statement2");
   > channel.CallMethod(NULL, &crudCntl2, &crudReq2, &curdRsp2, NULL);
   > // end crud operation
   > 
   > // commit transaction
   > // after that release the connect to pool
   > brpc::MysqlRequest commitReq;
   > brpc::MysqlResponse commitRsp;
   > brpc::Controller commitCntl;
   > commitCntl.tx = tx;
   > commitCntl.txState = END_TX;
   > commitReq.Commit();
   > channel.CallMethod(NULL, &commitCntl, &commitReq, &commitRsp, NULL);
   > 
   > 需要对代码修改的地方有
   > 1、在开始事务的controller里面设置一个标识,这样在它的OnComplete调用的时候,不释放连接到pool里面,返回的接口里面包含事务的信息。
   > 2、后续的crud的controller里面设置事务的信息,在IssueRPC的时候,lb和选择连接的地方,可以根据是否设置事务做分支处理,主要是在选择连接的地方。
   > 3、在结束事务的controller里面设置一个标识,这样它在OnComplete的时候会释放连接。
   > 
   > prepared statement和这个类似。
   > 
   > 事务和prepared statement的处理流程在所有关系型数据库都类似,也可以抽象出来一些公共的内容。我参考了golang的database/sql库
   > 
   > 以上请戈君评审一下,看有什么建议。
   
   实现上需要多次交互,并不意味着用户一定要感知到多次交互,本质上一个tx对用户也是一件事(要么成功要么失败),一个tx里的所有请求能否让用户一次性输入?即用户调用request中的BeginTx/Query/EndTx等接口可以编排一次tx,然后再CallMethod。另外这部分功能就别添加在这个pr中了,可以另启新的。

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org