]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Add missing initialization
authorÁlvaro Herrera <alvherre@kurilemu.de>
Thu, 16 Apr 2026 20:27:04 +0000 (22:27 +0200)
committerÁlvaro Herrera <alvherre@kurilemu.de>
Thu, 16 Apr 2026 20:27:04 +0000 (22:27 +0200)
The backend running REPACK can check DecodingWorkerShared->initialized
before the worker could have the chance to initialize it, possibly
leading to wrong behavior.

While at it, remove DecodingWorkerShared->worker_dsm_segment, because
that doesn't actually need to be in shared memory; a simple local-memory
global variable is enough.

Oversights in commit 28d534e2ae0a.

Author: Antonin Houska <ah@cybertec.at>
Reported-by: Alexander Lakhin <exclusion@gmail.com>
Discussion: https://postgr.es/m/18181295-8375-4789-ad32-269d78d6001e@gmail.com

src/backend/commands/repack.c
src/backend/commands/repack_worker.c
src/include/commands/repack_internal.h

index 58e3867246f1c1d8b0d0760ff89ea43f4f4a8605..67364cc60e3fbdcd89fd5908a61c340f6ffdd5c3 100644 (file)
@@ -3311,6 +3311,7 @@ start_repack_decoding_worker(Oid relid)
                BUFFERALIGN(REPACK_ERROR_QUEUE_SIZE);
        seg = dsm_create(size, 0);
        shared = (DecodingWorkerShared *) dsm_segment_address(seg);
+       shared->initialized = false;
        shared->lsn_upto = InvalidXLogRecPtr;
        shared->done = false;
        SharedFileSetInit(&shared->sfs, seg);
index 362e0766c4125880fe4aebb04f8c27e3dc469aeb..b17edd771e28e1927b935ac2cc93d0f9d99782fc 100644 (file)
@@ -44,6 +44,9 @@ static bool am_repack_worker = false;
 /* The WAL segment being decoded. */
 static XLogSegNo repack_current_segment = 0;
 
+/* Our DSM segment, for shutting down */
+static dsm_segment *worker_dsm_segment = NULL;
+
 /*
  * Keep track of the table we're processing, to skip logical decoding of data
  * from other relations.
@@ -78,9 +81,9 @@ RepackWorkerMain(Datum main_arg)
                ereport(ERROR,
                                errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
                                errmsg("could not map dynamic shared memory segment"));
+       worker_dsm_segment = seg;
 
        shared = (DecodingWorkerShared *) dsm_segment_address(seg);
-       shared->dsm_seg = seg;
 
        /* Arrange to signal the leader if we exit. */
        before_shmem_exit(RepackWorkerShutdown, PointerGetDatum(shared));
@@ -176,7 +179,7 @@ RepackWorkerShutdown(int code, Datum arg)
                                   PROCSIG_REPACK_MESSAGE,
                                   shared->backend_proc_number);
 
-       dsm_detach(shared->dsm_seg);
+       dsm_detach(worker_dsm_segment);
 }
 
 bool
index 3ff64444351e71c384702e6f189daa4519d413c0..6a85cee8910123a6207b24f0ce8591c7ca35d217 100644 (file)
@@ -107,7 +107,6 @@ typedef struct DecodingWorkerShared
        PGPROC     *backend_proc;
        pid_t           backend_pid;
        ProcNumber      backend_proc_number;
-       dsm_segment *dsm_seg;
 
        /*
         * Memory the queue is located in.