Replace magic number with defined constant

And use it to restrict the number of rows retrieved to avoid
overflowing the array.
This commit is contained in:
Ian Barwick
2015-01-08 17:19:02 +09:00
parent 7bafd490c1
commit acf2744ed7
2 changed files with 6 additions and 4 deletions

View File

@@ -46,6 +46,8 @@
#define DEFAULT_DBNAME "postgres" #define DEFAULT_DBNAME "postgres"
#define DEFAULT_REPMGR_SCHEMA_PREFIX "repmgr_" #define DEFAULT_REPMGR_SCHEMA_PREFIX "repmgr_"
#define FAILOVER_NODES_MAX_CHECK 50
#define MANUAL_FAILOVER 0 #define MANUAL_FAILOVER 0
#define AUTOMATIC_FAILOVER 1 #define AUTOMATIC_FAILOVER 1

View File

@@ -275,7 +275,7 @@ main(int argc, char **argv)
/* /*
* MAIN LOOP This loops cicles once per failover and at startup * MAIN LOOP This loops cycles at startup and once per failover and
* Requisites: - my_local_conn needs to be already setted with an active * Requisites: - my_local_conn needs to be already setted with an active
* connection - no master connection * connection - no master connection
*/ */
@@ -782,7 +782,7 @@ do_failover(void)
* will get info about until 50 nodes, which seems to be large enough for * will get info about until 50 nodes, which seems to be large enough for
* most scenarios * most scenarios
*/ */
t_node_info nodes[50]; t_node_info nodes[FAILOVER_NODES_MAX_CHECK];
/* initialize to keep compiler quiet */ /* initialize to keep compiler quiet */
t_node_info best_candidate = {-1, "", InvalidXLogRecPtr, false, false, false}; t_node_info best_candidate = {-1, "", InvalidXLogRecPtr, false, false, false};
@@ -791,8 +791,8 @@ do_failover(void)
sprintf(sqlquery, "SELECT id, conninfo, witness " sprintf(sqlquery, "SELECT id, conninfo, witness "
" FROM %s.repl_nodes " " FROM %s.repl_nodes "
" WHERE cluster = '%s' " " WHERE cluster = '%s' "
" ORDER BY priority, id ", " ORDER BY priority, id LIMIT %i",
repmgr_schema, local_options.cluster_name); repmgr_schema, local_options.cluster_name, FAILOVER_NODES_MAX_CHECK);
res = PQexec(my_local_conn, sqlquery); res = PQexec(my_local_conn, sqlquery);
if (PQresultStatus(res) != PGRES_TUPLES_OK) if (PQresultStatus(res) != PGRES_TUPLES_OK)