Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private SystemConfig() {
//unit: ms
private long releaseTimeout = 10L;

private int appendTraceId = 1;
private int appendTraceId = 0;


public int getAppendTraceId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Create Date: 2025-04-17
*/
public interface ITraceResult {
public enum SqlTraceType {
enum SqlTraceType {
SINGLE_NODE_QUERY, MULTI_NODE_QUERY, MULTI_NODE_GROUP, COMPLEX_QUERY, RWSPLIT_QUERY;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public void setVeryStartPrepare(long veryStartPrepare) {
this.requestStartPrepare = new TraceRecord(veryStartPrepare);
}

public void setDBInstance(PhysicalDbInstance dbInstance) {
this.dbInstance = dbInstance;
public void setDBInstance(PhysicalDbInstance tmpDbInstance) {
this.dbInstance = tmpDbInstance;
}

public void setParseStartPrepare(TraceRecord parseStartPrepare) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import java.io.ByteArrayOutputStream;

import static com.actiontech.dble.net.mysql.MySQLPacket.COM_QUERY;


public class RWSplitQueryHandler implements FrontendQueryHandler {

Expand Down Expand Up @@ -46,21 +48,21 @@ public void query(String sql) {
return;
}
int rs = RwSplitServerParse.parse(sql);
int sqlType = rs & 0xff;
if (AppendTraceId.getInstance().isEnable()) {
sql = String.format("/*+ trace_id=%d-%d */ %s", session.getService().getConnection().getId(), session.getService().getSqlUniqueId().incrementAndGet(), sql);
}

session.getService().setExecuteSql(sql);
session.endParse();
int hintLength = RouteService.isHintSql(sql);
int sqlType = rs & 0xff;

if (hintLength >= 0) {
session.executeHint(sqlType, sql, null);
} else {

if (AppendTraceId.getInstance().isEnable()) {
CommandPacket packet = new CommandPacket();
final byte COM_QUERY = 0x3;
packet.setCommand(COM_QUERY);
packet.setArg(sql.getBytes());
packet.setPacketId(session.getService().getExecuteSqlBytes()[3]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static com.actiontech.dble.net.mysql.MySQLPacket.COM_STMT_PREPARE;

public class RWSplitService extends BusinessService {

private static final Logger LOGGER = LoggerFactory.getLogger(RWSplitService.class);
Expand Down Expand Up @@ -122,7 +124,7 @@ protected void handleInnerData(byte[] data) {
handleComQuery(data);
break;
// prepared statement
case MySQLPacket.COM_STMT_PREPARE:
case COM_STMT_PREPARE:
commands.doStmtPrepare();
handleComStmtPrepare(data);
break;
Expand Down Expand Up @@ -225,15 +227,13 @@ private void handleComStmtPrepare(byte[] data) {
sql = sql.substring(0, sql.length() - 1).trim();
}
sql = sql.trim();
int rs = ServerParse.parse(sql);
int sqlType = rs & 0xff;


String tmpSql = sql;
byte[] tmpData = data;
if (AppendTraceId.getInstance().isEnable()) {
tmpSql = String.format("/*+ trace_id=%d-%d */ %s", session.getService().getConnection().getId(), getSqlUniqueId().incrementAndGet(), sql);
CommandPacket packet = new CommandPacket();
final byte COM_STMT_PREPARE = 0x16;
packet.setCommand(COM_STMT_PREPARE);
packet.setArg(tmpSql.getBytes());
packet.setPacketId(data[3]);
Expand All @@ -242,6 +242,8 @@ private void handleComStmtPrepare(byte[] data) {
tmpData = out.toByteArray();
}

int rs = ServerParse.parse(sql);
int sqlType = rs & 0xff;
final String finalSql = tmpSql;
setExecuteSql(finalSql);
final byte[] finalData = tmpData;
Expand Down
Loading