Skip to content

Commit

Permalink
A few fixes after merge to unbroke what the merge broke, and to make
Browse files Browse the repository at this point in the history
the new logging system more consistent through the system
  • Loading branch information
Jaime Casanova authored and Jaime Casanova committed Mar 16, 2011
1 parent 7ff621b commit 788ff98
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 58 deletions.
1 change: 1 addition & 0 deletions check_dir.c
Expand Up @@ -105,6 +105,7 @@ create_directory(char *dir)
return false;
}


bool
set_directory_permissions(char *dir)
{
Expand Down
28 changes: 14 additions & 14 deletions config.c
Expand Up @@ -46,8 +46,8 @@ parse_config(const char *config_file, t_configuration_options *options)
*/
if (fp == NULL)
{
fprintf(stderr, _("Did not find the configuration file '%s', continuing\n"), config_file);
return;
log_err(_("Did not find the configuration file '%s', continuing\n"), config_file);
exit(ERR_BAD_CONFIG);
}

/* Read next line */
Expand Down Expand Up @@ -84,7 +84,7 @@ parse_config(const char *config_file, t_configuration_options *options)
*failover = AUTOMATIC_FAILOVER;
else
{
printf ("WARNING: value for failover option is incorrect, it should be automatic or manual. Defaulting to manual.\n");
log_warning(_("value for failover option is incorrect, it should be automatic or manual. Defaulting to manual.\n"));
options->failover = MANUAL_FAILOVER;
}
}
Expand All @@ -95,7 +95,7 @@ parse_config(const char *config_file, t_configuration_options *options)
else if (strcmp(name, "follow_command") == 0)
strncpy(options->follow_command, value, MAXLEN);
else
printf ("WARNING: %s/%s: Unknown name/value pair!\n", name, value);
log_warning(_("%s/%s: Unknown name/value pair!\n", name, value));
}

/* Close file */
Expand All @@ -104,19 +104,18 @@ parse_config(const char *config_file, t_configuration_options *options)
/* Check config settings */
if (strnlen(options->cluster_name, MAXLEN)==0)
{
fprintf(stderr, "Cluster name is missing. "
"Check the configuration file.\n");
log_err(_("Cluster name is missing. Check the configuration file.\n"));
exit(ERR_BAD_CONFIG);
}

if (options->node == -1)
{
fprintf(stderr, "Node information is missing. "
"Check the configuration file.\n");
log_err(_("Node information is missing. Check the configuration file.\n"));
exit(ERR_BAD_CONFIG);
}
}


char *
trim (char *s)
{
Expand All @@ -137,6 +136,7 @@ trim (char *s)
return s;
}


void
parse_line(char *buff, char *name, char *value)
{
Expand Down Expand Up @@ -180,37 +180,37 @@ bool reload_configuration(char *config_file, t_configuration_options *orig_optio
/*
* Re-read the configuration file: repmgr.conf
*/
fprintf(stderr, "Reloading configuration file and updating repmgr tables\n");
log_info(_("Reloading configuration file and updating repmgr tables\n"));
parse_config(config_file, &new_options);
if (new_options.node == -1)
{
fprintf(stderr, "\nCannot load new configuration, will keep current one.\n");
log_warning(_("\nCannot load new configuration, will keep current one.\n"));
return false;
}

if (strcmp(new_options.cluster_name, orig_options->cluster_name) != 0)
{
fprintf(stderr, "\nCannot change cluster name, will keep current configuration.\n");
log_warning(_("\nCannot change cluster name, will keep current configuration.\n"));
return false;
}

if (new_options.node != orig_options->node)
{
fprintf(stderr, "\nCannot change node number, will keep current configuration.\n");
log_warning(_("\nCannot change node number, will keep current configuration.\n"));
return false;
}

if (new_options.failover != MANUAL_FAILOVER && new_options.failover != AUTOMATIC_FAILOVER)
{
fprintf(stderr, "\nNew value for failover is not valid. Should be manual or automatic.\n");
log_warning(_("\nNew value for failover is not valid. Should be manual or automatic.\n"));
return false;
}

/* Test conninfo string */
conn = establishDBConnection(new_options.conninfo, false);
if (!conn || (PQstatus(conn) != CONNECTION_OK))
{
fprintf(stderr, "\nconninfo string is not valid, will keep current configuration.\n");
log_warning(_("\nconninfo string is not valid, will keep current configuration.\n"));
return false;
}
PQfinish(conn);
Expand Down
1 change: 1 addition & 0 deletions config.h
Expand Up @@ -41,4 +41,5 @@ void parse_config(const char *config_file, t_configuration_options *options);
void parse_line(char *buff, char *name, char *value);
char *trim(char *s);
bool reload_configuration(char *config_file, t_configuration_options *orig_options);

#endif
24 changes: 11 additions & 13 deletions dbutils.c
Expand Up @@ -93,21 +93,21 @@ is_standby(PGconn *conn)


bool
is_witness(PGconn *conn, char *cluster, int node_id)
is_witness(PGconn *conn, char *schema, char *cluster, int node_id)
{
PGresult *res;
bool result;
char sqlquery[MAXQUERY];

snprintf(sqlquery, MAXQUERY, "SELECT witness from repmgr_%s.repl_nodes where id = %d",
cluster, node_id);
sqlquery_snprintf(sqlquery, "SELECT witness from %s.repl_nodes where cluster = '%s' and id = %d",
schema, cluster, node_id);
res = PQexec(conn, sqlquery);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
fprintf(stderr, "Can't query server mode: %s", PQerrorMessage(conn));
log_err(_("Can't query server mode: %s", PQerrorMessage(conn)));
PQclear(res);
PQfinish(conn);
exit(1);
exit(ERR_DB_QUERY);
}

if (strcmp(PQgetvalue(res, 0, 0), "f") == 0)
Expand All @@ -119,6 +119,7 @@ is_witness(PGconn *conn, char *cluster, int node_id)
return result;
}


/* check the PQStatus and try to 'select 1' to confirm good connection */
bool
is_pgup(PGconn *conn)
Expand Down Expand Up @@ -146,13 +147,12 @@ is_pgup(PGconn *conn)
* XXXX
* the error message can be used by repmgrd
*/
sprintf(sqlquery, "SELECT 1");
sqlquery_snprintf(sqlquery, "SELECT 1");
res = PQexec(conn, sqlquery);
// we need to retry, because we might just have loose the connection once
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
fprintf(stderr, "[ERROR] : PQexec failed: %s\n",
PQerrorMessage(conn));
log_err(_("PQexec failed: %s\n", PQerrorMessage(conn)));
PQclear(res);
if (twice)
return false;
Expand Down Expand Up @@ -280,7 +280,7 @@ get_cluster_size(PGconn *conn)
* connection string is placed there.
*/
PGconn *
getMasterConnection(PGconn *standby_conn, int id, char *cluster,
getMasterConnection(PGconn *standby_conn, char *schema, int id, char *cluster,
int *master_id, char *master_conninfo_out)
{
PGconn *master_conn = NULL;
Expand All @@ -289,7 +289,6 @@ getMasterConnection(PGconn *standby_conn, int id, char *cluster,
char sqlquery[QUERY_STR_LEN];
char master_conninfo_stack[MAXCONNINFO];
char *master_conninfo = &*master_conninfo_stack;
char schema_str[MAXLEN];
char schema_quoted[MAXLEN];

int i;
Expand All @@ -306,10 +305,9 @@ getMasterConnection(PGconn *standby_conn, int id, char *cluster,
*
* Assemble the unquoted schema name
*/
maxlen_snprintf(schema_str, "repmgr_%s", cluster);
{
char *identifier = PQescapeIdentifier(standby_conn, schema_str,
strlen(schema_str));
char *identifier = PQescapeIdentifier(standby_conn, schema,
strlen(schema));

maxlen_snprintf(schema_quoted, "%s", identifier);
PQfreemem(identifier);
Expand Down
4 changes: 2 additions & 2 deletions dbutils.h
Expand Up @@ -25,13 +25,13 @@ PGconn *establishDBConnectionByParams(const char *keywords[],
const char *values[],
const bool exit_on_error);
bool is_standby(PGconn *conn);
bool is_witness(PGconn *conn, char *cluster, int node_id);
bool is_witness(PGconn *conn, char *schema, char *cluster, int node_id);
bool is_pgup(PGconn *conn);
char *pg_version(PGconn *conn, char* major_version);
bool guc_setted(PGconn *conn, const char *parameter, const char *op,
const char *value);
const char *get_cluster_size(PGconn *conn);
PGconn *getMasterConnection(PGconn *standby_conn, int id, char *cluster,
PGconn *getMasterConnection(PGconn *standby_conn, char *schema, int id, char *cluster,
int *master_id, char *master_conninfo_out);

#endif
29 changes: 1 addition & 28 deletions repmgr.c
Expand Up @@ -1280,39 +1280,12 @@ do_witness_create(void)

char master_version[MAXVERSIONSTR];

char myClusterName[MAXLEN];
char createcommand[MAXLEN];
int myLocalId = -1;
char conninfo[MAXLEN];
char master_hba_file[MAXLEN];

/* these are no used here, but they can be in the repmgr.conf */
int failover;
int priority = -1;
char promote_command[MAXLEN];
char follow_command[MAXLEN];

/*
* Read the configuration file: repmgr.conf
*/
parse_config(config_file, myClusterName, &myLocalId, conninfo,
&failover, &priority, promote_command, follow_command);
if (myLocalId == -1)
{
fprintf(stderr, "Node information is missing. "
"Check the configuration file.\n");
exit(1);
}

/* if dest_dir hasn't been provided, initialize to current directory */
if (dest_dir == NULL)
{
dest_dir = malloc(5);
strcpy(dest_dir, ".");
}

/* Check this directory could be used as a PGDATA dir */
if (!create_pgdir(dest_dir, runtime_options.force))
if (!create_pgdir(runtime_options.dest_dir, runtime_options.force))
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion repmgrd.c
Expand Up @@ -190,7 +190,7 @@ main(int argc, char **argv)
* Set my server mode, establish a connection to primary
* and start monitor
*/
if (is_witness(myLocalConn, myClusterName, myLocalId))
if (is_witness(myLocalConn, repmgr_schema, local_options.cluster_name, local_options.node))
myLocalMode = WITNESS_MODE;
else if (is_standby(myLocalConn))
myLocalMode = STANDBY_MODE;
Expand Down

0 comments on commit 788ff98

Please sign in to comment.