Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3db4f66

Browse files
committed
new bgw api
1 parent 404450f commit 3db4f66

File tree

4 files changed

+47
-18
lines changed

4 files changed

+47
-18
lines changed

arbiter.c

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ static TimeoutId heartbeat_timer;
9191
static nodemask_t busy_mask;
9292
static timestamp_t last_heartbeat_to_node[MAX_NODES];
9393

94-
static void MtmSender(Datum arg);
95-
static void MtmReceiver(Datum arg);
96-
static void MtmMonitor(Datum arg);
94+
void MtmSender(Datum arg);
95+
void MtmReceiver(Datum arg);
96+
void MtmMonitor(Datum arg);
9797
static void MtmSendHeartbeat(void);
9898
static bool MtmSendToNode(int node, void const* buf, int size);
9999

@@ -116,23 +116,37 @@ static BackgroundWorker MtmSenderWorker = {
116116
BGWORKER_SHMEM_ACCESS | BGWORKER_BACKEND_DATABASE_CONNECTION,
117117
BgWorkerStart_ConsistentState,
118118
MULTIMASTER_BGW_RESTART_TIMEOUT,
119-
MtmSender
119+
// MtmSender
120+
"multimaster",
121+
"MtmSender",
122+
(Datum) 0,
123+
"",
124+
0
120125
};
121126

122127
static BackgroundWorker MtmRecevierWorker = {
123128
"mtm-receiver",
124129
BGWORKER_SHMEM_ACCESS | BGWORKER_BACKEND_DATABASE_CONNECTION,
125130
BgWorkerStart_ConsistentState,
126131
MULTIMASTER_BGW_RESTART_TIMEOUT,
127-
MtmReceiver
132+
// MtmReceiver
133+
"multimaster",
134+
"MtmReceiver",
135+
(Datum) 0,
136+
"",
137+
0
128138
};
129139

130140
static BackgroundWorker MtmMonitorWorker = {
131141
"mtm-monitor",
132142
BGWORKER_SHMEM_ACCESS | BGWORKER_BACKEND_DATABASE_CONNECTION,
133143
BgWorkerStart_ConsistentState,
134144
MULTIMASTER_BGW_RESTART_TIMEOUT,
135-
MtmMonitor
145+
"multimaster",
146+
"MtmMonitor",
147+
(Datum) 0,
148+
"",
149+
0
136150
};
137151

138152

@@ -711,7 +725,7 @@ static void MtmAppendBuffer(MtmBuffer* txBuffer, MtmArbiterMessage* msg)
711725
}
712726

713727

714-
static void MtmSender(Datum arg)
728+
void MtmSender(Datum arg)
715729
{
716730
int nNodes = MtmMaxNodes;
717731
int i;
@@ -807,7 +821,7 @@ static bool MtmRecovery()
807821
}
808822
#endif
809823

810-
static void MtmMonitor(Datum arg)
824+
void MtmMonitor(Datum arg)
811825
{
812826
pqsignal(SIGINT, SetStop);
813827
pqsignal(SIGQUIT, SetStop);
@@ -838,7 +852,7 @@ static void MtmMonitor(Datum arg)
838852
}
839853
}
840854

841-
static void MtmReceiver(Datum arg)
855+
void MtmReceiver(Datum arg)
842856
{
843857
int nNodes = MtmMaxNodes;
844858
int nResponses;

bgwpool.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ int MtmMaxWorkers;
2121

2222
static BgwPool* MtmPool;
2323

24+
void BgwPoolStaticWorkerMainLoop(Datum arg);
25+
void BgwPoolDynamicWorkerMainLoop(Datum arg);
26+
2427
static void BgwShutdownWorker(int sig)
2528
{
2629
MTM_LOG1("Background worker %d receive shutdown request", MyProcPid);
@@ -132,13 +135,13 @@ timestamp_t BgwGetLastPeekTime(BgwPool* pool)
132135
return pool->lastPeakTime;
133136
}
134137

135-
static void BgwPoolStaticWorkerMainLoop(Datum arg)
138+
void BgwPoolStaticWorkerMainLoop(Datum arg)
136139
{
137140
BgwPoolConstructor constructor = (BgwPoolConstructor)DatumGetPointer(arg);
138141
BgwPoolMainLoop(constructor());
139142
}
140143

141-
static void BgwPoolDynamicWorkerMainLoop(Datum arg)
144+
void BgwPoolDynamicWorkerMainLoop(Datum arg)
142145
{
143146
BgwPoolMainLoop((BgwPool*)DatumGetPointer(arg));
144147
}
@@ -151,7 +154,8 @@ void BgwPoolStart(int nWorkers, BgwPoolConstructor constructor)
151154
MemSet(&worker, 0, sizeof(BackgroundWorker));
152155
worker.bgw_flags = BGWORKER_SHMEM_ACCESS | BGWORKER_BACKEND_DATABASE_CONNECTION;
153156
worker.bgw_start_time = BgWorkerStart_ConsistentState;
154-
worker.bgw_main = BgwPoolStaticWorkerMainLoop;
157+
sprintf(worker.bgw_library_name, "multimaster");
158+
sprintf(worker.bgw_function_name, "BgwPoolStaticWorkerMainLoop");
155159
worker.bgw_restart_time = MULTIMASTER_BGW_RESTART_TIMEOUT;
156160

157161
for (i = 0; i < nWorkers; i++) {
@@ -182,7 +186,8 @@ static void BgwStartExtraWorker(BgwPool* pool)
182186
MemSet(&worker, 0, sizeof(BackgroundWorker));
183187
worker.bgw_flags = BGWORKER_SHMEM_ACCESS | BGWORKER_BACKEND_DATABASE_CONNECTION;
184188
worker.bgw_start_time = BgWorkerStart_ConsistentState;
185-
worker.bgw_main = BgwPoolDynamicWorkerMainLoop;
189+
sprintf(worker.bgw_library_name, "multimaster");
190+
sprintf(worker.bgw_function_name, "BgwPoolDynamicWorkerMainLoop");
186191
worker.bgw_restart_time = MULTIMASTER_BGW_RESTART_TIMEOUT;
187192
snprintf(worker.bgw_name, BGW_MAXLEN, "bgw_pool_dynworker_%d", (int)++pool->nWorkers);
188193
worker.bgw_main_arg = PointerGetDatum(pool);

pglogical_receiver.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ lsn_t MtmSenderWalEnd;
6767
static void fe_sendint64(int64 i, char *buf);
6868
static int64 fe_recvint64(char *buf);
6969

70+
void pglogical_receiver_main(Datum main_arg);
71+
7072
static void
7173
receiver_raw_sigterm(SIGNAL_ARGS)
7274
{
@@ -207,7 +209,7 @@ static char const* const MtmReplicationModeName[] =
207209
"open_existed" /* normal mode: use existed slot or create new one and start receiving data from it from the rememered position */
208210
};
209211

210-
static void
212+
void
211213
pglogical_receiver_main(Datum main_arg)
212214
{
213215
int nodeId = DatumGetInt32(main_arg);
@@ -717,7 +719,9 @@ void MtmStartReceiver(int nodeId, bool dynamic)
717719
MemSet(&worker, 0, sizeof(BackgroundWorker));
718720
worker.bgw_flags = BGWORKER_SHMEM_ACCESS | BGWORKER_BACKEND_DATABASE_CONNECTION;
719721
worker.bgw_start_time = BgWorkerStart_ConsistentState;
720-
worker.bgw_main = pglogical_receiver_main;
722+
// worker.bgw_main = pglogical_receiver_main;
723+
sprintf(worker.bgw_library_name, "multimaster");
724+
sprintf(worker.bgw_function_name, "pglogical_receiver_main");
721725
worker.bgw_restart_time = MULTIMASTER_BGW_RESTART_TIMEOUT;
722726

723727
/* Worker parameter and registration */

referee.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
static bool MtmRefereeStop;
3636

37+
void MtmRefereeMain(Datum arg);
38+
3739
static void MtmShutdownReferee(int sig)
3840
{
3941
MtmRefereeStop = true;
@@ -144,7 +146,7 @@ static void MtmRefereeLoop(char const** connections, int nConns)
144146
}
145147
}
146148

147-
static void MtmRefereeMain(Datum arg)
149+
void MtmRefereeMain(Datum arg)
148150
{
149151
char const* connections[MAX_NODES];
150152
int i;
@@ -168,10 +170,14 @@ static BackgroundWorker MtmRefereeWorker = {
168170
0,
169171
BgWorkerStart_ConsistentState,
170172
REFEREE_RECONNECT_TIMEOUT,
171-
MtmRefereeMain
173+
// MtmRefereeMain
174+
"referee",
175+
"MtmRefereeMain",
176+
(Datum) 0,
177+
"",
178+
0
172179
};
173180

174-
175181
void MtmRefereeInitialize(void)
176182
{
177183
RegisterBackgroundWorker(&MtmRefereeWorker);

0 commit comments

Comments
 (0)