From d683b158b1652bd235eec4385d2d5307f0c5995c Mon Sep 17 00:00:00 2001 From: Manan Gupta Date: Thu, 28 Nov 2024 16:08:13 +0530 Subject: [PATCH 1/2] test: add multi-table update in 2pc testing Signed-off-by: Manan Gupta --- .../transaction/twopc/fuzz/fuzzer_test.go | 20 +++++++++++++++++-- .../transaction/twopc/fuzz/main_test.go | 1 + .../transaction/twopc/fuzz/schema.sql | 5 +++++ .../transaction/twopc/fuzz/vschema.json | 11 ++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/go/test/endtoend/transaction/twopc/fuzz/fuzzer_test.go b/go/test/endtoend/transaction/twopc/fuzz/fuzzer_test.go index 75bc46bacab..c3a72491020 100644 --- a/go/test/endtoend/transaction/twopc/fuzz/fuzzer_test.go +++ b/go/test/endtoend/transaction/twopc/fuzz/fuzzer_test.go @@ -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" @@ -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) } } } @@ -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] @@ -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) } /* diff --git a/go/test/endtoend/transaction/twopc/fuzz/main_test.go b/go/test/endtoend/transaction/twopc/fuzz/main_test.go index 1b05615d51a..15574c8d072 100644 --- a/go/test/endtoend/transaction/twopc/fuzz/main_test.go +++ b/go/test/endtoend/transaction/twopc/fuzz/main_test.go @@ -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") } diff --git a/go/test/endtoend/transaction/twopc/fuzz/schema.sql b/go/test/endtoend/transaction/twopc/fuzz/schema.sql index 5173166bfd4..b070466087d 100644 --- a/go/test/endtoend/transaction/twopc/fuzz/schema.sql +++ b/go/test/endtoend/transaction/twopc/fuzz/schema.sql @@ -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, diff --git a/go/test/endtoend/transaction/twopc/fuzz/vschema.json b/go/test/endtoend/transaction/twopc/fuzz/vschema.json index 415b5958f54..83107bc96ff 100644 --- a/go/test/endtoend/transaction/twopc/fuzz/vschema.json +++ b/go/test/endtoend/transaction/twopc/fuzz/vschema.json @@ -3,6 +3,9 @@ "vindexes": { "reverse_bits": { "type": "reverse_bits" + }, + "xxhash": { + "type": "xxhash" } }, "tables": { @@ -22,6 +25,14 @@ } ] }, + "twopc_fuzzer_multi": { + "column_vindexes": [ + { + "column": "id", + "name": "xxhash" + } + ] + }, "twopc_t1": { "column_vindexes": [ { From 98967de4a31e6f7e86e0dd1bb9b32fffa7d45c73 Mon Sep 17 00:00:00 2001 From: Manan Gupta Date: Thu, 28 Nov 2024 16:33:42 +0530 Subject: [PATCH 2/2] feat: remove debug logging Signed-off-by: Manan Gupta --- go/test/endtoend/transaction/twopc/fuzz/fuzzer_test.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/go/test/endtoend/transaction/twopc/fuzz/fuzzer_test.go b/go/test/endtoend/transaction/twopc/fuzz/fuzzer_test.go index c3a72491020..da6486242df 100644 --- a/go/test/endtoend/transaction/twopc/fuzz/fuzzer_test.go +++ b/go/test/endtoend/transaction/twopc/fuzz/fuzzer_test.go @@ -339,9 +339,7 @@ func (fz *fuzzer) generateAndExecuteTransaction(threadId int) { 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(updateFuzzUpdateMulti, incrementVal, id) } return fmt.Sprintf(updateFuzzUpdate, incrementVal, id) }