21
21
#include "postgres.h"
22
22
#include "fmgr.h"
23
23
#include "miscadmin.h"
24
- // #include "common/pg_socket.h"
25
24
#include "pqexpbuffer.h"
26
25
#include "access/xact.h"
27
26
#include "access/clog.h"
@@ -67,8 +66,8 @@ bool MtmIsReceiver;
67
66
68
67
typedef struct MtmFlushPosition
69
68
{
70
- dlist_node node ;
71
- int node_id ;
69
+ dlist_node node ;
70
+ int node_id ;
72
71
XLogRecPtr local_end ;
73
72
XLogRecPtr remote_end ;
74
73
} MtmFlushPosition ;
@@ -81,7 +80,7 @@ char const* const MtmReplicationModeName[] =
81
80
82
81
static dlist_head MtmLsnMapping = DLIST_STATIC_INIT (MtmLsnMapping );
83
82
84
- MtmConfig * receiver_mtm_cfg ;
83
+ MtmConfig * receiver_mtm_cfg ;
85
84
bool receiver_mtm_cfg_valid ;
86
85
87
86
/* Signal handling */
@@ -308,15 +307,15 @@ MtmExecute(void* work, int size, MtmReceiverContext *receiver_ctx, bool no_pool)
308
307
static bool
309
308
MtmFilterTransaction (char * record , int size , Syncpoint * spvector , HTAB * filter_map )
310
309
{
311
- StringInfoData s ;
312
- uint8 event ;
310
+ StringInfoData s ;
311
+ uint8 event ;
313
312
XLogRecPtr origin_lsn ;
314
313
XLogRecPtr end_lsn ;
315
314
XLogRecPtr tx_lsn ;
316
- int replication_node ;
317
- int origin_node ;
318
- char const * gid = "" ;
319
- char msgtype PG_USED_FOR_ASSERTS_ONLY ;
315
+ int replication_node ;
316
+ int origin_node ;
317
+ char const * gid = "" ;
318
+ char msgtype PG_USED_FOR_ASSERTS_ONLY ;
320
319
321
320
s .data = record ;
322
321
s .len = size ;
@@ -377,12 +376,10 @@ MtmFilterTransaction(char *record, int size, Syncpoint *spvector, HTAB *filter_m
377
376
378
377
hash_search (filter_map , & entry , HASH_FIND , & found );
379
378
380
- {
381
- mtm_log (MtmReceiverFilter ,
382
- "Filter (map) transaction %s from node %d event=%x (restrt=%" INT64_MODIFIER "x, tx=%d/%" INT64_MODIFIER "x) -> %d" ,
383
- gid , replication_node , event ,
384
- spvector [origin_node - 1 ].origin_lsn , origin_node , tx_lsn , found );
385
- }
379
+ mtm_log (MtmReceiverFilter ,
380
+ "Filter (map) transaction %s from node %d event=%x (restrt=%" INT64_MODIFIER "x, tx=%d/%" INT64_MODIFIER "x) -> %d" ,
381
+ gid , replication_node , event ,
382
+ spvector [origin_node - 1 ].origin_lsn , origin_node , tx_lsn , found );
386
383
387
384
return found ;
388
385
}
@@ -422,10 +419,10 @@ MtmEndSession(int nodeId, bool unlock)
422
419
static PGconn *
423
420
receiver_connect (char * conninfo )
424
421
{
425
- PGconn * conn ;
426
- ConnStatusType status ;
427
- const char * keys [] = {"dbname" , "replication" , NULL };
428
- const char * vals [] = {conninfo , "database" , NULL };
422
+ PGconn * conn ;
423
+ ConnStatusType status ;
424
+ const char * keys [] = {"dbname" , "replication" , NULL };
425
+ const char * vals [] = {conninfo , "database" , NULL };
429
426
430
427
conn = PQconnectdbParams (keys , vals , /* expand_dbname = */ true);
431
428
status = PQstatus (conn );
@@ -447,9 +444,9 @@ receiver_connect(char *conninfo)
447
444
void
448
445
MtmReceiverCreateSlot (char * conninfo , int my_node_id )
449
446
{
450
- StringInfoData cmd ;
451
- PGresult * res ;
452
- PGconn * conn = receiver_connect (conninfo );
447
+ StringInfoData cmd ;
448
+ PGresult * res ;
449
+ PGconn * conn = receiver_connect (conninfo );
453
450
454
451
if (!conn )
455
452
mtm_log (ERROR , "Could not connect to '%s'" , conninfo );
@@ -846,15 +843,11 @@ pglogical_receiver_main(Datum main_arg)
846
843
}
847
844
if (stmt [0 ] == 'Z' || (stmt [0 ] == 'M' && (stmt [1 ] == 'L' || stmt [1 ] == 'P' || stmt [1 ] == 'C' || stmt [1 ] == 'S' ))) {
848
845
if (stmt [0 ] == 'M' && stmt [1 ] == 'C' )
849
- {
850
846
/* concurrent DDL should be executed by parallel workers */
851
847
MtmExecute (stmt , msg_len , & receiver_ctx , false);
852
- }
853
848
else
854
- {
855
849
/* all other messages should be processed by receiver itself */
856
850
MtmExecute (stmt , msg_len , & receiver_ctx , true);
857
- }
858
851
}
859
852
else
860
853
{
@@ -877,7 +870,8 @@ pglogical_receiver_main(Datum main_arg)
877
870
else
878
871
MtmExecute (buf .data , buf .used , & receiver_ctx , false);
879
872
880
- } else if (spill_file >= 0 )
873
+ }
874
+ else if (spill_file >= 0 )
881
875
{
882
876
MtmCloseSpillFile (spill_file );
883
877
resetStringInfo (& spill_info );
@@ -899,16 +893,16 @@ pglogical_receiver_main(Datum main_arg)
899
893
* not more than the specified timeout, so that we can send a
900
894
* response back to the client.
901
895
*/
902
- int r ;
903
- fd_set input_mask ;
904
- int64 message_target = 0 ;
905
- int64 fsync_target = 0 ;
906
- struct timeval timeout ;
907
- struct timeval * timeoutptr = NULL ;
908
- int64 targettime ;
909
- long secs ;
910
- int usecs ;
911
- int64 now ;
896
+ int r ;
897
+ fd_set input_mask ;
898
+ int64 message_target = 0 ;
899
+ int64 fsync_target = 0 ;
900
+ struct timeval timeout ;
901
+ struct timeval * timeoutptr = NULL ;
902
+ int64 targettime ;
903
+ long secs ;
904
+ int usecs ;
905
+ int64 now ;
912
906
913
907
FD_ZERO (& input_mask );
914
908
FD_SET (PQsocket (conn ), & input_mask );
@@ -919,10 +913,7 @@ pglogical_receiver_main(Datum main_arg)
919
913
if (fsync_target > 0 && fsync_target < targettime )
920
914
targettime = fsync_target ;
921
915
now = feGetCurrentTimestamp ();
922
- feTimestampDifference (now ,
923
- targettime ,
924
- & secs ,
925
- & usecs );
916
+ feTimestampDifference (now , targettime , & secs , & usecs );
926
917
if (secs <= 0 )
927
918
timeout .tv_sec = 1 ; /* Always sleep at least 1 sec */
928
919
else
@@ -940,14 +931,13 @@ pglogical_receiver_main(Datum main_arg)
940
931
sendFeedback (conn , now , nodeId );
941
932
}
942
933
else if (r < 0 && errno == EINTR )
943
- {
944
934
/*
945
935
* Got a timeout or signal. Continue the loop and either
946
936
* deliver a status packet to the server or just go back into
947
937
* blocking.
948
938
*/
949
939
continue ;
950
- }
940
+
951
941
else if (r < 0 )
952
942
{
953
943
ereport (LOG , (MTM_ERRMSG ("%s: Incorrect status received." ,
@@ -1003,17 +993,16 @@ pglogical_receiver_main(Datum main_arg)
1003
993
BgwPoolCancel (& Mtm -> pools [nodeId - 1 ]);
1004
994
MtmSleep (RECEIVER_SUSPEND_TIMEOUT );
1005
995
}
1006
- // ByteBufferFree(&buf);
1007
- /* Never reach that point */
1008
996
997
+ /* Never reach that point */
1009
998
proc_exit (2 );
1010
999
}
1011
1000
1012
1001
BackgroundWorkerHandle *
1013
1002
MtmStartReceiver (int nodeId , Oid db_id , Oid user_id , pid_t monitor_pid )
1014
1003
{
1015
- BackgroundWorker worker ;
1016
- BackgroundWorkerHandle * handle ;
1004
+ BackgroundWorker worker ;
1005
+ BackgroundWorkerHandle * handle ;
1017
1006
1018
1007
MemSet (& worker , 0 , sizeof (BackgroundWorker ));
1019
1008
worker .bgw_flags = BGWORKER_SHMEM_ACCESS | BGWORKER_BACKEND_DATABASE_CONNECTION ;
0 commit comments