Skip to content

Commit

Permalink
Merge pull request #45 from citusdata/pg12_compat
Browse files Browse the repository at this point in the history
Fix PG12 build breaks and unused_variable warnings

However,  PG12 support is not complete yet. Thus also added checks to support
only PG10 and PG11, and fail with other versions

Partially fixes 45. Issue is to be left open
  • Loading branch information
mtuncer committed Jul 30, 2019
2 parents 3b2c31b + f0692b6 commit 70a0196
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 37 deletions.
1 change: 0 additions & 1 deletion src/bin/pg_autoctl/cli_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ CommandLine config_commands =
static void
cli_config_check(int argc, char **argv)
{
int errors = 0;
const bool missingPgdataIsOk = true;
const bool pgIsNotRunningIsOk = true;

Expand Down
2 changes: 0 additions & 2 deletions src/bin/pg_autoctl/cli_create_drop_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,7 @@ cli_create_monitor(int argc, char **argv)
{
Monitor monitor = { 0 };
MonitorConfig config = monitorOptions;
PostgresSetup pgSetup = config.pgSetup;
char connInfo[MAXCONNINFO];
char ipAddr[BUFSIZE];
bool missingPgdataIsOk = true;
bool pgIsNotRunningIsOk = true;

Expand Down
1 change: 0 additions & 1 deletion src/bin/pg_autoctl/cli_do_root.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ int
keeper_cli_keeper_setup_getopts(int argc, char **argv)
{
KeeperConfig options = { 0 };
int c, option_index, errors = 0;

static struct option long_options[] = {
{ "pgctl", required_argument, NULL, 'C' },
Expand Down
1 change: 0 additions & 1 deletion src/bin/pg_autoctl/cli_root.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ CommandLine root =
int
root_options(int argc, char **argv)
{
int debugCount = 0;
int verboseCount = 0;

static struct option long_options[] = {
Expand Down
5 changes: 0 additions & 5 deletions src/bin/pg_autoctl/cli_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,14 @@ cli_keeper_run(int argc, char **argv)
static void
cli_monitor_run(int argc, char **argv)
{
char configFilePath[MAXPGPATH];
KeeperConfig kconfig = keeperOptions;
MonitorConfig mconfig = { 0 };

Monitor monitor = { 0 };
MonitorExtensionVersion version = { 0 };
char postgresUri[MAXCONNINFO];

PostgresSetup existingPgSetup = { 0 };
bool missingPgdataIsOk = false;
bool pgIsNotRunningIsOk = true;
char connInfo[MAXCONNINFO];

char *channels[] = { "log", "state", NULL };

if (!monitor_config_init_from_pgsetup(&monitor,
Expand Down
2 changes: 0 additions & 2 deletions src/bin/pg_autoctl/cli_show.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,6 @@ static void
cli_show_uri(int argc, char **argv)
{
KeeperConfig config = keeperOptions;
Monitor monitor = { 0 };

if (!IS_EMPTY_STRING_BUFFER(config.formation))
{
(void) cli_show_formation_uri(argc, argv);
Expand Down
2 changes: 1 addition & 1 deletion src/bin/pg_autoctl/cli_systemd.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ cli_systemd_getopt(int argc, char **argv)
{
SystemdServiceConfig options = { 0 };

int c = 0, option_index = 0, errors = 0;
int c = 0, option_index = 0;

static struct option long_options[] = {
{ "pgdata", required_argument, NULL, 'D' },
Expand Down
2 changes: 0 additions & 2 deletions src/bin/pg_autoctl/ipaddr.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,6 @@ findHostnameFromLocalIpAddress(char *localIpAddress, char *hostname, int size)
int ret = 0;
char hbuf[NI_MAXHOST];
struct addrinfo *lookup, *ai;
struct sockaddr_storage address;
socklen_t address_len;

/* parse ipv4 or ipv6 address using getaddrinfo() */
ret = getaddrinfo(localIpAddress, NULL, 0, &lookup);
Expand Down
1 change: 0 additions & 1 deletion src/bin/pg_autoctl/monitor_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,6 @@ monitor_config_set_setting(MonitorConfig *config,
char *value)
{
const char *filename = config->pathnames.config;
IniOption *option;
IniOption monitorOptions[] = SET_INI_OPTIONS_ARRAY(config);

if (ini_set_setting(filename, monitorOptions, path, value))
Expand Down
1 change: 0 additions & 1 deletion src/bin/pg_autoctl/monitor_pg_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ monitor_pg_init(Monitor *monitor, MonitorConfig *config)
char configFilePath[MAXPGPATH];
char postgresUri[MAXCONNINFO];
PostgresSetup pgSetup = config->pgSetup;
bool postgresInstanceExists = pg_setup_pgdata_exists(&pgSetup);

if (directory_exists(pgSetup.pgdata))
{
Expand Down
2 changes: 0 additions & 2 deletions src/bin/pg_autoctl/pgsetup.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,6 @@ static bool
get_pgpid(PostgresSetup *pgSetup, bool pg_is_not_running_is_ok)
{
FILE *fp;
int lineno;
char line[BUFSIZE];
char pidfile[MAXPGPATH];
long pid = -1;

Expand Down
24 changes: 12 additions & 12 deletions src/monitor/health_check_worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,11 @@ HealthCheckWorkerLauncherMain(Datum arg)
/* Make background worker recognisable in pg_stat_activity */
pgstat_report_appname("pg_auto_failover monitor launcher");

launcherContext = AllocSetContextCreateExtended(CurrentMemoryContext,
"Health Check Launcher Context",
ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);
launcherContext = AllocSetContextCreate(CurrentMemoryContext,
"Health Check Launcher Context",
ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);

MemoryContextSwitchTo(launcherContext);

Expand Down Expand Up @@ -352,15 +352,15 @@ BuildDatabaseList(void)
{
List *databaseList = NIL;
Relation pgDatabaseRelation;
HeapScanDesc scan;
TableScanDesc scan;
HeapTuple dbTuple;
MemoryContext originalContext = CurrentMemoryContext;

StartTransactionCommand();

pgDatabaseRelation = heap_open(DatabaseRelationId, AccessShareLock);

scan = heap_beginscan_catalog(pgDatabaseRelation, 0, NULL);
scan = table_beginscan_catalog(pgDatabaseRelation, 0, NULL);

while (HeapTupleIsValid(dbTuple = heap_getnext(scan, ForwardScanDirection)))
{
Expand Down Expand Up @@ -449,11 +449,11 @@ HealthCheckWorkerMain(Datum arg)
* Only process given database when the extension has been loaded.
* Otherwise, happily quit.
*/
healthCheckContext = AllocSetContextCreateExtended(CurrentMemoryContext,
"Health check context",
ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);
healthCheckContext = AllocSetContextCreate(CurrentMemoryContext,
"Health check context",
ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);

MemoryContextSwitchTo(healthCheckContext);

Expand Down
1 change: 1 addition & 0 deletions src/monitor/replication_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "metadata.h"
#include "replication_state.h"
#include "version_compat.h"

#include "access/htup.h"
#include "access/htup_details.h"
Expand Down
29 changes: 23 additions & 6 deletions src/monitor/version_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@

#include "postgres.h"

#if (PG_VERSION_NUM >= 90600 && PG_VERSION_NUM < 110000)
/* we only support PG10 and PG11, PG 12 is not supported yet*/
#if (PG_VERSION_NUM < 100000 || PG_VERSION_NUM >= 120000)
#error "Unknown or unsupported postgresql version"
#endif

#if (PG_VERSION_NUM < 110000)

#include "postmaster/bgworker.h"
#include "utils/memutils.h"
Expand All @@ -27,12 +32,24 @@
#define BackgroundWorkerInitializeConnectionByOid(dboid, useroid, flags) \
BackgroundWorkerInitializeConnectionByOid(dboid, useroid)

static inline MemoryContext
AllocSetContextCreateExtended(MemoryContext parent, const char *name, Size minContextSize,
Size initBlockSize, Size maxBlockSize)
#endif

#if (PG_VERSION_NUM < 120000)

#define table_beginscan_catalog heap_beginscan_catalog
#define TableScanDesc HeapScanDesc

#endif

#if (PG_VERSION_NUM >= 120000)

#include "access/htup_details.h"
#include "catalog/pg_database.h"

static inline Oid HeapTupleGetOid(HeapTuple tuple)
{
return AllocSetContextCreate(parent, name, minContextSize, initBlockSize,
maxBlockSize);
Form_pg_database dbForm = (Form_pg_database) GETSTRUCT(tuple);
return dbForm->oid;
}

#endif
Expand Down

0 comments on commit 70a0196

Please sign in to comment.