@@ -121,7 +121,7 @@ PG_FUNCTION_INFO_V1(mtm_get_trans_by_xid);
121
121
PG_FUNCTION_INFO_V1 (mtm_get_last_csn );
122
122
PG_FUNCTION_INFO_V1 (mtm_get_nodes_state );
123
123
PG_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 );
125
125
PG_FUNCTION_INFO_V1 (mtm_make_table_local );
126
126
PG_FUNCTION_INFO_V1 (mtm_dump_lock_graph );
127
127
PG_FUNCTION_INFO_V1 (mtm_inject_2pc_error );
@@ -4096,25 +4096,26 @@ mtm_get_cluster_state(PG_FUNCTION_ARGS)
4096
4096
bool nulls [Natts_mtm_cluster_state ] = {false};
4097
4097
get_call_result_type (fcinfo , NULL , & desc );
4098
4098
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 ));
4118
4119
4119
4120
PG_RETURN_DATUM (HeapTupleGetDatum (heap_form_tuple (desc , values , nulls )));
4120
4121
}
@@ -4152,7 +4153,7 @@ PGconn *PQconnectdb_safe(const char *conninfo)
4152
4153
}
4153
4154
4154
4155
Datum
4155
- mtm_get_cluster_info (PG_FUNCTION_ARGS )
4156
+ mtm_collect_cluster_info (PG_FUNCTION_ARGS )
4156
4157
{
4157
4158
4158
4159
FuncCallContext * funcctx ;
@@ -4182,23 +4183,30 @@ mtm_get_cluster_info(PG_FUNCTION_ARGS)
4182
4183
if (usrfctx -> nodeId > Mtm -> nAllNodes ) {
4183
4184
SRF_RETURN_DONE (funcctx );
4184
4185
}
4186
+
4185
4187
conn = 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 );
4188
4193
}
4189
- result = PQexec (conn , "select * from mtm.get_cluster_state()" );
4194
+ else
4195
+ {
4196
+ result = PQexec (conn , "select * from mtm.get_cluster_state()" );
4190
4197
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
+ }
4194
4201
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 ));
4197
4209
}
4198
- tuple = BuildTupleFromCStrings (funcctx -> attinmeta , values );
4199
- PQclear (result );
4200
- PQfinish (conn );
4201
- SRF_RETURN_NEXT (funcctx , HeapTupleGetDatum (tuple ));
4202
4210
}
4203
4211
4204
4212
0 commit comments