From 4a7a8b88359a83faceb5a0e2fd3c54776923f349 Mon Sep 17 00:00:00 2001 From: Burak Velioglu Date: Mon, 10 Jan 2022 11:30:52 +0300 Subject: [PATCH] Fix sequence owner, reference shards and update tests --- .../distributed/commands/dependencies.c | 6 ++-- .../distributed/utils/reference_table_utils.c | 9 ++++++ .../regress/sql/multi_colocation_utils.sql | 32 ++++++++++++++----- src/test/regress/sql/multi_metadata_sync.sql | 17 ++++------ 4 files changed, 41 insertions(+), 23 deletions(-) diff --git a/src/backend/distributed/commands/dependencies.c b/src/backend/distributed/commands/dependencies.c index 7f97c8648..4fd1f813a 100644 --- a/src/backend/distributed/commands/dependencies.c +++ b/src/backend/distributed/commands/dependencies.c @@ -58,7 +58,6 @@ EnsureDependenciesExistOnAllNodes(const ObjectAddress *target) /* collect all dependencies in creation order and get their ddl commands */ List *dependencies = GetDependenciesForObject(target); - ObjectAddress *dependency = NULL; foreach_ptr(dependency, dependencies) { @@ -265,9 +264,8 @@ GetDependencyCreateDDLCommands(const ObjectAddress *dependency) if (relKind == RELKIND_SEQUENCE) { - /* TODO: Check user name for different scenarios */ - char *userName = GetUserNameFromId(GetUserId(), false); - return DDLCommandsForSequence(dependency->objectId, userName); + char *sequenceOwnerName = TableOwner(dependency->objectId); + return DDLCommandsForSequence(dependency->objectId, sequenceOwnerName); } /* if this relation is not supported, break to the error at the end */ diff --git a/src/backend/distributed/utils/reference_table_utils.c b/src/backend/distributed/utils/reference_table_utils.c index 0a0feab1d..3f8d2fd5c 100644 --- a/src/backend/distributed/utils/reference_table_utils.c +++ b/src/backend/distributed/utils/reference_table_utils.c @@ -377,6 +377,15 @@ ReplicateShardToNode(ShardInterval *shardInterval, char *nodeName, int nodePort) uint64 placementId = GetNextPlacementId(); InsertShardPlacementRow(shardId, placementId, SHARD_STATE_ACTIVE, 0, groupId); + + if (ShouldSyncTableMetadata(shardInterval->relationId)) + { + char *placementCommand = PlacementUpsertCommand(shardId, placementId, + SHARD_STATE_ACTIVE, 0, + groupId); + + SendCommandToWorkersWithMetadata(placementCommand); + } } diff --git a/src/test/regress/sql/multi_colocation_utils.sql b/src/test/regress/sql/multi_colocation_utils.sql index 63b122405..a87999761 100644 --- a/src/test/regress/sql/multi_colocation_utils.sql +++ b/src/test/regress/sql/multi_colocation_utils.sql @@ -71,26 +71,34 @@ CREATE TABLE table1_group1 ( id int ); SELECT master_create_distributed_table('table1_group1', 'id', 'hash'); SELECT master_create_worker_shards('table1_group1', 4, 2); +select last_value from pg_dist_colocationid_seq ; + CREATE TABLE table2_group1 ( id int ); SELECT master_create_distributed_table('table2_group1', 'id', 'hash'); SELECT master_create_worker_shards('table2_group1', 4, 2); - +table pg_dist_colocation; +table pg_dist_partition; CREATE TABLE table3_group2 ( id int ); SELECT master_create_distributed_table('table3_group2', 'id', 'hash'); SELECT master_create_worker_shards('table3_group2', 4, 2); +select last_value from pg_dist_colocationid_seq ; CREATE TABLE table4_group2 ( id int ); SELECT master_create_distributed_table('table4_group2', 'id', 'hash'); SELECT master_create_worker_shards('table4_group2', 4, 2); +select last_value from pg_dist_colocationid_seq ; CREATE TABLE table5_groupX ( id int ); SELECT master_create_distributed_table('table5_groupX', 'id', 'hash'); SELECT master_create_worker_shards('table5_groupX', 4, 2); - +table pg_dist_colocation; +table pg_dist_partition; CREATE TABLE table6_append ( id int ); SELECT master_create_distributed_table('table6_append', 'id', 'append'); -SELECT master_create_empty_shard('table6_append'); -SELECT master_create_empty_shard('table6_append'); +SELECT master_create_empty_shard('table6_append');select last_value from pg_dist_colocationid_seq ; + +SELECT master_create_empty_shard('table6_append');select last_value from pg_dist_colocationid_seq ; + -- make table1_group1 and table2_group1 co-located manually @@ -100,7 +108,8 @@ SELECT colocation_test_colocate_tables('table1_group1', 'table2_group1'); SELECT get_table_colocation_id('table1_group1'); SELECT get_table_colocation_id('table5_groupX'); SELECT get_table_colocation_id('table6_append'); - +table pg_dist_colocation; +table pg_dist_partition; -- check self table co-location SELECT tables_colocated('table1_group1', 'table1_group1'); SELECT tables_colocated('table5_groupX', 'table5_groupX'); @@ -115,7 +124,8 @@ SELECT tables_colocated('table1_group1', 'table3_group2'); -- check table co-location with invalid co-location group SELECT tables_colocated('table1_group1', 'table5_groupX'); SELECT tables_colocated('table1_group1', 'table6_append'); - +table pg_dist_colocation; +table pg_dist_partition; -- check self shard co-location SELECT shards_colocated(1300000, 1300000); SELECT shards_colocated(1300016, 1300016); @@ -129,7 +139,8 @@ SELECT shards_colocated(1300000, 1300001); -- check shard co-location with different co-location group SELECT shards_colocated(1300000, 1300005); - +table pg_dist_colocation; +table pg_dist_partition; -- check shard co-location with invalid co-location group SELECT shards_colocated(1300000, 1300016); SELECT shards_colocated(1300000, 1300020); @@ -150,7 +161,8 @@ SELECT find_shard_interval_index(1300001); SELECT find_shard_interval_index(1300002); SELECT find_shard_interval_index(1300003); SELECT find_shard_interval_index(1300016); - +table pg_dist_colocation; +table pg_dist_partition; -- check external colocation API SELECT count(*) FROM pg_dist_partition WHERE colocationid IN (4, 5); @@ -180,8 +192,12 @@ UPDATE pg_dist_partition SET repmodel='c' WHERE logicalrelid='table2_groupB'::re SET citus.shard_replication_factor to DEFAULT; -- change partition column type +table pg_dist_colocation; +table pg_dist_partition; +set citus.log_remote_commands to true; CREATE TABLE table1_groupC ( id text ); SELECT create_distributed_table('table1_groupC', 'id'); +reset citus.log_remote_commands; CREATE TABLE table2_groupC ( id text ); SELECT create_distributed_table('table2_groupC', 'id'); diff --git a/src/test/regress/sql/multi_metadata_sync.sql b/src/test/regress/sql/multi_metadata_sync.sql index 145f9b1cb..dbf87d90c 100644 --- a/src/test/regress/sql/multi_metadata_sync.sql +++ b/src/test/regress/sql/multi_metadata_sync.sql @@ -189,13 +189,12 @@ SELECT "Column", "Type", "Definition" FROM index_attrs WHERE SELECT count(*) FROM pg_trigger WHERE tgrelid='mx_testing_schema.mx_test_table'::regclass; -- Make sure that citus_activate_node can be called inside a transaction and rollbacked -\c - - - :master_port -BEGIN; -SELECT start_metadata_sync_to_node('localhost', :worker_2_port); -SELECT citus_activate_node('localhost', :worker_2_port); -ROLLBACK; +--\c - - - :master_port +--BEGIN; +--SELECT citus_activate_node('localhost', :worker_2_port); +--ROLLBACK; -SELECT hasmetadata FROM pg_dist_node WHERE nodeport=:worker_2_port; +--SELECT hasmetadata FROM pg_dist_node WHERE nodeport=:worker_2_port; -- Check that the distributed table can be queried from the worker \c - - - :master_port @@ -575,7 +574,6 @@ SELECT create_distributed_table('mx_table', 'a'); \c - postgres - :master_port SELECT master_add_node('localhost', :worker_2_port); -SELECT citus_activate_node('localhost', :worker_2_port); \c - mx_user - :worker_1_port SELECT nextval('mx_table_b_seq'); @@ -789,7 +787,6 @@ SELECT pg_reload_conf(); UPDATE pg_dist_node SET metadatasynced=true WHERE nodeport=:worker_1_port; SELECT master_add_node('localhost', :worker_2_port); -SELECT citus_activate_node('localhost', :worker_2_port); CREATE SEQUENCE mx_test_sequence_0; CREATE SEQUENCE mx_test_sequence_1; @@ -883,8 +880,6 @@ ALTER SEQUENCE pg_catalog.pg_dist_node_nodeid_seq RESTART :last_node_id; ALTER SEQUENCE pg_catalog.pg_dist_colocationid_seq RESTART :last_colocation_id; ALTER SEQUENCE pg_catalog.pg_dist_placement_placementid_seq RESTART :last_placement_id; --- Turn metadata sync back on and ativate them at the end -SELECT start_metadata_sync_to_node('localhost', :worker_1_port); -SELECT start_metadata_sync_to_node('localhost', :worker_2_port); +-- Activate them at the end SELECT citus_activate_node('localhost', :worker_1_port); SELECT citus_activate_node('localhost', :worker_2_port);