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

Commitb2b023a

Browse files
committed
injection_points: Add initialization of shmem state when loading module
This commits adds callbacks to initialize the shared memory state of themodule when loaded with shared_preload_libraries. This is necessary tobe able to update the test introduced in768a9fd to use the macrosINJECTION_POINT_{LOAD,CACHED}() rather than a SQL function in the moduleinjection_points forcing a load, as this test runs a callback in acritical section where no memory allocation should happen.Initializing the shared memory state of the module while loadingprovides a strict control on the timing of its allocation. If themodule is not loaded at startup, it will use a GetNamedDSMSegment()instead to initialize its shmem state on-the-fly.Per discussion with Álvaro Herrera.Author: Michael PaquierDiscussion:https://postgr.es/m/ZsUnJUlSOBNAzwW1@paquier.xyz
1 parentedcb712 commitb2b023a

File tree

1 file changed

+59
-3
lines changed

1 file changed

+59
-3
lines changed

‎src/test/modules/injection_points/injection_points.c

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ typedef struct InjectionPointCondition
6868
*/
6969
staticList*inj_list_local=NIL;
7070

71-
/* Shared state information for injection points. */
71+
/*
72+
* Shared state information for injection points.
73+
*
74+
* This state data can be initialized in two ways: dynamically with a DSM
75+
* or when loading the module.
76+
*/
7277
typedefstructInjectionPointSharedState
7378
{
7479
/* Protects access to other fields */
@@ -97,8 +102,13 @@ extern PGDLLEXPORT void injection_wait(const char *name,
97102
/* track if injection points attached in this process are linked to it */
98103
staticboolinjection_point_local= false;
99104

105+
/* Shared memory init callbacks */
106+
staticshmem_request_hook_typeprev_shmem_request_hook=NULL;
107+
staticshmem_startup_hook_typeprev_shmem_startup_hook=NULL;
108+
100109
/*
101-
* Callback for shared memory area initialization.
110+
* Routine for shared memory area initialization, used as a callback
111+
* when initializing dynamically with a DSM or when loading the module.
102112
*/
103113
staticvoid
104114
injection_point_init_state(void*ptr)
@@ -111,8 +121,48 @@ injection_point_init_state(void *ptr)
111121
ConditionVariableInit(&state->wait_point);
112122
}
113123

124+
/* Shared memory initialization when loading module */
125+
staticvoid
126+
injection_shmem_request(void)
127+
{
128+
Sizesize;
129+
130+
if (prev_shmem_request_hook)
131+
prev_shmem_request_hook();
132+
133+
size=MAXALIGN(sizeof(InjectionPointSharedState));
134+
RequestAddinShmemSpace(size);
135+
}
136+
137+
staticvoid
138+
injection_shmem_startup(void)
139+
{
140+
boolfound;
141+
142+
if (prev_shmem_startup_hook)
143+
prev_shmem_startup_hook();
144+
145+
/* Create or attach to the shared memory state */
146+
LWLockAcquire(AddinShmemInitLock,LW_EXCLUSIVE);
147+
148+
inj_state=ShmemInitStruct("injection_points",
149+
sizeof(InjectionPointSharedState),
150+
&found);
151+
152+
if (!found)
153+
{
154+
/*
155+
* First time through, so initialize. This is shared with the dynamic
156+
* initialization using a DSM.
157+
*/
158+
injection_point_init_state(inj_state);
159+
}
160+
161+
LWLockRelease(AddinShmemInitLock);
162+
}
163+
114164
/*
115-
* Initialize shared memory area for this module.
165+
* Initialize shared memory area for this module through DSM.
116166
*/
117167
staticvoid
118168
injection_init_shmem(void)
@@ -463,6 +513,12 @@ _PG_init(void)
463513
if (!process_shared_preload_libraries_in_progress)
464514
return;
465515

516+
/* Shared memory initialization */
517+
prev_shmem_request_hook=shmem_request_hook;
518+
shmem_request_hook=injection_shmem_request;
519+
prev_shmem_startup_hook=shmem_startup_hook;
520+
shmem_startup_hook=injection_shmem_startup;
521+
466522
pgstat_register_inj();
467523
pgstat_register_inj_fixed();
468524
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp