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 */
1924PG_FUNCTION_INFO_V1 (on_partitions_created );
2025PG_FUNCTION_INFO_V1 (on_partitions_updated );
@@ -30,18 +35,50 @@ PG_FUNCTION_INFO_V1( get_max_range_value );
3035PG_FUNCTION_INFO_V1 (get_type_hash_func );
3136PG_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 */
3660Datum
3761on_partitions_created (PG_FUNCTION_ARGS )
3862{
63+ MemoryContext old_ctx ;
64+ Oid * relid ;
65+
66+ /* Acquire lock */
3967LWLockAcquire (pmstate -> load_config_lock ,LW_EXCLUSIVE );
4068
4169/* Reload config */
4270/* TODO: reload just the specified relation */
4371load_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 */
4582LWLockRelease (pmstate -> load_config_lock );
4683
4784PG_RETURN_NULL ();