Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add log #16831

Closed
wants to merge 5 commits into from
Closed

add log #16831

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
2 changes: 1 addition & 1 deletion pkg/frontend/mysql_cmd_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2303,7 +2303,7 @@ func executeStmtWithWorkspace(ses FeSession,

//refresh txn id
ses.SetTxnId(txnOp.Txn().ID)
ses.SetStaticTxnId(txnOp.Txn().ID)
ses.SetStaticTxnInfo(txnOp.Txn().DebugString())

//refresh proc txnOp
execCtx.proc.TxnOperator = txnOp
Expand Down
15 changes: 13 additions & 2 deletions pkg/frontend/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package frontend
import (
"context"
"errors"
"strings"
"sync"

"github.com/google/uuid"
Expand Down Expand Up @@ -107,6 +108,8 @@ func finishTxnFunc(ses FeSession, execErr error, execCtx *ExecCtx) (err error) {
err = ses.GetTxnHandler().Commit(execCtx)
if err != nil {
logStatementStatus(execCtx.reqCtx, ses, execCtx.stmt, fail, err)
} else {
logStatementStatus(execCtx.reqCtx, ses, execCtx.stmt, success, nil)
}
} else if execCtx.txnOpt.byRollback {
//roll back the txn by the ROLLBACK statement
Expand All @@ -119,6 +122,10 @@ func finishTxnFunc(ses FeSession, execErr error, execCtx *ExecCtx) (err error) {
if execErr == nil {
err = commitTxnFunc(ses, execCtx)
if err == nil {
sql := ses.GetSql()
if strings.Contains(strings.ToLower(sql), "create database sysbench_db") {
logStatementStatus(execCtx.reqCtx, ses, execCtx.stmt, success, nil)
}
return err
}
// if commitTxnFunc failed, we will roll back the transaction.
Expand Down Expand Up @@ -504,12 +511,16 @@ func (th *TxnHandler) commitUnsafe(execCtx *ExecCtx) error {
if th.txnOp != nil {
execCtx.ses.EnterFPrint(79)
defer execCtx.ses.ExitFPrint(79)
commitTs := th.txnOp.Txn().CommitTS
execCtx.ses.SetTxnId(th.txnOp.Txn().ID)
//commitTs := th.txnOp.Txn().CommitTS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要了,都删掉吧。

//execCtx.ses.SetTxnId(th.txnOp.Txn().ID)
err = th.txnOp.Commit(ctx2)
if err != nil {
th.invalidateTxnUnsafe()
}
commitTs := th.txnOp.Txn().CommitTS
execCtx.ses.SetTxnId(th.txnOp.Txn().ID)
execCtx.ses.SetStaticTxnInfo(th.txnOp.Txn().DebugString())

execCtx.ses.updateLastCommitTS(commitTs)
}
th.invalidateTxnUnsafe()
Expand Down
24 changes: 15 additions & 9 deletions pkg/frontend/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import (
"github.com/fagongzi/goetty/v2"
"github.com/fagongzi/goetty/v2/buf"
"github.com/google/uuid"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"

"github.com/matrixorigin/matrixone/pkg/common/buffer"
"github.com/matrixorigin/matrixone/pkg/common/moerr"
"github.com/matrixorigin/matrixone/pkg/common/mpool"
Expand All @@ -39,8 +42,6 @@ import (
"github.com/matrixorigin/matrixone/pkg/util"
"github.com/matrixorigin/matrixone/pkg/util/trace/impl/motrace"
"github.com/matrixorigin/matrixone/pkg/vm/process"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)

const (
Expand Down Expand Up @@ -337,8 +338,10 @@ type FeSession interface {
ResetFPrints()
EnterFPrint(idx int)
ExitFPrint(idx int)
SetStaticTxnId(id []byte)
GetStaticTxnId() uuid.UUID
//SetStaticTxnId(id []byte)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要都删掉吧。

//GetStaticTxnId() uuid.UUID
SetStaticTxnInfo(info string)
GetStaticTxnInfo() string
GetShareTxnBackgroundExec(ctx context.Context, newRawBatch bool) BackgroundExec
SessionLogger
}
Expand Down Expand Up @@ -456,7 +459,9 @@ type feSessionImpl struct {
fprints footPrints
respr Responser
//refreshed once
staticTxnId uuid.UUID
// staticTxnId uuid.UUID
//txn info
txnInfo string
}

func (ses *feSessionImpl) EnterFPrint(idx int) {
Expand Down Expand Up @@ -856,11 +861,12 @@ func (ses *feSessionImpl) GetResponser() Responser {
return ses.respr
}

func (ses *feSessionImpl) SetStaticTxnId(id []byte) {
copy(ses.staticTxnId[:], id)
func (ses *feSessionImpl) SetStaticTxnInfo(info string) {
ses.txnInfo = info
}
func (ses *feSessionImpl) GetStaticTxnId() uuid.UUID {
return ses.staticTxnId

func (ses *feSessionImpl) GetStaticTxnInfo() string {
return ses.txnInfo
}

func (ses *Session) GetDebugString() string {
Expand Down
9 changes: 6 additions & 3 deletions pkg/frontend/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,13 +497,16 @@ func logStatementStringStatus(ctx context.Context, ses FeSession, stmtStr string

}

txnInfo := ses.GetStaticTxnInfo()
if status == success {
ses.Debug(ctx, "query trace status", logutil.StatementField(str), logutil.StatusField(status.String()))
sql := ses.GetSql()
if strings.Contains(strings.ToLower(sql), "create database sysbench_db") {
ses.Info(ctx, "query trace status", logutil.StatementField(str), logutil.StatusField(status.String()), logutil.TxnIdField(txnInfo))
}
err = nil // make sure: it is nil for EndStatement
} else {
txnId := ses.GetStaticTxnId()
ses.Error(ctx, "query trace status", logutil.StatementField(str), logutil.StatusField(status.String()), logutil.ErrorField(err),
logutil.TxnIdField(hex.EncodeToString(txnId[:])))
logutil.TxnIdField(txnInfo))
}

// pls make sure: NO ONE use the ses.tStmt after EndStatement
Expand Down
Loading