Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aykut-bozkurt committed Jul 10, 2023
1 parent 8553c8d commit ca4c0fb
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 4 deletions.
3 changes: 0 additions & 3 deletions src/backend/distributed/commands/create_distributed_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -1316,9 +1316,6 @@ CreateCitusTable(Oid relationId, CitusTableType tableType,
bool skip_validation = true;
ExecuteForeignKeyCreateCommandList(originalForeignKeyRecreationCommands,
skip_validation);

/* track the creation of the distributed table in the current transaction */
AddTableToCurrentDistObjects(relationId);
}


Expand Down
8 changes: 7 additions & 1 deletion src/backend/distributed/commands/dependencies.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ ResetDistObjects(void)


/*
* HasAnyDepInTxDistObjects decides if any distributed object is created in the current
* HasAnyDepInTxDistObjects decides if any object in given list is created in the current
* transaction.
*/
bool
Expand Down Expand Up @@ -310,6 +310,12 @@ EnsureDependenciesExistOnAllNodes(const ObjectAddress *target)
*/
MarkObjectDistributedViaSuperUser(dependency);
}

/* track the creation of the distributed table in the current transaction */
if (target->classId == RelationRelationId)
{
AddTableToCurrentDistObjects(target->objectId);
}
}


Expand Down
47 changes: 47 additions & 0 deletions src/test/regress/expected/multi_schema_support.out
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,53 @@ BEGIN;

ALTER SCHEMA bar RENAME TO foo;
ROLLBACK;
-- verify that Citus uses current user's metadata connection to propagate table deps since sc1, which is one of the deps of table s1, is created in the same transaction.
BEGIN;
CREATE SCHEMA sc1;
CREATE SEQUENCE sc1.seq;
CREATE TABLE sc1.s1(id int default(nextval('sc1.seq')));
SELECT create_distributed_table('sc1.s1','id');
create_distributed_table
---------------------------------------------------------------------

(1 row)

COMMIT;
DROP SCHEMA sc1 CASCADE;
NOTICE: drop cascades to 2 other objects
DETAIL: drop cascades to sequence sc1.seq
drop cascades to table sc1.s1
-- verify that Citus uses current user's metadata connection to propagate table deps since seq1, which is one of the deps of table s1, is created in the same transaction.
CREATE SCHEMA sc1;
BEGIN;
CREATE SEQUENCE sc1.seq1;
CREATE TABLE sc1.s1(id int default(nextval('sc1.seq1')));
SELECT create_distributed_table('sc1.s1','id');
create_distributed_table
---------------------------------------------------------------------

(1 row)

COMMIT;
DROP SCHEMA sc1 CASCADE;
NOTICE: drop cascades to 2 other objects
DETAIL: drop cascades to sequence sc1.seq1
drop cascades to table sc1.s1
-- verify that Citus uses superuser outside connection to propagate table deps since noneof the table's deps is created in the same transaction.
SET citus.enable_metadata_sync TO off;
CREATE SCHEMA sc1;
SET citus.enable_metadata_sync TO on;
BEGIN;
CREATE TABLE sc1.s1(id int);
SELECT create_distributed_table('sc1.s1','id');
create_distributed_table
---------------------------------------------------------------------

(1 row)

COMMIT;
DROP SCHEMA sc1 CASCADE;
NOTICE: drop cascades to table sc1.s1
-- Clean up the created schema
SET client_min_messages TO WARNING;
SELECT pg_identify_object_as_address(classid, objid, objsubid) FROM pg_catalog.pg_dist_object
Expand Down
28 changes: 28 additions & 0 deletions src/test/regress/sql/multi_schema_support.sql
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,34 @@ BEGIN;
ALTER SCHEMA bar RENAME TO foo;
ROLLBACK;

-- verify that Citus uses current user's metadata connection to propagate table deps since sc1, which is one of the deps of table s1, is created in the same transaction.
BEGIN;
CREATE SCHEMA sc1;
CREATE SEQUENCE sc1.seq;
CREATE TABLE sc1.s1(id int default(nextval('sc1.seq')));
SELECT create_distributed_table('sc1.s1','id');
COMMIT;
DROP SCHEMA sc1 CASCADE;

-- verify that Citus uses current user's metadata connection to propagate table deps since seq1, which is one of the deps of table s1, is created in the same transaction.
CREATE SCHEMA sc1;
BEGIN;
CREATE SEQUENCE sc1.seq1;
CREATE TABLE sc1.s1(id int default(nextval('sc1.seq1')));
SELECT create_distributed_table('sc1.s1','id');
COMMIT;
DROP SCHEMA sc1 CASCADE;

-- verify that Citus uses superuser outside connection to propagate table deps since noneof the table's deps is created in the same transaction.
SET citus.enable_metadata_sync TO off;
CREATE SCHEMA sc1;
SET citus.enable_metadata_sync TO on;
BEGIN;
CREATE TABLE sc1.s1(id int);
SELECT create_distributed_table('sc1.s1','id');
COMMIT;
DROP SCHEMA sc1 CASCADE;

-- Clean up the created schema
SET client_min_messages TO WARNING;

Expand Down

0 comments on commit ca4c0fb

Please sign in to comment.