Skip to content

Commit

Permalink
Resolve conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
CbcWestwolf committed Dec 26, 2022
1 parent 4f9670c commit 7e6f16e
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 830 deletions.
53 changes: 16 additions & 37 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1394,43 +1394,22 @@ func (s *session) SetProcessInfo(sql string, t time.Time, command byte, maxExecu
p = explain.TargetPlan
}
pi := util.ProcessInfo{
<<<<<<< HEAD
ID: s.sessionVars.ConnectionID,
Port: s.sessionVars.Port,
DB: s.sessionVars.CurrentDB,
Command: command,
Plan: p,
PlanExplainRows: plannercore.GetExplainRowsForPlan(p),
RuntimeStatsColl: s.sessionVars.StmtCtx.RuntimeStatsColl,
Time: t,
State: s.Status(),
Info: sql,
CurTxnStartTS: curTxnStartTS,
StmtCtx: s.sessionVars.StmtCtx,
StatsInfo: plannercore.GetStatsInfo,
MaxExecutionTime: maxExecutionTime,
RedactSQL: s.sessionVars.EnableRedactLog,
=======
ID: s.sessionVars.ConnectionID,
Port: s.sessionVars.Port,
DB: s.sessionVars.CurrentDB,
Command: command,
Plan: p,
PlanExplainRows: plannercore.GetExplainRowsForPlan(p),
RuntimeStatsColl: s.sessionVars.StmtCtx.RuntimeStatsColl,
Time: t,
State: s.Status(),
Info: sql,
CurTxnStartTS: curTxnStartTS,
StmtCtx: s.sessionVars.StmtCtx,
RefCountOfStmtCtx: &s.sessionVars.RefCountOfStmtCtx,
MemTracker: s.sessionVars.MemTracker,
DiskTracker: s.sessionVars.DiskTracker,
StatsInfo: plannercore.GetStatsInfo,
OOMAlarmVariablesInfo: s.getOomAlarmVariablesInfo(),
MaxExecutionTime: maxExecutionTime,
RedactSQL: s.sessionVars.EnableRedactLog,
>>>>>>> f8a6bde954 (*: add a reference count for StmtCtx (#39368))
ID: s.sessionVars.ConnectionID,
Port: s.sessionVars.Port,
DB: s.sessionVars.CurrentDB,
Command: command,
Plan: p,
PlanExplainRows: plannercore.GetExplainRowsForPlan(p),
RuntimeStatsColl: s.sessionVars.StmtCtx.RuntimeStatsColl,
Time: t,
State: s.Status(),
Info: sql,
CurTxnStartTS: curTxnStartTS,
StmtCtx: s.sessionVars.StmtCtx,
RefCountOfStmtCtx: &s.sessionVars.RefCountOfStmtCtx,
StatsInfo: plannercore.GetStatsInfo,
MaxExecutionTime: maxExecutionTime,
RedactSQL: s.sessionVars.EnableRedactLog,
}
oldPi := s.ShowProcess()
if p == nil {
Expand Down
40 changes: 0 additions & 40 deletions sessionctx/stmtctx/stmtctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,45 +60,6 @@ type SQLWarn struct {
Err error
}

<<<<<<< HEAD
=======
type jsonSQLWarn struct {
Level string `json:"level"`
SQLErr *terror.Error `json:"err,omitempty"`
Msg string `json:"msg,omitempty"`
}

// MarshalJSON implements the Marshaler.MarshalJSON interface.
func (warn *SQLWarn) MarshalJSON() ([]byte, error) {
w := &jsonSQLWarn{
Level: warn.Level,
}
e := errors.Cause(warn.Err)
switch x := e.(type) {
case *terror.Error:
// Omit outter errors because only the most inner error matters.
w.SQLErr = x
default:
w.Msg = e.Error()
}
return json.Marshal(w)
}

// UnmarshalJSON implements the Unmarshaler.UnmarshalJSON interface.
func (warn *SQLWarn) UnmarshalJSON(data []byte) error {
var w jsonSQLWarn
if err := json.Unmarshal(data, &w); err != nil {
return err
}
warn.Level = w.Level
if w.SQLErr != nil {
warn.Err = w.SQLErr
} else {
warn.Err = errors.New(w.Msg)
}
return nil
}

// ReferenceCount indicates the reference count of StmtCtx.
type ReferenceCount int32

Expand Down Expand Up @@ -135,7 +96,6 @@ func (rf *ReferenceCount) UnFreeze() {
atomic.StoreInt32((*int32)(rf), ReferenceCountNoReference)
}

>>>>>>> f8a6bde954 (*: add a reference count for StmtCtx (#39368))
// StatementContext contains variables for a statement.
// It should be reset before executing a statement.
type StatementContext struct {
Expand Down
13 changes: 2 additions & 11 deletions sessionctx/variable/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1006,11 +1006,8 @@ type SessionVars struct {
// ReadStaleness indicates the staleness duration for the following query
ReadStaleness time.Duration

// cached is used to optimze the object allocation.
cached struct {
curr int8
data [2]stmtctx.StatementContext
}
// cachedStmtCtx is used to optimze the object allocation.
cachedStmtCtx [2]stmtctx.StatementContext

// Rng stores the rand_seed1 and rand_seed2 for Rand() function
Rng *mathutil.MysqlRng
Expand Down Expand Up @@ -1054,11 +1051,6 @@ type SessionVars struct {

// InitStatementContext initializes a StatementContext, the object is reused to reduce allocation.
func (s *SessionVars) InitStatementContext() *stmtctx.StatementContext {
<<<<<<< HEAD
s.cached.curr = (s.cached.curr + 1) % 2
s.cached.data[s.cached.curr] = stmtctx.StatementContext{}
return &s.cached.data[s.cached.curr]
=======
sc := &s.cachedStmtCtx[0]
if sc == s.StmtCtx {
sc = &s.cachedStmtCtx[1]
Expand All @@ -1070,7 +1062,6 @@ func (s *SessionVars) InitStatementContext() *stmtctx.StatementContext {
sc = &stmtctx.StatementContext{}
}
return sc
>>>>>>> f8a6bde954 (*: add a reference count for StmtCtx (#39368))
}

// AllocMPPTaskID allocates task id for mpp tasks. It will reset the task id if the query's
Expand Down
4 changes: 3 additions & 1 deletion util/expensivequery/expensivequerey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func TestMain(m *testing.M) {
func TestLogFormat(t *testing.T) {
mem := memory.NewTracker(-1, -1)
mem.Consume(1<<30 + 1<<29 + 1<<28 + 1<<27)
var refCount stmtctx.ReferenceCount = 0
info := &util.ProcessInfo{
ID: 233,
User: "PingCAP",
Expand All @@ -52,7 +53,8 @@ func TestLogFormat(t *testing.T) {
StmtCtx: &stmtctx.StatementContext{
MemTracker: mem,
},
RedactSQL: false,
RefCountOfStmtCtx: &refCount,
RedactSQL: false,
}
costTime := time.Second * 233
logFields := genLogFields(costTime, info)
Expand Down
13 changes: 6 additions & 7 deletions util/expensivequery/expensivequery.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ func (eqh *Handle) LogOnQueryExceedMemQuota(connID uint64) {
}

func genLogFields(costTime time.Duration, info *util.ProcessInfo) []zap.Field {
if info.RefCountOfStmtCtx != nil && !info.RefCountOfStmtCtx.TryIncrease() {
return nil
}
defer info.RefCountOfStmtCtx.Decrease()
logFields := make([]zap.Field, 0, 20)
logFields = append(logFields, zap.String("cost_time", strconv.FormatFloat(costTime.Seconds(), 'f', -1, 64)+"s"))
execDetail := info.StmtCtx.GetExecDetails()
Expand Down Expand Up @@ -184,15 +188,10 @@ func genLogFields(costTime time.Duration, info *util.ProcessInfo) []zap.Field {
}

// logExpensiveQuery logs the queries which exceed the time threshold or memory threshold.
<<<<<<< HEAD
func logExpensiveQuery(costTime time.Duration, info *util.ProcessInfo) {
logutil.BgLogger().Warn("expensive_query", genLogFields(costTime, info)...)
=======
func logExpensiveQuery(costTime time.Duration, info *util.ProcessInfo, msg string) {
fields := util.GenLogFields(costTime, info, true)
fields := genLogFields(costTime, info)
if fields == nil {
return
}
logutil.BgLogger().Warn(msg, fields...)
>>>>>>> f8a6bde954 (*: add a reference count for StmtCtx (#39368))
logutil.BgLogger().Warn("expensive_query", fields...)
}
Loading

0 comments on commit 7e6f16e

Please sign in to comment.