Fix sequence owner, reference shards and update tests

velioglu/wo_seq_test_1
Burak Velioglu 2022-01-10 11:30:52 +03:00
parent 76e1e1fd6b
commit 4a7a8b8835
No known key found for this signature in database
GPG Key ID: F6827E620F6549C6
4 changed files with 41 additions and 23 deletions

View File

@ -58,7 +58,6 @@ EnsureDependenciesExistOnAllNodes(const ObjectAddress *target)
/* collect all dependencies in creation order and get their ddl commands */ /* collect all dependencies in creation order and get their ddl commands */
List *dependencies = GetDependenciesForObject(target); List *dependencies = GetDependenciesForObject(target);
ObjectAddress *dependency = NULL; ObjectAddress *dependency = NULL;
foreach_ptr(dependency, dependencies) foreach_ptr(dependency, dependencies)
{ {
@ -265,9 +264,8 @@ GetDependencyCreateDDLCommands(const ObjectAddress *dependency)
if (relKind == RELKIND_SEQUENCE) if (relKind == RELKIND_SEQUENCE)
{ {
/* TODO: Check user name for different scenarios */ char *sequenceOwnerName = TableOwner(dependency->objectId);
char *userName = GetUserNameFromId(GetUserId(), false); return DDLCommandsForSequence(dependency->objectId, sequenceOwnerName);
return DDLCommandsForSequence(dependency->objectId, userName);
} }
/* if this relation is not supported, break to the error at the end */ /* if this relation is not supported, break to the error at the end */

View File

@ -377,6 +377,15 @@ ReplicateShardToNode(ShardInterval *shardInterval, char *nodeName, int nodePort)
uint64 placementId = GetNextPlacementId(); uint64 placementId = GetNextPlacementId();
InsertShardPlacementRow(shardId, placementId, SHARD_STATE_ACTIVE, 0, InsertShardPlacementRow(shardId, placementId, SHARD_STATE_ACTIVE, 0,
groupId); groupId);
if (ShouldSyncTableMetadata(shardInterval->relationId))
{
char *placementCommand = PlacementUpsertCommand(shardId, placementId,
SHARD_STATE_ACTIVE, 0,
groupId);
SendCommandToWorkersWithMetadata(placementCommand);
}
} }

View File

@ -71,26 +71,34 @@ CREATE TABLE table1_group1 ( id int );
SELECT master_create_distributed_table('table1_group1', 'id', 'hash'); SELECT master_create_distributed_table('table1_group1', 'id', 'hash');
SELECT master_create_worker_shards('table1_group1', 4, 2); SELECT master_create_worker_shards('table1_group1', 4, 2);
select last_value from pg_dist_colocationid_seq ;
CREATE TABLE table2_group1 ( id int ); CREATE TABLE table2_group1 ( id int );
SELECT master_create_distributed_table('table2_group1', 'id', 'hash'); SELECT master_create_distributed_table('table2_group1', 'id', 'hash');
SELECT master_create_worker_shards('table2_group1', 4, 2); SELECT master_create_worker_shards('table2_group1', 4, 2);
table pg_dist_colocation;
table pg_dist_partition;
CREATE TABLE table3_group2 ( id int ); CREATE TABLE table3_group2 ( id int );
SELECT master_create_distributed_table('table3_group2', 'id', 'hash'); SELECT master_create_distributed_table('table3_group2', 'id', 'hash');
SELECT master_create_worker_shards('table3_group2', 4, 2); SELECT master_create_worker_shards('table3_group2', 4, 2);
select last_value from pg_dist_colocationid_seq ;
CREATE TABLE table4_group2 ( id int ); CREATE TABLE table4_group2 ( id int );
SELECT master_create_distributed_table('table4_group2', 'id', 'hash'); SELECT master_create_distributed_table('table4_group2', 'id', 'hash');
SELECT master_create_worker_shards('table4_group2', 4, 2); SELECT master_create_worker_shards('table4_group2', 4, 2);
select last_value from pg_dist_colocationid_seq ;
CREATE TABLE table5_groupX ( id int ); CREATE TABLE table5_groupX ( id int );
SELECT master_create_distributed_table('table5_groupX', 'id', 'hash'); SELECT master_create_distributed_table('table5_groupX', 'id', 'hash');
SELECT master_create_worker_shards('table5_groupX', 4, 2); SELECT master_create_worker_shards('table5_groupX', 4, 2);
table pg_dist_colocation;
table pg_dist_partition;
CREATE TABLE table6_append ( id int ); CREATE TABLE table6_append ( id int );
SELECT master_create_distributed_table('table6_append', 'id', 'append'); SELECT master_create_distributed_table('table6_append', 'id', '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 master_create_empty_shard('table6_append');select last_value from pg_dist_colocationid_seq ;
-- make table1_group1 and table2_group1 co-located manually -- 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('table1_group1');
SELECT get_table_colocation_id('table5_groupX'); SELECT get_table_colocation_id('table5_groupX');
SELECT get_table_colocation_id('table6_append'); SELECT get_table_colocation_id('table6_append');
table pg_dist_colocation;
table pg_dist_partition;
-- check self table co-location -- check self table co-location
SELECT tables_colocated('table1_group1', 'table1_group1'); SELECT tables_colocated('table1_group1', 'table1_group1');
SELECT tables_colocated('table5_groupX', 'table5_groupX'); 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 -- check table co-location with invalid co-location group
SELECT tables_colocated('table1_group1', 'table5_groupX'); SELECT tables_colocated('table1_group1', 'table5_groupX');
SELECT tables_colocated('table1_group1', 'table6_append'); SELECT tables_colocated('table1_group1', 'table6_append');
table pg_dist_colocation;
table pg_dist_partition;
-- check self shard co-location -- check self shard co-location
SELECT shards_colocated(1300000, 1300000); SELECT shards_colocated(1300000, 1300000);
SELECT shards_colocated(1300016, 1300016); SELECT shards_colocated(1300016, 1300016);
@ -129,7 +139,8 @@ SELECT shards_colocated(1300000, 1300001);
-- check shard co-location with different co-location group -- check shard co-location with different co-location group
SELECT shards_colocated(1300000, 1300005); SELECT shards_colocated(1300000, 1300005);
table pg_dist_colocation;
table pg_dist_partition;
-- check shard co-location with invalid co-location group -- check shard co-location with invalid co-location group
SELECT shards_colocated(1300000, 1300016); SELECT shards_colocated(1300000, 1300016);
SELECT shards_colocated(1300000, 1300020); 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(1300002);
SELECT find_shard_interval_index(1300003); SELECT find_shard_interval_index(1300003);
SELECT find_shard_interval_index(1300016); SELECT find_shard_interval_index(1300016);
table pg_dist_colocation;
table pg_dist_partition;
-- check external colocation API -- check external colocation API
SELECT count(*) FROM pg_dist_partition WHERE colocationid IN (4, 5); 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; SET citus.shard_replication_factor to DEFAULT;
-- change partition column type -- 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 ); CREATE TABLE table1_groupC ( id text );
SELECT create_distributed_table('table1_groupC', 'id'); SELECT create_distributed_table('table1_groupC', 'id');
reset citus.log_remote_commands;
CREATE TABLE table2_groupC ( id text ); CREATE TABLE table2_groupC ( id text );
SELECT create_distributed_table('table2_groupC', 'id'); SELECT create_distributed_table('table2_groupC', 'id');

View File

@ -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; 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 -- Make sure that citus_activate_node can be called inside a transaction and rollbacked
\c - - - :master_port --\c - - - :master_port
BEGIN; --BEGIN;
SELECT start_metadata_sync_to_node('localhost', :worker_2_port); --SELECT citus_activate_node('localhost', :worker_2_port);
SELECT citus_activate_node('localhost', :worker_2_port); --ROLLBACK;
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 -- Check that the distributed table can be queried from the worker
\c - - - :master_port \c - - - :master_port
@ -575,7 +574,6 @@ SELECT create_distributed_table('mx_table', 'a');
\c - postgres - :master_port \c - postgres - :master_port
SELECT master_add_node('localhost', :worker_2_port); SELECT master_add_node('localhost', :worker_2_port);
SELECT citus_activate_node('localhost', :worker_2_port);
\c - mx_user - :worker_1_port \c - mx_user - :worker_1_port
SELECT nextval('mx_table_b_seq'); 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; UPDATE pg_dist_node SET metadatasynced=true WHERE nodeport=:worker_1_port;
SELECT master_add_node('localhost', :worker_2_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_0;
CREATE SEQUENCE mx_test_sequence_1; 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_colocationid_seq RESTART :last_colocation_id;
ALTER SEQUENCE pg_catalog.pg_dist_placement_placementid_seq RESTART :last_placement_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 -- Activate them at the end
SELECT start_metadata_sync_to_node('localhost', :worker_1_port);
SELECT start_metadata_sync_to_node('localhost', :worker_2_port);
SELECT citus_activate_node('localhost', :worker_1_port); SELECT citus_activate_node('localhost', :worker_1_port);
SELECT citus_activate_node('localhost', :worker_2_port); SELECT citus_activate_node('localhost', :worker_2_port);