Skip to content

Commit

Permalink
Merge #70655
Browse files Browse the repository at this point in the history
70655: sql: TestDropColumnAfterMutations fails intermittently r=fqazi a=fqazi

Fixes: #70329

Previously, the TestDropColumnAfterMutations did not correctly
filter out unrelated applications when scanning sessions. This
was inadequate because the count of number of commits could vary
if internal applications also executed commits. To address this
this patch explicitly sets the application name on the connections
used for starting jobs so we can observe the COMMIT operation count
only from relevant connections.

Release note: None

Co-authored-by: Faizan Qazi <[email protected]>
  • Loading branch information
craig[bot] and fqazi committed Sep 24, 2021
2 parents 9167a60 + dabd1a3 commit a0d6d46
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pkg/sql/schema_changer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7201,6 +7201,7 @@ COMMIT;
// This transaction will not complete. Therefore, we don't check the returned error.
_, _ = conn2.DB.ExecContext(context.Background(),
`
SET application_name='TestDropColumnAfterMutations';
BEGIN;
ALTER TABLE t ALTER COLUMN j SET NOT NULL;
ALTER TABLE t ADD COLUMN k INT8 DEFAULT 42 NOT NULL UNIQUE;
Expand All @@ -7215,6 +7216,7 @@ COMMIT;
// This transaction will not complete. Therefore, we don't check the returned error.
_, _ = conn1.DB.ExecContext(context.Background(),
`
SET application_name='TestDropColumnAfterMutations';
SET sql_safe_updates = false;
BEGIN;
ALTER TABLE t DROP COLUMN j;
Expand Down Expand Up @@ -7251,7 +7253,8 @@ COMMIT;
conn1.CheckQueryResults(t, fmt.Sprintf("SELECT status from system.jobs WHERE id = %d", jobIDs[0]), [][]string{{string(jobs.StatusRunning)}})
// Both jobs should be stuck in COMMIT, waiting for jobs to complete.
conn1.CheckQueryResults(t,
"SELECT count(*) FROM [SHOW SESSIONS] WHERE last_active_query LIKE '%COMMIT%' AND session_id != (SELECT * FROM [SHOW session_id])",
"SELECT count(*) FROM [SHOW SESSIONS] WHERE last_active_query LIKE '%COMMIT%' AND session_id != (SELECT * FROM [SHOW session_id]) "+
"AND application_name='TestDropColumnAfterMutations'",
[][]string{{"2"}},
)

Expand Down Expand Up @@ -7281,6 +7284,7 @@ COMMIT;
// This transaction will not complete. Therefore, we don't check the returned error.
_, _ = conn2.DB.ExecContext(context.Background(),
`
SET application_name='TestDropColumnAfterMutations';
BEGIN;
ALTER TABLE t ALTER COLUMN j SET NOT NULL;
ALTER TABLE t ADD COLUMN k INT8 DEFAULT 42 NOT NULL;
Expand All @@ -7293,6 +7297,7 @@ COMMIT;
// This transaction will not complete. Therefore, we don't check the returned error.
_, _ = conn1.DB.ExecContext(context.Background(),
`
SET application_name='TestDropColumnAfterMutations';
SET sql_safe_updates = false;
BEGIN;
ALTER TABLE t DROP COLUMN j;
Expand Down Expand Up @@ -7343,7 +7348,8 @@ COMMIT;
)
// Both jobs should be stuck in COMMIT, waiting for jobs to complete.
conn1.CheckQueryResults(t,
"SELECT count(*) FROM [SHOW SESSIONS] WHERE last_active_query LIKE '%COMMIT%' AND session_id != (SELECT * FROM [SHOW session_id])",
"SELECT count(*) FROM [SHOW SESSIONS] WHERE last_active_query LIKE '%COMMIT%' AND session_id != (SELECT * FROM [SHOW session_id]) "+
"AND application_name='TestDropColumnAfterMutations'",
[][]string{{"2"}},
)

Expand Down

0 comments on commit a0d6d46

Please sign in to comment.