Skip to content

Commit 468c842

Browse files
committed
fix function parameter
1 parent d7c1cb6 commit 468c842

File tree

10 files changed

+40
-29
lines changed

10 files changed

+40
-29
lines changed

pkg/frontend/mysql_cmd_executor.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2689,7 +2689,7 @@ func executeStmtWithWorkspace(ses FeSession,
26892689
defer ses.ExitFPrint(FPExecStmtWithWorkspaceBeforeStart)
26902690
//!!!NOTE!!!: statement management
26912691
//2. start statement on workspace
2692-
txnOp.GetWorkspace().StartStatement(execCtx.stmt.String())
2692+
txnOp.GetWorkspace().StartStatement(execCtx.stmt)
26932693
//3. end statement on workspace
26942694
// defer Start/End Statement management, called after finishTxnFunc()
26952695
defer func() {

pkg/frontend/test/txn_mock.go

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/frontend/txn_test.go

+16-12
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,12 @@ func newTestWorkspace() *testWorkspace {
7474
return &testWorkspace{}
7575
}
7676

77-
func (txn *testWorkspace) StartStatement(sql string) {
77+
func (txn *testWorkspace) StartStatement(stmt tree.Statement) {
7878
if txn.start {
79+
var sql string
80+
if stmt != nil {
81+
sql = stmt.String()
82+
}
7983
panic(fmt.Sprintf("BUG: StartStatement called twice, sql: %s", sql))
8084
}
8185
txn.start = true
@@ -177,7 +181,7 @@ func TestWorkspace(t *testing.T) {
177181
convey.So(
178182
func() {
179183
wsp := newTestWorkspace()
180-
wsp.StartStatement("")
184+
wsp.StartStatement(nil)
181185
wsp.EndStatement()
182186
},
183187
convey.ShouldNotPanic,
@@ -196,8 +200,8 @@ func TestWorkspace(t *testing.T) {
196200
convey.So(
197201
func() {
198202
wsp := newTestWorkspace()
199-
wsp.StartStatement("")
200-
wsp.StartStatement("")
203+
wsp.StartStatement(nil)
204+
wsp.StartStatement(nil)
201205
},
202206
convey.ShouldPanic,
203207
)
@@ -217,7 +221,7 @@ func TestWorkspace(t *testing.T) {
217221
convey.So(
218222
func() {
219223
wsp := newTestWorkspace()
220-
wsp.StartStatement("")
224+
wsp.StartStatement(nil)
221225
err := wsp.IncrStatementID(context.TODO(), false)
222226
convey.So(err, convey.ShouldBeNil)
223227
//incr twice
@@ -231,7 +235,7 @@ func TestWorkspace(t *testing.T) {
231235
convey.So(
232236
func() {
233237
wsp := newTestWorkspace()
234-
wsp.StartStatement("")
238+
wsp.StartStatement(nil)
235239
err := wsp.RollbackLastStatement(context.TODO())
236240
convey.So(err, convey.ShouldBeNil)
237241
},
@@ -242,7 +246,7 @@ func TestWorkspace(t *testing.T) {
242246
convey.So(
243247
func() {
244248
wsp := newTestWorkspace()
245-
wsp.StartStatement("")
249+
wsp.StartStatement(nil)
246250
err := wsp.IncrStatementID(context.TODO(), false)
247251
convey.So(err, convey.ShouldBeNil)
248252
err = wsp.RollbackLastStatement(context.TODO())
@@ -484,7 +488,7 @@ func Test_rollbackStatement(t *testing.T) {
484488
NeedToBeCommittedInActiveTransaction(&tree.Insert{}), convey.ShouldBeFalse)
485489
convey.So(txnOp != nil && !ses.IsDerivedStmt(), convey.ShouldBeTrue)
486490
//called incrStatement
487-
txnOp.GetWorkspace().StartStatement("")
491+
txnOp.GetWorkspace().StartStatement(nil)
488492
err = txnOp.GetWorkspace().IncrStatementID(ctx, false)
489493
convey.So(err, convey.ShouldBeNil)
490494
ec.stmt = &tree.Insert{}
@@ -514,7 +518,7 @@ func Test_rollbackStatement(t *testing.T) {
514518
NeedToBeCommittedInActiveTransaction(&tree.Insert{}), convey.ShouldBeFalse)
515519
convey.So(txnOp != nil && !ses.IsDerivedStmt(), convey.ShouldBeTrue)
516520
//called incrStatement
517-
txnOp.GetWorkspace().StartStatement("")
521+
txnOp.GetWorkspace().StartStatement(nil)
518522
err = txnOp.GetWorkspace().IncrStatementID(ctx, false)
519523
convey.So(err, convey.ShouldBeNil)
520524
ec.stmt = &tree.Insert{}
@@ -671,7 +675,7 @@ func Test_rollbackStatement5(t *testing.T) {
671675
NeedToBeCommittedInActiveTransaction(&tree.Insert{}), convey.ShouldBeFalse)
672676
convey.So(txnOp != nil && !ses.IsDerivedStmt(), convey.ShouldBeTrue)
673677
//called incrStatement
674-
txnOp.GetWorkspace().StartStatement("")
678+
txnOp.GetWorkspace().StartStatement(nil)
675679
err = txnOp.GetWorkspace().IncrStatementID(ctx, false)
676680
convey.So(err, convey.ShouldBeNil)
677681
ec.stmt = &tree.Insert{}
@@ -710,7 +714,7 @@ func Test_rollbackStatement6(t *testing.T) {
710714
NeedToBeCommittedInActiveTransaction(&tree.Insert{}), convey.ShouldBeFalse)
711715
convey.So(txnOp != nil && !ses.IsDerivedStmt(), convey.ShouldBeTrue)
712716
//called incrStatement
713-
txnOp.GetWorkspace().StartStatement("")
717+
txnOp.GetWorkspace().StartStatement(nil)
714718
err = txnOp.GetWorkspace().IncrStatementID(ctx, false)
715719
convey.So(err, convey.ShouldBeNil)
716720
ec.stmt = &tree.Insert{}
@@ -745,7 +749,7 @@ func Test_rollbackStatement6(t *testing.T) {
745749
NeedToBeCommittedInActiveTransaction(&tree.Insert{}), convey.ShouldBeFalse)
746750
convey.So(txnOp != nil && !ses.IsDerivedStmt(), convey.ShouldBeTrue)
747751
//called incrStatement
748-
txnOp.GetWorkspace().StartStatement("")
752+
txnOp.GetWorkspace().StartStatement(nil)
749753
err = txnOp.GetWorkspace().IncrStatementID(ctx, false)
750754
convey.So(err, convey.ShouldBeNil)
751755
ec.stmt = &tree.Insert{}

pkg/frontend/util_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ func TestGetExprValue(t *testing.T) {
621621
ws.EXPECT().IncrStatementID(gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
622622
ws.EXPECT().IncrSQLCount().AnyTimes()
623623
ws.EXPECT().GetSQLCount().AnyTimes()
624-
ws.EXPECT().StartStatement("").AnyTimes()
624+
ws.EXPECT().StartStatement(nil).AnyTimes()
625625
ws.EXPECT().EndStatement().AnyTimes()
626626
ws.EXPECT().GetSnapshotWriteOffset().Return(0).AnyTimes()
627627
ws.EXPECT().UpdateSnapshotWriteOffset().AnyTimes()
@@ -729,7 +729,7 @@ func TestGetExprValue(t *testing.T) {
729729

730730
ws := mock_frontend.NewMockWorkspace(ctrl)
731731
ws.EXPECT().IncrStatementID(gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
732-
ws.EXPECT().StartStatement("").AnyTimes()
732+
ws.EXPECT().StartStatement(nil).AnyTimes()
733733
ws.EXPECT().EndStatement().AnyTimes()
734734
ws.EXPECT().GetSnapshotWriteOffset().Return(0).AnyTimes()
735735
ws.EXPECT().UpdateSnapshotWriteOffset().AnyTimes()

pkg/sql/compile/sql_executor.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (s *sqlExecutor) NewTxnOperator(ctx context.Context) client.TxnOperator {
9999
return nil
100100
}
101101
}
102-
opts.Txn().GetWorkspace().StartStatement("")
102+
opts.Txn().GetWorkspace().StartStatement(nil)
103103
opts.Txn().GetWorkspace().IncrStatementID(ctx, false)
104104
return opts.Txn()
105105
}
@@ -282,7 +282,7 @@ func (exec *txnExecutor) Exec(
282282
// maybe we should fix it.
283283
txnOp := exec.opts.Txn()
284284
if txnOp != nil && !exec.opts.DisableIncrStatement() {
285-
txnOp.GetWorkspace().StartStatement(sql)
285+
txnOp.GetWorkspace().StartStatement(nil)
286286
defer func() {
287287
txnOp.GetWorkspace().EndStatement()
288288
}()

pkg/txn/client/types.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/matrixorigin/matrixone/pkg/pb/lock"
2323
"github.com/matrixorigin/matrixone/pkg/pb/timestamp"
2424
"github.com/matrixorigin/matrixone/pkg/pb/txn"
25+
"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
2526
"github.com/matrixorigin/matrixone/pkg/txn/rpc"
2627
)
2728

@@ -250,7 +251,7 @@ type Workspace interface {
250251
Readonly() bool
251252

252253
// StartStatement tag a statement is running
253-
StartStatement(string)
254+
StartStatement(tree.Statement)
254255
// EndStatement tag end a statement is completed
255256
EndStatement()
256257

pkg/vm/engine/disttae/types.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"context"
2020
"encoding/hex"
2121
"fmt"
22+
"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
2223
"math"
2324
"strconv"
2425
"sync"
@@ -525,8 +526,12 @@ func (txn *Transaction) PPString() string {
525526
stringifySlice(txn.transfer.timestamps, func(a any) string { t := a.(timestamp.Timestamp); return t.DebugString() }))
526527
}
527528

528-
func (txn *Transaction) StartStatement(sql string) {
529+
func (txn *Transaction) StartStatement(stmt tree.Statement) {
529530
if txn.startStatementCalled {
531+
var sql string
532+
if stmt != nil {
533+
sql = stmt.String()
534+
}
530535
logutil.Fatal("BUG: StartStatement called twice",
531536
zap.String("txn", hex.EncodeToString(txn.op.Txn().ID)),
532537
zap.String("SQL", sql),

pkg/vm/engine/test/disttae_engine_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func TestSystemDB1(t *testing.T) {
163163
txnop = p.StartCNTxn()
164164
dbs, err = p.D.Engine.Databases(p.Ctx, txnop)
165165
require.NoError(t, err)
166-
txnop.GetWorkspace().StartStatement("")
166+
txnop.GetWorkspace().StartStatement(nil)
167167
require.Equal(t, 2+1, len(dbs))
168168

169169
txn, err := p.T.StartTxn()
@@ -561,7 +561,7 @@ func TestColumnsTransfer(t *testing.T) {
561561
require.NoError(t, txnop.Commit(p.Ctx))
562562

563563
txnop = p.StartCNTxn()
564-
txnop.GetWorkspace().StartStatement("")
564+
txnop.GetWorkspace().StartStatement(nil)
565565
p.DeleteTableInDB(txnop, "db", schema2.Name)
566566

567567
txn, _ := tae.StartTxn(nil)

pkg/vm/engine/test/testutil/util.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ func WriteToRelation(
444444
bat *batch.Batch,
445445
isDelete, toEndStatement bool,
446446
) (err error) {
447-
txn.GetWorkspace().StartStatement("")
447+
txn.GetWorkspace().StartStatement(nil)
448448
if isDelete {
449449
err = relation.Delete(ctx, bat, catalog2.Row_ID)
450450
} else {

pkg/vm/engine/test/workspace_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ func Test_BasicRollbackStatement(t *testing.T) {
809809

810810
require.NoError(t, testutil.WriteToRelation(ctx, txn, relation, bat1, false, true))
811811

812-
txn.GetWorkspace().StartStatement("")
812+
txn.GetWorkspace().StartStatement(nil)
813813
require.NoError(t, relation.Write(ctx, bat2))
814814
require.NoError(t, txn.GetWorkspace().RollbackLastStatement(ctx))
815815
require.NoError(t, txn.GetWorkspace().IncrStatementID(ctx, false))
@@ -921,7 +921,7 @@ func Test_BasicRollbackStatementS3(t *testing.T) {
921921

922922
require.NoError(t, testutil.WriteToRelation(ctx, txn, relation, bat1, false, true))
923923

924-
txn.GetWorkspace().StartStatement("")
924+
txn.GetWorkspace().StartStatement(nil)
925925
require.NoError(t, relation.Write(ctx, bat2))
926926
require.NoError(t, txn.GetWorkspace().RollbackLastStatement(ctx))
927927
require.NoError(t, txn.GetWorkspace().IncrStatementID(ctx, false))
@@ -1033,7 +1033,7 @@ func Test_RollbackDeleteAndDrop(t *testing.T) {
10331033
txnop = p.StartCNTxn()
10341034
exec := v.(executor.SQLExecutor)
10351035
execopts := executor.Options{}.WithTxn(txnop).WithDisableIncrStatement()
1036-
txnop.GetWorkspace().StartStatement("")
1036+
txnop.GetWorkspace().StartStatement(nil)
10371037
txnop.GetWorkspace().IncrStatementID(p.Ctx, false)
10381038
dropTable := func() {
10391039
_, err := exec.Exec(p.Ctx, "delete from db.test3 where mock_1 = 0", execopts)
@@ -1182,7 +1182,7 @@ func Test_MultiTxnRollbackStatement(t *testing.T) {
11821182
{
11831183
require.NoError(t, testutil.WriteToRelation(ctx, txn, relation, bat2, false, true))
11841184

1185-
txn.GetWorkspace().StartStatement("")
1185+
txn.GetWorkspace().StartStatement(nil)
11861186
require.NoError(t, relation.Write(ctx, bat2))
11871187
require.NoError(t, txn.GetWorkspace().RollbackLastStatement(ctx))
11881188
require.NoError(t, txn.GetWorkspace().IncrStatementID(ctx, false))
@@ -1357,7 +1357,7 @@ func Test_MultiTxnRollbackStatementS3(t *testing.T) {
13571357

13581358
// txn2 delete 5-15
13591359
{
1360-
txn.GetWorkspace().StartStatement("")
1360+
txn.GetWorkspace().StartStatement(nil)
13611361
require.NoError(t, relation.Write(ctx, bat2))
13621362
require.NoError(t, txn.GetWorkspace().RollbackLastStatement(ctx))
13631363
require.NoError(t, txn.GetWorkspace().IncrStatementID(ctx, false))
@@ -1662,7 +1662,7 @@ func Test_CNTransferTombstoneObjects(t *testing.T) {
16621662
_, _, cnTxnOp, err = p.D.GetTable(ctx, databaseName, tableName)
16631663
require.NoError(t, err)
16641664

1665-
cnTxnOp.GetWorkspace().StartStatement("")
1665+
cnTxnOp.GetWorkspace().StartStatement(nil)
16661666
err = cnTxnOp.GetWorkspace().IncrStatementID(ctx, false)
16671667
require.NoError(t, err)
16681668
}

0 commit comments

Comments
 (0)