Skip to content

Commit

Permalink
Add primary_node_info inline function
Browse files Browse the repository at this point in the history
When a t_node_info struct must be re initilised, it was re-declared
only. Moreover, a macro was user for any var creation of this type
impeding use the same to reset the values later if needed.

This new function allows to re initilise again a t_node_info typed
variable without the need to redeclare it to create other varibles for
the same purpose, and also shadowing is now avoided from pg16.

Macros seems to be replaced by `static inline` functions in upstream
postgres, credits to  Alvaro Herrera <[email protected]> for this
idea.

References: HL-40
  • Loading branch information
gonzalemario committed Nov 18, 2024
1 parent a469221 commit 7f3a26f
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion repmgr-action-primary.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,38 @@ do_primary_register(void)
return;
}

static inline void reset_node_info(t_node_info *info)
{
info->node_id = NODE_NOT_FOUND;
info->upstream_node_id = NO_UPSTREAM_NODE;
info->type = UNKNOWN;
info->node_name[0] = '\0';
info->upstream_node_name[0] = '\0';
info->conninfo[0] = '\0';
info->repluser[0] = '\0';
info->priority = DEFAULT_PRIORITY;
info->active = true;
info->slot_name[0] = '\0';
info->config_file[0] = '\0';
info->last_wal_receive_lsn = InvalidXLogRecPtr;
info->node_status = NODE_STATUS_UNKNOWN;
info->recovery_type = RECTYPE_UNKNOWN;
info->monitoring_state = MS_NORMAL;
info->conn = NULL;
info->details[0] = '\0';
info->reachable = true;
info->attached = true;
/* various statistics */
info->max_wal_senders = -1;
info->attached_wal_receivers = -1;
info->max_replication_slots = -1;
info->total_replication_slots = -1;
info->active_replication_slots = -1;
info->inactive_replication_slots = -1;
info->replication_info = NULL;

strlcpy(info->location, DEFAULT_LOCATION, sizeof(info->location));
}

/*
* do_primary_unregister()
Expand Down Expand Up @@ -436,7 +468,7 @@ do_primary_unregister(void)
}
else if (recovery_type == RECTYPE_PRIMARY)
{
t_node_info primary_node_info = T_NODE_INFO_INITIALIZER;
reset_node_info(&primary_node_info);
bool primary_record_found = false;

primary_record_found = get_primary_node_record(primary_conn, &primary_node_info);
Expand Down

0 comments on commit 7f3a26f

Please sign in to comment.