Skip to content

Commit e5280fb

Browse files
committed
WIP some fundamental changes to caches
1 parent 2c24811 commit e5280fb

10 files changed

+1078
-1445
lines changed

Diff for: src/hooks.c

+12-36
Original file line numberDiff line numberDiff line change
@@ -812,60 +812,36 @@ pathman_shmem_startup_hook(void)
812812
void
813813
pathman_relcache_hook(Datum arg, Oid relid)
814814
{
815-
Oid parent_relid;
816-
817815
/* See cook_partitioning_expression() */
818816
if (!pathman_hooks_enabled)
819817
return;
820818

821819
if (!IsPathmanReady())
822820
return;
823821

824-
/* Special case: flush whole relcache */
822+
/* Invalidation event for whole cache */
825823
if (relid == InvalidOid)
826824
{
827-
delay_invalidation_whole_cache();
828-
829-
#ifdef USE_RELCACHE_LOGGING
830-
elog(DEBUG2, "Invalidation message for all relations [%u]", MyProcPid);
831-
#endif
832-
833-
return;
825+
invalidate_pathman_status_info_cache();
834826
}
835827

836-
/* We shouldn't even consider special OIDs */
837-
if (relid < FirstNormalObjectId)
838-
return;
839-
840828
/* Invalidation event for PATHMAN_CONFIG table (probably DROP) */
841829
if (relid == get_pathman_config_relid(false))
830+
{
842831
delay_pathman_shutdown();
832+
}
843833

844-
/* Invalidate PartBoundInfo cache if needed */
845-
forget_bounds_of_partition(relid);
846-
847-
/* Invalidate PartParentInfo cache if needed */
848-
parent_relid = forget_parent_of_partition(relid, NULL);
849-
850-
/* It *might have been a partition*, invalidate parent */
851-
if (OidIsValid(parent_relid))
834+
/* Invalidation event for some user table */
835+
else if (relid >= FirstNormalObjectId)
852836
{
853-
delay_invalidation_parent_rel(parent_relid);
837+
/* Invalidate PartBoundInfo entry if needed */
838+
forget_bounds_of_partition(relid);
854839

855-
#ifdef USE_RELCACHE_LOGGING
856-
elog(DEBUG2, "Invalidation message for partition %u [%u]",
857-
relid, MyProcPid);
858-
#endif
859-
}
860-
/* We can't say, perform full invalidation procedure */
861-
else
862-
{
863-
delay_invalidation_vague_rel(relid);
840+
/* Invalidate PartParentInfo entry if needed */
841+
forget_parent_of_partition(relid);
864842

865-
#ifdef USE_RELCACHE_LOGGING
866-
elog(DEBUG2, "Invalidation message for vague rel %u [%u]",
867-
relid, MyProcPid);
868-
#endif
843+
/* Invalidate PartStatusInfo entry if needed */
844+
invalidate_pathman_status_info(relid);
869845
}
870846
}
871847

Diff for: src/include/init.h

+24-24
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,21 @@ typedef struct
4646
do { \
4747
Assert(CurrentMemoryContext != TopMemoryContext); \
4848
Assert(CurrentMemoryContext != TopPathmanContext); \
49-
Assert(CurrentMemoryContext != PathmanRelationCacheContext); \
50-
Assert(CurrentMemoryContext != PathmanParentCacheContext); \
51-
Assert(CurrentMemoryContext != PathmanBoundCacheContext); \
49+
Assert(CurrentMemoryContext != PathmanParentsCacheContext); \
50+
Assert(CurrentMemoryContext != PathmanStatusCacheContext); \
51+
Assert(CurrentMemoryContext != PathmanBoundsCacheContext); \
5252
} while (0)
5353

5454

5555
#define PATHMAN_MCXT_COUNT 4
5656
extern MemoryContext TopPathmanContext;
57-
extern MemoryContext PathmanInvalJobsContext;
58-
extern MemoryContext PathmanRelationCacheContext;
59-
extern MemoryContext PathmanParentCacheContext;
60-
extern MemoryContext PathmanBoundCacheContext;
57+
extern MemoryContext PathmanParentsCacheContext;
58+
extern MemoryContext PathmanStatusCacheContext;
59+
extern MemoryContext PathmanBoundsCacheContext;
6160

62-
extern HTAB *partitioned_rels;
63-
extern HTAB *parent_cache;
64-
extern HTAB *bound_cache;
61+
extern HTAB *parents_cache;
62+
extern HTAB *status_cache;
63+
extern HTAB *bounds_cache;
6564

6665
/* pg_pathman's initialization state */
6766
extern PathmanInitState pathman_init_state;
@@ -70,28 +69,29 @@ extern PathmanInitState pathman_init_state;
7069
extern bool pathman_hooks_enabled;
7170

7271

72+
#define PATHMAN_TOP_CONTEXT "maintenance"
73+
#define PATHMAN_PARENTS_CACHE "partition parents cache"
74+
#define PATHMAN_STATUS_CACHE "partition status cache"
75+
#define PATHMAN_BOUNDS_CACHE "partition bounds cache"
76+
77+
7378
/* Transform pg_pathman's memory context into simple name */
7479
static inline const char *
75-
simpify_mcxt_name(MemoryContext mcxt)
80+
simplify_mcxt_name(MemoryContext mcxt)
7681
{
77-
static const char *top_mcxt = "maintenance",
78-
*rel_mcxt = "partition dispatch cache",
79-
*parent_mcxt = "partition parents cache",
80-
*bound_mcxt = "partition bounds cache";
81-
8282
if (mcxt == TopPathmanContext)
83-
return top_mcxt;
83+
return PATHMAN_TOP_CONTEXT;
8484

85-
else if (mcxt == PathmanRelationCacheContext)
86-
return rel_mcxt;
85+
else if (mcxt == PathmanParentsCacheContext)
86+
return PATHMAN_PARENTS_CACHE;
8787

88-
else if (mcxt == PathmanParentCacheContext)
89-
return parent_mcxt;
88+
else if (mcxt == PathmanStatusCacheContext)
89+
return PATHMAN_STATUS_CACHE;
9090

91-
else if (mcxt == PathmanBoundCacheContext)
92-
return bound_mcxt;
91+
else if (mcxt == PathmanBoundsCacheContext)
92+
return PATHMAN_BOUNDS_CACHE;
9393

94-
else elog(ERROR, "error in function " CppAsString(simpify_mcxt_name));
94+
else elog(ERROR, "unknown memory context");
9595
}
9696

9797

0 commit comments

Comments
 (0)