Re: shmem_seq may be a bad idea - Mailing list pgsql-hackers

From Tom Lane
Subject Re: shmem_seq may be a bad idea
Date
Msg-id 1579.957215306@sss.pgh.pa.us
Whole thread Raw
In response to Re: shmem_seq may be a bad idea  (Peter Eisentraut <peter_e@gmx.net>)
Responses Re: shmem_seq may be a bad idea  (Peter Eisentraut <e99re41@DoCS.UU.SE>)
List pgsql-hackers
Peter Eisentraut <peter_e@gmx.net> writes:
> Why not use IPC_EXCL to ensure you're getting a freshly baked shmem
> segment rather than a recycled one?

Hmm, that might work --- we'd need to add some logic to try to delete
a conflicting segment and/or move on to another key if we can't.
But that seems like it'd resolve both the wrong-size issue and the
conflict-with-another-program issue.  I like it.

>> The intent of this logic is evidently to ensure that the old, failed
>> backends can't somehow corrupt the new ones.

> But what if someone runs another postmaster at port 5433, will it
> eventually interfere?

No; I neglected to mention that shmem_seq wraps around at 10.  So
there's no possible conflict between postmasters at different port#s
in the current scheme.

> Or some totally different program?

That, on the other hand, is a very real risk.  Trying a new key if we
fail to get a new shmem seg (or semaphore set) seems like a good
recovery method.

We'd need to rejigger the meaning of shmem_seq a little bit --- it'd
no longer be a global variable, but rather a local count of the number
of tries to create a particular seg or set.  So, logic would be
something like
for (seq = 0; seq < 10; seq++) {    key = port*1000 + seq*100 + (id for particular item);    shmctl(key, IPC_RMID, 0);
// ignore error    shmget(key, size, IPC_CREAT | IPC_EXCL);    if (success)        return key;}// if get here, report
shmgetfailure ...
 

It looks like we can apply the same method for semaphore sets, too.

Sound good?
        regards, tom lane


pgsql-hackers by date:

Previous
From: "Ross J. Reedstrom"
Date:
Subject: Re: RE: [PATCHES] relation filename patch
Next
From: Tom Lane
Date:
Subject: Re: When malloc returns zero ...