Skip to content

Commit

Permalink
Merge branch 'main' into fix-20766
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Dec 17, 2024
2 parents f784699 + e791f93 commit 120d091
Show file tree
Hide file tree
Showing 40 changed files with 3,531 additions and 579 deletions.
47 changes: 0 additions & 47 deletions pkg/frontend/authenticate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10992,53 +10992,6 @@ func TestDoCreateSnapshot(t *testing.T) {
})
}

func TestDoResolveSnapshotTsWithSnapShotName(t *testing.T) {
convey.Convey("doResolveSnapshotWithSnapshotName success", t, func() {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

ses := newTestSession(t, ctrl)
defer ses.Close()

bh := &backgroundExecTest{}
bh.init()

bhStub := gostub.StubFunc(&NewBackgroundExec, bh)
defer bhStub.Reset()

pu := config.NewParameterUnit(&config.FrontendParameters{}, nil, nil, nil)
pu.SV.SetDefaultValues()
pu.SV.KillRountinesInterval = 0
setPu("", pu)
ctx := context.WithValue(context.TODO(), config.ParameterUnitKey, pu)
rm, _ := NewRoutineManager(ctx, "")
ses.rm = rm

tenant := &TenantInfo{
Tenant: sysAccountName,
User: rootName,
DefaultRole: moAdminRoleName,
TenantID: sysAccountID,
UserID: rootID,
DefaultRoleID: moAdminRoleID,
}
ses.SetTenantInfo(tenant)
ses.GetTxnHandler().txnOp = newTestTxnOp()

//no result set
bh.sql2result["begin;"] = nil
bh.sql2result["commit;"] = nil
bh.sql2result["rollback;"] = nil

sql, _ := getSqlForGetSnapshotTsWithSnapshotName(ctx, "test_sp")
mrs := newMrsForPasswordOfUser([][]interface{}{})
bh.sql2result[sql] = mrs

_, err := doResolveSnapshotWithSnapshotName(ctx, ses, "test_sp")
convey.So(err, convey.ShouldNotBeNil)
})
}

func TestCheckTimeStampValid(t *testing.T) {
convey.Convey("checkTimeStampValid success", t, func() {
ctrl := gomock.NewController(t)
Expand Down
12 changes: 8 additions & 4 deletions pkg/frontend/back_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,11 @@ func (back *backExec) ExecRestore(ctx context.Context, sql string, opAccount uin
}

userInput := &UserInput{
sql: sql,
isRestore: true,
opAccount: opAccount,
toAccount: toAccount,
sql: sql,
isRestore: true,
opAccount: opAccount,
toAccount: toAccount,
isRestoreByTs: true,
}

execCtx := ExecCtx{
Expand Down Expand Up @@ -403,6 +404,9 @@ func doComQueryInBack(
if insertStmt, ok := stmt.(*tree.Insert); ok && input.isRestore {
insertStmt.IsRestore = true
insertStmt.FromDataTenantID = input.opAccount
if input.isRestoreByTs {
insertStmt.IsRestoreByTs = true
}
}

statsInfo.Reset()
Expand Down
10 changes: 10 additions & 0 deletions pkg/frontend/mysql_cmd_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,16 @@ func handleShowTableStatus(ses *Session, execCtx *ExecCtx, stmt *tree.ShowTableS
}

getRoleName := func(roleId uint32) (roleName string, err error) {
accountId, err := defines.GetAccountId(ctx)
if err != nil {
return
}

if accountId != sysAccountID && roleId == moAdminRoleID {
roleName = accountAdminRoleName
return
}

sql := getSqlForRoleNameOfRoleId(int64(roleId))

var rets []ExecResult
Expand Down
63 changes: 63 additions & 0 deletions pkg/frontend/mysql_cmd_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1610,3 +1610,66 @@ func Test_run_panic(t *testing.T) {
runPanic(fault.PanicUseMoErr)
runPanic(fault.PanicUseNonMoErr)
}

func Test_handleShowTableStatus(t *testing.T) {
ctx := defines.AttachAccountId(context.TODO(), 1)
convey.Convey("handleShowTableStatus succ", t, func() {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

relation := mock_frontend.NewMockRelation(ctrl)
relation.EXPECT().GetTableDef(gomock.Any()).Return(&plan.TableDef{TableType: catalog.SystemViewRel}).AnyTimes()

database := mock_frontend.NewMockDatabase(ctrl)
database.EXPECT().IsSubscription(gomock.Any()).Return(false).AnyTimes()
database.EXPECT().Relation(gomock.Any(), gomock.Any(), nil).Return(relation, nil).AnyTimes()

eng := mock_frontend.NewMockEngine(ctrl)
eng.EXPECT().New(gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
eng.EXPECT().Database(gomock.Any(), gomock.Any(), nil).Return(database, nil).AnyTimes()

txnOperator := mock_frontend.NewMockTxnOperator(ctrl)
txnOperator.EXPECT().Commit(gomock.Any()).Return(nil).AnyTimes()
txnOperator.EXPECT().Rollback(gomock.Any()).Return(nil).AnyTimes()
txnOperator.EXPECT().Status().Return(txn.TxnStatus_Active).AnyTimes()
txnOperator.EXPECT().EnterRunSql().Return().AnyTimes()
txnOperator.EXPECT().ExitRunSql().Return().AnyTimes()

txnClient := mock_frontend.NewMockTxnClient(ctrl)
txnClient.EXPECT().New(gomock.Any(), gomock.Any()).Return(txnOperator, nil).AnyTimes()

sv, err := getSystemVariables("test/system_vars_config.toml")
if err != nil {
t.Error(err)
}
pu := config.NewParameterUnit(sv, eng, txnClient, nil)
pu.SV.SkipCheckUser = true
setPu("", pu)
setSessionAlloc("", NewLeakCheckAllocator())
ioses, err := NewIOSession(&testConn{}, pu, "")
convey.So(err, convey.ShouldBeNil)
pu.StorageEngine = eng
pu.TxnClient = txnClient
proto := NewMysqlClientProtocol("", 0, ioses, 1024, pu.SV)

ses := NewSession(ctx, "", proto, nil)
tenant := &TenantInfo{
Tenant: "sys",
TenantID: 0,
User: DefaultTenantMoAdmin,
}
ses.SetTenantInfo(tenant)
ses.mrs = &MysqlResultSet{}
ses.SetDatabaseName("t")
ses.data = [][]interface{}{{[]byte("t"), nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, uint32(0), nil}}

proto.SetSession(ses)

ec := newTestExecCtx(ctx, ctrl)
shv := &tree.ShowTableStatus{}
convey.So(handleShowTableStatus(ses, ec, shv), convey.ShouldBeNil)

ec = newTestExecCtx(context.Background(), ctrl)
convey.So(handleShowTableStatus(ses, ec, shv), convey.ShouldNotBeNil)
})
}
4 changes: 2 additions & 2 deletions pkg/frontend/pitr.go
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ func doRestorePitr(ctx context.Context, ses *Session, stmt *tree.RestorePitr) (s
sortedFkTbls []string
fkTableMap map[string]*tableInfo
)
// reslove timestamp
// resolve timestamp
ts, err = doResolveTimeStamp(stmt.TimeStamp)
if err != nil {
return stats, err
Expand Down Expand Up @@ -1599,7 +1599,7 @@ func deleteCurFkTableInPitrRestore(ctx context.Context,
)

// get topo sorted tables with foreign key
sortedFkTbls, err = fkTablesTopoSort(ctx, bh, "", dbName, tblName)
sortedFkTbls, err = fkTablesTopoSortInPitrRestore(ctx, bh, 0, dbName, tblName)
if err != nil {
return
}
Expand Down
Loading

0 comments on commit 120d091

Please sign in to comment.