30
30
#include <string.h>
31
31
#include <inttypes.h>
32
32
33
+ #include <storage/shmem.h>
34
+
33
35
#include "util.h"
34
36
#include "core.h"
35
37
@@ -40,17 +42,25 @@ _Static_assert(LIBCURL_VERSION_NUM >= MIN_LIBCURL_VERSION_NUM, REQUIRED_LIBCURL_
40
42
41
43
PG_MODULE_MAGIC ;
42
44
43
- static char * guc_ttl ;
44
- static int guc_batch_size ;
45
- static char * guc_database_name ;
46
- static MemoryContext CurlMemContext = NULL ;
45
+ static char * guc_ttl ;
46
+ static int guc_batch_size ;
47
+ static char * guc_database_name ;
48
+ static MemoryContext CurlMemContext = NULL ;
49
+ static shmem_startup_hook_type prev_shmem_startup_hook = NULL ;
50
+ static long latch_timeout = 1000 ;
51
+ static volatile sig_atomic_t got_sigterm = false;
52
+ static volatile sig_atomic_t got_sighup = false;
53
+ static bool * restart_worker = NULL ;
47
54
48
55
void _PG_init (void );
49
56
PGDLLEXPORT void pg_net_worker (Datum main_arg ) pg_attribute_noreturn ();
50
57
51
- static long latch_timeout = 1000 ;
52
- static volatile sig_atomic_t got_sigterm = false;
53
- static volatile sig_atomic_t got_sighup = false;
58
+ PG_FUNCTION_INFO_V1 (worker_restart );
59
+ Datum worker_restart (PG_FUNCTION_ARGS ) {
60
+ bool result = DatumGetBool (DirectFunctionCall1 (pg_reload_conf , (Datum ) NULL )); // reload the config
61
+ * restart_worker = true;
62
+ PG_RETURN_BOOL (result && * restart_worker ); // TODO is not necessary to return a bool here, but we do it to maintain backward compatibility
63
+ }
54
64
55
65
static void
56
66
handle_sigterm (SIGNAL_ARGS )
@@ -141,6 +151,12 @@ void pg_net_worker(Datum main_arg) {
141
151
ProcessConfigFile (PGC_SIGHUP );
142
152
}
143
153
154
+ if (restart_worker && * restart_worker ) {
155
+ * restart_worker = false;
156
+ elog (INFO , "Restarting pg_net worker" );
157
+ break ;
158
+ }
159
+
144
160
delete_expired_responses (guc_ttl , guc_batch_size );
145
161
146
162
consume_request_queue (lstate .curl_mhandle , guc_batch_size , CurlMemContext );
@@ -206,6 +222,14 @@ void pg_net_worker(Datum main_arg) {
206
222
proc_exit (EXIT_FAILURE );
207
223
}
208
224
225
+ static void net_shmem_startup (void ) {
226
+ if (prev_shmem_startup_hook )
227
+ prev_shmem_startup_hook ();
228
+
229
+ restart_worker = ShmemAlloc (sizeof (bool ));
230
+ * restart_worker = false;
231
+ }
232
+
209
233
void _PG_init (void ) {
210
234
if (IsBinaryUpgrade ) {
211
235
return ;
@@ -226,6 +250,9 @@ void _PG_init(void) {
226
250
.bgw_restart_time = 1 ,
227
251
});
228
252
253
+ prev_shmem_startup_hook = shmem_startup_hook ;
254
+ shmem_startup_hook = net_shmem_startup ;
255
+
229
256
CurlMemContext = AllocSetContextCreate (TopMemoryContext ,
230
257
"pg_net curl context" ,
231
258
ALLOCSET_DEFAULT_MINSIZE ,
0 commit comments