Fix segfault when adding/dropping fkey from ref to citus local via remote exec (#4528)

pull/4507/head
Onur Tirtir 2021-01-17 20:43:33 +03:00 committed by GitHub
parent 5a3e8a6e24
commit f1ecbc3a53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 2 deletions

View File

@ -2049,8 +2049,9 @@ SetInterShardDDLTaskPlacementList(Task *task, ShardInterval *leftShardInterval,
* to a citus local table, then we will execute ADD/DROP constraint
* command only for coordinator placement of reference table.
*/
task->taskPlacementList = GroupShardPlacementsForTableOnGroup(leftRelationId,
COORDINATOR_GROUP_ID);
uint64 leftShardId = leftShardInterval->shardId;
task->taskPlacementList = ActiveShardPlacementListOnGroup(leftShardId,
COORDINATOR_GROUP_ID);
}
else
{

View File

@ -963,6 +963,30 @@ NodeGroupHasShardPlacements(int32 groupId, bool onlyConsiderActivePlacements)
}
/*
* ActiveShardPlacementListOnGroup returns a list of active shard placements
* that are sitting on group with groupId for given shardId.
*/
List *
ActiveShardPlacementListOnGroup(uint64 shardId, int32 groupId)
{
List *activeShardPlacementListOnGroup = NIL;
List *activePlacementList = ActiveShardPlacementList(shardId);
ShardPlacement *shardPlacement = NULL;
foreach_ptr(shardPlacement, activePlacementList)
{
if (shardPlacement->groupId == groupId)
{
activeShardPlacementListOnGroup = lappend(activeShardPlacementListOnGroup,
shardPlacement);
}
}
return activeShardPlacementListOnGroup;
}
/*
* ActiveShardPlacementList finds shard placements for the given shardId from
* system catalogs, chooses placements that are in active state, and returns

View File

@ -188,6 +188,7 @@ extern ShardInterval * CopyShardInterval(ShardInterval *srcInterval);
extern uint64 ShardLength(uint64 shardId);
extern bool NodeGroupHasShardPlacements(int32 groupId,
bool onlyConsiderActivePlacements);
extern List * ActiveShardPlacementListOnGroup(uint64 shardId, int32 groupId);
extern List * ActiveShardPlacementList(uint64 shardId);
extern ShardPlacement * ActiveShardPlacement(uint64 shardId, bool missingOk);
extern List * BuildShardPlacementList(ShardInterval *shardInterval);

View File

@ -169,6 +169,12 @@ ROLLBACK;
-- .. and we allow such foreign keys with NO ACTION behavior
ALTER TABLE reference_table ADD CONSTRAINT fkey_ref_to_local FOREIGN KEY(r1) REFERENCES citus_local_table(l1) ON DELETE NO ACTION;
NOTICE: executing the command locally: SELECT worker_apply_inter_shard_ddl_command (1506003, 'ref_citus_local_fkeys', 1506002, 'ref_citus_local_fkeys', 'ALTER TABLE reference_table ADD CONSTRAINT fkey_ref_to_local FOREIGN KEY(r1) REFERENCES citus_local_table(l1) ON DELETE NO ACTION;')
-- show that adding/dropping foreign keys from reference to citus local
-- tables works fine with remote execution too
SET citus.enable_local_execution TO OFF;
ALTER TABLE reference_table DROP CONSTRAINT fkey_ref_to_local;
ALTER TABLE reference_table ADD CONSTRAINT fkey_ref_to_local FOREIGN KEY(r1) REFERENCES citus_local_table(l1) ON DELETE NO ACTION;
SET citus.enable_local_execution TO ON;
-- show that we are checking for foreign key constraint after defining, this should fail
INSERT INTO reference_table VALUES (4);
NOTICE: executing the command locally: INSERT INTO ref_citus_local_fkeys.reference_table_1506003 (r1) VALUES (4)

View File

@ -113,6 +113,13 @@ ROLLBACK;
-- .. and we allow such foreign keys with NO ACTION behavior
ALTER TABLE reference_table ADD CONSTRAINT fkey_ref_to_local FOREIGN KEY(r1) REFERENCES citus_local_table(l1) ON DELETE NO ACTION;
-- show that adding/dropping foreign keys from reference to citus local
-- tables works fine with remote execution too
SET citus.enable_local_execution TO OFF;
ALTER TABLE reference_table DROP CONSTRAINT fkey_ref_to_local;
ALTER TABLE reference_table ADD CONSTRAINT fkey_ref_to_local FOREIGN KEY(r1) REFERENCES citus_local_table(l1) ON DELETE NO ACTION;
SET citus.enable_local_execution TO ON;
-- show that we are checking for foreign key constraint after defining, this should fail
INSERT INTO reference_table VALUES (4);