Skip to content

Commit de5eb89

Browse files
Make checkPgAutoFailoverVersion void (#949)
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.
1 parent d7997ff commit de5eb89

2 files changed

Lines changed: 8 additions & 12 deletions

File tree

src/monitor/metadata.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -173,19 +173,24 @@ LockNodeGroup(char *formationId, int groupId, LOCKMODE lockMode)
173173
/*
174174
* checkPgAutoFailoverVersion checks whether there is a version mismatch
175175
* between the available version and the loaded version or between the
176-
* installed version and the loaded version. Returns true if compatible, false
176+
* installed version and the loaded version. Returns if compatible, errors out
177177
* otherwise.
178178
*
179179
* We need to be careful that the pgautofailover.so that is currently loaded in
180180
* the Postgres backend is intended to work with the current extension version
181181
* definition (schema and SQL definitions of C coded functions).
182182
*/
183-
bool
183+
void
184184
checkPgAutoFailoverVersion()
185185
{
186186
char *installedVersion = NULL;
187187
char *availableVersion = NULL;
188188

189+
if (!EnableVersionChecks)
190+
{
191+
return;
192+
}
193+
189194
const int argCount = 1;
190195
Oid argTypes[] = { TEXTOID };
191196
Datum argValues[] = { CStringGetTextDatum(AUTO_FAILOVER_EXTENSION_NAME) };
@@ -195,11 +200,6 @@ checkPgAutoFailoverVersion()
195200
"SELECT default_version, installed_version "
196201
"FROM pg_catalog.pg_available_extensions WHERE name = $1;";
197202

198-
if (!EnableVersionChecks)
199-
{
200-
return true;
201-
}
202-
203203
SPI_connect();
204204

205205
int spiStatus = SPI_execute_with_args(selectQuery, argCount, argTypes, argValues,
@@ -255,7 +255,6 @@ checkPgAutoFailoverVersion()
255255
errhint("Restart the database to load the latest version "
256256
"of the \"%s\" library.",
257257
AUTO_FAILOVER_EXTENSION_NAME)));
258-
return false;
259258
}
260259

261260
if (strcmp(AUTO_FAILOVER_EXTENSION_VERSION, installedVersion) != 0)
@@ -270,8 +269,5 @@ checkPgAutoFailoverVersion()
270269
installedVersion),
271270
errhint("Run ALTER EXTENSION %s UPDATE and try again.",
272271
AUTO_FAILOVER_EXTENSION_NAME)));
273-
return false;
274272
}
275-
276-
return true;
277273
}

src/monitor/metadata.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ extern Oid pgAutoFailoverSchemaId(void);
4444
extern Oid pgAutoFailoverExtensionOwner(void);
4545
extern void LockFormation(char *formationId, LOCKMODE lockMode);
4646
extern void LockNodeGroup(char *formationId, int groupId, LOCKMODE lockMode);
47-
extern bool checkPgAutoFailoverVersion(void);
47+
extern void checkPgAutoFailoverVersion(void);

0 commit comments

Comments
 (0)