@@ -1859,8 +1859,6 @@ void MtmUpdateNodeConnectionInfo(MtmConnectionInfo* conn, char const* connStr)
1859
1859
elog (ERROR , "Invalid raftable port: %s" , port + 9 );
1860
1860
}
1861
1861
n += 9 ;
1862
- memmove (port , port + n , connStrLen - n + 1 );
1863
- connStrLen -= n ;
1864
1862
} else {
1865
1863
conn -> raftablePort = 0 ;
1866
1864
}
@@ -1872,8 +1870,6 @@ void MtmUpdateNodeConnectionInfo(MtmConnectionInfo* conn, char const* connStr)
1872
1870
elog (ERROR , "Invalid arbiter port: %s" , port + 12 );
1873
1871
}
1874
1872
n += 12 ;
1875
- memmove (port , port + n , connStrLen - n + 1 );
1876
- connStrLen -= n ;
1877
1873
} else {
1878
1874
conn -> arbiterPort = 0 ;
1879
1875
}
@@ -2796,6 +2792,32 @@ typedef struct
2796
2792
int nodeId ;
2797
2793
} MtmGetClusterInfoCtx ;
2798
2794
2795
+ static void erase_option_from_connstr (const char * option , char * connstr )
2796
+ {
2797
+ char * needle = psprintf ("%s=" , option );
2798
+ while (1 ) {
2799
+ char * found = strstr (connstr , needle );
2800
+ if (found == NULL ) break ;
2801
+ while (* found != '\0' && * found != ' ' ) {
2802
+ * found = ' ' ;
2803
+ found ++ ;
2804
+ }
2805
+ }
2806
+ pfree (needle );
2807
+ }
2808
+
2809
+ PGconn * PQconnectdb_safe (const char * conninfo )
2810
+ {
2811
+ PGconn * conn ;
2812
+ char * safe_connstr = pstrdup (conninfo );
2813
+ erase_option_from_connstr ("raftport" , safe_connstr );
2814
+ erase_option_from_connstr ("arbiterport" , safe_connstr );
2815
+
2816
+ conn = PQconnectdb (safe_connstr );
2817
+
2818
+ pfree (safe_connstr );
2819
+ return conn ;
2820
+ }
2799
2821
2800
2822
Datum
2801
2823
mtm_get_cluster_info (PG_FUNCTION_ARGS )
@@ -2828,9 +2850,9 @@ mtm_get_cluster_info(PG_FUNCTION_ARGS)
2828
2850
if (usrfctx -> nodeId > Mtm -> nAllNodes ) {
2829
2851
SRF_RETURN_DONE (funcctx );
2830
2852
}
2831
- conn = PQconnectdb (Mtm -> nodes [usrfctx -> nodeId - 1 ].con .connStr );
2853
+ conn = PQconnectdb_safe (Mtm -> nodes [usrfctx -> nodeId - 1 ].con .connStr );
2832
2854
if (PQstatus (conn ) != CONNECTION_OK ) {
2833
- elog (ERROR , "Failed to establish connection '%s' to node %d" , Mtm -> nodes [usrfctx -> nodeId - 1 ].con .connStr , usrfctx -> nodeId );
2855
+ elog (ERROR , "Failed to establish connection '%s' to node %d: error = %s " , Mtm -> nodes [usrfctx -> nodeId - 1 ].con .connStr , usrfctx -> nodeId , PQerrorMessage ( conn ) );
2834
2856
}
2835
2857
result = PQexec (conn , "select * from mtm.get_cluster_state()" );
2836
2858
@@ -3004,7 +3026,7 @@ static void MtmBroadcastUtilityStmt(char const* sql, bool ignoreError)
3004
3026
{
3005
3027
if (!BIT_CHECK (disabledNodeMask , i ))
3006
3028
{
3007
- conns [i ] = PQconnectdb (psprintf ("%s application_name=%s" , Mtm -> nodes [i ].con .connStr , MULTIMASTER_BROADCAST_SERVICE ));
3029
+ conns [i ] = PQconnectdb_safe (psprintf ("%s application_name=%s" , Mtm -> nodes [i ].con .connStr , MULTIMASTER_BROADCAST_SERVICE ));
3008
3030
if (PQstatus (conns [i ]) != CONNECTION_OK )
3009
3031
{
3010
3032
if (ignoreError )
@@ -3016,7 +3038,7 @@ static void MtmBroadcastUtilityStmt(char const* sql, bool ignoreError)
3016
3038
do {
3017
3039
PQfinish (conns [i ]);
3018
3040
} while (-- i >= 0 );
3019
- elog (ERROR , "Failed to establish connection '%s' to node %d" , Mtm -> nodes [failedNode ].con .connStr , failedNode + 1 );
3041
+ elog (ERROR , "Failed to establish connection '%s' to node %d, error = %s " , Mtm -> nodes [failedNode ].con .connStr , failedNode + 1 , PQerrorMessage ( conns [ i ]) );
3020
3042
}
3021
3043
}
3022
3044
PQsetNoticeReceiver (conns [i ], MtmNoticeReceiver , & i );
0 commit comments