Whitespace to adjust for longer snprintf identifier

This is done in a separate patch to try and reduce the sound and fury
of the patch that actually did the conversion from sprintf to
snprintf-alikes.

Signed-off-by: Dan Farina <drfarina@acm.org>
Signed-off-by: Peter van Hardenberg <pvh@heroku.com>
This commit is contained in:
Dan Farina
2010-12-07 21:37:56 -08:00
committed by Peter van Hardenberg
parent 916c0492fb
commit 84b69b3bd4
4 changed files with 85 additions and 68 deletions

View File

@@ -43,7 +43,7 @@ parse_config(const char *config_file, char *cluster_name, int *node,
strncpy (conninfo, value, MAXLEN); strncpy (conninfo, value, MAXLEN);
else else
printf("WARNING: %s/%s: Unknown name/value pair!\n", printf("WARNING: %s/%s: Unknown name/value pair!\n",
name, value); name, value);
} }
/* Close file */ /* Close file */

View File

@@ -116,8 +116,8 @@ guc_setted(PGconn *conn, const char *parameter, const char *op,
char sqlquery[QUERY_STR_LEN]; char sqlquery[QUERY_STR_LEN];
sqlquery_snprintf(sqlquery, "SELECT true FROM pg_settings " sqlquery_snprintf(sqlquery, "SELECT true FROM pg_settings "
" WHERE name = '%s' AND setting %s '%s'", " WHERE name = '%s' AND setting %s '%s'",
parameter, op, value); parameter, op, value);
res = PQexec(conn, sqlquery); res = PQexec(conn, sqlquery);
if (PQresultStatus(res) != PGRES_TUPLES_OK) if (PQresultStatus(res) != PGRES_TUPLES_OK)
@@ -145,9 +145,10 @@ get_cluster_size(PGconn *conn)
const char *size; const char *size;
char sqlquery[QUERY_STR_LEN]; char sqlquery[QUERY_STR_LEN];
sqlquery_snprintf(sqlquery, sqlquery_snprintf(
"SELECT pg_size_pretty(SUM(pg_database_size(oid))::bigint) " sqlquery,
" FROM pg_database "); "SELECT pg_size_pretty(SUM(pg_database_size(oid))::bigint) "
" FROM pg_database ");
res = PQexec(conn, sqlquery); res = PQexec(conn, sqlquery);
if (PQresultStatus(res) != PGRES_TUPLES_OK) if (PQresultStatus(res) != PGRES_TUPLES_OK)
@@ -179,8 +180,8 @@ getMasterConnection(PGconn *standby_conn, int id, char *cluster,
/* find all nodes belonging to this cluster */ /* find all nodes belonging to this cluster */
sqlquery_snprintf(sqlquery, "SELECT * FROM repmgr_%s.repl_nodes " sqlquery_snprintf(sqlquery, "SELECT * FROM repmgr_%s.repl_nodes "
" WHERE cluster = '%s' and id <> %d", " WHERE cluster = '%s' and id <> %d",
cluster, cluster, id); cluster, cluster, id);
res1 = PQexec(standby_conn, sqlquery); res1 = PQexec(standby_conn, sqlquery);
if (PQresultStatus(res1) != PGRES_TUPLES_OK) if (PQresultStatus(res1) != PGRES_TUPLES_OK)

View File

@@ -335,7 +335,7 @@ do_master_register(void)
/* Check if there is a schema for this cluster */ /* Check if there is a schema for this cluster */
sqlquery_snprintf(sqlquery, sqlquery_snprintf(sqlquery,
"SELECT 1 FROM pg_namespace WHERE nspname = 'repmgr_%s'", "SELECT 1 FROM pg_namespace WHERE nspname = 'repmgr_%s'",
myClusterName); myClusterName);
res = PQexec(conn, sqlquery); res = PQexec(conn, sqlquery);
if (PQresultStatus(res) != PGRES_TUPLES_OK) if (PQresultStatus(res) != PGRES_TUPLES_OK)
{ {
@@ -373,9 +373,9 @@ do_master_register(void)
/* ... the tables */ /* ... the tables */
sqlquery_snprintf(sqlquery, "CREATE TABLE repmgr_%s.repl_nodes ( " sqlquery_snprintf(sqlquery, "CREATE TABLE repmgr_%s.repl_nodes ( "
" id integer primary key, " " id integer primary key, "
" cluster text not null, " " cluster text not null, "
" conninfo text not null)", myClusterName); " conninfo text not null)", myClusterName);
if (!PQexec(conn, sqlquery)) if (!PQexec(conn, sqlquery))
{ {
fprintf(stderr, fprintf(stderr,
@@ -386,14 +386,14 @@ do_master_register(void)
} }
sqlquery_snprintf(sqlquery, "CREATE TABLE repmgr_%s.repl_monitor ( " sqlquery_snprintf(sqlquery, "CREATE TABLE repmgr_%s.repl_monitor ( "
" primary_node INTEGER NOT NULL, " " primary_node INTEGER NOT NULL, "
" standby_node INTEGER NOT NULL, " " standby_node INTEGER NOT NULL, "
" last_monitor_time TIMESTAMP WITH TIME ZONE NOT NULL, " " last_monitor_time TIMESTAMP WITH TIME ZONE NOT NULL, "
" last_wal_primary_location TEXT NOT NULL, " " last_wal_primary_location TEXT NOT NULL, "
" last_wal_standby_location TEXT NOT NULL, " " last_wal_standby_location TEXT NOT NULL, "
" replication_lag BIGINT NOT NULL, " " replication_lag BIGINT NOT NULL, "
" apply_lag BIGINT NOT NULL) ", " apply_lag BIGINT NOT NULL) ",
myClusterName); myClusterName);
if (!PQexec(conn, sqlquery)) if (!PQexec(conn, sqlquery))
{ {
fprintf(stderr, fprintf(stderr,
@@ -405,14 +405,14 @@ do_master_register(void)
/* and the view */ /* and the view */
sqlquery_snprintf(sqlquery, "CREATE VIEW repmgr_%s.repl_status AS " sqlquery_snprintf(sqlquery, "CREATE VIEW repmgr_%s.repl_status AS "
" WITH monitor_info AS (SELECT *, ROW_NUMBER() OVER (PARTITION BY primary_node, standby_node " " WITH monitor_info AS (SELECT *, ROW_NUMBER() OVER (PARTITION BY primary_node, standby_node "
" ORDER BY last_monitor_time desc) " " ORDER BY last_monitor_time desc) "
" FROM repmgr_%s.repl_monitor) " " FROM repmgr_%s.repl_monitor) "
" SELECT primary_node, standby_node, last_monitor_time, last_wal_primary_location, " " SELECT primary_node, standby_node, last_monitor_time, last_wal_primary_location, "
" last_wal_standby_location, pg_size_pretty(replication_lag) replication_lag, " " last_wal_standby_location, pg_size_pretty(replication_lag) replication_lag, "
" pg_size_pretty(apply_lag) apply_lag, age(now(), last_monitor_time) AS time_lag " " pg_size_pretty(apply_lag) apply_lag, age(now(), last_monitor_time) AS time_lag "
" FROM monitor_info a " " FROM monitor_info a "
" WHERE row_number = 1", myClusterName, myClusterName); " WHERE row_number = 1", myClusterName, myClusterName);
if (!PQexec(conn, sqlquery)) if (!PQexec(conn, sqlquery))
{ {
fprintf(stderr, fprintf(stderr,
@@ -441,8 +441,8 @@ do_master_register(void)
if (force) if (force)
{ {
sqlquery_snprintf(sqlquery, "DELETE FROM repmgr_%s.repl_nodes " sqlquery_snprintf(sqlquery, "DELETE FROM repmgr_%s.repl_nodes "
" WHERE id = %d", " WHERE id = %d",
myClusterName, myLocalId); myClusterName, myLocalId);
if (!PQexec(conn, sqlquery)) if (!PQexec(conn, sqlquery))
{ {
@@ -454,8 +454,8 @@ do_master_register(void)
} }
sqlquery_snprintf(sqlquery, "INSERT INTO repmgr_%s.repl_nodes " sqlquery_snprintf(sqlquery, "INSERT INTO repmgr_%s.repl_nodes "
"VALUES (%d, '%s', '%s')", "VALUES (%d, '%s', '%s')",
myClusterName, myLocalId, myClusterName, conninfo); myClusterName, myLocalId, myClusterName, conninfo);
if (!PQexec(conn, sqlquery)) if (!PQexec(conn, sqlquery))
{ {
@@ -519,8 +519,9 @@ do_standby_register(void)
} }
/* Check if there is a schema for this cluster */ /* Check if there is a schema for this cluster */
sqlquery_snprintf(sqlquery, "SELECT 1 FROM pg_namespace WHERE nspname = 'repmgr_%s'", sqlquery_snprintf(sqlquery,
myClusterName); "SELECT 1 FROM pg_namespace WHERE nspname = 'repmgr_%s'",
myClusterName);
res = PQexec(conn, sqlquery); res = PQexec(conn, sqlquery);
if (PQresultStatus(res) != PGRES_TUPLES_OK) if (PQresultStatus(res) != PGRES_TUPLES_OK)
{ {
@@ -572,8 +573,8 @@ do_standby_register(void)
if (force) if (force)
{ {
sqlquery_snprintf(sqlquery, "DELETE FROM repmgr_%s.repl_nodes " sqlquery_snprintf(sqlquery, "DELETE FROM repmgr_%s.repl_nodes "
" WHERE id = %d", " WHERE id = %d",
myClusterName, myLocalId); myClusterName, myLocalId);
if (!PQexec(master_conn, sqlquery)) if (!PQexec(master_conn, sqlquery))
{ {
@@ -586,8 +587,8 @@ do_standby_register(void)
} }
sqlquery_snprintf(sqlquery, "INSERT INTO repmgr_%s.repl_nodes " sqlquery_snprintf(sqlquery, "INSERT INTO repmgr_%s.repl_nodes "
"VALUES (%d, '%s', '%s')", "VALUES (%d, '%s', '%s')",
myClusterName, myLocalId, myClusterName, conninfo); myClusterName, myLocalId, myClusterName, conninfo);
if (!PQexec(master_conn, sqlquery)) if (!PQexec(master_conn, sqlquery))
{ {
@@ -748,8 +749,13 @@ do_standby_clone(void)
if (verbose) if (verbose)
printf(_("Succesfully connected to primary. Current installation size is %s\n"), get_cluster_size(conn)); printf(_("Succesfully connected to primary. Current installation size is %s\n"), get_cluster_size(conn));
/* Check if the tablespace locations exists and that we can write to them */ /*
sqlquery_snprintf(sqlquery, "select spclocation from pg_tablespace where spcname not in ('pg_default', 'pg_global')"); * Check if the tablespace locations exists and that we can write to them.
*/
sqlquery_snprintf(sqlquery,
"SELECT spclocation "
" FROM pg_tablespace "
"WHERE spcname NOT IN ('pg_default', 'pg_global')");
res = PQexec(conn, sqlquery); res = PQexec(conn, sqlquery);
if (PQresultStatus(res) != PGRES_TUPLES_OK) if (PQresultStatus(res) != PGRES_TUPLES_OK)
{ {
@@ -824,9 +830,12 @@ do_standby_clone(void)
fprintf(stderr, "Starting backup...\n"); fprintf(stderr, "Starting backup...\n");
/* Get the data directory full path and the configuration files location */ /* Get the data directory full path and the configuration files location */
sqlquery_snprintf(sqlquery, "SELECT name, setting " sqlquery_snprintf(
" FROM pg_settings " sqlquery,
" WHERE name IN ('data_directory', 'config_file', 'hba_file', 'ident_file')"); "SELECT name, setting "
" FROM pg_settings "
" WHERE name IN ('data_directory', 'config_file', 'hba_file', "
" 'ident_file')");
res = PQexec(conn, sqlquery); res = PQexec(conn, sqlquery);
if (PQresultStatus(res) != PGRES_TUPLES_OK) if (PQresultStatus(res) != PGRES_TUPLES_OK)
{ {
@@ -854,7 +863,10 @@ do_standby_clone(void)
* inform the master we will start a backup and get the first XLog filename * inform the master we will start a backup and get the first XLog filename
* so we can say to the user we need those files * so we can say to the user we need those files
*/ */
sqlquery_snprintf(sqlquery, "SELECT pg_xlogfile_name(pg_start_backup('repmgr_standby_clone_%ld'))", time(NULL)); sqlquery_snprintf(
sqlquery,
"SELECT pg_xlogfile_name(pg_start_backup('repmgr_standby_clone_%ld'))",
time(NULL));
res = PQexec(conn, sqlquery); res = PQexec(conn, sqlquery);
if (PQresultStatus(res) != PGRES_TUPLES_OK) if (PQresultStatus(res) != PGRES_TUPLES_OK)
{ {
@@ -906,7 +918,10 @@ do_standby_clone(void)
* find and appropiate rsync option but besides we could someday make all * find and appropiate rsync option but besides we could someday make all
* these rsync happen concurrently * these rsync happen concurrently
*/ */
sqlquery_snprintf(sqlquery, "select spclocation from pg_tablespace where spcname not in ('pg_default', 'pg_global')"); sqlquery_snprintf(sqlquery,
"SELECT spclocation "
" FROM pg_tablespace "
" WHERE spcname NOT IN ('pg_default', 'pg_global')");
res = PQexec(conn, sqlquery); res = PQexec(conn, sqlquery);
if (PQresultStatus(res) != PGRES_TUPLES_OK) if (PQresultStatus(res) != PGRES_TUPLES_OK)
{ {
@@ -1062,7 +1077,7 @@ do_standby_promote(void)
/* Get the data directory full path and the last subdirectory */ /* Get the data directory full path and the last subdirectory */
sqlquery_snprintf(sqlquery, "SELECT setting " sqlquery_snprintf(sqlquery, "SELECT setting "
" FROM pg_settings WHERE name = 'data_directory'"); " FROM pg_settings WHERE name = 'data_directory'");
res = PQexec(conn, sqlquery); res = PQexec(conn, sqlquery);
if (PQresultStatus(res) != PGRES_TUPLES_OK) if (PQresultStatus(res) != PGRES_TUPLES_OK)
{ {
@@ -1212,7 +1227,7 @@ do_standby_follow(void)
/* Get the data directory full path */ /* Get the data directory full path */
sqlquery_snprintf(sqlquery, "SELECT setting " sqlquery_snprintf(sqlquery, "SELECT setting "
" FROM pg_settings WHERE name = 'data_directory'"); " FROM pg_settings WHERE name = 'data_directory'");
res = PQexec(conn, sqlquery); res = PQexec(conn, sqlquery);
if (PQresultStatus(res) != PGRES_TUPLES_OK) if (PQresultStatus(res) != PGRES_TUPLES_OK)
{ {
@@ -1305,7 +1320,7 @@ create_recovery_file(const char *data_dir)
} }
maxlen_snprintf(line, "primary_conninfo = 'host=%s port=%s'\n", host, maxlen_snprintf(line, "primary_conninfo = 'host=%s port=%s'\n", host,
((masterport==NULL) ? "5432" : masterport)); ((masterport==NULL) ? "5432" : masterport));
if (fputs(line, recovery_file) == EOF) if (fputs(line, recovery_file) == EOF)
{ {
fprintf(stderr, "recovery file could not be written, it could be necesary to create it manually\n"); fprintf(stderr, "recovery file could not be written, it could be necesary to create it manually\n");
@@ -1348,7 +1363,7 @@ copy_remote_files(char *host, char *remote_user, char *remote_path,
strcat(options, strcat(options,
" --exclude=pg_xlog* --exclude=pg_control --exclude=*.pid"); " --exclude=pg_xlog* --exclude=pg_control --exclude=*.pid");
maxlen_snprintf(script, "rsync %s %s:%s/* %s", maxlen_snprintf(script, "rsync %s %s:%s/* %s",
options, host_string, remote_path, local_path); options, host_string, remote_path, local_path);
} }
else else
{ {

View File

@@ -61,7 +61,7 @@ static void setup_cancel_handler(void);
/* /*
* Every 3 seconds, insert monitor info * Every 3 seconds, insert monitor info
*/ */
#define MonitorCheck() \ #define MonitorCheck() \
for (;;) \ for (;;) \
{ \ { \
MonitorExecute(); \ MonitorExecute(); \
@@ -273,9 +273,10 @@ MonitorExecute(void)
CancelQuery(); CancelQuery();
/* Get local xlog info */ /* Get local xlog info */
sqlquery_snprintf(sqlquery, sqlquery_snprintf(
"SELECT CURRENT_TIMESTAMP, pg_last_xlog_receive_location(), " sqlquery,
"pg_last_xlog_replay_location()"); "SELECT CURRENT_TIMESTAMP, pg_last_xlog_receive_location(), "
"pg_last_xlog_replay_location()");
res = PQexec(myLocalConn, sqlquery); res = PQexec(myLocalConn, sqlquery);
if (PQresultStatus(res) != PGRES_TUPLES_OK) if (PQresultStatus(res) != PGRES_TUPLES_OK)
@@ -314,15 +315,15 @@ MonitorExecute(void)
* Build the SQL to execute on primary * Build the SQL to execute on primary
*/ */
sqlquery_snprintf(sqlquery, sqlquery_snprintf(sqlquery,
"INSERT INTO repmgr_%s.repl_monitor " "INSERT INTO repmgr_%s.repl_monitor "
"VALUES(%d, %d, '%s'::timestamp with time zone, " "VALUES(%d, %d, '%s'::timestamp with time zone, "
" '%s', '%s', " " '%s', '%s', "
" %lld, %lld)", myClusterName, " %lld, %lld)", myClusterName,
primaryId, myLocalId, monitor_standby_timestamp, primaryId, myLocalId, monitor_standby_timestamp,
last_wal_primary_location, last_wal_primary_location,
last_wal_standby_received, last_wal_standby_received,
(lsn_primary - lsn_standby_received), (lsn_primary - lsn_standby_received),
(lsn_standby_received - lsn_standby_applied)); (lsn_standby_received - lsn_standby_applied));
/* /*
* Execute the query asynchronously, but don't check for a result. We * Execute the query asynchronously, but don't check for a result. We
@@ -340,8 +341,8 @@ checkClusterConfiguration(void)
PGresult *res; PGresult *res;
sqlquery_snprintf(sqlquery, "SELECT oid FROM pg_class " sqlquery_snprintf(sqlquery, "SELECT oid FROM pg_class "
" WHERE oid = 'repmgr_%s.repl_nodes'::regclass", " WHERE oid = 'repmgr_%s.repl_nodes'::regclass",
myClusterName); myClusterName);
res = PQexec(myLocalConn, sqlquery); res = PQexec(myLocalConn, sqlquery);
if (PQresultStatus(res) != PGRES_TUPLES_OK) if (PQresultStatus(res) != PGRES_TUPLES_OK)
{ {
@@ -378,8 +379,8 @@ checkNodeConfiguration(char *conninfo)
/* Check if we have my node information in repl_nodes */ /* Check if we have my node information in repl_nodes */
sqlquery_snprintf(sqlquery, "SELECT * FROM repmgr_%s.repl_nodes " sqlquery_snprintf(sqlquery, "SELECT * FROM repmgr_%s.repl_nodes "
" WHERE id = %d AND cluster = '%s' ", " WHERE id = %d AND cluster = '%s' ",
myClusterName, myLocalId, myClusterName); myClusterName, myLocalId, myClusterName);
res = PQexec(myLocalConn, sqlquery); res = PQexec(myLocalConn, sqlquery);
if (PQresultStatus(res) != PGRES_TUPLES_OK) if (PQresultStatus(res) != PGRES_TUPLES_OK)
@@ -401,8 +402,8 @@ checkNodeConfiguration(char *conninfo)
/* Adding the node */ /* Adding the node */
sqlquery_snprintf(sqlquery, "INSERT INTO repmgr_%s.repl_nodes " sqlquery_snprintf(sqlquery, "INSERT INTO repmgr_%s.repl_nodes "
"VALUES (%d, '%s', '%s')", "VALUES (%d, '%s', '%s')",
myClusterName, myLocalId, myClusterName, conninfo); myClusterName, myLocalId, myClusterName, conninfo);
if (!PQexec(primaryConn, sqlquery)) if (!PQexec(primaryConn, sqlquery))
{ {