mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-26 00:26:30 +00:00
repmgrd: check shared library is loaded
If this isn't the case, "repmgrd" will appear to run but not handle failover correctly. Address GitHub #337.
This commit is contained in:
22
dbutils.c
22
dbutils.c
@@ -1554,7 +1554,7 @@ repmgrd_set_local_node_id(PGconn *conn, int local_node_id)
|
|||||||
initPQExpBuffer(&query);
|
initPQExpBuffer(&query);
|
||||||
|
|
||||||
appendPQExpBuffer(&query,
|
appendPQExpBuffer(&query,
|
||||||
" SELECT repmgr.set_local_node_id(%i)",
|
"SELECT repmgr.set_local_node_id(%i)",
|
||||||
local_node_id);
|
local_node_id);
|
||||||
|
|
||||||
res = PQexec(conn, query.data);
|
res = PQexec(conn, query.data);
|
||||||
@@ -1572,6 +1572,26 @@ repmgrd_set_local_node_id(PGconn *conn, int local_node_id)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
repmgrd_get_local_node_id(PGconn *conn)
|
||||||
|
{
|
||||||
|
PGresult *res = NULL;
|
||||||
|
int local_node_id = UNKNOWN_NODE_ID;
|
||||||
|
|
||||||
|
res = PQexec(conn, "SELECT repmgr.get_local_node_id()");
|
||||||
|
|
||||||
|
if (!PQgetisnull(res, 0, 0))
|
||||||
|
{
|
||||||
|
local_node_id = atoi(PQgetvalue(res, 0, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
PQclear(res);
|
||||||
|
|
||||||
|
return local_node_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ================ */
|
/* ================ */
|
||||||
/* result functions */
|
/* result functions */
|
||||||
/* ================ */
|
/* ================ */
|
||||||
|
|||||||
@@ -382,6 +382,7 @@ bool can_use_pg_rewind(PGconn *conn, const char *data_directory, PQExpBufferDat
|
|||||||
int get_ready_archive_files(PGconn *conn, const char *data_directory);
|
int get_ready_archive_files(PGconn *conn, const char *data_directory);
|
||||||
bool identify_system(PGconn *repl_conn, t_system_identification *identification);
|
bool identify_system(PGconn *repl_conn, t_system_identification *identification);
|
||||||
bool repmgrd_set_local_node_id(PGconn *conn, int local_node_id);
|
bool repmgrd_set_local_node_id(PGconn *conn, int local_node_id);
|
||||||
|
int repmgrd_get_local_node_id(PGconn *conn);
|
||||||
|
|
||||||
/* extension functions */
|
/* extension functions */
|
||||||
ExtensionStatus get_repmgr_extension_status(PGconn *conn);
|
ExtensionStatus get_repmgr_extension_status(PGconn *conn);
|
||||||
|
|||||||
1
repmgr.c
1
repmgr.c
@@ -124,7 +124,6 @@ _PG_init(void)
|
|||||||
{
|
{
|
||||||
elog(DEBUG1, "repmgr init");
|
elog(DEBUG1, "repmgr init");
|
||||||
|
|
||||||
/* error here? */
|
|
||||||
if (!process_shared_preload_libraries_in_progress)
|
if (!process_shared_preload_libraries_in_progress)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
18
repmgrd.c
18
repmgrd.c
@@ -332,6 +332,24 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
repmgrd_set_local_node_id(local_conn, config_file_options.node_id);
|
repmgrd_set_local_node_id(local_conn, config_file_options.node_id);
|
||||||
|
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* sanity-check that the shared library is loaded and shared memory
|
||||||
|
* can be written by attempting to retrieve the previously stored node_id
|
||||||
|
*/
|
||||||
|
int stored_local_node_id = UNKNOWN_NODE_ID;
|
||||||
|
|
||||||
|
stored_local_node_id = repmgrd_get_local_node_id(local_conn);
|
||||||
|
|
||||||
|
if (stored_local_node_id == UNKNOWN_NODE_ID)
|
||||||
|
{
|
||||||
|
log_error(_("unable to write to shared memory"));
|
||||||
|
log_hint(_("ensure \"shared_preload_libraries\" includes \"repmgr\""));
|
||||||
|
PQfinish(local_conn);
|
||||||
|
terminate(ERR_BAD_CONFIG);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (config_file_options.replication_type == REPLICATION_TYPE_BDR)
|
if (config_file_options.replication_type == REPLICATION_TYPE_BDR)
|
||||||
{
|
{
|
||||||
log_debug("node id is %i", local_node_info.node_id);
|
log_debug("node id is %i", local_node_info.node_id);
|
||||||
|
|||||||
Reference in New Issue
Block a user