@@ -121,7 +121,7 @@ PG_FUNCTION_INFO_V1(mtm_get_trans_by_xid);
121121PG_FUNCTION_INFO_V1 (mtm_get_last_csn );
122122PG_FUNCTION_INFO_V1 (mtm_get_nodes_state );
123123PG_FUNCTION_INFO_V1 (mtm_get_cluster_state );
124- PG_FUNCTION_INFO_V1 (mtm_get_cluster_info );
124+ PG_FUNCTION_INFO_V1 (mtm_collect_cluster_info );
125125PG_FUNCTION_INFO_V1 (mtm_make_table_local );
126126PG_FUNCTION_INFO_V1 (mtm_dump_lock_graph );
127127PG_FUNCTION_INFO_V1 (mtm_inject_2pc_error );
@@ -4096,25 +4096,26 @@ mtm_get_cluster_state(PG_FUNCTION_ARGS)
40964096bool nulls [Natts_mtm_cluster_state ]= {false};
40974097get_call_result_type (fcinfo ,NULL ,& desc );
40984098
4099- values [0 ]= CStringGetTextDatum (MtmNodeStatusMnem [Mtm -> status ]);
4100- values [1 ]= Int64GetDatum (Mtm -> disabledNodeMask );
4101- values [2 ]= Int64GetDatum (SELF_CONNECTIVITY_MASK );
4102- values [3 ]= Int64GetDatum (Mtm -> nodeLockerMask );
4103- values [4 ]= Int32GetDatum (Mtm -> nLiveNodes );
4104- values [5 ]= Int32GetDatum (Mtm -> nAllNodes );
4105- values [6 ]= Int32GetDatum ((int )Mtm -> pool .active );
4106- values [7 ]= Int32GetDatum ((int )Mtm -> pool .pending );
4107- values [8 ]= Int64GetDatum (BgwPoolGetQueueSize (& Mtm -> pool ));
4108- values [9 ]= Int64GetDatum (Mtm -> transCount );
4109- values [10 ]= Int64GetDatum (Mtm -> timeShift );
4110- values [11 ]= Int32GetDatum (Mtm -> recoverySlot );
4111- values [12 ]= Int64GetDatum (hash_get_num_entries (MtmXid2State ));
4112- values [13 ]= Int64GetDatum (hash_get_num_entries (MtmGid2State ));
4113- values [14 ]= Int64GetDatum (Mtm -> oldestXid );
4114- values [15 ]= Int32GetDatum (Mtm -> nConfigChanges );
4115- values [16 ]= Int64GetDatum (Mtm -> stalledNodeMask );
4116- values [17 ]= Int64GetDatum (Mtm -> stoppedNodeMask );
4117- values [18 ]= TimestampTzGetDatum (time_t_to_timestamptz (Mtm -> nodes [MtmNodeId - 1 ].lastStatusChangeTime /USECS_PER_SEC ));
4099+ values [0 ]= Int32GetDatum (MtmNodeId );
4100+ values [1 ]= CStringGetTextDatum (MtmNodeStatusMnem [Mtm -> status ]);
4101+ values [2 ]= Int64GetDatum (Mtm -> disabledNodeMask );
4102+ values [3 ]= Int64GetDatum (SELF_CONNECTIVITY_MASK );
4103+ values [4 ]= Int64GetDatum (Mtm -> nodeLockerMask );
4104+ values [5 ]= Int32GetDatum (Mtm -> nLiveNodes );
4105+ values [6 ]= Int32GetDatum (Mtm -> nAllNodes );
4106+ values [7 ]= Int32GetDatum ((int )Mtm -> pool .active );
4107+ values [8 ]= Int32GetDatum ((int )Mtm -> pool .pending );
4108+ values [9 ]= Int64GetDatum (BgwPoolGetQueueSize (& Mtm -> pool ));
4109+ values [10 ]= Int64GetDatum (Mtm -> transCount );
4110+ values [11 ]= Int64GetDatum (Mtm -> timeShift );
4111+ values [12 ]= Int32GetDatum (Mtm -> recoverySlot );
4112+ values [13 ]= Int64GetDatum (hash_get_num_entries (MtmXid2State ));
4113+ values [14 ]= Int64GetDatum (hash_get_num_entries (MtmGid2State ));
4114+ values [15 ]= Int64GetDatum (Mtm -> oldestXid );
4115+ values [16 ]= Int32GetDatum (Mtm -> nConfigChanges );
4116+ values [17 ]= Int64GetDatum (Mtm -> stalledNodeMask );
4117+ values [18 ]= Int64GetDatum (Mtm -> stoppedNodeMask );
4118+ values [19 ]= TimestampTzGetDatum (time_t_to_timestamptz (Mtm -> nodes [MtmNodeId - 1 ].lastStatusChangeTime /USECS_PER_SEC ));
41184119
41194120PG_RETURN_DATUM (HeapTupleGetDatum (heap_form_tuple (desc ,values ,nulls )));
41204121}
@@ -4152,7 +4153,7 @@ PGconn *PQconnectdb_safe(const char *conninfo)
41524153}
41534154
41544155Datum
4155- mtm_get_cluster_info (PG_FUNCTION_ARGS )
4156+ mtm_collect_cluster_info (PG_FUNCTION_ARGS )
41564157{
41574158
41584159FuncCallContext * funcctx ;
@@ -4182,23 +4183,30 @@ mtm_get_cluster_info(PG_FUNCTION_ARGS)
41824183if (usrfctx -> nodeId > Mtm -> nAllNodes ) {
41834184SRF_RETURN_DONE (funcctx );
41844185}
4186+
41854187conn = PQconnectdb_safe (Mtm -> nodes [usrfctx -> nodeId - 1 ].con .connStr );
4186- if (PQstatus (conn )!= CONNECTION_OK ) {
4187- MTM_ELOG (ERROR ,"Failed to establish connection '%s' to node %d: error = %s" ,Mtm -> nodes [usrfctx -> nodeId - 1 ].con .connStr ,usrfctx -> nodeId ,PQerrorMessage (conn ));
4188+ if (PQstatus (conn )!= CONNECTION_OK )
4189+ {
4190+ MTM_ELOG (WARNING ,"Failed to establish connection '%s' to node %d: error = %s" ,Mtm -> nodes [usrfctx -> nodeId - 1 ].con .connStr ,usrfctx -> nodeId ,PQerrorMessage (conn ));
4191+ PQfinish (conn );
4192+ SRF_RETURN_NEXT_NULL (funcctx );
41884193}
4189- result = PQexec (conn ,"select * from mtm.get_cluster_state()" );
4194+ else
4195+ {
4196+ result = PQexec (conn ,"select * from mtm.get_cluster_state()" );
41904197
4191- if (PQresultStatus (result )!= PGRES_TUPLES_OK || PQntuples (result )!= 1 ) {
4192- MTM_ELOG (ERROR ,"Failed to receive data from %d" ,usrfctx -> nodeId );
4193- }
4198+ if (PQresultStatus (result )!= PGRES_TUPLES_OK || PQntuples (result )!= 1 ) {
4199+ MTM_ELOG (ERROR ,"Failed to receive data from %d" ,usrfctx -> nodeId );
4200+ }
41944201
4195- for (i = 0 ;i < Natts_mtm_cluster_state ;i ++ ) {
4196- values [i ]= PQgetvalue (result ,0 ,i );
4202+ for (i = 0 ;i < Natts_mtm_cluster_state ;i ++ ) {
4203+ values [i ]= PQgetvalue (result ,0 ,i );
4204+ }
4205+ tuple = BuildTupleFromCStrings (funcctx -> attinmeta ,values );
4206+ PQclear (result );
4207+ PQfinish (conn );
4208+ SRF_RETURN_NEXT (funcctx ,HeapTupleGetDatum (tuple ));
41974209}
4198- tuple = BuildTupleFromCStrings (funcctx -> attinmeta ,values );
4199- PQclear (result );
4200- PQfinish (conn );
4201- SRF_RETURN_NEXT (funcctx ,HeapTupleGetDatum (tuple ));
42024210}
42034211
42044212