Lists: | pgsql-hackersPostg윈 토토SQL : Postg윈pgsql-patches |
---|
From: | Claudio Natoli <claudio(dot)natoli(at)memetrics(dot)com> |
---|---|
To: | "'pgsql-patches(at)postgresql(dot)org'" <pgsql-patches(at)postgresql(dot)org> |
Subject: | fork/exec patch |
Date: | 2003-12-13 07:24:28 |
Message-ID: | A02DEC4D1073D611BAE8525405FCCE2B02808C@harris.memetrics.local |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | Postg젠 토토SQL : pgsql-hackers-win32 pgsql-patches |
This patch is the next step towards (re)allowing fork/exec.
Bruce, I've cleaned up the parts we discussed, and, pending objections from
anyone else, it is ready for application to HEAD.
Cheers,
Claudio
---
Certain disclaimers and policies apply to all email sent from Memetrics.
For the full text of these disclaimers and policies see
<a
href="http://www.memetrics.com/emailpolicy.html">http://www.memetrics.com/em
ailpolicy.html</a>
Attachment | Content-Type | Size |
---|---|---|
diff2c.out | application/octet-stream | 55.1 KB |
From: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> |
---|---|
To: | Claudio Natoli <claudio(dot)natoli(at)memetrics(dot)com> |
Cc: | "'pgsql-patches(at)postgresql(dot)org'" <pgsql-patches(at)postgresql(dot)org> |
Subject: | Re: fork/exec patch |
Date: | 2003-12-13 15:46:06 |
Message-ID: | 200312131546.hBDFk6h08312@candle.pha.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers pgsql-hackers-win32 pgsql-patches |
Let me provide a summary of this patch because I reviewed the first
version.
The patch basically is a slight rearrangement of the code to allow
fork/exec on Unix, with the ultimate goal of doing CreateProcess on
Win32. The changes are:
o Write out postmaster global variables and per-backend
variables to be read by the exec'ed backend
o Mark some static variables as global when exec is used so
then can be dumped from postmaster.c, marked NON_EXEC_STATIC
o Remove value passing with -p now that we have per-backend
file
o Move some pointer storage out of shared memory for easier
dumping.
o Modified pgsql_temp directory cleanup to handle per-database
directories and the backend exec directory under datadir.
Let me add that Claudio is doing a fantastic job on this. The changes
are minimal and clean. I think the writing of a per-backend temp file
has allowed this patch to be smaller than it might have been.
---------------------------------------------------------------------------
Claudio Natoli wrote:
>
> This patch is the next step towards (re)allowing fork/exec.
>
> Bruce, I've cleaned up the parts we discussed, and, pending objections from
> anyone else, it is ready for application to HEAD.
>
> Cheers,
> Claudio
>
> ---
> Certain disclaimers and policies apply to all email sent from Memetrics.
> For the full text of these disclaimers and policies see
> <a
> href="http://www.memetrics.com/emailpolicy.html">http://www.memetrics.com/em
> ailpolicy.html</a>
>
>
[ Attachment, skipping... ]
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
From: | Neil Conway <neilc(at)samurai(dot)com> |
---|---|
To: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> |
Cc: | Claudio Natoli <claudio(dot)natoli(at)memetrics(dot)com>, "'pgsql-patches(at)postgresql(dot)org'" <pgsql-patches(at)postgresql(dot)org> |
Subject: | Re: fork/exec patch |
Date: | 2003-12-14 21:06:26 |
Message-ID: | 873cbnaz3h.fsf@mailbox.samurai.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers pgsql-hackers-win32 pgsql-patches |
Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> Let me add that Claudio is doing a fantastic job on this. The
> changes are minimal and clean. I think the writing of a per-backend
> temp file has allowed this patch to be smaller than it might have
> been.
Did we REALLY conclude that the best way to work around the lack of
fork() on Win32 is by writing variables out to disk and reading them
back in? Frankly, that seems like an enormous kludge.
For example, couldn't we write this data into a particular location in
shared memory, and then pass that location to the child? That is still
ugly, slow, and prone to failure (shmem being statically sized), but
ISTM that the proposed implementation already possesses those
attributes :-)
(/me goes off to re-read the archives on this issue...)
-Neil
From: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> |
---|---|
To: | Neil Conway <neilc(at)samurai(dot)com> |
Cc: | Claudio Natoli <claudio(dot)natoli(at)memetrics(dot)com>, "'pgsql-patches(at)postgresql(dot)org'" <pgsql-patches(at)postgresql(dot)org> |
Subject: | Re: fork/exec patch |
Date: | 2003-12-14 21:29:48 |
Message-ID: | 200312142129.hBELTmY13251@candle.pha.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers pgsql-hackers-win32 pgsql-patches |
Neil Conway wrote:
> Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> > Let me add that Claudio is doing a fantastic job on this. The
> > changes are minimal and clean. I think the writing of a per-backend
> > temp file has allowed this patch to be smaller than it might have
> > been.
>
> Did we REALLY conclude that the best way to work around the lack of
> fork() on Win32 is by writing variables out to disk and reading them
> back in? Frankly, that seems like an enormous kludge.
>
> For example, couldn't we write this data into a particular location in
> shared memory, and then pass that location to the child? That is still
> ugly, slow, and prone to failure (shmem being statically sized), but
> ISTM that the proposed implementation already possesses those
> attributes :-)
I don't think we ever discussed it, but it seemed logical and a minimal
change to the code. We already have a GUC write of non-default values
for exec and no one had issues with that. Of course, this one is
per-backend.
Yea, we could use shared memory for this too, but I don't see a problem
with using the file system. Older releases of PostgreSQL read from
postgresql.conf or pg_hba.conf or other files for every connection so I
don't see that using the file system is going to be that slow. Of
course, we removed those file reads because they were slow, but they
were also much larger and more complex in requiring parsing and stuff,
while this is just a list of binary values. We also have a GUC dump
file that is read by exec too.
The downside of shared memory is that you would need the postmaster to
write into shared memory and you have to allocate enough shared memory
for all backends, but clearly it could be done. You could just pass the
backend slot number to the child and the child could read from the
offset. Not sure how to cleanly do the GUC dump file because it is of
variable length depending on the number of GUC variables changed.
I guess the big question is whether it is worth doing in shared memory.
We also would have to pass the shared memory address to the child, and
make sure the child knew the proper offset in shared memory to find its
values.
Of course, stuff that is variable length would be a problem in shared
memory, and we have some of those for the GUC defaults.
--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
From: | Neil Conway <neilc(at)samurai(dot)com> |
---|---|
To: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> |
Cc: | Claudio Natoli <claudio(dot)natoli(at)memetrics(dot)com>, "'pgsql-patches(at)postgresql(dot)org'" <pgsql-patches(at)postgresql(dot)org> |
Subject: | Re: fork/exec patch |
Date: | 2003-12-14 21:41:16 |
Message-ID: | 87y8tf9iwz.fsf@mailbox.samurai.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers pgsql-hackers-win32 pgsql-patches |
Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> I don't think we ever discussed it, but it seemed logical and a minimal
> change to the code. We already have a GUC write of non-default values
> for exec and no one had issues with that.
For the record, I think that is ugly as well :-)
Anyway, I'm not necessarily arguing that using shmem is the right way
to go here -- that was merely an off-the-cuff suggestion. I'm just
saying that whatever solution we end up with, ISTM we can do better
than writing out + reading in a file for /every/ new connection.
-Neil
From: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> |
---|---|
To: | Neil Conway <neilc(at)samurai(dot)com> |
Cc: | Claudio Natoli <claudio(dot)natoli(at)memetrics(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>, PostgreSQL Win32 port list <pgsql-hackers-win32(at)postgreSQL(dot)org> |
Subject: | Re: [PATCHES] fork/exec patch |
Date: | 2003-12-14 21:56:42 |
Message-ID: | 200312142156.hBELugo16491@candle.pha.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers pgsql-hackers-win32 pgsql-patches |
Neil Conway wrote:
> Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> > I don't think we ever discussed it, but it seemed logical and a minimal
> > change to the code. We already have a GUC write of non-default values
> > for exec and no one had issues with that.
>
> For the record, I think that is ugly as well :-)
>
> Anyway, I'm not necessarily arguing that using shmem is the right way
> to go here -- that was merely an off-the-cuff suggestion. I'm just
> saying that whatever solution we end up with, ISTM we can do better
> than writing out + reading in a file for /every/ new connection.
[ Moved to hackers and win32. Discussion is writing postmaster-constant
and per-backend variables to a file for exec'ed backends to read.]
Sure --- I am all ears. I am looking for suggestions. I couldn't think
of anything better. I did ask a month ago for ideas on how to do this,
but got no reply.
One idea I had was to write the postmaster-constant values into one
file, and the per-backend values into another so you would write less
data for every backend, but then every backend has to read two files.
Is that a win?
--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
From: | Dennis Bjorklund <db(at)zigo(dot)dhs(dot)org> |
---|---|
To: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> |
Cc: | Neil Conway <neilc(at)samurai(dot)com>, Claudio Natoli <claudio(dot)natoli(at)memetrics(dot)com>, "'pgsql-patches(at)postgresql(dot)org'" <pgsql-patches(at)postgresql(dot)org> |
Subject: | Re: fork/exec patch |
Date: | 2003-12-14 22:10:36 |
Message-ID: | Pine.LNX.4.44.0312142306560.10157-100000@zigo.dhs.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers pgsql-hackers-win32 pgsql-patches |
On Sun, 14 Dec 2003, Bruce Momjian wrote:
> change to the code. We already have a GUC write of non-default values
> for exec and no one had issues with that. Of course, this one is
> per-backend.
>
> Yea, we could use shared memory for this too, but I don't see a problem
> with using the file system.
Why not use an anonymous pipe to send data from the parent to the child
process? That is a common way to handle this problem in win32 (and in unix
by the way). The parent sets up the pipe and the child process inherits
the handle, and after that the child and parent can excange information in
private.
--
/Dennis
From: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> |
---|---|
To: | Dennis Bjorklund <db(at)zigo(dot)dhs(dot)org> |
Cc: | Neil Conway <neilc(at)samurai(dot)com>, Claudio Natoli <claudio(dot)natoli(at)memetrics(dot)com>, "'pgsql-patches(at)postgresql(dot)org'" <pgsql-patches(at)postgresql(dot)org> |
Subject: | Re: fork/exec patch |
Date: | 2003-12-14 22:21:48 |
Message-ID: | 200312142221.hBEMLmT20146@candle.pha.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers pgsql-hackers-win32 pgsql-patches |
Dennis Bjorklund wrote:
> On Sun, 14 Dec 2003, Bruce Momjian wrote:
>
> > change to the code. We already have a GUC write of non-default values
> > for exec and no one had issues with that. Of course, this one is
> > per-backend.
> >
> > Yea, we could use shared memory for this too, but I don't see a problem
> > with using the file system.
>
> Why not use an anonymous pipe to send data from the parent to the child
> process? That is a common way to handle this problem in win32 (and in unix
> by the way). The parent sets up the pipe and the child process inherits
> the handle, and after that the child and parent can excange information in
> private.
Doesn't that require the postmaster to stay around to feed that
information into the pipe or can the postmaster just shove the data and
continue on, and how do the old pipes get cleaned up? Seems messy.
Also has to work on Unix too for testing.
--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
From: | Dennis Bjorklund <db(at)zigo(dot)dhs(dot)org> |
---|---|
To: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> |
Cc: | Neil Conway <neilc(at)samurai(dot)com>, Claudio Natoli <claudio(dot)natoli(at)memetrics(dot)com>, "'pgsql-patches(at)postgresql(dot)org'" <pgsql-patches(at)postgresql(dot)org> |
Subject: | Re: fork/exec patch |
Date: | 2003-12-14 22:40:09 |
Message-ID: | Pine.LNX.4.44.0312142329580.10157-100000@zigo.dhs.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers pgsql-hackers-win32 pgsql-patches |
On Sun, 14 Dec 2003, Bruce Momjian wrote:
> > Why not use an anonymous pipe to send data from the parent to the child
> > process?
>
> Doesn't that require the postmaster to stay around to feed that
> information into the pipe or can the postmaster just shove the data and
> continue on, and how do the old pipes get cleaned up?
I think that one can just output the data and close that end of the pipe.
But i've not looked at win32 the last 5 years or so, I could be wrong.
> Seems messy.
Maybe, but to me the solution where you write to files are much more ugly.
If one does not like pipes, there are other ipc mechanisms that does not
involve creating, reading and deleting a file on each connect.
Does windows have a temp filesystem where the temp files are not actually
written out on disk? It's still ugly but better then hitting a disk all
the time.
> Also has to work on Unix too for testing.
Everything can not work in unix, CreateProcess() and fork() are different.
However, the pipe solution can be mimiced in unix, but it will not be the
same code since the api's are different. So that does not give much.
--
/Dennis
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> |
Cc: | Neil Conway <neilc(at)samurai(dot)com>, Claudio Natoli <claudio(dot)natoli(at)memetrics(dot)com>, "'pgsql-patches(at)postgresql(dot)org'" <pgsql-patches(at)postgresql(dot)org> |
Subject: | Re: fork/exec patch |
Date: | 2003-12-14 23:53:22 |
Message-ID: | 3694.1071446002@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers Postg윈 토토SQL : Postg윈 pgsql-patches |
Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> I don't think we ever discussed it, but it seemed logical and a minimal
> change to the code. We already have a GUC write of non-default values
> for exec and no one had issues with that.
You can hardly claim that "no one had issues with that". I complained
about it and I think other people did too. It's a messy, ugly approach;
moreover we have no field experience that says it's reliable.
It may be the least messy, ugly approach available, but I concur with
Neil's wish to at least look for other answers.
regards, tom lane
From: | Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, Neil Conway <neilc(at)samurai(dot)com>, Claudio Natoli <claudio(dot)natoli(at)memetrics(dot)com>, "'pgsql-patches(at)postgresql(dot)org'" <pgsql-patches(at)postgresql(dot)org> |
Subject: | Re: fork/exec patch |
Date: | 2003-12-15 00:02:31 |
Message-ID: | 20031215000231.GB9015@dcc.uchile.cl |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers pgsql-hackers-win32 pgsql-patches |
On Sun, Dec 14, 2003 at 06:53:22PM -0500, Tom Lane wrote:
> Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> > I don't think we ever discussed it, but it seemed logical and a minimal
> > change to the code. We already have a GUC write of non-default values
> > for exec and no one had issues with that.
>
> You can hardly claim that "no one had issues with that". I complained
> about it and I think other people did too. It's a messy, ugly approach;
> moreover we have no field experience that says it's reliable.
Don't the FSM and the system catalog cache use a similar mechanism?
--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"Limítate a mirar... y algun día veras"
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl> |
Cc: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, Neil Conway <neilc(at)samurai(dot)com>, Claudio Natoli <claudio(dot)natoli(at)memetrics(dot)com>, "'pgsql-patches(at)postgresql(dot)org'" <pgsql-patches(at)postgresql(dot)org> |
Subject: | Re: fork/exec patch |
Date: | 2003-12-15 00:14:53 |
Message-ID: | 3836.1071447293@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers pgsql-hackers-win32 pgsql-patches |
Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl> writes:
> On Sun, Dec 14, 2003 at 06:53:22PM -0500, Tom Lane wrote:
>> You can hardly claim that "no one had issues with that".
> Don't the FSM and the system catalog cache use a similar mechanism?
FSM uses a backing file to hold information over a database shutdown
(write once during shutdown, read once during startup). That's a little
different from once per backend fork. Also, there are no race
conditions to worry about, and finally the system does not *require* the
backing file to be either present or correct.
The catalog cache uses a file that typically gets updated once per
VACUUM. Again, the file does not have to be present, nor correct.
There are mechanisms in place to deal with the cases (including race
conditions) where it's broken or obsolete.
I have not looked at the proposed fork/exec code in any detail, but
IIUC it will be *necessary* that the intermediate file be present, and
correct. I think a minimum requirement for accepting this solution is a
sketch of how race conditions will be dealt with (ie, postmaster changes
its own value of some variable immediately after making the temp file).
I don't necessarily say that the first-cut patch has to get it right,
but we'd better understand how we will get to where it is right.
regards, tom lane
From: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl>, Neil Conway <neilc(at)samurai(dot)com>, Claudio Natoli <claudio(dot)natoli(at)memetrics(dot)com>, "'pgsql-patches(at)postgresql(dot)org'" <pgsql-patches(at)postgresql(dot)org> |
Subject: | Re: fork/exec patch |
Date: | 2003-12-15 03:14:48 |
Message-ID: | 200312150314.hBF3Emf27049@candle.pha.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers pgsql-hackers-win32 pgsql-patches |
Tom Lane wrote:
> Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl> writes:
> > On Sun, Dec 14, 2003 at 06:53:22PM -0500, Tom Lane wrote:
> >> You can hardly claim that "no one had issues with that".
>
> > Don't the FSM and the system catalog cache use a similar mechanism?
>
> FSM uses a backing file to hold information over a database shutdown
> (write once during shutdown, read once during startup). That's a little
> different from once per backend fork. Also, there are no race
> conditions to worry about, and finally the system does not *require* the
> backing file to be either present or correct.
>
> The catalog cache uses a file that typically gets updated once per
> VACUUM. Again, the file does not have to be present, nor correct.
> There are mechanisms in place to deal with the cases (including race
> conditions) where it's broken or obsolete.
>
> I have not looked at the proposed fork/exec code in any detail, but
> IIUC it will be *necessary* that the intermediate file be present, and
> correct. I think a minimum requirement for accepting this solution is a
> sketch of how race conditions will be dealt with (ie, postmaster changes
> its own value of some variable immediately after making the temp file).
> I don't necessarily say that the first-cut patch has to get it right,
> but we'd better understand how we will get to where it is right.
Agreed, added to the Win32 status page:
* remove per-backend parameter file and move into shared memory
--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
From: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Neil Conway <neilc(at)samurai(dot)com>, Claudio Natoli <claudio(dot)natoli(at)memetrics(dot)com>, "'pgsql-patches(at)postgresql(dot)org'" <pgsql-patches(at)postgresql(dot)org> |
Subject: | Re: fork/exec patch |
Date: | 2003-12-15 03:17:30 |
Message-ID: | 200312150317.hBF3HUb27387@candle.pha.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers pgsql-hackers-win32 pgsql-patches |
Tom Lane wrote:
> Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> > I don't think we ever discussed it, but it seemed logical and a minimal
> > change to the code. We already have a GUC write of non-default values
> > for exec and no one had issues with that.
>
> You can hardly claim that "no one had issues with that". I complained
> about it and I think other people did too. It's a messy, ugly approach;
> moreover we have no field experience that says it's reliable.
>
> It may be the least messy, ugly approach available, but I concur with
> Neil's wish to at least look for other answers.
Absolutely. I am not happy with the GUC file either, but can't see a
better way right now. I have already documented your concern about the
GUC race condition issue on the Win32 status page so we will not forget
about it.
--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> |
Cc: | Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl>, Neil Conway <neilc(at)samurai(dot)com>, Claudio Natoli <claudio(dot)natoli(at)memetrics(dot)com>, "'pgsql-patches(at)postgresql(dot)org'" <pgsql-patches(at)postgresql(dot)org> |
Subject: | Re: fork/exec patch |
Date: | 2003-12-15 03:34:09 |
Message-ID: | 5557.1071459249@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers pgsql-hackers-win32 pgsql-patches |
Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> Agreed, added to the Win32 status page:
> * remove per-backend parameter file and move into shared memory
[itch] I'm not sure that's an answer either; see my comments about how
the postmaster shouldn't depend on the contents of shared memory being
valid.
We could get away with the postmaster having a write-only relationship
to shared memory (put value of variable X into predetermined location
Y), but I don't think that helps. It doesn't work for variable-size
values --- we certainly don't want the postmaster dependent on memory
allocation structures being valid within shared memory --- and what
about locks? Do you want the postmaster writing shared values without
taking a lock, or relying on shared-memory lock structures to be valid
enough to not lock it up or crash it? My answer to either of those is
"no way, Jose" ...
Writing temp files may actually be a cleaner solution than writing
shared memory, once we take these considerations into account. My gripe
about race conditions was "I want to see how you solve this", and wasn't
intended to mean "I don't think that is soluble".
regards, tom lane
From: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl>, Neil Conway <neilc(at)samurai(dot)com>, Claudio Natoli <claudio(dot)natoli(at)memetrics(dot)com>, "'pgsql-patches(at)postgresql(dot)org'" <pgsql-patches(at)postgresql(dot)org> |
Subject: | Re: fork/exec patch |
Date: | 2003-12-15 03:41:34 |
Message-ID: | 200312150341.hBF3fYR01068@candle.pha.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers pgsql-hackers-win32 pgsql-patches |
Tom Lane wrote:
> Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> > Agreed, added to the Win32 status page:
> > * remove per-backend parameter file and move into shared memory
>
> [itch] I'm not sure that's an answer either; see my comments about how
> the postmaster shouldn't depend on the contents of shared memory being
> valid.
>
> We could get away with the postmaster having a write-only relationship
> to shared memory (put value of variable X into predetermined location
> Y), but I don't think that helps. It doesn't work for variable-size
> values --- we certainly don't want the postmaster dependent on memory
> allocation structures being valid within shared memory --- and what
> about locks? Do you want the postmaster writing shared values without
> taking a lock, or relying on shared-memory lock structures to be valid
> enough to not lock it up or crash it? My answer to either of those is
> "no way, Jose" ...
>
> Writing temp files may actually be a cleaner solution than writing
> shared memory, once we take these considerations into account. My gripe
> about race conditions was "I want to see how you solve this", and wasn't
> intended to mean "I don't think that is soluble".
Read my idea that shared memory for signals might be required, and a
separate shared memory segment might be used for parameter passing too.
I added a question mark to the win32 TODO item, so we can keep as an
open item.
--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
From: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> |
---|---|
To: | Claudio Natoli <claudio(dot)natoli(at)memetrics(dot)com> |
Cc: | "'pgsql-patches(at)postgresql(dot)org'" <pgsql-patches(at)postgresql(dot)org> |
Subject: | Re: fork/exec patch |
Date: | 2003-12-16 01:23:41 |
Message-ID: | 200312160123.hBG1Nf019439@candle.pha.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers pgsql-hackers-win32 pgsql-patches |
Your patch has been added to the PostgreSQL unapplied patches list at:
http://momjian.postgresql.org/cgi-bin/pgpatches
I will try to apply it within the next 48 hours.
---------------------------------------------------------------------------
Claudio Natoli wrote:
>
> This patch is the next step towards (re)allowing fork/exec.
>
> Bruce, I've cleaned up the parts we discussed, and, pending objections from
> anyone else, it is ready for application to HEAD.
>
> Cheers,
> Claudio
>
> ---
> Certain disclaimers and policies apply to all email sent from Memetrics.
> For the full text of these disclaimers and policies see
> <a
> href="http://www.memetrics.com/emailpolicy.html">http://www.memetrics.com/em
> ailpolicy.html</a>
>
>
[ Attachment, skipping... ]
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
From: | Neil Conway <neilc(at)samurai(dot)com> |
---|---|
To: | Claudio Natoli <claudio(dot)natoli(at)memetrics(dot)com> |
Cc: | "'pgsql-patches(at)postgresql(dot)org'" <pgsql-patches(at)postgresql(dot)org> |
Subject: | Re: fork/exec patch |
Date: | 2003-12-16 04:37:40 |
Message-ID: | 87d6ap74yz.fsf@mailbox.samurai.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers pgsql-hackers-win32 pgsql-patches |
Claudio Natoli <claudio(dot)natoli(at)memetrics(dot)com> writes:
> This patch is the next step towards (re)allowing fork/exec.
I've included a few comments on the patch below. Unfortunately I only
had time to briefly look over the code...
Why did you change ShmemIndexLock from an LWLock to a spinlock?
The number of "FIXME" or "This is ugly" comments doesn't ease my mind
about this patch :-) How many of these issues do you plan to resolve?
Index: src/backend/tcop/postgres.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/backend/tcop/postgres.c,v
retrieving revision 1.379
diff -c -w -r1.379 postgres.c
*** src/backend/tcop/postgres.c 1 Dec 2003 22:15:37 -0000 1.379
--- src/backend/tcop/postgres.c 13 Dec 2003 06:18:44 -0000
***************
*** 2133,2139 ****
case 'D': /* PGDATA directory */
if (secure)
potential_DataDir = optarg;
- break;
case 'd': /* debug level */
{
Why was this change made? If you actually intend to fall through the
case here, please make it clear via a comment.
+ /*
+ * The following need to be available to the read/write_backend_variables
+ * functions
+ */
+ extern XLogRecPtr RedoRecPtr;
+ extern XLogwrtResult LogwrtResult;
+ extern slock_t *ShmemLock;
+ extern slock_t *ShmemIndexLock;
+ extern void *ShmemIndexAlloc;
+ typedef struct LWLock LWLock;
+ extern LWLock *LWLockArray;
+ extern slock_t *ProcStructLock;
+ extern int pgStatSock;
I wonder whether it is cleaner to make these properly public, rather
than using the NON_EXEC_STATIC #ifdef... (I'm not necessarily saying
it is, I'm just tossing it out there).
+ #define get_tmp_backend_var_file_name(buf,id) \
+ Assert(DataDir); \
+ sprintf((buf), \
+ "%s/%s/%s.backend_var.%d", \
+ DataDir, \
+ PG_TEMP_FILES_DIR, \
+ PG_TEMP_FILE_PREFIX, \
+ (id))
This macro needs to be enclosed in a do {} while (0) block. Also,
what does the "var" in the name of this macro refer to?
+ #define get_tmp_backend_var_dir(buf) \
+ sprintf((buf),"%s/%s",DataDir,PG_TEMP_FILES_DIR)
This seems a little pointless, IMHO.
+ static void
+ write_backend_variables(pid_t pid, Port *port)
+ {
+ char filename[MAXPGPATH];
+ FILE *fp;
+ get_tmp_backend_var_file_name(filename,pid);
+
+ /* Open file */
+ fp = AllocateFile(filename, PG_BINARY_W);
+ if (!fp)
+ {
+ /* As per OpenTemporaryFile... */
+ char dirname[MAXPGPATH];
+ get_tmp_backend_var_dir(dirname);
+ mkdir(dirname, S_IRWXU);
+
+ fp = AllocateFile(filename, PG_BINARY_W);
+ if (!fp)
+ {
+ ereport(FATAL,
+ (errcode_for_file_access(),
+ errmsg("could not write to file \"%s\": %m", filename)));
+ return;
+ }
+ }
ereport(FATAL) seems too strong, doesn't it?
+ read_var(LWLockArray,fp);
+ read_var(ProcStructLock,fp);
+ read_var(pgStatSock,fp);
+
+ /* Release file */
+ FreeFile(fp);
+ unlink(filename);
You should probably check the return value of unlink().
(circa line 335 of ipc/shmem.c:)
/*
* If the shmem index doesn't exist, we are bootstrapping: we must
* be trying to init the shmem index itself.
*
! * Notice that the ShmemLock is held until the shmem index has
* been completely initialized.
*/
Doesn't this function still acquire ShmemIndexLock? (i.e. why was this
comment changed?)
-Neil
From: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> |
---|---|
To: | Neil Conway <neilc(at)samurai(dot)com> |
Cc: | Claudio Natoli <claudio(dot)natoli(at)memetrics(dot)com>, "'pgsql-patches(at)postgresql(dot)org'" <pgsql-patches(at)postgresql(dot)org> |
Subject: | Re: fork/exec patch |
Date: | 2003-12-16 05:06:03 |
Message-ID: | 200312160506.hBG563Z21654@candle.pha.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers Postg사설 토토SQL : Postg사설 pgsql-patches |
Neil Conway wrote:
> + /*
> + * The following need to be available to the read/write_backend_variables
> + * functions
> + */
> + extern XLogRecPtr RedoRecPtr;
> + extern XLogwrtResult LogwrtResult;
> + extern slock_t *ShmemLock;
> + extern slock_t *ShmemIndexLock;
> + extern void *ShmemIndexAlloc;
> + typedef struct LWLock LWLock;
> + extern LWLock *LWLockArray;
> + extern slock_t *ProcStructLock;
> + extern int pgStatSock;
>
> I wonder whether it is cleaner to make these properly public, rather
> than using the NON_EXEC_STATIC #ifdef... (I'm not necessarily saying
> it is, I'm just tossing it out there).
This was my idea. Rather than making statics as globals, they are
global only for exec() builds. This seemed safest. They need to be
extern for exec() because we need to reference them in a function that
writes all the postmaster globals to a file. We could have had a write
function in every C file that needed it and call the write function from
postmaster.c, but that seems like too much bloat. If we make them
extern in all builds we lose the safety of a static.
Your other comments are good and I will wait for Claudio to respond.
--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Neil Conway <neilc(at)samurai(dot)com> |
Cc: | Claudio Natoli <claudio(dot)natoli(at)memetrics(dot)com>, "'pgsql-patches(at)postgresql(dot)org'" <pgsql-patches(at)postgresql(dot)org> |
Subject: | Re: fork/exec patch |
Date: | 2003-12-16 05:11:04 |
Message-ID: | 18723.1071551464@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers pgsql-hackers-win32 pgsql-patches |
Neil Conway <neilc(at)samurai(dot)com> writes:
> Why did you change ShmemIndexLock from an LWLock to a spinlock?
That one I can answer --- it's a bootstrapping issue: we can't use
LWLocks until we have a PGProc (*MyProc), and we can't set that up
without looking in the ShmemIndex for the related data structures.
So ShmemIndex needs to use a more primitive lock type. This is actually
the way the code used to do it; I changed the lock type when the
opportunity presented itself, but if we're going to support fork/exec
again then we have to go back to how it was done before.
Your other comments seem pretty germane to me, except for
> I wonder whether it is cleaner to make these properly public, rather
> than using the NON_EXEC_STATIC #ifdef... (I'm not necessarily saying
> it is, I'm just tossing it out there).
I don't want to make these things public, because we don't really want
any other modules accessing them. NON_EXEC_STATIC is pretty ugly,
but it does guarantee that we will soon find out about any unintended
cross-module references, because they won't compile on Unix systems.
If you've got an idea about a cleaner way to do it, I'm all ears ...
regards, tom lane
From: | Neil Conway <neilc(at)samurai(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Claudio Natoli <claudio(dot)natoli(at)memetrics(dot)com>, "'pgsql-patches(at)postgresql(dot)org'" <pgsql-patches(at)postgresql(dot)org> |
Subject: | Re: fork/exec patch |
Date: | 2003-12-16 07:44:43 |
Message-ID: | 87llpd2olw.fsf@mailbox.samurai.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers pgsql-hackers-win32 Postg사설 토토SQL |
Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:
> That one I can answer --- it's a bootstrapping issue: we can't use
> LWLocks until we have a PGProc (*MyProc), and we can't set that up
> without looking in the ShmemIndex for the related data structures.
> So ShmemIndex needs to use a more primitive lock type.
Fair enough.
My next question would have been to ask whether switching to a
spinlock here will be a performance problem. In looking at the code,
it seems we only hold the ShmemIndexLock for a long time (hundreds of
instructions & multiple system calls) while bootstrapping the shmem
index hash table itself. Otherwise, the lock is acquired and released
quickly, and even then it is only done during backend initialization,
so there shouldn't be much contention for it. Is this analysis
correct?
> I don't want to make these things public, because we don't really
> want any other modules accessing them.
I agree, both ways are non-optimal for different reasons. Can anyone
else see a better way to do this?
-Neil
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Neil Conway <neilc(at)samurai(dot)com> |
Cc: | Claudio Natoli <claudio(dot)natoli(at)memetrics(dot)com>, "'pgsql-patches(at)postgresql(dot)org'" <pgsql-patches(at)postgresql(dot)org> |
Subject: | Re: fork/exec patch |
Date: | 2003-12-16 14:01:33 |
Message-ID: | 20772.1071583293@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers pgsql-hackers-win32 pgsql-patches |
Neil Conway <neilc(at)samurai(dot)com> writes:
> My next question would have been to ask whether switching to a
> spinlock here will be a performance problem. In looking at the code,
> it seems we only hold the ShmemIndexLock for a long time (hundreds of
> instructions & multiple system calls) while bootstrapping the shmem
> index hash table itself. Otherwise, the lock is acquired and released
> quickly, and even then it is only done during backend initialization,
> so there shouldn't be much contention for it. Is this analysis
> correct?
Yes, at least that was the theory I was working from when I suggested
Claudio do it this way ...
regards, tom lane
From: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> |
---|---|
To: | Claudio Natoli <claudio(dot)natoli(at)memetrics(dot)com> |
Cc: | "'pgsql-patches(at)postgresql(dot)org'" <pgsql-patches(at)postgresql(dot)org> |
Subject: | Re: fork/exec patch |
Date: | 2003-12-17 00:12:29 |
Message-ID: | 200312170012.hBH0CTo15868@candle.pha.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers pgsql-hackers-win32 pgsql-patches |
Patch withdrawn. Author will resubmit new version.
---------------------------------------------------------------------------
Claudio Natoli wrote:
>
> This patch is the next step towards (re)allowing fork/exec.
>
> Bruce, I've cleaned up the parts we discussed, and, pending objections from
> anyone else, it is ready for application to HEAD.
>
> Cheers,
> Claudio
>
> ---
> Certain disclaimers and policies apply to all email sent from Memetrics.
> For the full text of these disclaimers and policies see
> <a
> href="http://www.memetrics.com/emailpolicy.html">http://www.memetrics.com/em
> ailpolicy.html</a>
>
>
[ Attachment, skipping... ]
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073