Skip to content

Commit

Permalink
*: batch write for admin pause (#45857)
Browse files Browse the repository at this point in the history
close #45906
  • Loading branch information
hawkingrei authored Aug 8, 2023
1 parent 6886ef8 commit cdeac4c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 33 deletions.
2 changes: 1 addition & 1 deletion ddl/tests/adminpause/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ go_library(

go_test(
name = "adminpause_test",
timeout = "moderate",
timeout = "short",
srcs = [
"main_test.go",
"pause_cancel_test.go",
Expand Down
38 changes: 16 additions & 22 deletions ddl/tests/adminpause/ddl_data_generation.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,36 +121,30 @@ func (tu *TestTableUser) generateAttributes(id int) (err error) {
return nil
}

func (tu *TestTableUser) insertStmt(tableName string) string {
return fmt.Sprintf("INSERT INTO %s(tenant, name, age, province, city, phone, created_time, updated_time) "+
"VALUES ('%s', '%s', %d, '%s', '%s', '%s', '%s', '%s')",
tableName, tu.tenant, tu.name, tu.age, tu.province, tu.city, tu.phone, tu.createdTime, tu.updatedTime)
func (tu *TestTableUser) insertStmt(tableName string, count int) string {
sql := fmt.Sprintf("INSERT INTO %s(tenant, name, age, province, city, phone, created_time, updated_time) VALUES ", tableName)
for n := 0; n < count; n++ {
_ = tu.generateAttributes(n)
sql += fmt.Sprintf("('%s', '%s', %d, '%s', '%s', '%s', '%s', '%s')",
tu.tenant, tu.name, tu.age, tu.province, tu.city, tu.phone, tu.createdTime, tu.updatedTime)
if n != count-1 {
sql += ", "
}
}
return sql
}

func generateTblUser(tk *testkit.TestKit, rowCount int) error {
tk.MustExec(adminPauseTestTableStmt)

tu := &TestTableUser{}
for idx := 0; idx < rowCount; {
_ = tu.generateAttributes(idx)
tk.MustExec(tu.insertStmt(adminPauseTestTable))

idx++
if rowCount == 0 {
return nil
}

tu := &TestTableUser{}
tk.MustExec(tu.insertStmt(adminPauseTestTable, rowCount))
return nil
}

func generateTblUserParition(tk *testkit.TestKit, rowCount int) error {
func generateTblUserParition(tk *testkit.TestKit) error {
tk.MustExec(adminPauseTestPartitionTableStmt)

tu := &TestTableUser{}
for idx := 0; idx < rowCount; {
_ = tu.generateAttributes(idx)
tk.MustExec(tu.insertStmt(adminPauseTestPartitionTable))

idx++
}

return nil
}
8 changes: 1 addition & 7 deletions ddl/tests/adminpause/pause_cancel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ func TestPauseCancelAndRerunSchemaStmt(t *testing.T) {
zap.String("DDL Statement", stmtCase.stmt))
stmtCase.simpleRunStmt(stmtKit)
}
Logger.Info("TestPauseCancelAndRerunSchemaStmt: all cases finished.")
}

func TestPauseCancelAndRerunIndexStmt(t *testing.T) {
Expand All @@ -204,7 +203,6 @@ func TestPauseCancelAndRerunIndexStmt(t *testing.T) {
zap.String("DDL Statement", stmtCase.stmt))
stmtCase.simpleRunStmt(stmtKit)
}
Logger.Info("TestPauseCancelAndRerunIndexStmt: all cases finished.")
}

func TestPauseCancelAndRerunColumnStmt(t *testing.T) {
Expand All @@ -219,23 +217,19 @@ func TestPauseCancelAndRerunColumnStmt(t *testing.T) {
zap.String("DDL Statement", stmtCase.stmt))
stmtCase.simpleRunStmt(stmtKit)
}

Logger.Info("TestPauseCancelAndRerunColumnStmt: all cases finished.")
}

func TestPauseCancelAndRerunPartitionTableStmt(t *testing.T) {
var dom, stmtKit, adminCommandKit = prepareDomain(t)

require.Nil(t, generateTblUser(stmtKit, 0))

require.Nil(t, generateTblUserParition(stmtKit, 0))
require.Nil(t, generateTblUserParition(stmtKit))
for _, stmtCase := range tablePartitionDDLStmtCase {
pauseAndCancelStmt(t, stmtKit, adminCommandKit, dom, &stmtCase)

Logger.Info("TestPauseCancelAndRerunPartitionTableStmt: statement execution again after `admin cancel`",
zap.String("DDL Statement", stmtCase.stmt))
stmtCase.simpleRunStmt(stmtKit)
}

Logger.Info("TestPauseCancelAndRerunPartitionTableStmt: all cases finished.")
}
6 changes: 3 additions & 3 deletions ddl/tests/adminpause/pause_resume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func TestPauseAndResumePartitionTableStmt(t *testing.T) {

require.Nil(t, generateTblUser(stmtKit, 0))

require.Nil(t, generateTblUserParition(stmtKit, 0))
require.Nil(t, generateTblUserParition(stmtKit))
for _, stmtCase := range tablePartitionDDLStmtCase {
pauseResumeAndCancel(t, stmtKit, adminCommandKit, dom, &stmtCase, false)
}
Expand Down Expand Up @@ -326,7 +326,7 @@ func TestPauseResumeCancelAndRerunColumnStmt(t *testing.T) {
// fail. Just truncate the tuples here because we don't care about the partition itself but the DDL.
stmtKit.MustExec("truncate " + adminPauseTestTable)

require.Nil(t, generateTblUserParition(stmtKit, 0))
require.Nil(t, generateTblUserParition(stmtKit))
for _, stmtCase := range tablePartitionDDLStmtCase {
pauseResumeAndCancel(t, stmtKit, adminCommandKit, dom, &stmtCase, true)

Expand All @@ -343,7 +343,7 @@ func TestPauseResumeCancelAndRerunPartitionTableStmt(t *testing.T) {

require.Nil(t, generateTblUser(stmtKit, 0))

require.Nil(t, generateTblUserParition(stmtKit, 0))
require.Nil(t, generateTblUserParition(stmtKit))
for _, stmtCase := range tablePartitionDDLStmtCase {
pauseResumeAndCancel(t, stmtKit, adminCommandKit, dom, &stmtCase, true)

Expand Down

0 comments on commit cdeac4c

Please sign in to comment.