Skip to content

Commit

Permalink
backupccl: stop relying on fixed IDs in datadriven tests
Browse files Browse the repository at this point in the history
The IDs of objects created in this test are not deterministic between
runs. If a transaction auto-retries while creating an object, an ID can
be skipped.

Release note: None
  • Loading branch information
rafiss committed Mar 26, 2024
1 parent 215ece4 commit bc86457
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ CREATE DATABASE d;
CREATE TABLE d.foo (id INT);
----

let $d_id
SELECT id FROM system.namespace WHERE name = 'd' AND "parentID" = 0;
----

schema-change expect-pausepoint
DROP DATABASE d CASCADE;
----
Expand All @@ -28,7 +32,7 @@ query-sql
WITH tbls AS (
SELECT id, crdb_internal.pb_to_json('cockroach.sql.sqlbase.Descriptor', descriptor) AS orig FROM system.descriptor
)
SELECT orig->'database'->'name', orig->'database'->'state' FROM tbls WHERE id = 107;
SELECT orig->'database'->'name', orig->'database'->'state' FROM tbls WHERE id = $d_id;
----
"d" "DROP"

Expand Down Expand Up @@ -122,6 +126,22 @@ CREATE SCHEMA d2.s;
CREATE TABLE d2.s.t (id INT);
----

let $d2_id
SELECT id FROM system.namespace WHERE name = 'd2' AND "parentID" = 0;
----

let $s_id
SELECT id FROM system.namespace WHERE name = 's' AND "parentID" = $d2_id;
----

let $typ_id
SELECT id FROM system.namespace WHERE name = 'typ' AND "parentID" = $d2_id;
----

let $typArray_id
SELECT id FROM system.namespace WHERE name = '_typ' AND "parentID" = $d2_id;
----

exec-sql
SET use_declarative_schema_changer = 'off';
----
Expand All @@ -148,7 +168,7 @@ query-sql
WITH tbls AS (
SELECT id, crdb_internal.pb_to_json('cockroach.sql.sqlbase.Descriptor', descriptor) AS orig FROM system.descriptor
)
SELECT orig->'schema'->'name', orig->'schema'->'state' FROM tbls WHERE id = 112;
SELECT orig->'schema'->'name', orig->'schema'->'state' FROM tbls WHERE id = $s_id;
----
"s" "DROP"

Expand All @@ -157,7 +177,7 @@ query-sql
WITH tbls AS (
SELECT id, crdb_internal.pb_to_json('cockroach.sql.sqlbase.Descriptor', descriptor) AS orig FROM system.descriptor
)
SELECT orig->'type'->'name', orig->'type'->'state' FROM tbls WHERE id = 110 OR id = 111;
SELECT orig->'type'->'name', orig->'type'->'state' FROM tbls WHERE id = $typ_id OR id = $typArray_id;
----
"typ" "DROP"
"_typ" "DROP"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ CREATE TABLE dd.foo (id INT);
CREATE SCHEMA dd.s;
----

let $dd_id
SELECT id FROM system.namespace WHERE name = 'dd' AND "parentID" = 0;
----

new-schema-change expect-pausepoint
DROP DATABASE dd CASCADE;
----
Expand All @@ -29,7 +33,7 @@ query-sql
WITH tbls AS (
SELECT id, crdb_internal.pb_to_json('cockroach.sql.sqlbase.Descriptor', descriptor) AS orig FROM system.descriptor
)
SELECT orig->'database'->'name', orig->'database'->'state' FROM tbls WHERE id = 107;
SELECT orig->'database'->'name', orig->'database'->'state' FROM tbls WHERE id = $dd_id;
----
"dd" "DROP"

Expand Down Expand Up @@ -75,6 +79,22 @@ CREATE SCHEMA d2.s;
CREATE TABLE d2.s.t (id INT);
----

let $d2_id
SELECT id FROM system.namespace WHERE name = 'd2' AND "parentID" = 0;
----

let $s_id
SELECT id FROM system.namespace WHERE name = 's' AND "parentID" = $d2_id;
----

let $typ_id
SELECT id FROM system.namespace WHERE name = 'typ' AND "parentID" = $d2_id;
----

let $typArray_id
SELECT id FROM system.namespace WHERE name = '_typ' AND "parentID" = $d2_id;
----

exec-sql
SET use_declarative_schema_changer = 'on';
----
Expand All @@ -97,15 +117,15 @@ query-sql
WITH tbls AS (
SELECT id, crdb_internal.pb_to_json('cockroach.sql.sqlbase.Descriptor', descriptor) AS orig FROM system.descriptor
)
SELECT orig->'schema'->'name', orig->'schema'->'state' FROM tbls WHERE id = 112;
SELECT orig->'schema'->'name', orig->'schema'->'state' FROM tbls WHERE id = $s_id;
----
"s" "DROP"

query-sql
WITH tbls AS (
SELECT id, crdb_internal.pb_to_json('cockroach.sql.sqlbase.Descriptor', descriptor) AS orig FROM system.descriptor
)
SELECT orig->'type'->'name', orig->'type'->'state' FROM tbls WHERE id = 110 OR id = 111;
SELECT orig->'type'->'name', orig->'type'->'state' FROM tbls WHERE id = $typ_id OR id = $typArray_id;
----
"typ" "DROP"
"_typ" "DROP"
Expand Down
10 changes: 4 additions & 6 deletions pkg/ccl/backupccl/testdata/backup-restore/plpgsql_procedures
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ CREATE PROCEDURE sc1.p() LANGUAGE PLpgSQL AS $$ BEGIN SELECT 1; END $$;
----

# Make sure the original schema has procedure signatures
query-sql
let $defaultdb_sc1_id
WITH db_id AS (
SELECT id FROM system.namespace WHERE name = 'defaultdb'
),
Expand All @@ -365,7 +365,6 @@ schema_id AS (
)
SELECT id FROM schema_id;
----
109

query-sql
WITH to_json AS (
Expand All @@ -378,7 +377,7 @@ WITH to_json AS (
) AS d
FROM
system.descriptor
WHERE id = 109
WHERE id = $defaultdb_sc1_id
)
SELECT d->'schema'->>'functions'::string FROM to_json;
----
Expand All @@ -396,7 +395,7 @@ exec-sql
USE db1;
----

query-sql
let $db1_sc1_id
WITH db_id AS (
SELECT id FROM system.namespace WHERE name = 'db1'
),
Expand All @@ -408,7 +407,6 @@ schema_id AS (
)
SELECT id FROM schema_id;
----
112

query-sql
WITH to_json AS (
Expand All @@ -421,7 +419,7 @@ WITH to_json AS (
) AS d
FROM
system.descriptor
WHERE id = 112
WHERE id = $db1_sc1_id
)
SELECT d->'schema'->>'functions'::string FROM to_json;
----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ CREATE FUNCTION sc1.f() RETURNS INT LANGUAGE PLpgSQL AS $$ BEGIN RETURN 1; END $
----

# Make sure the original schema has function signatures
query-sql
let $defaultdb_sc1_db
WITH db_id AS (
SELECT id FROM system.namespace WHERE name = 'defaultdb'
),
Expand All @@ -391,7 +391,6 @@ schema_id AS (
)
SELECT id FROM schema_id;
----
109

query-sql
WITH to_json AS (
Expand All @@ -404,7 +403,7 @@ WITH to_json AS (
) AS d
FROM
system.descriptor
WHERE id = 109
WHERE id = $defaultdb_sc1_db
)
SELECT d->'schema'->>'functions'::string FROM to_json;
----
Expand All @@ -422,7 +421,7 @@ exec-sql
USE db1;
----

query-sql
let $db1_sc1_id
WITH db_id AS (
SELECT id FROM system.namespace WHERE name = 'db1'
),
Expand All @@ -434,7 +433,6 @@ schema_id AS (
)
SELECT id FROM schema_id;
----
112

query-sql
WITH to_json AS (
Expand All @@ -447,7 +445,7 @@ WITH to_json AS (
) AS d
FROM
system.descriptor
WHERE id = 112
WHERE id = $db1_sc1_id
)
SELECT d->'schema'->>'functions'::string FROM to_json;
----
Expand Down
10 changes: 4 additions & 6 deletions pkg/ccl/backupccl/testdata/backup-restore/procedures
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ CREATE PROCEDURE sc1.p() LANGUAGE SQL AS $$ SELECT 1 $$;
----

# Make sure the original schema has procedure signatures
query-sql
let $defaultdb_sc1_db
WITH db_id AS (
SELECT id FROM system.namespace WHERE name = 'defaultdb'
),
Expand All @@ -337,7 +337,6 @@ schema_id AS (
)
SELECT id FROM schema_id;
----
109

query-sql
WITH to_json AS (
Expand All @@ -350,7 +349,7 @@ WITH to_json AS (
) AS d
FROM
system.descriptor
WHERE id = 109
WHERE id = $defaultdb_sc1_db
)
SELECT d->'schema'->>'functions'::string FROM to_json;
----
Expand All @@ -368,7 +367,7 @@ exec-sql
USE db1;
----

query-sql
let $db1_sc1_id
WITH db_id AS (
SELECT id FROM system.namespace WHERE name = 'db1'
),
Expand All @@ -380,7 +379,6 @@ schema_id AS (
)
SELECT id FROM schema_id;
----
112

query-sql
WITH to_json AS (
Expand All @@ -393,7 +391,7 @@ WITH to_json AS (
) AS d
FROM
system.descriptor
WHERE id = 112
WHERE id = $db1_sc1_id
)
SELECT d->'schema'->>'functions'::string FROM to_json;
----
Expand Down
14 changes: 4 additions & 10 deletions pkg/ccl/backupccl/testdata/backup-restore/regression-tests
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ exec-sql
CREATE DATABASE b;
----

# The ID of "me" is normally 109. However, we can't add an assertion for that since ID
# generation is not deterministic.
exec-sql
CREATE SCHEMA b.me;
----
Expand All @@ -199,11 +201,6 @@ exec-sql
BACKUP INTO 'nodelocal://1/cluster'
----

query-sql
SELECT id, name FROM system.namespace WHERE name = 'me';
----
109 me

new-cluster name=s5 share-io-dir=s4
----

Expand All @@ -217,15 +214,12 @@ CREATE SCHEMA d.bar;
CREATE SCHEMA d.baz;
----

# The ID of "collide" is normally 109. However, we can't add an assertion for that since ID
# generation is not deterministic.
exec-sql
CREATE DATABASE collide
----

query-sql
SELECT id, name FROM system.namespace WHERE name = 'collide'
----
109 collide

exec-sql
RESTORE TABLE b.me.foo FROM LATEST IN 'nodelocal://1/cluster' WITH into_db=collide
----
Expand Down
10 changes: 4 additions & 6 deletions pkg/ccl/backupccl/testdata/backup-restore/user-defined-functions
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ CREATE FUNCTION sc1.f() RETURNS INT LANGUAGE SQL AS $$ SELECT 1 $$;
----

# Make sure the original schema has function signatures
query-sql
let $defaultdb_sc1_db
WITH db_id AS (
SELECT id FROM system.namespace WHERE name = 'defaultdb'
),
Expand All @@ -333,7 +333,6 @@ schema_id AS (
)
SELECT id FROM schema_id;
----
109

query-sql
WITH to_json AS (
Expand All @@ -346,7 +345,7 @@ WITH to_json AS (
) AS d
FROM
system.descriptor
WHERE id = 109
WHERE id = $defaultdb_sc1_db
)
SELECT d->'schema'->>'functions'::string FROM to_json;
----
Expand All @@ -364,7 +363,7 @@ exec-sql
USE db1;
----

query-sql
let $db1_sc1_id
WITH db_id AS (
SELECT id FROM system.namespace WHERE name = 'db1'
),
Expand All @@ -376,7 +375,6 @@ schema_id AS (
)
SELECT id FROM schema_id;
----
112

query-sql
WITH to_json AS (
Expand All @@ -389,7 +387,7 @@ WITH to_json AS (
) AS d
FROM
system.descriptor
WHERE id = 112
WHERE id = $db1_sc1_id
)
SELECT d->'schema'->>'functions'::string FROM to_json;
----
Expand Down

0 comments on commit bc86457

Please sign in to comment.