Skip to content

Commit

Permalink
Merge pull request pingcap#6 from TszKitLo40/fix-replay-bug
Browse files Browse the repository at this point in the history
fix replay bug
  • Loading branch information
jyz0309 authored Jan 3, 2022
2 parents 7b52fee + 19903a7 commit 1b11557
Show file tree
Hide file tree
Showing 2 changed files with 238,146 additions and 19 deletions.
43 changes: 24 additions & 19 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"crypto/tls"
"encoding/json"
"fmt"
"github.com/google/uuid"
"runtime/pprof"
"runtime/trace"
"strconv"
Expand All @@ -33,6 +32,8 @@ import (
"sync/atomic"
"time"

"github.com/google/uuid"

"github.com/ngaut/pools"
"github.com/opentracing/opentracing-go"
"github.com/pingcap/errors"
Expand Down Expand Up @@ -2866,25 +2867,29 @@ func logGeneralQuery(execStmt *executor.ExecStmt, s *session, isPrepared bool) {
cfg := config.GetGlobalConfig()
vars := s.GetSessionVars()
if !s.isInternal() && cfg.EnableReplaySQL.Load() {
go func(sql string) {
//TODO: We need to add a client col also.
var builder strings.Builder
builder.WriteString(fmt.Sprintf("%v", vars.ConnectionID))
//go func(vars *variable.SessionVars) {
//TODO: We need to add a client col also.
var builder strings.Builder
builder.WriteString(fmt.Sprintf("%v", vars.ConnectionID))
builder.WriteString(" ")
// Logic TS
ts := strconv.FormatInt(s.sessionVars.StartTime.Unix()-cfg.ReplayMetaTS, 10)
builder.WriteString(ts)
builder.WriteString(" ")
builder.WriteString(vars.CurrentDB)
builder.WriteString(" ")
//text := executor.QueryReplacer.Replace(s.sessionVars.StmtCtx.OriginalSQL)
builder.WriteString(s.sessionVars.StmtCtx.OriginalSQL)
//fmt.Printf("SQL %s ", vars.SQL)
//fmt.Printf("origin sql %v", s.sessionVars.StmtCtx.OriginalSQL)
if vars.PreparedParams != nil {
builder.WriteString(" ")
// Logic TS
ts := strconv.FormatInt(s.sessionVars.StartTime.Unix()-cfg.ReplayMetaTS, 10)
builder.WriteString(ts)
builder.WriteString(" ")
builder.WriteString(vars.CurrentDB)
text := executor.QueryReplacer.Replace(sql)
builder.WriteString(text)
if vars.PreparedParams != nil {
builder.WriteString(" ")
builder.WriteString(vars.PreparedParams.String())
}
builder.WriteString("\n")
logutil.PutRecordOrDrop(builder.String())
}(vars.SQL)
builder.WriteString(vars.PreparedParams.String())
//fmt.Printf("params %s", vars.PreparedParams.String())
}
builder.WriteString("\n")
logutil.PutRecordOrDrop(builder.String())
//}(vars)
}

if variable.ProcessGeneralLog.Load() && !vars.InRestrictedSQL {
Expand Down
Loading

0 comments on commit 1b11557

Please sign in to comment.