Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ced7603

Browse files
committed
mtm.collect_cluster_info(): do not refuse to show info when there are some disabled nodes
1 parent cf55766 commit ced7603

File tree

3 files changed

+45
-37
lines changed

3 files changed

+45
-37
lines changed

multimaster--1.0.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ CREATE FUNCTION mtm.get_nodes_state() RETURNS SETOF mtm.node_state
4141
AS 'MODULE_PATHNAME','mtm_get_nodes_state'
4242
LANGUAGE C;
4343

44-
CREATE TYPE mtm.cluster_state AS ("status" text, "disabledNodeMask" bigint, "disconnectedNodeMask" bigint, "catchUpNodeMask" bigint, "liveNodes" integer, "allNodes" integer, "nActiveQueries" integer, "nPendingQueries" integer, "queueSize" bigint, "transCount" bigint, "timeShift" bigint, "recoverySlot" integer,
44+
CREATE TYPE mtm.cluster_state AS ("id" integer, "status" text, "disabledNodeMask" bigint, "disconnectedNodeMask" bigint, "catchUpNodeMask" bigint, "liveNodes" integer, "allNodes" integer, "nActiveQueries" integer, "nPendingQueries" integer, "queueSize" bigint, "transCount" bigint, "timeShift" bigint, "recoverySlot" integer,
4545
"xidHashSize" bigint, "gidHashSize" bigint, "oldestXid" bigint, "configChanges" integer, "stalledNodeMask" bigint, "stoppedNodeMask" bigint, "lastStatusChange" timestamp);
4646

4747
CREATE TYPE mtm.trans_state AS ("status" text, "gid" text, "xid" bigint, "coordinator" integer, "gxid" bigint, "csn" timestamp, "snapshot" timestamp, "local" boolean, "prepared" boolean, "active" boolean, "twophase" boolean, "votingCompleted" boolean, "participants" bigint, "voted" bigint, "configChanges" integer);
@@ -58,8 +58,8 @@ CREATE FUNCTION mtm.get_cluster_state() RETURNS mtm.cluster_state
5858
AS 'MODULE_PATHNAME','mtm_get_cluster_state'
5959
LANGUAGE C;
6060

61-
CREATE FUNCTION mtm.get_cluster_info() RETURNS SETOF mtm.cluster_state
62-
AS 'MODULE_PATHNAME','mtm_get_cluster_info'
61+
CREATE FUNCTION mtm.collect_cluster_info() RETURNS SETOF mtm.cluster_state
62+
AS 'MODULE_PATHNAME','mtm_collect_cluster_info'
6363
LANGUAGE C;
6464

6565
CREATE FUNCTION mtm.make_table_local(relation regclass) RETURNS void

multimaster.c

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ PG_FUNCTION_INFO_V1(mtm_get_trans_by_xid);
121121
PG_FUNCTION_INFO_V1(mtm_get_last_csn);
122122
PG_FUNCTION_INFO_V1(mtm_get_nodes_state);
123123
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);
125125
PG_FUNCTION_INFO_V1(mtm_make_table_local);
126126
PG_FUNCTION_INFO_V1(mtm_dump_lock_graph);
127127
PG_FUNCTION_INFO_V1(mtm_inject_2pc_error);
@@ -4096,25 +4096,26 @@ mtm_get_cluster_state(PG_FUNCTION_ARGS)
40964096
bool nulls[Natts_mtm_cluster_state] = {false};
40974097
get_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

41194120
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(desc, values, nulls)));
41204121
}
@@ -4152,7 +4153,7 @@ PGconn *PQconnectdb_safe(const char *conninfo)
41524153
}
41534154

41544155
Datum
4155-
mtm_get_cluster_info(PG_FUNCTION_ARGS)
4156+
mtm_collect_cluster_info(PG_FUNCTION_ARGS)
41564157
{
41574158

41584159
FuncCallContext* funcctx;
@@ -4182,23 +4183,30 @@ mtm_get_cluster_info(PG_FUNCTION_ARGS)
41824183
if (usrfctx->nodeId > Mtm->nAllNodes) {
41834184
SRF_RETURN_DONE(funcctx);
41844185
}
4186+
41854187
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);
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

multimaster.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585

8686
#define Natts_mtm_trans_state 15
8787
#define Natts_mtm_nodes_state 17
88-
#define Natts_mtm_cluster_state 19
88+
#define Natts_mtm_cluster_state 20
8989

9090
typedef ulong64 csn_t; /* commit serial number */
9191
#define INVALID_CSN ((csn_t)-1)

0 commit comments

Comments
 (0)