Verify trigger relation before reading old/new tuples

master_dist_placement_cache_invalidate: bail when triggering on pg_dist_shard_placement
pull/3719/head
Philip Dubé 2020-04-06 15:18:45 +00:00
parent 9fb83d6e5d
commit 26797bfb94
2 changed files with 30 additions and 1 deletions

View File

@ -2558,6 +2558,12 @@ master_dist_partition_cache_invalidate(PG_FUNCTION_ARGS)
CheckCitusVersion(ERROR); CheckCitusVersion(ERROR);
if (RelationGetRelid(triggerData->tg_relation) != DistPartitionRelationId())
{
ereport(ERROR, (errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
errmsg("triggered on incorrect relation")));
}
HeapTuple newTuple = triggerData->tg_newtuple; HeapTuple newTuple = triggerData->tg_newtuple;
HeapTuple oldTuple = triggerData->tg_trigtuple; HeapTuple oldTuple = triggerData->tg_trigtuple;
@ -2619,6 +2625,12 @@ master_dist_shard_cache_invalidate(PG_FUNCTION_ARGS)
CheckCitusVersion(ERROR); CheckCitusVersion(ERROR);
if (RelationGetRelid(triggerData->tg_relation) != DistShardRelationId())
{
ereport(ERROR, (errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
errmsg("triggered on incorrect relation")));
}
HeapTuple newTuple = triggerData->tg_newtuple; HeapTuple newTuple = triggerData->tg_newtuple;
HeapTuple oldTuple = triggerData->tg_trigtuple; HeapTuple oldTuple = triggerData->tg_trigtuple;
@ -2680,6 +2692,23 @@ master_dist_placement_cache_invalidate(PG_FUNCTION_ARGS)
CheckCitusVersion(ERROR); CheckCitusVersion(ERROR);
/*
* Before 7.0-2 this trigger is on pg_dist_shard_placement,
* ignore trigger in this scenario.
*/
Oid pgDistShardPlacementId = get_relname_relid("pg_dist_shard_placement",
PG_CATALOG_NAMESPACE);
if (RelationGetRelid(triggerData->tg_relation) == pgDistShardPlacementId)
{
PG_RETURN_DATUM(PointerGetDatum(NULL));
}
if (RelationGetRelid(triggerData->tg_relation) != DistPlacementRelationId())
{
ereport(ERROR, (errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
errmsg("triggered on incorrect relation")));
}
HeapTuple newTuple = triggerData->tg_newtuple; HeapTuple newTuple = triggerData->tg_newtuple;
HeapTuple oldTuple = triggerData->tg_trigtuple; HeapTuple oldTuple = triggerData->tg_trigtuple;

View File

@ -242,7 +242,7 @@ task_tracker_cleanup_job(PG_FUNCTION_ARGS)
/* /*
* task_tracker_conninfo_cache_invalidate is a trigger function that signals to * task_tracker_conninfo_cache_invalidate is a trigger function that signals to
* the task tracker to refresh its conn params cache after a authinfo change. * the task tracker to refresh its conn params cache after an authinfo change.
* *
* NB: We decided there is little point in checking permissions here, there * NB: We decided there is little point in checking permissions here, there
* are much easier ways to waste CPU than causing cache invalidations. * are much easier ways to waste CPU than causing cache invalidations.