diff --git a/src/backend/utils/cache/inval.c b/src/backend/utils/cache/inval.c index f5775880416..4fbca7b5711 100644 --- a/src/backend/utils/cache/inval.c +++ b/src/backend/utils/cache/inval.c @@ -240,6 +240,9 @@ static TransInvalidationInfo *transInvalInfo = NULL; /* GUC storage */ int debug_discard_caches = 0; +/* Hook for extensions to receive custom invalidation messages */ +ReceiveCustomInvalMessage_hook_type ReceiveCustomInvalMessage_hook = NULL; + /* * Dynamically-registered callback functions. Current implementation * assumes there won't be enough of these to justify a dynamically resizable @@ -827,6 +830,18 @@ InvalidateSystemCaches(void) InvalidateSystemCachesExtended(false); } +/* + * ReceiveCustomInvalMessage + * Call the ReceiveCustomInvalMessage_hook if set, allowing extensions + * to process their own invalidation messages. + */ +void +ReceiveCustomInvalMessage(void) +{ + if (ReceiveCustomInvalMessage_hook) + (*ReceiveCustomInvalMessage_hook) (); +} + /* * AcceptInvalidationMessages * Read and process invalidation messages from the shared invalidation @@ -838,6 +853,9 @@ InvalidateSystemCaches(void) void AcceptInvalidationMessages(void) { + /* Process any messages from external sources first. */ + ReceiveCustomInvalMessage(); + ReceiveSharedInvalidMessages(LocalExecuteInvalidationMessage, InvalidateSystemCaches); diff --git a/src/include/utils/inval.h b/src/include/utils/inval.h index 69498b9f77f..1ab129f9376 100644 --- a/src/include/utils/inval.h +++ b/src/include/utils/inval.h @@ -20,12 +20,17 @@ extern PGDLLIMPORT int debug_discard_caches; +/* Hook for extensions to receive custom invalidation messages */ +typedef void (*ReceiveCustomInvalMessage_hook_type) (void); +extern PGDLLIMPORT ReceiveCustomInvalMessage_hook_type ReceiveCustomInvalMessage_hook; + typedef void (*SyscacheCallbackFunction) (Datum arg, int cacheid, uint32 hashvalue); typedef void (*RelcacheCallbackFunction) (Datum arg, Oid relid); typedef void (*UsercacheCallbackFunction) (Datum arg, Oid arg1, Oid arg2, Oid arg3); extern void AcceptInvalidationMessages(void); +extern void ReceiveCustomInvalMessage(void); extern void AtEOXact_Inval(bool isCommit);