yiguolei commented on code in PR #25919: URL: https://github.com/apache/doris/pull/25919#discussion_r1377255355
########## fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java: ########## @@ -160,144 +159,50 @@ private void handleInitDb() { ctx.getState().setOk(); } - // COM_QUIT: set killed flag and then return OK packet. - private void handleQuit() { + // set killed flag + protected void handleQuit() { ctx.setKilled(); ctx.getState().setOk(); } - // process COM_PING statement, do nothing, just return one OK packet. - private void handlePing() { + // do nothing + protected void handlePing() { ctx.getState().setOk(); } - private void handleStmtReset() { + protected void handleStmtReset() { ctx.getState().setOk(); } - private void handleStmtClose() { - packetBuf = packetBuf.order(ByteOrder.LITTLE_ENDIAN); - int stmtId = packetBuf.getInt(); + protected void handleStmtClose(int stmtId) { LOG.debug("close stmt id: {}", stmtId); ConnectContext.get().removePrepareStmt(String.valueOf(stmtId)); // No response packet is sent back to the client, see // https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_com_stmt_close.html ctx.getState().setNoop(); } - private void debugPacket() { - byte[] bytes = packetBuf.array(); - StringBuilder printB = new StringBuilder(); - for (byte b : bytes) { - if (Character.isLetterOrDigit((char) b & 0xFF)) { - char x = (char) b; - printB.append(x); - } else { - printB.append("0x" + Integer.toHexString(b & 0xFF)); - } - printB.append(" "); - } - LOG.debug("debug packet {}", printB.toString().substring(0, 200)); - } - - private static boolean isNull(byte[] bitmap, int position) { + protected static boolean isNull(byte[] bitmap, int position) { return (bitmap[position / 8] & (1 << (position & 7))) != 0; } - // process COM_EXECUTE, parse binary row data - // https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_com_stmt_execute.html - private void handleExecute() { - // debugPacket(); - packetBuf = packetBuf.order(ByteOrder.LITTLE_ENDIAN); - // parse stmt_id, flags, params - int stmtId = packetBuf.getInt(); - // flag - packetBuf.get(); - // iteration_count always 1, - packetBuf.getInt(); - LOG.debug("execute prepared statement {}", stmtId); - PrepareStmtContext prepareCtx = ctx.getPreparedStmt(String.valueOf(stmtId)); - if (prepareCtx == null) { - LOG.debug("No such statement in context, stmtId:{}", stmtId); - ctx.getState().setError(ErrorCode.ERR_UNKNOWN_COM_ERROR, - "msg: Not supported such prepared statement"); - return; - } - ctx.setStartTime(); - if (prepareCtx.stmt.getInnerStmt() instanceof QueryStmt) { - ctx.getState().setIsQuery(true); - } - prepareCtx.stmt.setIsPrepared(); - int paramCount = prepareCtx.stmt.getParmCount(); - // null bitmap - byte[] nullbitmapData = new byte[(paramCount + 7) / 8]; - packetBuf.get(nullbitmapData); - String stmtStr = ""; - try { - // new_params_bind_flag - if ((int) packetBuf.get() != 0) { - // parse params's types - for (int i = 0; i < paramCount; ++i) { - int typeCode = packetBuf.getChar(); - LOG.debug("code {}", typeCode); - prepareCtx.stmt.placeholders().get(i).setTypeCode(typeCode); - } - } - List<LiteralExpr> realValueExprs = new ArrayList<>(); - // parse param data - for (int i = 0; i < paramCount; ++i) { - if (isNull(nullbitmapData, i)) { - realValueExprs.add(new NullLiteral()); - continue; - } - LiteralExpr l = prepareCtx.stmt.placeholders().get(i).createLiteralFromType(); - l.setupParamFromBinary(packetBuf); - realValueExprs.add(l); - } - ExecuteStmt executeStmt = new ExecuteStmt(String.valueOf(stmtId), realValueExprs); - // TODO set real origin statement - executeStmt.setOrigStmt(new OriginStatement("null", 0)); - executeStmt.setUserInfo(ctx.getCurrentUserIdentity()); - LOG.debug("executeStmt {}", executeStmt); - executor = new StmtExecutor(ctx, executeStmt); - ctx.setExecutor(executor); - executor.execute(); - stmtStr = executeStmt.toSql(); - } catch (Throwable e) { - // Catch all throwable. - // If reach here, maybe palo bug. - LOG.warn("Process one query failed because unknown reason: ", e); - ctx.getState().setError(ErrorCode.ERR_UNKNOWN_ERROR, - e.getClass().getSimpleName() + ", msg: " + e.getMessage()); - } - auditAfterExec(stmtStr, prepareCtx.stmt.getInnerStmt(), null, false); - } - - private void auditAfterExec(String origStmt, StatementBase parsedStmt, - Data.PQueryStatistics statistics, boolean printFuzzyVariables) { + protected void auditAfterExec(String origStmt, StatementBase parsedStmt, + Data.PQueryStatistics statistics, boolean printFuzzyVariables) { AuditLogHelper.logAuditLog(ctx, origStmt, parsedStmt, statistics, printFuzzyVariables); } - // Process COM_QUERY statement, // only throw an exception when there is a problem interacting with the requesting client - private void handleQuery(MysqlCommand mysqlCommand) { + protected void handleQuery(MysqlCommand mysqlCommand, String originStmt) { Review Comment: 我感觉这个接口,可以不要mysql command了,因为这个代码 flight 也在调用。 直接 handleQuqery(isComQuery, stmt) 是否就可以了 ########## fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java: ########## @@ -160,144 +159,50 @@ private void handleInitDb() { ctx.getState().setOk(); } - // COM_QUIT: set killed flag and then return OK packet. - private void handleQuit() { + // set killed flag + protected void handleQuit() { ctx.setKilled(); ctx.getState().setOk(); } - // process COM_PING statement, do nothing, just return one OK packet. - private void handlePing() { + // do nothing + protected void handlePing() { ctx.getState().setOk(); } - private void handleStmtReset() { + protected void handleStmtReset() { ctx.getState().setOk(); } - private void handleStmtClose() { - packetBuf = packetBuf.order(ByteOrder.LITTLE_ENDIAN); - int stmtId = packetBuf.getInt(); + protected void handleStmtClose(int stmtId) { LOG.debug("close stmt id: {}", stmtId); ConnectContext.get().removePrepareStmt(String.valueOf(stmtId)); // No response packet is sent back to the client, see // https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_com_stmt_close.html ctx.getState().setNoop(); } - private void debugPacket() { - byte[] bytes = packetBuf.array(); - StringBuilder printB = new StringBuilder(); - for (byte b : bytes) { - if (Character.isLetterOrDigit((char) b & 0xFF)) { - char x = (char) b; - printB.append(x); - } else { - printB.append("0x" + Integer.toHexString(b & 0xFF)); - } - printB.append(" "); - } - LOG.debug("debug packet {}", printB.toString().substring(0, 200)); - } - - private static boolean isNull(byte[] bitmap, int position) { + protected static boolean isNull(byte[] bitmap, int position) { return (bitmap[position / 8] & (1 << (position & 7))) != 0; } - // process COM_EXECUTE, parse binary row data - // https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_com_stmt_execute.html - private void handleExecute() { - // debugPacket(); - packetBuf = packetBuf.order(ByteOrder.LITTLE_ENDIAN); - // parse stmt_id, flags, params - int stmtId = packetBuf.getInt(); - // flag - packetBuf.get(); - // iteration_count always 1, - packetBuf.getInt(); - LOG.debug("execute prepared statement {}", stmtId); - PrepareStmtContext prepareCtx = ctx.getPreparedStmt(String.valueOf(stmtId)); - if (prepareCtx == null) { - LOG.debug("No such statement in context, stmtId:{}", stmtId); - ctx.getState().setError(ErrorCode.ERR_UNKNOWN_COM_ERROR, - "msg: Not supported such prepared statement"); - return; - } - ctx.setStartTime(); - if (prepareCtx.stmt.getInnerStmt() instanceof QueryStmt) { - ctx.getState().setIsQuery(true); - } - prepareCtx.stmt.setIsPrepared(); - int paramCount = prepareCtx.stmt.getParmCount(); - // null bitmap - byte[] nullbitmapData = new byte[(paramCount + 7) / 8]; - packetBuf.get(nullbitmapData); - String stmtStr = ""; - try { - // new_params_bind_flag - if ((int) packetBuf.get() != 0) { - // parse params's types - for (int i = 0; i < paramCount; ++i) { - int typeCode = packetBuf.getChar(); - LOG.debug("code {}", typeCode); - prepareCtx.stmt.placeholders().get(i).setTypeCode(typeCode); - } - } - List<LiteralExpr> realValueExprs = new ArrayList<>(); - // parse param data - for (int i = 0; i < paramCount; ++i) { - if (isNull(nullbitmapData, i)) { - realValueExprs.add(new NullLiteral()); - continue; - } - LiteralExpr l = prepareCtx.stmt.placeholders().get(i).createLiteralFromType(); - l.setupParamFromBinary(packetBuf); - realValueExprs.add(l); - } - ExecuteStmt executeStmt = new ExecuteStmt(String.valueOf(stmtId), realValueExprs); - // TODO set real origin statement - executeStmt.setOrigStmt(new OriginStatement("null", 0)); - executeStmt.setUserInfo(ctx.getCurrentUserIdentity()); - LOG.debug("executeStmt {}", executeStmt); - executor = new StmtExecutor(ctx, executeStmt); - ctx.setExecutor(executor); - executor.execute(); - stmtStr = executeStmt.toSql(); - } catch (Throwable e) { - // Catch all throwable. - // If reach here, maybe palo bug. - LOG.warn("Process one query failed because unknown reason: ", e); - ctx.getState().setError(ErrorCode.ERR_UNKNOWN_ERROR, - e.getClass().getSimpleName() + ", msg: " + e.getMessage()); - } - auditAfterExec(stmtStr, prepareCtx.stmt.getInnerStmt(), null, false); - } - - private void auditAfterExec(String origStmt, StatementBase parsedStmt, - Data.PQueryStatistics statistics, boolean printFuzzyVariables) { + protected void auditAfterExec(String origStmt, StatementBase parsedStmt, + Data.PQueryStatistics statistics, boolean printFuzzyVariables) { AuditLogHelper.logAuditLog(ctx, origStmt, parsedStmt, statistics, printFuzzyVariables); } - // Process COM_QUERY statement, // only throw an exception when there is a problem interacting with the requesting client - private void handleQuery(MysqlCommand mysqlCommand) { + protected void handleQuery(MysqlCommand mysqlCommand, String originStmt) { Review Comment: 我感觉这个接口,可以不要mysql command了,因为这个代码 flight 也在调用。 直接 handleQuqery(isComQuery, stmt) 是否就可以了 -- 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. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org