Re: PostmasterContext survives into parallel workers!? - Mailing list pgsql-hackers

From Tom Lane
Subject Re: PostmasterContext survives into parallel workers!?
Date
Msg-id 758.1470163099@sss.pgh.pa.us
Whole thread Raw
In response to Re: PostmasterContext survives into parallel workers!?  (Alvaro Herrera <alvherre@2ndquadrant.com>)
Responses Re: PostmasterContext survives into parallel workers!?  (Alvaro Herrera <alvherre@2ndquadrant.com>)
List pgsql-hackers
Alvaro Herrera <alvherre@2ndquadrant.com> writes:
> Tom Lane wrote:
>> It looks to me like the reason for it is simply not having bothered to
>> copy the rw->rw_worker data to somewhere that would survive deletion
>> of the PostmasterContext.  I wonder though if anyone remembers a more
>> fundamental reason?  Surely the bgworker is not supposed to touch any
>> of the rest of the BackgroundWorkerList?

> I just checked BDR, which is the more complex code using workers I know
> of, and I don't see any reason why this cannot be changed.

The attached patch passes "make check-world" for me.  Can you check it
against BDR?

(I'd be hesitant to back-patch it in any case, but I think it's okay for
HEAD unless we can easily find something it breaks.)

            regards, tom lane

diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 19d11e0..e48703a 100644
*** a/src/backend/postmaster/postmaster.c
--- b/src/backend/postmaster/postmaster.c
*************** do_start_bgworker(RegisteredBgWorker *rw
*** 5529,5537 ****
              /* Close the postmaster's sockets */
              ClosePostmasterPorts(false);

!             /* Do NOT release postmaster's working memory context */

-             MyBgworkerEntry = &rw->rw_worker;
              StartBackgroundWorker();
              break;
  #endif
--- 5529,5547 ----
              /* Close the postmaster's sockets */
              ClosePostmasterPorts(false);

!             /*
!              * Before blowing away PostmasterContext, save this bgworker's
!              * data where it can find it.
!              */
!             MyBgworkerEntry = (BackgroundWorker *)
!                 MemoryContextAlloc(TopMemoryContext, sizeof(BackgroundWorker));
!             memcpy(MyBgworkerEntry, &rw->rw_worker, sizeof(BackgroundWorker));
!
!             /* Release postmaster's working memory context */
!             MemoryContextSwitchTo(TopMemoryContext);
!             MemoryContextDelete(PostmasterContext);
!             PostmasterContext = NULL;

              StartBackgroundWorker();
              break;
  #endif

pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: Increasing timeout of poll_query_until for TAP tests
Next
From: Karan Sikka
Date:
Subject: Re: TODO item: Implement Boyer-Moore searching in LIKE queries