Skip to content

Commit

Permalink
Make checkPgAutoFailoverVersion void (#949)
Browse files Browse the repository at this point in the history
The checkPgAutoFailoverVersion() function was defined having a bool return
type, but in practice it could only return true as the error paths were
using ereport() which doesn't return. No callers of the function inspected
the return value for good reason. Refactor to a void function which better
match reality.

While there, also make sure that that fast-exit path is taken before any
memory is allocated.
  • Loading branch information
danielgustafsson committed Oct 12, 2022
1 parent d7997ff commit de5eb89
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
18 changes: 7 additions & 11 deletions src/monitor/metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,24 @@ LockNodeGroup(char *formationId, int groupId, LOCKMODE lockMode)
/*
* checkPgAutoFailoverVersion checks whether there is a version mismatch
* between the available version and the loaded version or between the
* installed version and the loaded version. Returns true if compatible, false
* installed version and the loaded version. Returns if compatible, errors out
* otherwise.
*
* We need to be careful that the pgautofailover.so that is currently loaded in
* the Postgres backend is intended to work with the current extension version
* definition (schema and SQL definitions of C coded functions).
*/
bool
void
checkPgAutoFailoverVersion()
{
char *installedVersion = NULL;
char *availableVersion = NULL;

if (!EnableVersionChecks)
{
return;
}

const int argCount = 1;
Oid argTypes[] = { TEXTOID };
Datum argValues[] = { CStringGetTextDatum(AUTO_FAILOVER_EXTENSION_NAME) };
Expand All @@ -195,11 +200,6 @@ checkPgAutoFailoverVersion()
"SELECT default_version, installed_version "
"FROM pg_catalog.pg_available_extensions WHERE name = $1;";

if (!EnableVersionChecks)
{
return true;
}

SPI_connect();

int spiStatus = SPI_execute_with_args(selectQuery, argCount, argTypes, argValues,
Expand Down Expand Up @@ -255,7 +255,6 @@ checkPgAutoFailoverVersion()
errhint("Restart the database to load the latest version "
"of the \"%s\" library.",
AUTO_FAILOVER_EXTENSION_NAME)));
return false;
}

if (strcmp(AUTO_FAILOVER_EXTENSION_VERSION, installedVersion) != 0)
Expand All @@ -270,8 +269,5 @@ checkPgAutoFailoverVersion()
installedVersion),
errhint("Run ALTER EXTENSION %s UPDATE and try again.",
AUTO_FAILOVER_EXTENSION_NAME)));
return false;
}

return true;
}
2 changes: 1 addition & 1 deletion src/monitor/metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ extern Oid pgAutoFailoverSchemaId(void);
extern Oid pgAutoFailoverExtensionOwner(void);
extern void LockFormation(char *formationId, LOCKMODE lockMode);
extern void LockNodeGroup(char *formationId, int groupId, LOCKMODE lockMode);
extern bool checkPgAutoFailoverVersion(void);
extern void checkPgAutoFailoverVersion(void);

0 comments on commit de5eb89

Please sign in to comment.