fix bug of lost user info and use db stmt

This commit is contained in:
hebo 2019-08-30 12:45:04 +08:00
parent a09af431ee
commit 10b08dec52
1 changed files with 49 additions and 43 deletions

View File

@ -6,8 +6,8 @@ import (
"sync"
"time"
"github.com/siddontang/go/hack"
log "github.com/sirupsen/logrus"
"github.com/pingcap/tidb/util/hack"
"github.com/zr-hebo/sniffer-agent/model"
)
@ -269,8 +269,7 @@ func (ms *MysqlSession) GenerateQueryPiece() (qp model.QueryPiece) {
var mqp *model.PooledMysqlQueryPiece
var querySQLInBytes []byte
switch ms.cachedStmtBytes[0] {
case ComAuth:
if ms.cachedStmtBytes[0] > 32 {
var userName, dbName string
var err error
userName, dbName, err = parseAuthInfo(ms.cachedStmtBytes)
@ -280,9 +279,12 @@ func (ms *MysqlSession) GenerateQueryPiece() (qp model.QueryPiece) {
ms.visitUser = &userName
ms.visitDB = &dbName
} else {
switch ms.cachedStmtBytes[0] {
case ComInitDB:
newDBName := string(ms.cachedStmtBytes[1:])
useSQL := fmt.Sprintf("use %s", newDBName)
querySQLInBytes = hack.Slice(useSQL)
mqp = ms.composeQueryPiece()
mqp.QuerySQL = &useSQL
// update session database
@ -324,6 +326,8 @@ func (ms *MysqlSession) GenerateQueryPiece() (qp model.QueryPiece) {
default:
return
}
}
if strictMode && mqp != nil && mqp.VisitUser == nil {
user, db, err := querySessionInfo(ms.serverPort, mqp.SessionID)
@ -341,10 +345,12 @@ func (ms *MysqlSession) GenerateQueryPiece() (qp model.QueryPiece) {
func filterQueryPieceBySQL(mqp *model.PooledMysqlQueryPiece, querySQL []byte) (model.QueryPiece) {
if mqp == nil || querySQL == nil {
return nil
} else if (uselessSQLPattern.Match(querySQL)) {
}
/*
else if (uselessSQLPattern.Match(querySQL)) {
return nil
}
*/
if ddlPatern.Match(querySQL) {
mqp.SetNeedSyncSend(true)