Skip to content

Commit 9a57913

Browse files
committed
clear cache on transaction abortion
1 parent f561b2a commit 9a57913

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/pl_funcs.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
#include "utils/typcache.h"
1313
#include "utils/array.h"
1414
#include "utils/snapmgr.h"
15+
#include "utils/memutils.h"
1516
#include "access/nbtree.h"
1617
#include "access/xact.h"
1718
#include "catalog/pg_type.h"
1819
#include "executor/spi.h"
1920
#include "storage/lmgr.h"
2021

22+
static void on_rollback_after_partitions_created(XactEvent event, void *arg);
2123

2224
/* declarations */
2325
PG_FUNCTION_INFO_V1( on_partitions_created );
@@ -34,18 +36,50 @@ PG_FUNCTION_INFO_V1( get_max_range_value );
3436
PG_FUNCTION_INFO_V1( get_type_hash_func );
3537
PG_FUNCTION_INFO_V1( get_hash );
3638

39+
static void
40+
on_rollback_after_partitions_created(XactEvent event, void *arg)
41+
{
42+
Oid relid = *(Oid *) arg;
43+
44+
/* Catch abort event */
45+
if (event == XACT_EVENT_ABORT)
46+
{
47+
/* Clear cache */
48+
LWLockAcquire(pmstate->load_config_lock, LW_EXCLUSIVE);
49+
elog(WARNING, "Removing '%s' partitions from pg_pathman's cache", get_rel_name(relid));
50+
remove_relation_info(relid);
51+
LWLockRelease(pmstate->load_config_lock);
52+
}
53+
54+
UnregisterXactCallback(on_rollback_after_partitions_created, arg);
55+
pfree(arg);
56+
}
57+
3758
/*
3859
* Callbacks
3960
*/
4061
Datum
4162
on_partitions_created(PG_FUNCTION_ARGS)
4263
{
64+
MemoryContext old_ctx;
65+
Oid *relid;
66+
67+
/* Acquire lock */
4368
LWLockAcquire(pmstate->load_config_lock, LW_EXCLUSIVE);
4469

4570
/* Reload config */
4671
/* TODO: reload just the specified relation */
4772
load_relations(false);
4873

74+
/* Register callback to handle transaction abortion */
75+
old_ctx = CurrentMemoryContext;
76+
MemoryContextSwitchTo(CurTransactionContext);
77+
relid = palloc0(sizeof(Oid));
78+
*relid = PG_GETARG_OID(0);
79+
RegisterXactCallback(on_rollback_after_partitions_created, relid);
80+
MemoryContextSwitchTo(old_ctx);
81+
82+
/* Release lock */
4983
LWLockRelease(pmstate->load_config_lock);
5084

5185
PG_RETURN_NULL();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy