@@ -1850,8 +1850,6 @@ void MtmUpdateNodeConnectionInfo(MtmConnectionInfo* conn, char const* connStr)
1850
1850
elog (ERROR , "Invalid raftable port: %s" , port + 9 );
1851
1851
}
1852
1852
n += 9 ;
1853
- memmove (port , port + n , connStrLen - n + 1 );
1854
- connStrLen -= n ;
1855
1853
} else {
1856
1854
conn -> raftablePort = 0 ;
1857
1855
}
@@ -1863,8 +1861,6 @@ void MtmUpdateNodeConnectionInfo(MtmConnectionInfo* conn, char const* connStr)
1863
1861
elog (ERROR , "Invalid arbiter port: %s" , port + 12 );
1864
1862
}
1865
1863
n += 12 ;
1866
- memmove (port , port + n , connStrLen - n + 1 );
1867
- connStrLen -= n ;
1868
1864
} else {
1869
1865
conn -> arbiterPort = 0 ;
1870
1866
}
@@ -2787,6 +2783,32 @@ typedef struct
2787
2783
int nodeId ;
2788
2784
} MtmGetClusterInfoCtx ;
2789
2785
2786
+ static void erase_option_from_connstr (const char * option , char * connstr )
2787
+ {
2788
+ char * needle = psprintf ("%s=" , option );
2789
+ while (1 ) {
2790
+ char * found = strstr (connstr , needle );
2791
+ if (found == NULL ) break ;
2792
+ while (* found != '\0' && * found != ' ' ) {
2793
+ * found = ' ' ;
2794
+ found ++ ;
2795
+ }
2796
+ }
2797
+ pfree (needle );
2798
+ }
2799
+
2800
+ PGconn * PQconnectdb_safe (const char * conninfo )
2801
+ {
2802
+ PGconn * conn ;
2803
+ char * safe_connstr = pstrdup (conninfo );
2804
+ erase_option_from_connstr ("raftport" , safe_connstr );
2805
+ erase_option_from_connstr ("arbiterport" , safe_connstr );
2806
+
2807
+ conn = PQconnectdb (safe_connstr );
2808
+
2809
+ pfree (safe_connstr );
2810
+ return conn ;
2811
+ }
2790
2812
2791
2813
Datum
2792
2814
mtm_get_cluster_info (PG_FUNCTION_ARGS )
@@ -2819,9 +2841,9 @@ mtm_get_cluster_info(PG_FUNCTION_ARGS)
2819
2841
if (usrfctx -> nodeId > Mtm -> nAllNodes ) {
2820
2842
SRF_RETURN_DONE (funcctx );
2821
2843
}
2822
- conn = PQconnectdb (Mtm -> nodes [usrfctx -> nodeId - 1 ].con .connStr );
2844
+ conn = PQconnectdb_safe (Mtm -> nodes [usrfctx -> nodeId - 1 ].con .connStr );
2823
2845
if (PQstatus (conn ) != CONNECTION_OK ) {
2824
- elog (ERROR , "Failed to establish connection '%s' to node %d" , Mtm -> nodes [usrfctx -> nodeId - 1 ].con .connStr , usrfctx -> nodeId );
2846
+ elog (ERROR , "Failed to establish connection '%s' to node %d: error = %s " , Mtm -> nodes [usrfctx -> nodeId - 1 ].con .connStr , usrfctx -> nodeId , PQerrorMessage ( conn ) );
2825
2847
}
2826
2848
result = PQexec (conn , "select * from mtm.get_cluster_state()" );
2827
2849
@@ -2996,7 +3018,7 @@ static void MtmBroadcastUtilityStmt(char const* sql, bool ignoreError)
2996
3018
{
2997
3019
if (!BIT_CHECK (disabledNodeMask , i ))
2998
3020
{
2999
- conns [i ] = PQconnectdb (psprintf ("%s application_name=%s" , Mtm -> nodes [i ].con .connStr , MULTIMASTER_BROADCAST_SERVICE ));
3021
+ conns [i ] = PQconnectdb_safe (psprintf ("%s application_name=%s" , Mtm -> nodes [i ].con .connStr , MULTIMASTER_BROADCAST_SERVICE ));
3000
3022
if (PQstatus (conns [i ]) != CONNECTION_OK )
3001
3023
{
3002
3024
if (ignoreError )
@@ -3008,7 +3030,7 @@ static void MtmBroadcastUtilityStmt(char const* sql, bool ignoreError)
3008
3030
do {
3009
3031
PQfinish (conns [i ]);
3010
3032
} while (-- i >= 0 );
3011
- elog (ERROR , "Failed to establish connection '%s' to node %d" , Mtm -> nodes [failedNode ].con .connStr , failedNode + 1 );
3033
+ elog (ERROR , "Failed to establish connection '%s' to node %d, error = %s " , Mtm -> nodes [failedNode ].con .connStr , failedNode + 1 , PQerrorMessage ( conns [ i ]) );
3012
3034
}
3013
3035
}
3014
3036
PQsetNoticeReceiver (conns [i ], MtmNoticeReceiver , & i );
0 commit comments