Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multi table updates in the 2pc fuzzer testing #17293

Merged
merged 2 commits into from
Dec 3, 2024
Merged
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
18 changes: 16 additions & 2 deletions go/test/endtoend/transaction/twopc/fuzz/fuzzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ var (
}

insertIntoFuzzUpdate = "INSERT INTO twopc_fuzzer_update (id, col) VALUES (%d, %d)"
insertIntoFuzzMulti = "INSERT INTO twopc_fuzzer_multi (id) VALUES (%d)"
updateFuzzUpdate = "UPDATE twopc_fuzzer_update SET col = col + %d WHERE id = %d"
updateFuzzUpdateMulti = "UPDATE twopc_fuzzer_update join twopc_fuzzer_multi using (id) SET col = col + %d WHERE id = %d"
insertIntoFuzzInsert = "INSERT INTO twopc_fuzzer_insert (id, updateSet, threadId) VALUES (%d, %d, %d)"
selectFromFuzzUpdate = "SELECT col FROM twopc_fuzzer_update WHERE id = %d"
selectIdFromFuzzInsert = "SELECT threadId FROM twopc_fuzzer_insert WHERE updateSet = %d AND id = %d ORDER BY col"
Expand Down Expand Up @@ -294,6 +296,10 @@ func (fz *fuzzer) initialize(t *testing.T, conn *mysql.Conn) {
for _, id := range updateSet {
_, err := conn.ExecuteFetch(fmt.Sprintf(insertIntoFuzzUpdate, id, 0), 0, false)
require.NoError(t, err)
// We insert the same id values in multi table as we in the update table. We use this for running
// multi-table updates and inserts.
_, err = conn.ExecuteFetch(fmt.Sprintf(insertIntoFuzzMulti, id), 0, false)
require.NoError(t, err)
}
}
}
Expand Down Expand Up @@ -331,12 +337,20 @@ func (fz *fuzzer) generateAndExecuteTransaction(threadId int) {
_, _ = conn.ExecuteFetch(finalCommand, 0, false)
}

func getUpdateQuery(incrementVal int32, id int) string {
if rand.Intn(2) == 1 {
return fmt.Sprintf(updateFuzzUpdateMulti, incrementVal, id)
}
return fmt.Sprintf(updateFuzzUpdate, incrementVal, id)
}

// generateUpdateQueries generates the queries to run updates on the twopc_fuzzer_update table.
// It takes the update set index and the value to increment the set by.
func (fz *fuzzer) generateUpdateQueries(updateSet int, incrementVal int32) []string {
var queries []string
for _, id := range fz.updateRowsVals[updateSet] {
queries = append(queries, fmt.Sprintf(updateFuzzUpdate, incrementVal, id))
// Use multi table DML queries half the time.
queries = append(queries, getUpdateQuery(incrementVal, id))
}
rand.Shuffle(len(queries), func(i, j int) {
queries[i], queries[j] = queries[j], queries[i]
Expand Down Expand Up @@ -427,7 +441,7 @@ func (fz *fuzzer) randomDML() string {
}
// Generate UPDATE
updateId := fz.updateRowsVals[rand.Intn(len(fz.updateRowsVals))][rand.Intn(len(updateRowBaseVals))]
return fmt.Sprintf(updateFuzzUpdate, rand.Intn(100000), updateId)
return getUpdateQuery(rand.Int31n(100000), updateId)
}

/*
Expand Down
1 change: 1 addition & 0 deletions go/test/endtoend/transaction/twopc/fuzz/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,6 @@ func cleanup(t *testing.T) {

utils.ClearOutTable(t, vtParams, "twopc_fuzzer_insert")
utils.ClearOutTable(t, vtParams, "twopc_fuzzer_update")
utils.ClearOutTable(t, vtParams, "twopc_fuzzer_multi")
utils.ClearOutTable(t, vtParams, "twopc_t1")
}
5 changes: 5 additions & 0 deletions go/test/endtoend/transaction/twopc/fuzz/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ create table twopc_fuzzer_update (
primary key (id)
) Engine=InnoDB;

create table twopc_fuzzer_multi (
id bigint,
primary key (id)
) Engine=InnoDB;

create table twopc_fuzzer_insert (
id bigint,
updateSet bigint,
Expand Down
11 changes: 11 additions & 0 deletions go/test/endtoend/transaction/twopc/fuzz/vschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"vindexes": {
"reverse_bits": {
"type": "reverse_bits"
},
"xxhash": {
"type": "xxhash"
}
},
"tables": {
Expand All @@ -22,6 +25,14 @@
}
]
},
"twopc_fuzzer_multi": {
"column_vindexes": [
{
"column": "id",
"name": "xxhash"
}
]
},
"twopc_t1": {
"column_vindexes": [
{
Expand Down
Loading