Skip to content

Commit

Permalink
fix:add failpoints; divide code into files; batchID start from x-2; d…
Browse files Browse the repository at this point in the history
…eclare unsupported PK type; fix failpolicy bugs

Signed-off-by: newborn22 <[email protected]>
  • Loading branch information
newborn22 committed Jan 10, 2024
1 parent 5112127 commit 47b6a8d
Show file tree
Hide file tree
Showing 9 changed files with 656 additions and 526 deletions.
12 changes: 12 additions & 0 deletions go/vt/failpointkey/failpoint_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ var (
Name: "AssertRoutingTabletType",
ExampleStr: "return(\"primary\")",
}
ModifyBatchSize = FailpointValue{
FullName: "vitess.io/vitess/go/vt/vttablet/jobcontroller/ModifyBatchSize",
Name: "ModifyBatchSize",
ExampleStr: "return(30)",
}
CreateErrorWhenExecutingBatch = FailpointValue{
FullName: "vitess.io/vitess/go/vt/vttablet/jobcontroller/CreateErrorWhenExecutingBatch",
Name: "CreateErrorWhenExecutingBatch",
ExampleStr: "return(true)",
}
)

func init() {
Expand All @@ -60,4 +70,6 @@ func init() {
FailpointTable[WaitJustBeforeStopVreplication.FullName] = WaitJustBeforeStopVreplication
FailpointTable[WaitJustAfterStopVreplication.FullName] = WaitJustAfterStopVreplication
FailpointTable[AssertRoutingTabletType.FullName] = AssertRoutingTabletType
FailpointTable[ModifyBatchSize.FullName] = ModifyBatchSize
FailpointTable[CreateErrorWhenExecutingBatch.FullName] = CreateErrorWhenExecutingBatch
}
12 changes: 10 additions & 2 deletions go/vt/sqlparser/comments.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const (
DirectiveDMLTimeGap = "DML_TIME_GAP"
DirectiveBATCHSIZE = "DML_BATCH_SIZE"
DirectiveDMLPostponeLaunch = "DML_POSTPONE_LAUNCH"
DirectiveDMLAutoRetry = "DML_AUTO_RETRY"
DirectiveDMLAutoRetry = "DML_FAIL_POLICY"
DirectiveDMLTimePeriodStart = "DML_TIME_PERIOD_START"
DirectiveDMLTimePeriodEnd = "DML_TIME_PERIOD_END"
)
Expand Down Expand Up @@ -197,6 +197,7 @@ func StripLeadingComments(sql string) string {
func StripComments(sql string) string {
var output strings.Builder
inComment := false
lastByte := ""

for i := 0; i < len(sql); i++ {
if !inComment && i+1 < len(sql) && sql[i:i+2] == "/*" {
Expand All @@ -207,12 +208,19 @@ func StripComments(sql string) string {

if inComment && i+1 < len(sql) && sql[i:i+2] == "*/" {
inComment = false
if lastByte != " " {
output.WriteByte(' ')
lastByte = " "
}
i++
continue
}

if !inComment {
output.WriteByte(sql[i])
if lastByte != " " || string(sql[i]) != " " {
output.WriteByte(sql[i])
lastByte = string(sql[i])
}
}
}
return output.String()
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func buildShowDMLJobPlan(show *sqlparser.ShowDMLJob, vschema plancontext.VSchema
}
} else {
UUID := strings.Replace(show.UUID, "-", "_", -1)
sql = fmt.Sprintf("SELECT * FROM batch_info_table_%s order by CAST(SUBSTRING_INDEX(batch_id, '-', 1) AS SIGNED),id", UUID)
sql = fmt.Sprintf("SELECT * FROM _vt_BATCH_%s order by CAST(SUBSTRING_INDEX(batch_id, '-', 1) AS SIGNED),id", UUID)
}

return &engine.Send{
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,38 @@ func TestBatchSQL(t *testing.T) {
assert.Equalf(t, expectedLsStr, lsStr, "getBatchSQLGreatThanAndLessThanExprNode(%v)", batchSQLStmt)

}

func TestStripComments(t *testing.T) {
tests := []struct {
name string
sql string
want string
}{
{
name: "TestStripComments-Test1",
sql: "select * from t1 where 1 = 1 /* comment */ and 2 = 2",
want: "select * from t1 where 1 = 1 and 2 = 2",
},
{
name: "TestStripComments-Test2",
sql: "select/* comment */ * from t1 where 1 = 1 and 2 = 2",
want: "select * from t1 where 1 = 1 and 2 = 2",
},
{
name: "TestStripComments-Test3",
sql: "update/*vt+ dml_split=true */your_table set name='brainsplit' where 1=1;",
want: "update your_table set name='brainsplit' where 1=1;",
},
{
name: "TestStripComments-Test3",
sql: "update /*vt+ dml_split=true */ your_table set name='brainsplit' where 1=1;",
want: "update your_table set name='brainsplit' where 1=1;",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := sqlparser.StripComments(tt.sql)
assert.Equalf(t, tt.want, got, "stripComments(%v)", tt.sql)
})
}
}
Loading

0 comments on commit 47b6a8d

Please sign in to comment.