Skip to content

Commit

Permalink
Fix monitor extension for new Postgres 15 shared memory hooks. (#922)
Browse files Browse the repository at this point in the history
* Fix monitor extension for new Postgres 15 shared memory hooks.

* Per review, we didn't introduce PG_VERSION_15 in this project.
  • Loading branch information
DimCitus committed Aug 18, 2022
1 parent 856d4e7 commit 54fafca
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ RUN apt-get update \
&& rm -rf /var/lib/apt/lists/*

RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
RUN echo "deb http://apt.postgresql.org/pub/repos/apt buster-pgdg main" > /etc/apt/sources.list.d/pgdg.list
RUN echo "deb http://apt.postgresql.org/pub/repos/apt buster-pgdg main ${PGVERSION}" > /etc/apt/sources.list.d/pgdg.list

# bypass initdb of a "main" cluster
RUN echo 'create_main_cluster = false' | sudo tee -a /etc/postgresql-common/createcluster.conf
Expand Down Expand Up @@ -132,7 +132,7 @@ RUN apt-get update \
&& rm -rf /var/lib/apt/lists/*

RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
RUN echo "deb http://apt.postgresql.org/pub/repos/apt buster-pgdg main" > /etc/apt/sources.list.d/pgdg.list
RUN echo "deb http://apt.postgresql.org/pub/repos/apt buster-pgdg main ${PGVERSION}" > /etc/apt/sources.list.d/pgdg.list

# bypass initdb of a "main" cluster
RUN echo 'create_main_cluster = false' | sudo tee -a /etc/postgresql-common/createcluster.conf
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ build-test-pg13:
build-test-pg14:
docker build --build-arg PGVERSION=14 --target test -t $(TEST_CONTAINER_NAME):pg14 .

build-test-pg15:
docker build --build-arg PGVERSION=15 --target test -t $(TEST_CONTAINER_NAME):pg15 .

run-test: build-test-pg$(PGVERSION)
docker run \
--name $(TEST_CONTAINER_NAME) \
Expand All @@ -197,6 +200,9 @@ build-pg13: build-test-pg13
build-pg14: build-test-pg14
docker build --build-arg PGVERSION=14 $(DOCKER_BUILD_OPTS) -t $(CONTAINER_NAME):pg14 .

build-pg15: build-test-pg15
docker build --build-arg PGVERSION=15 $(DOCKER_BUILD_OPTS) -t $(CONTAINER_NAME):pg15 .

build: build-pg10 build-pg11 build-pg12 build-pg13 build-pg14 ;

build-check:
Expand Down
1 change: 1 addition & 0 deletions src/monitor/health_check.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ extern int HealthCheckTimeout;
extern int HealthCheckMaxRetries;
extern int HealthCheckRetryDelay;

extern size_t HealthCheckWorkerShmemSize(void);

extern void InitializeHealthCheckWorker(void);
extern void HealthCheckWorkerMain(Datum arg);
Expand Down
6 changes: 4 additions & 2 deletions src/monitor/health_check_worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ static int CompareTimes(struct timeval *leftTime, struct timeval *rightTime);
static int SubtractTimes(struct timeval base, struct timeval subtract);
static struct timeval AddTimeMillis(struct timeval base, uint32 additionalMs);
static void LatchWait(long timeoutMs);
static size_t HealthCheckWorkerShmemSize(void);
static void HealthCheckWorkerShmemInit(void);


Expand Down Expand Up @@ -196,10 +195,13 @@ pg_auto_failover_monitor_sighup(SIGNAL_ARGS)
void
InitializeHealthCheckWorker(void)
{
/* on PG 15, we use shmem_request_hook_type */
#if PG_VERSION_NUM < 150000
if (!IsUnderPostmaster)
{
RequestAddinShmemSpace(HealthCheckWorkerShmemSize());
}
#endif

prev_shmem_startup_hook = shmem_startup_hook;
shmem_startup_hook = HealthCheckWorkerShmemInit;
Expand Down Expand Up @@ -1086,7 +1088,7 @@ AddTimeMillis(struct timeval base, uint32 additionalMs)
/*
* HealthCheckWorkerShmemSize computes how much shared memory is required.
*/
static size_t
size_t
HealthCheckWorkerShmemSize(void)
{
Size size = 0;
Expand Down
31 changes: 31 additions & 0 deletions src/monitor/pg_auto_failover.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
ProcessUtility_hook_type PreviousProcessUtility_hook = NULL;


#if PG_VERSION_NUM >= 150000
static shmem_request_hook_type prev_shmem_request_hook = NULL;
static void pgautofailover_shmem_request(void);
#endif


void _PG_init(void);
static void StartMonitorNode(void);

Expand Down Expand Up @@ -77,10 +83,35 @@ _PG_init(void)
"configuration variable in postgresql.conf.")));
}

#if PG_VERSION_NUM >= 150000
prev_shmem_request_hook = shmem_request_hook;
shmem_request_hook = pgautofailover_shmem_request;
#endif

StartMonitorNode();
}


#if PG_VERSION_NUM >= 150000

/*
* Requests any additional shared memory required for pg_auto_failover health
* check worker.
*/
static void
pgautofailover_shmem_request(void)
{
if (prev_shmem_request_hook)
{
prev_shmem_request_hook();
}

RequestAddinShmemSpace(HealthCheckWorkerShmemSize());
}


#endif

/*
* StartMonitor register GUCs for monitor mode and starts the
* health check worker.
Expand Down

0 comments on commit 54fafca

Please sign in to comment.