node rejoin: improve error code handling

- return ERR_REJOIN_FAIL in all cases where the rejoin operation fails
 - ensure ERR_FOLLOW_FAIL is not returned
 - document error codes
This commit is contained in:
Ian Barwick
2019-01-24 10:31:45 +09:00
parent dfe57d2406
commit 59eca2be30
5 changed files with 65 additions and 9 deletions

View File

@@ -165,6 +165,7 @@
Following exit codes can be emitted by <command>repmgr status check</command>
if no individual check was specified.
</para>
<variablelist>
<varlistentry>
@@ -186,6 +187,7 @@
</varlistentry>
</variablelist>
</refsect1>

View File

@@ -255,6 +255,59 @@
</refsect1>
<refsect1>
<title>Exit codes</title>
<para>
Following exit codes can be emitted by <command>repmgr node rejoin</command>:
</para>
<variablelist>
<varlistentry>
<term><option>SUCCESS (0)</option></term>
<listitem>
<para>
The node rejoin succeeded; or if <option>--dry-run</option> was provided,
no issues were detected which would prevent the node rejoin.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>ERR_BAD_CONFIG (1)</option></term>
<listitem>
<para>
A configuration issue was detected which prevented &repmgr; from
continuing with the node rejoin.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>ERR_NO_RESTART (4)</option></term>
<listitem>
<para>
The node could not be restarted.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>ERR_REJOIN_FAIL (24)</option></term>
<listitem>
<para>
The node rejoin operation failed.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
</refsect1>
<refsect1>
<title>See also</title>
<para>

View File

@@ -2174,7 +2174,7 @@ do_node_rejoin(void)
log_error(_("database is still running in state \"%s\""),
describe_db_state(db_state));
log_hint(_("\"repmgr node rejoin\" cannot be executed on a running node"));
exit(ERR_BAD_CONFIG);
exit(ERR_REJOIN_FAIL);
}
/* check if cleanly shut down */
@@ -2193,7 +2193,7 @@ do_node_rejoin(void)
log_detail(_("pg_rewind will not be able to run"));
}
log_hint(_("database should be restarted then shut down cleanly after crash recovery completes"));
exit(ERR_BAD_CONFIG);
exit(ERR_REJOIN_FAIL);
}
}
@@ -2255,7 +2255,7 @@ do_node_rejoin(void)
if (can_follow == false)
{
PQfinish(upstream_conn);
exit(ERR_BAD_CONFIG);
exit(ERR_REJOIN_FAIL);
}
}
@@ -2358,7 +2358,7 @@ do_node_rejoin(void)
termPQExpBuffer(&command_output);
exit(ERR_BAD_CONFIG);
exit(ERR_REJOIN_FAIL);
}
termPQExpBuffer(&command_output);
@@ -2471,6 +2471,7 @@ do_node_rejoin(void)
upstream_conn,
&primary_node_record,
&follow_output,
ERR_REJOIN_FAIL,
&follow_error_code);
if (success == false)

View File

@@ -2561,6 +2561,7 @@ do_standby_follow(void)
follow_target_conn,
&follow_target_node_record,
&follow_output,
ERR_FOLLOW_FAIL,
&follow_error_code);
/* unable to restart the standby */
@@ -2665,7 +2666,7 @@ do_standby_follow(void)
* this function.
*/
bool
do_standby_follow_internal(PGconn *primary_conn, PGconn *follow_target_conn, t_node_info *follow_target_node_record, PQExpBufferData *output, int *error_code)
do_standby_follow_internal(PGconn *primary_conn, PGconn *follow_target_conn, t_node_info *follow_target_node_record, PQExpBufferData *output, int general_error_code, int *error_code)
{
t_node_info local_node_record = T_NODE_INFO_INITIALIZER;
int original_upstream_node_id = UNKNOWN_NODE_ID;
@@ -2691,7 +2692,7 @@ do_standby_follow_internal(PGconn *primary_conn, PGconn *follow_target_conn, t_n
log_error(_("unable to retrieve record for node %i"),
config_file_options.node_id);
*error_code = ERR_FOLLOW_FAIL;
*error_code = ERR_BAD_CONFIG;
return false;
}
@@ -2818,7 +2819,7 @@ do_standby_follow_internal(PGconn *primary_conn, PGconn *follow_target_conn, t_n
if (!create_recovery_file(&local_node_record, &recovery_conninfo, config_file_options.data_directory, true))
{
*error_code = ERR_FOLLOW_FAIL;
*error_code = general_error_code;
return false;
}
@@ -2969,7 +2970,6 @@ do_standby_follow_internal(PGconn *primary_conn, PGconn *follow_target_conn, t_n
return false;
}
appendPQExpBuffer(output,
_("node %i is now attached to node %i"),
config_file_options.node_id,

View File

@@ -28,7 +28,7 @@ extern void do_standby_switchover(void);
extern void do_standby_help(void);
extern bool do_standby_follow_internal(PGconn *primary_conn, PGconn *follow_target_conn, t_node_info *follow_target_node_record, PQExpBufferData *output, int *error_code);
extern bool do_standby_follow_internal(PGconn *primary_conn, PGconn *follow_target_conn, t_node_info *follow_target_node_record, PQExpBufferData *output, int general_error_code, int *error_code);