Skip to content

Commit 86e4bc1

Browse files
committed
Merge branch 'master' into picky_nodes (resolve conflicts)
2 parents fb49f76 + 9a57913 commit 86e4bc1

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/pl_funcs.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@
99
*/
1010
#include "pathman.h"
1111
#include "access/nbtree.h"
12+
#include "access/xact.h"
1213
#include "utils/lsyscache.h"
1314
#include "utils/typcache.h"
1415
#include "utils/array.h"
16+
#include "utils/snapmgr.h"
17+
#include "utils/memutils.h"
1518
#include "utils.h"
1619

1720

21+
static void on_rollback_after_partitions_created(XactEvent event, void *arg);
22+
1823
/* declarations */
1924
PG_FUNCTION_INFO_V1( on_partitions_created );
2025
PG_FUNCTION_INFO_V1( on_partitions_updated );
@@ -30,18 +35,50 @@ PG_FUNCTION_INFO_V1( get_max_range_value );
3035
PG_FUNCTION_INFO_V1( get_type_hash_func );
3136
PG_FUNCTION_INFO_V1( get_hash );
3237

38+
static void
39+
on_rollback_after_partitions_created(XactEvent event, void *arg)
40+
{
41+
Oid relid = *(Oid *) arg;
42+
43+
/* Catch abort event */
44+
if (event == XACT_EVENT_ABORT)
45+
{
46+
/* Clear cache */
47+
LWLockAcquire(pmstate->load_config_lock, LW_EXCLUSIVE);
48+
elog(WARNING, "Removing '%s' partitions from pg_pathman's cache", get_rel_name(relid));
49+
remove_relation_info(relid);
50+
LWLockRelease(pmstate->load_config_lock);
51+
}
52+
53+
UnregisterXactCallback(on_rollback_after_partitions_created, arg);
54+
pfree(arg);
55+
}
56+
3357
/*
3458
* Callbacks
3559
*/
3660
Datum
3761
on_partitions_created(PG_FUNCTION_ARGS)
3862
{
63+
MemoryContext old_ctx;
64+
Oid *relid;
65+
66+
/* Acquire lock */
3967
LWLockAcquire(pmstate->load_config_lock, LW_EXCLUSIVE);
4068

4169
/* Reload config */
4270
/* TODO: reload just the specified relation */
4371
load_relations(false);
4472

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

4784
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