Skip to content
Open
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
11 changes: 9 additions & 2 deletions pkg/executor/staticrecordset/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package staticrecordset_test

import (
"context"
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -241,8 +242,14 @@ func TestFinishStmtError(t *testing.T) {
require.NoError(t, err)
drs := rs.(sqlexec.DetachableRecordSet)

failpoint.Enable("github.com/pingcap/tidb/pkg/session/finishStmtError", "return")
defer failpoint.Disable("github.com/pingcap/tidb/pkg/session/finishStmtError")
const finishStmtErrFpName = "github.com/pingcap/tidb/pkg/session/finishStmtError"
connID := tk.Session().GetSessionVars().ConnectionID
if err := failpoint.Enable(finishStmtErrFpName, fmt.Sprintf("return(%d)", connID)); err != nil {
t.Skipf("skip because failpoint is not enabled: %v", err)
}
t.Cleanup(func() {
require.NoError(t, failpoint.Disable(finishStmtErrFpName))
})
// Then `TryDetach` should return `true`, because the original record set is detached and cannot be used anymore.
_, ok, err := drs.TryDetach()
require.True(t, ok)
Expand Down
23 changes: 20 additions & 3 deletions pkg/session/tidb.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,33 @@ func recordAbortTxnDuration(sessVars *variable.SessionVars, isInternal bool) {
}

func finishStmt(ctx context.Context, se *session, meetsErr error, sql sqlexec.Statement) error {
failpoint.Inject("finishStmtError", func() {
failpoint.Return(errors.New("occur an error after finishStmt"))
})
sessVars := se.sessionVars
<<<<<<< HEAD
readOnly := sql.IsReadOnly(sessVars)
if !readOnly && meetsErr == nil && shouldCheckConnectionAliveBeforeCommit(sessVars, sql) {
sessVars.SQLKiller.CheckConnectionAlive()
meetsErr = sessVars.SQLKiller.HandleSignal()
}
if !readOnly {
=======
failpoint.Inject("finishStmtError", func(val failpoint.Value) {
failCurrentSession := true
switch v := val.(type) {
case int:
failCurrentSession = uint64(v) == sessVars.ConnectionID
case int64:
failCurrentSession = uint64(v) == sessVars.ConnectionID
case uint64:
failCurrentSession = v == sessVars.ConnectionID
case float64:
failCurrentSession = uint64(v) == sessVars.ConnectionID
}
if failCurrentSession {
failpoint.Return(errors.New("occur an error after finishStmt"))
}
})
if !sql.IsReadOnly(sessVars) {
>>>>>>> 74a77b9dd8e (session,executor: scope finishStmt failpoint to current connection (#67655))
Comment on lines +247 to +272

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Resolve the cherry-pick conflict before merging.

The Git conflict markers remain in the Go source, so pkg/session/tidb.go cannot compile. Resolve this hunk by retaining both the connection-alive check and the connection-scoped failpoint, computing readOnly once, and using it for the later branch; selecting either side wholesale drops part of the intended behavior.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/session/tidb.go` around lines 247 - 272, Resolve the conflict in the
finish-statement flow by removing all Git conflict markers and retaining both
behaviors: compute readOnly once with sql.IsReadOnly(sessVars), run the existing
connection-alive check when applicable, and preserve the finishStmtError
failpoint scoped to sessVars.ConnectionID. Use the computed readOnly value for
the subsequent non-read-only branch.

// All the history should be added here.
if meetsErr == nil && sessVars.TxnCtx.CouldRetry {
GetHistory(se).Add(sql, sessVars.StmtCtx)
Expand Down