Skip to content

Commit

Permalink
Set candidate priority without waiting for state changes in more case…
Browse files Browse the repository at this point in the history
…s. (#756)

When dropping the last node with candidate priority greater than zero, we
might want to change the candidate priority of the last remaining node. The
client-side implementation of the command would wait for the APPLY_SETTINGS
cycle in some cases with dropped nodes, which is unfortunate: this PR fixes
that.
  • Loading branch information
DimCitus committed Jul 7, 2021
1 parent c962167 commit 3d50d67
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/bin/pg_autoctl/cli_get_set_properties.c
Original file line number Diff line number Diff line change
Expand Up @@ -668,22 +668,27 @@ static bool
set_node_candidate_priority(Keeper *keeper, int candidatePriority)
{
KeeperConfig *config = &(keeper->config);
NodeAddressArray nodesArray = { 0 };
CurrentNodeStateArray nodesArray = { 0 };

/*
* There might be some race conditions here, but it's all to be
* user-friendly so in the worst case we're going to be less friendly that
* we could have.
*/
if (!monitor_get_nodes(&(keeper->monitor),
config->formation,
config->groupId,
&nodesArray))
if (!monitor_get_current_state(&(keeper->monitor),
config->formation,
config->groupId,
&nodesArray))
{
/* ignore the error, just don't wait in that case */
log_warn("Failed to get_nodes() on the monitor");
log_warn("Failed to get the list of all the nodes in formation \"%s\" "
"from the monitor, see above for details",
keeper->config.formation);
}

/* ignore the result of the filtering, worst case we don't wait */
(void) nodestateFilterArrayGroup(&nodesArray, config->name);

/* listen for state changes BEFORE we apply new settings */
if (nodesArray.count > 1)
{
Expand Down
1 change: 1 addition & 0 deletions src/bin/pg_autoctl/pgsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,7 @@ pgsql_execute_with_params(PGSQL *pgsql, const char *sql, int paramCount,
* with a badly formed SQL query etc.
*/
if (pgsql->connectionType == PGSQL_CONN_MONITOR &&
sqlstate != NULL &&
!(strcmp(sqlstate, ERRCODE_INVALID_OBJECT_DEFINITION) == 0 ||
strcmp(sqlstate, ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE) == 0 ||
strcmp(sqlstate, ERRCODE_OBJECT_IN_USE) == 0 ||
Expand Down

0 comments on commit 3d50d67

Please sign in to comment.