Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 83dc5af

Browse files
committed
fix complete cache invalidation event handling
1 parent 3370dc4 commit 83dc5af

File tree

5 files changed

+199
-67
lines changed

5 files changed

+199
-67
lines changed

src/hooks.c

+22-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
#include "utils/lsyscache.h"
3737

3838

39+
#ifdef USE_ASSERT_CHECKING
40+
#define USE_RELCACHE_LOGGING
41+
#endif
42+
43+
3944
/* Borrowed from joinpath.c */
4045
#define PATH_PARAM_BY_REL(path, rel) \
4146
((path)->param_info && bms_overlap(PATH_REQ_OUTER(path), (rel)->relids))
@@ -808,6 +813,18 @@ pathman_relcache_hook(Datum arg, Oid relid)
808813
if (!IsPathmanReady())
809814
return;
810815

816+
/* Special case: flush whole relcache */
817+
if (relid == InvalidOid)
818+
{
819+
delay_invalidation_whole_cache();
820+
821+
#ifdef USE_RELCACHE_LOGGING
822+
elog(DEBUG2, "Invalidation message for all relations [%u]", MyProcPid);
823+
#endif
824+
825+
return;
826+
}
827+
811828
/* We shouldn't even consider special OIDs */
812829
if (relid < FirstNormalObjectId)
813830
return;
@@ -827,16 +844,20 @@ pathman_relcache_hook(Datum arg, Oid relid)
827844
{
828845
delay_invalidation_parent_rel(parent_relid);
829846

847+
#ifdef USE_RELCACHE_LOGGING
830848
elog(DEBUG2, "Invalidation message for partition %u [%u]",
831849
relid, MyProcPid);
850+
#endif
832851
}
833852
/* We can't say, perform full invalidation procedure */
834853
else
835854
{
836855
delay_invalidation_vague_rel(relid);
837856

838-
elog(DEBUG2, "Invalidation message for vague relation %u [%u]",
857+
#ifdef USE_RELCACHE_LOGGING
858+
elog(DEBUG2, "Invalidation message for vague rel %u [%u]",
839859
relid, MyProcPid);
860+
#endif
840861
}
841862
}
842863

src/include/init.h

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ typedef struct
5454

5555
#define PATHMAN_MCXT_COUNT 4
5656
extern MemoryContext TopPathmanContext;
57+
extern MemoryContext PathmanInvalJobsContext;
5758
extern MemoryContext PathmanRelationCacheContext;
5859
extern MemoryContext PathmanParentCacheContext;
5960
extern MemoryContext PathmanBoundCacheContext;

src/include/relation_info.h

+2
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ const PartRelationInfo *refresh_pathman_relation_info(Oid relid,
275275
Datum *values,
276276
bool allow_incomplete);
277277
PartRelationInfo *invalidate_pathman_relation_info(Oid relid, bool *found);
278+
void invalidate_pathman_relation_info_cache(const Oid *parents, int parents_count);
278279
void remove_pathman_relation_info(Oid relid);
279280
const PartRelationInfo *get_pathman_relation_info(Oid relid);
280281
const PartRelationInfo *get_pathman_relation_info_after_lock(Oid relid,
@@ -296,6 +297,7 @@ char *canonicalize_partitioning_expression(const Oid relid,
296297

297298
/* Global invalidation routines */
298299
void delay_pathman_shutdown(void);
300+
void delay_invalidation_whole_cache(void);
299301
void delay_invalidation_parent_rel(Oid parent);
300302
void delay_invalidation_vague_rel(Oid vague_rel);
301303
void finish_delayed_invalidation(void);

src/init.c

+8
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
/* Various memory contexts for caches */
4343
MemoryContext TopPathmanContext = NULL;
44+
MemoryContext PathmanInvalJobsContext = NULL;
4445
MemoryContext PathmanRelationCacheContext = NULL;
4546
MemoryContext PathmanParentCacheContext = NULL;
4647
MemoryContext PathmanBoundCacheContext = NULL;
@@ -312,6 +313,7 @@ init_local_cache(void)
312313
if (TopPathmanContext)
313314
{
314315
/* Check that child contexts exist */
316+
Assert(MemoryContextIsValid(PathmanInvalJobsContext));
315317
Assert(MemoryContextIsValid(PathmanRelationCacheContext));
316318
Assert(MemoryContextIsValid(PathmanParentCacheContext));
317319
Assert(MemoryContextIsValid(PathmanBoundCacheContext));
@@ -322,6 +324,7 @@ init_local_cache(void)
322324
/* Initialize pg_pathman's memory contexts */
323325
else
324326
{
327+
Assert(PathmanInvalJobsContext == NULL);
325328
Assert(PathmanRelationCacheContext == NULL);
326329
Assert(PathmanParentCacheContext == NULL);
327330
Assert(PathmanBoundCacheContext == NULL);
@@ -331,6 +334,11 @@ init_local_cache(void)
331334
CppAsString(TopPathmanContext),
332335
ALLOCSET_DEFAULT_SIZES);
333336

337+
PathmanInvalJobsContext =
338+
AllocSetContextCreate(TopMemoryContext,
339+
CppAsString(PathmanInvalJobsContext),
340+
ALLOCSET_SMALL_SIZES);
341+
334342
/* For PartRelationInfo */
335343
PathmanRelationCacheContext =
336344
AllocSetContextCreate(TopPathmanContext,

0 commit comments

Comments
 (0)