mirror of https://github.com/citusdata/citus.git
Fix segfault when adding/dropping fkey from ref to citus local via remote exec (#4528)
parent
5a3e8a6e24
commit
f1ecbc3a53
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue