Skip to content

Commit

Permalink
test: add multi-table update in 2pc testing
Browse files Browse the repository at this point in the history
Signed-off-by: Manan Gupta <[email protected]>
  • Loading branch information
GuptaManan100 committed Nov 28, 2024
1 parent 0726ea6 commit d683b15
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
20 changes: 18 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,22 @@ func (fz *fuzzer) generateAndExecuteTransaction(threadId int) {
_, _ = conn.ExecuteFetch(finalCommand, 0, false)
}

func getUpdateQuery(incrementVal int32, id int) string {
if rand.Intn(2) == 1 {
x := fmt.Sprintf(updateFuzzUpdateMulti, incrementVal, id)
log.Errorf(x)
return x
}
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 +443,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

0 comments on commit d683b15

Please sign in to comment.