Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9a57913

Browse files
committed
clear cache on transaction abortion
1 parentf561b2a commit9a57913

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+
staticvoidon_rollback_after_partitions_created(XactEventevent,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+
staticvoid
40+
on_rollback_after_partitions_created(XactEventevent,void*arg)
41+
{
42+
Oidrelid=*(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+
MemoryContextold_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)

[8]ページ先頭

©2009-2025 Movatter.jp