jamesge commented on a change in pull request #692: Add Mysql Protocol, only 
support text protocol now, not support trans…
URL: https://github.com/apache/incubator-brpc/pull/692#discussion_r270727922
 
 

 ##########
 File path: src/brpc/policy/mysql_protocol.cpp
 ##########
 @@ -0,0 +1,238 @@
+// Copyright (c) 2019 Baidu, Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Authors: Yang,Liming ([email protected])
+
+#include <google/protobuf/descriptor.h>  // MethodDescriptor
+#include <google/protobuf/message.h>     // Message
+#include <gflags/gflags.h>
+#include <sstream>
+#include "butil/logging.h"  // LOG()
+#include "butil/time.h"
+#include "butil/iobuf.h"  // butil::IOBuf
+#include "butil/sys_byteorder.h"
+#include "brpc/controller.h"  // Controller
+#include "brpc/details/controller_private_accessor.h"
+#include "brpc/socket.h"  // Socket
+#include "brpc/server.h"  // Server
+#include "brpc/details/server_private_accessor.h"
+#include "brpc/span.h"
+#include "brpc/mysql.h"
+#include "brpc/mysql_reply.h"
+#include "brpc/policy/mysql_protocol.h"
+#include "brpc/policy/most_common_message.h"
+#include "brpc/policy/mysql_authenticator.h"
+
+namespace brpc {
+
+DECLARE_bool(enable_rpcz);
+
+namespace policy {
+
+DEFINE_bool(mysql_verbose, false, "[DEBUG] Print EVERY mysql 
request/response");
+
+
+MysqlAuthenticator* global_mysql_authenticator();
+
+struct InputResponse : public InputMessageBase {
+    bthread_id_t id_wait;
+    MysqlResponse response;
+
+    // @InputMessageBase
+    void DestroyImpl() {
+        delete this;
+    }
+};
+
+// "Message" = "Response" as we only implement the client for mysql.
+ParseResult ParseMysqlMessage(butil::IOBuf* source,
+                              Socket* socket,
+                              bool /*read_eof*/,
+                              const void* /*arg*/) {
+    if (source->empty()) {
+        return MakeParseError(PARSE_ERROR_NOT_ENOUGH_DATA);
+    }
+
+    PipelinedInfo pi;
+    if (!socket->PopPipelinedInfo(&pi)) {
+        LOG(WARNING) << "No corresponding PipelinedInfo in socket";
+        return MakeParseError(PARSE_ERROR_TRY_OTHERS);
+    }
+
+    do {
+        InputResponse* msg = 
static_cast<InputResponse*>(socket->parsing_context());
+        if (msg == NULL) {
+            msg = new InputResponse;
+            socket->reset_parsing_context(msg);
+        }
+
+        ParseError err = msg->response.ConsumePartialIOBuf(*source, 
pi.with_auth);
+        if (err != PARSE_OK) {
+            socket->GivebackPipelinedInfo(pi);
+            return MakeParseError(err);
+        }
+        if (pi.with_auth) {
+            if (FLAGS_mysql_verbose) {
+                LOG(INFO) << "[MYSQL PARSE] " << msg->response;
+            }
+            const bthread_id_t cid = pi.id_wait;
+            Controller* cntl = NULL;
+            if (bthread_id_lock(cid, (void**)&cntl) != 0) {
+                LOG(ERROR) << "[MYSQL PARSE] fail to lock controller";
+                return MakeParseError(PARSE_ERROR_ABSOLUTELY_WRONG);
+            }
+            const AuthContext* ctx = cntl->auth_context();
+            if (ctx == NULL) {
+                LOG(ERROR) << "[MYSQL PARSE] auth context is null";
 
 Review comment:
   没有unlock id。相关的就是这段校验auth的代码能封装个函数么?这样也不会需要每个return前都unlock id了

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to