From 63435707c3acb4d7c4d633ba36b8dcf84cbe0757 Mon Sep 17 00:00:00 2001 From: Yahor Yuzefovich Date: Mon, 4 Nov 2024 18:29:58 -0800 Subject: [PATCH] roachtest: give longer timeout for MR schema changes We just saw a test failure where `ALTER TABLE ... SET LOCALITY ...` stmt timed out when setting up the MR database due to the stmt timeout of 60s set on the connection. In the logs it appeared that the schema change actually succeeded, so prevent this type of failures we'll temporarily increase the timeout by 3x for all MR setup queries. Release note: None --- pkg/cmd/roachtest/tests/sqlsmith.go | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/pkg/cmd/roachtest/tests/sqlsmith.go b/pkg/cmd/roachtest/tests/sqlsmith.go index 760a682b9e8e..6cb2562d4e5d 100644 --- a/pkg/cmd/roachtest/tests/sqlsmith.go +++ b/pkg/cmd/roachtest/tests/sqlsmith.go @@ -366,6 +366,26 @@ WITH into_db = 'defaultdb', unsafe_restore_incompatible_version; // setupMultiRegionDatabase is used to set up a multi-region database. func setupMultiRegionDatabase(t test.Test, conn *gosql.DB, rnd *rand.Rand, logStmt func(string)) { t.Helper() + + execStmt := func(stmt string) { + logStmt(stmt) + if _, err := conn.Exec(stmt); err != nil { + t.Fatal(err) + } + } + + // If we have a stmt timeout set on the session, then increase it 3x given + // that schema changes below can take non-trivial amount of time. + row := conn.QueryRow("SHOW statement_timeout") + var stmtTimeout int + if err := row.Scan(&stmtTimeout); err != nil { + t.Fatal(err) + } else if stmtTimeout != 0 { + t.L().Printf("temporarily increasing the statement timeout") + execStmt(fmt.Sprintf("SET statement_timeout = %d", 3*stmtTimeout)) + defer execStmt(fmt.Sprintf("SET statement_timeout = %d", stmtTimeout)) + } + regionsSet := make(map[string]struct{}) var region, zone string rows, err := conn.Query("SHOW REGIONS FROM CLUSTER") @@ -390,13 +410,6 @@ func setupMultiRegionDatabase(t test.Test, conn *gosql.DB, rnd *rand.Rand, logSt t.Fatal(errors.New("no regions, cannot run multi-region config")) } - execStmt := func(stmt string) { - logStmt(stmt) - if _, err := conn.Exec(stmt); err != nil { - t.Fatal(err) - } - } - for i, region := range regionList { if i == 0 { execStmt(fmt.Sprintf(`ALTER DATABASE defaultdb SET PRIMARY REGION "%s";`, region))