fork/exec patch: pre-CreateProcess finalization

Started by Claudio Natoliover 22 years ago52 messagespatches
Jump to latest
#1Claudio Natoli
claudio.natoli@memetrics.com

For application to HEAD, pending community review.

Final rearrangement of main postgresql child process (ie.
BackendFork/SSDataBase/pgstat) startup, to allow fork/exec calls to closely
mimic (the soon to be provided) Win32 CreateProcess equivalent calls.

Whereas the existing code forks and allow the child process to marshal up
its "argument list", the EXEC_BACKEND case has been changed to allow the
parent process to do this marshalling, with the child process exec'ing
immediately after the fork.

This has required some reworking of the existing code base, particularly to
BackendFork (which now actually does the fork()). As such, I've been
anticipating that this will be the most controversial of the fork/exec
patches, so critique away :-)

This is the last patch required before the actual Win32 calls can be put in
place.

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>

Attachments:

diff5c.outapplication/octet-stream; name=diff5c.outDownload+263-218
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Claudio Natoli (#1)
Re: fork/exec patch: pre-CreateProcess finalization

Claudio Natoli <claudio.natoli@memetrics.com> writes:

This has required some reworking of the existing code base, particularly to
BackendFork (which now actually does the fork()). As such, I've been
anticipating that this will be the most controversial of the fork/exec
patches, so critique away :-)

You haven't explained why that's necessary. Given the fact that this
patch seems to hugely complicate the postmaster logic --- not so much
either path individually, but the messy #ifdef interleaving of two
radically different programs --- I am inclined to reject it on style
grounds alone.

We should either find a way to make the fork/exec path more like the
existing code, or bite the bullet and change them both. Doing it the
way you have here will create an unmaintainable mess. I'm not prepared
to work on a postmaster in which a step as basic as fork() happens in
two different places depending on an #ifdef.

If you want to change them both, let's first see the reason why it's
necessary.

regards, tom lane

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Tom Lane (#2)
Re: fork/exec patch: pre-CreateProcess finalization

I said:

We should either find a way to make the fork/exec path more like the
existing code, or bite the bullet and change them both.

It occurs to me that you probably need some concrete suggestions about
what to do. Here's one.

There are really three separate sections in this code: the postmaster
(which no longer does much except fork off a subprocess on receipt of a
new connection), the "sub-postmaster" which does client authentication,
and the backend.

Historical note: formerly the sub-postmaster actions were done in the
parent postmaster process, with a sort of poor man's threading logic
to allow the postmaster to interleave multiple client authentication
operations. We had to change that because various libraries like SSL,
PAM, and Kerberos weren't amenable to pseudo-threading.

It is worth maintaining a clean distinction between sub-postmaster and
backend because when we launch a standalone backend, we don't want the
sub-postmaster part of the code. The command line syntax accepted by
PostgresMain() is largely designed for the convenience of the standalone
backend case, with a couple of simple hacks for the under-postmaster case.

Now it seems to me that a lot of the mess in your latest patch comes
from trying to set up the backend command string before you've forked,
and therefore before you've done any of the sub-postmaster actions.
That's not gonna work.

What I'd suggest is adding a new entry point from main.c, say
SubPostmasterMain(), with its own command line syntax. Perhaps
postmaster -fork ... additional args ...
(where -fork is what cues main.c where to dispatch to, and the
additional args are just those that need to be passed from the
postmaster to the sub-postmaster, without any of the additional
information that will be learned by the sub-postmaster during
client authentication.)

In the Windows case the postmaster would fork/exec to this routine,
which would re-load as much of the postmaster context as was needed
and then call BackendFork (which we really oughta rename to something
else). BackendFork would execute the client auth process and then
simply call PostgresMain with a correctly constructed argument list.

In the Unix case we don't bother compiling SubPostmasterMain, we just
fork and go straight to BackendFork as the code does now.

In essence, this design makes SubPostmasterMain responsible for
emulating Unix-style fork(), ie, fork without loss of static variable
contents. It would need to reload as many variables as we needed.

I think this is a cleaner approach since it creates a layer of code
which is simply there in one case and not there in the other, rather
than making arbitrary changes in the layers above and below depending
on #ifdefs.

regards, tom lane

#4Claudio Natoli
claudio.natoli@memetrics.com
In reply to: Tom Lane (#3)
Re: fork/exec patch: pre-CreateProcess finalization

Thanks for your comments Tom.

Tom Lane writes:

Claudio Natoli <claudio.natoli@memetrics.com> writes:

This has required some reworking of the existing code base, particularly

to

BackendFork (which now actually does the fork()). As such, I've been
anticipating that this will be the most controversial of

the fork/exec patches, so critique away :-)

You haven't explained why that's necessary. Given the fact that this
patch seems to hugely complicate the postmaster logic --- not so much
either path individually, but the messy #ifdef interleaving of two
radically different programs --- I am inclined to reject it on style
grounds alone.

I have to agree, as I wasn't particularly happy with the BackendFork section
of this patch. You didn't really seem to comment on the pgstat changes,
which were much cleaner, so perhaps (like me) you were happier with these
changes.

So, could you give me an indication as to whether or not making changes to
the BackendFork logic as done for the pgstat logic (specifically, replacing
fork() call with a new, argument marshalling routine to do fork/exec) would
be more acceptable? The reason I avoided this in the BackendFork case was,
predominantly, code duplication. Creating a new "BackendForkExec" would, I
think, result in a lot of similarity between the two routines. [yes,
BackendFork is poorly named, although I'd still think of moving the fork()
call into BackendFork anyway, thereby justifying its name. But, much more
importantly, for symmetry with the code format that will inevitably arise in
the fork/exec case; see below]

We should either find a way to make the fork/exec path more like the
existing code, or bite the bullet and change them both. Doing it the
way you have here will create an unmaintainable mess. I'm not prepared
to work on a postmaster in which a step as basic as fork() happens in
two different places depending on an #ifdef.

["unmaintainable mess": yeah, I had the exact same thought when I'd
finished. "No one's ever going to be able to rework this properly".]

I'm afraid that, short of removing all SubPostmaster actions from
BackendFork, the need to do fork in two different places (at least,
physically, if not logically different) will remain. After fork/exec'ing,
the child process can't recover the context needed to create the argument
list which it'll need to build up the PostgresMain arg list.

So, in summary, I see two solutions:

a) do something similar to BackendFork as done for pgstat, specifically:
- move the fork call into BackendFork
- create a fork/exec equivalent to BackendFork
- #ifdef the call to the appropriate function in BackendStartup
PRO: child is forked in the same logical place
CON: possible duplication in code between BackendFork + BackendForkExec

b) delay the fork() call to the end of BackendFork in both fork/exec and
normal cases, turning it into solely an argument formatter for PostgresMain
- move BackendInit, port->cmdline_options parsing + MemoryContext
calls into PostgresMain
PRO: forking in same (physical) location in code; no duplication
CON: additional complexity at the start of PostgresMain to avoid these
calls in stand-alone backend case

Which is the lesser of two evils? FWIW, I prefer the latter, as it makes the
normal + fork/exec cases effectively identical, for a little added
complexity to PostgresMain.

There's also the alternative you outlined, but I think it is less workable
than the above options:

Now it seems to me that a lot of the mess in your latest patch comes
from trying to set up the backend command string before you've forked,
and therefore before you've done any of the sub-postmaster actions.
That's not gonna work.

I agree that this is where the mess comes from, but I think this (setting up
backend command string before fork) is *exactly* what needs to occur in the
fork/exec case (leading into the Win32 CreateProcess calls). If we want this
code to work in the Win32 case, we basically can't do any processing between
the fork + exec calls, and I think recovering all the context to do the
command string marshalling post fork/exec is untenable.

What I'd suggest is adding a new entry point from main.c, say
SubPostmasterMain(), with its own command line syntax. Perhaps
postmaster -fork ... additional args ...
(where -fork is what cues main.c where to dispatch to, and the
additional args are just those that need to be passed from the
postmaster to the sub-postmaster, without any of the additional
information that will be learned by the sub-postmaster during
client authentication.)

In the Windows case the postmaster would fork/exec to this routine,
which would re-load as much of the postmaster context as was needed
and then call BackendFork (which we really oughta rename to something
else). BackendFork would execute the client auth process and then
simply call PostgresMain with a correctly constructed argument list.

Here's the critical difference in our thinking:

ISTM that we'll have to go to a lot of work to get the fork/exec
case to re-load the context required to format up the argument list to
PostgresMain. Certainly, it is a lot more work than allowing the postmaster
itself (not the forked child) to create the argument list, albeit moving
auth to PostgresMain.

Ok. So, in conclusion we are in agreement on at least one thing: the current
patch sucks.

But, I suspect we may have an impasse on a sole crucial point: setting up
the backend command string before forking. I'm all for it, and you seem
pretty much against it.

So, I guess I could try to bring you around with another, cleaner patch
using one of the alternatives listed above. But, before doing that, I guess
I should give you a chance to:
a) try to convince me otherwise
b) indicate which of the two alternatives you (even grudgingly :-) prefer
(or another alternative in light of the above)

Again, thanks for your comments, and looking forward to your reply (so that,
hopefully, I can get cracking on a new patch).

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>
#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: Claudio Natoli (#4)
Re: fork/exec patch: pre-CreateProcess finalization

Claudio Natoli <claudio.natoli@memetrics.com> writes:

Ok. So, in conclusion we are in agreement on at least one thing: the current
patch sucks.

Good, I'm glad we see eye to eye on that ;-)

Here's the critical difference in our thinking:

ISTM that we'll have to go to a lot of work to get the fork/exec
case to re-load the context required to format up the argument list to
PostgresMain. Certainly, it is a lot more work than allowing the postmaster
itself (not the forked child) to create the argument list, albeit moving
auth to PostgresMain.

I don't follow your thinking here. The information that has to be
reloaded *must* be passed across the fork/exec boundary in either case.
For example, there is no alternative to telling the backend process
where PGDATA is: it's got to be passed down some way or another. The
Unix implementation assumes it can just inherit the value of a static
variable, while the Windows version will have to do something else.
I take no position here on whether we pass it as a command line item,
or through a temporary file, or whatever: it has to be passed down.

The reason your patch is messy is that the PostgresMain command line
string involves both information passed down from the postmaster and
information acquired from the client's connection-request packet.
We could consider redesigning that command line behavior, but we don't
really want to since it would impact the standalone-backend case. So
I'm proposing substituting two levels of command-line processing within
the exec'd backend process. The first level is responsible for
transferring information inherited from the postmaster (which we are
going to have to do *anyway*, somewhere, and this provides a nice
localized place to do it) and then the second level is fully compatible
with the standalone-backend case and the Unix-fork case.

I'm afraid that, short of removing all SubPostmaster actions from
BackendFork, the need to do fork in two different places (at least,
physically, if not logically different) will remain.

I am not by any means saying that the fork() call has to stay exactly
where it is in the existing code. We clearly want to refactor things
so that fork() is close to the invocation of FooMain() (or equivalently
exec() in the Windows case). I think it's a historical artifact that
these steps got separated in the existing code base.

After fork/exec'ing,
the child process can't recover the context needed to create the argument
list which it'll need to build up the PostgresMain arg list.

If that's literally true, then we are screwed because things cannot
work. Pardon me for doubting this statement. All that information
*must* be available in the child, once it has analyzed the information
it must be able to collect from the postmaster and performed the client
authentication handshake.

So, in summary, I see two solutions:

I still think there's a third answer: create an intermediate layer
that's responsible for recovering the information that has to be
inherited from the parent process. I don't say this requires zero
rearrangement of existing code, I just say it's a more maintainable
design than either of the alternatives you suggest.

In particular, this alternative is quite unworkable:

b) delay the fork() call to the end of BackendFork in both fork/exec and
normal cases, turning it into solely an argument formatter for PostgresMain

We can *not* postpone the fork() until after client authentication.
That loses all of the work that's been done since circa 7.1 to eliminate
cases where the postmaster gets blocked waiting for a single client to
respond. SSL, PAM, and I think Kerberos all create denial-of-service
risks if we do that.

I believe most of what you are presently struggling with revolves
around the fact that the fork() got pushed up to happen before client
authentication, while the interface to PostgresMain didn't change.
I do not want to alter either of those decisions, however. What we need
is to provide an alternative exec-able interface that encapsulates the
processing that now occurs between these steps.

regards, tom lane

#6Claudio Natoli
claudio.natoli@memetrics.com
In reply to: Tom Lane (#5)
Re: fork/exec patch: pre-CreateProcess finalization

Here's the critical difference in our thinking:

ISTM that we'll have to go to a lot of work to get the fork/exec
case to re-load the context required to format up the argument list to
PostgresMain. Certainly, it is a lot more work than allowing the

postmaster

itself (not the forked child) to create the argument list, albeit moving
auth to PostgresMain.

I don't follow your thinking here. The information that has to be
reloaded *must* be passed across the fork/exec boundary in
either case.
For example, there is no alternative to telling the backend process
where PGDATA is: it's got to be passed down some way or another.

Yes. But not all of it. Sure, PGDATA is a trivial example of something
that's gotta get across one way or another. I take no argument with that.

How about things like, for instance, canAcceptConnections(). To make this
call successfully in a fork/exec'd child would take a bit of work. Of
course, there is a work-around... pass the value into BackendFork (or, in
the fork/exec case, on the command line). But, ISTM that, do this a few
times, and you might as well have just had the postmaster format up the
argument list.

The reason your patch is messy is that the PostgresMain command line
string involves both information passed down from the postmaster and
information acquired from the client's connection-request packet.

Hmm.. that's not the way I see it.

After fork/exec'ing, the child process can't recover the context needed

to

create the argument list which it'll need to build up the PostgresMain

arg list.

If that's literally true, then we are screwed because things cannot
work. Pardon me for doubting this statement. All that information
*must* be available in the child, once it has analyzed the information
it must be able to collect from the postmaster and performed
the client authentication handshake.

Ok. That, in the context of where it was written, instead of "can't" should
have read "can no longer ... [in the absence of passing a great deal of
additional context]". Mea culpa. Anyway, moving along...

In particular, this alternative is quite unworkable:

b) delay the fork() call to the end of BackendFork in both fork/exec and
normal cases, turning it into solely an argument formatter for

PostgresMain

We can *not* postpone the fork() until after client authentication.
That loses all of the work that's been done since circa 7.1
to eliminate cases where the postmaster gets blocked waiting for a
single client to respond. SSL, PAM, and I think Kerberos all create
denial-of-service risks if we do that.

Ah. OK! Now I see where we are talking at cross-purposes. Forking after
client auth was NOT what I was trying to suggest at all.

Let's have a look at BackendFork. Here's what it needs to set up the arg
list for PostgresMain, or otherwise uses:

* PreAuthDelay
* canAcceptConnections()
* ExtraOptions
* debugbuf
* DataDir (in EXEC_BACKEND case)
BackendInit (ie. client authentication)
port->cmdline_options
port->proto
port->database_name
port->user_name

What I was suggesting with b) was to format up the command line for the
items prefixed by * in the postmaster,
do the fork (or fork/exec), and then run the authentication in, say
PostgresMain. (Note: this is essentially what the fork/exec case currently
does).

Now, what I think you are suggesting (correct me if I'm wrong), is that we
should pass along whatever we need to in order to be able to setup the
fork/exec'd process to run BackendFork more or less unchanged.

I prefer the former option, as there is less duplication. Should anything be
changed/added to the items required for BackendFork'ing, no changes would be
required to the fork/exec code. This will not necessarily be true if we need
to pass a bunch of (additional) context, as in the latter case.

ISTM this would let us make BackendFork *very* simple, and pretty much
identical in both the normal and fork/exec cases, for the cost of pushing
the authenication step across to PostgresMain (non stand-alone case), which
is what the fork/exec case does now anyway!

What do you think?

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>
#7Claudio Natoli
claudio.natoli@memetrics.com
In reply to: Claudio Natoli (#6)
Re: fork/exec patch: pre-CreateProcess finalization

[patch edited + resubmitted for review; not for committing]

Hi Tom,

figuring that, on balance, you are in fact going to prefer to take a
potential future hit in duplicated work (in passing context in the fork/exec
case) over moving the client auth code to PostgresMain, I've just gone ahead
and made a patch that implements your BackendFork ideas...

Please let me know:

* if the changes to the BackendFork / SubPostmasterMain logic are more or
less what you envisaged, and if you are content with them [Note: we can also
roll BackendInit back into BackendFork, making BackendFork (now BackendRun?)
pretty much exactly as it was before the fork/exec changes began]

* if you are content with the above, whether or not you think I ought to do
the same for the SSDataBase logic. I'm hoping for a negative, as the #ifdef
logic is not as convoluted as that originally presented in BackendFork (ie.
to me, it looks like overkill in this case), but anticipating otherwise :-)

Also:
* are you ok with the pgstat changes (I'm guessing yes, as you haven't
mentioned them, and since these changes are pretty similar to what you
suggested for BackendFork)

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>

Attachments:

diff5c2.outapplication/octet-stream; name=diff5c2.outDownload+315-237
#8Tom Lane
tgl@sss.pgh.pa.us
In reply to: Claudio Natoli (#6)
Re: fork/exec patch: pre-CreateProcess finalization

Claudio Natoli <claudio.natoli@memetrics.com> writes:

I don't follow your thinking here. The information that has to be
reloaded *must* be passed across the fork/exec boundary in
either case.

Yes. But not all of it.

I'll throw that same argument back at you: some of the information
needed for PostgresMain's command line is available to the postmaster.
But not all of it. Therefore we have to change things around. I'm
proposing solving this by introducing a new layer of code that's
essentially separate from the non-fork-exec case. Your solution seems
much messier, and it doesn't have any redeeming social value (that I can
see) to justify the mess.

How about things like, for instance, canAcceptConnections(). To make this
call successfully in a fork/exec'd child would take a bit of work.

And your point is what? As long as you grant that the fork must occur
before we begin talking to the client, this information will have to be
passed down somehow (offhand, a command-line argument for the result of
canAcceptConnections() seems fairly reasonable). Obscuring the division
between "sub-postmaster" code and PostgresMain isn't going to save you
from that.

What I was suggesting with b) was to format up the command line for the
items prefixed by * in the postmaster,
do the fork (or fork/exec), and then run the authentication in, say
PostgresMain. (Note: this is essentially what the fork/exec case currently
does).

Yeah, I noticed. If I'd been paying more attention, the already-applied
patch wouldn't have gotten in either, because it already has created
what I consider an unacceptable amount of coupling between PostgresMain
and the sub-postmaster code. If it's still like that when the dust
settles then I will go in and change it myself. PostgresMain has no
business doing *any* of the stuff that is currently #ifdef EXEC_BACKEND
in postgres.c. It should certainly not be running authentication, and I
see no reason for it to be messing with restoring state that should have
been inherited from the postmaster. That just creates fragility and
order-of-operations dependency. As an example, it doesn't seem like a
good idea to me that reloading postmaster GUC variables happens after
scanning of PostgresMain command line options, because the option
processing both uses and sets GUC values. It is not hard to point out
three or four bugs associated with that alone, including security
violations (since we don't know at this point whether the user is a
superuser and thus don't know what he's allowed to set). In general,
PostgresMain assumes it is started with the inherited environment
already set up, and I don't see a good argument for changing that.

Now, what I think you are suggesting (correct me if I'm wrong), is that we
should pass along whatever we need to in order to be able to setup the
fork/exec'd process to run BackendFork more or less unchanged.

I don't mind making localized changes like passing in the result of
canAcceptConnections, but by and large, yes: I want to run BackendFork
pretty much as-is. I see no strong reason to do differently, and I am
convinced that we will spend the next six months ferreting out startup
bugs if we make wholesale revisions in the order in which things are
done.

regards, tom lane

#9Claudio Natoli
claudio.natoli@memetrics.com
In reply to: Tom Lane (#8)
Re: fork/exec patch: pre-CreateProcess finalization

What I was suggesting with b) was to format up the command line for the
items prefixed by * in the postmaster,
do the fork (or fork/exec), and then run the authentication in, say
PostgresMain. (Note: this is essentially what the fork/exec case

currently

does).

Yeah, I noticed. If I'd been paying more attention, the already-applied
patch wouldn't have gotten in either, because it already has created
what I consider an unacceptable amount of coupling between PostgresMain
and the sub-postmaster code. If it's still like that when the dust
settles then I will go in and change it myself. PostgresMain has no
business doing *any* of the stuff that is currently #ifdef
EXEC_BACKEND in postgres.c.

[snip]

Now, what I think you are suggesting (correct me if I'm wrong), is that

we

should pass along whatever we need to in order to be able to setup the
fork/exec'd process to run BackendFork more or less unchanged.

I don't mind making localized changes like passing in the result of
canAcceptConnections, but by and large, yes: I want to run BackendFork
pretty much as-is.

Check out the last patch I sent. It implements your ideas for
BackendFork'ing in the fork/exec case, and pretty much lets us revert the
previous changes to postgres.c and BackendFork (which I agree is a good
thing).

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>
#10Claudio Natoli
claudio.natoli@memetrics.com
In reply to: Claudio Natoli (#9)
Re: fork/exec patch: pre-CreateProcess finalization

[minor corrections (some duplication in arg passing); still under
discussion/review]

Cheers,
Claudio

-----Original Message-----
From: Claudio Natoli [mailto:claudio.natoli@memetrics.com]
Sent: Saturday, 27 December 2003 9:27 PM
To: 'Tom Lane'
Cc: 'pgsql-patches@postgresql.org'
Subject: Re: [PATCHES] fork/exec patch: pre-CreateProcess
finalization

[patch edited + resubmitted for review; not for committing]

Hi Tom,

figuring that, on balance, you are in fact going to prefer to take a
potential future hit in duplicated work (in passing context
in the fork/exec
case) over moving the client auth code to PostgresMain, I've
just gone ahead
and made a patch that implements your BackendFork ideas...

Please let me know:

* if the changes to the BackendFork / SubPostmasterMain logic
are more or
less what you envisaged, and if you are content with them
[Note: we can also
roll BackendInit back into BackendFork, making BackendFork
(now BackendRun?)
pretty much exactly as it was before the fork/exec changes began]

* if you are content with the above, whether or not you think
I ought to do
the same for the SSDataBase logic. I'm hoping for a negative,
as the #ifdef
logic is not as convoluted as that originally presented in
BackendFork (ie.
to me, it looks like overkill in this case), but anticipating
otherwise :-)

Also:
* are you ok with the pgstat changes (I'm guessing yes, as you haven't
mentioned them, and since these changes are pretty similar to what you
suggested for BackendFork)

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.me
metrics.com/em
ailpolicy.html</a>
--- 
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>

Attachments:

diff5c3.outapplication/octet-stream; name=diff5c3.outDownload+311-235
#11Bruce Momjian
bruce@momjian.us
In reply to: Claudio Natoli (#7)
Re: fork/exec patch: pre-CreateProcess finalization

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:

[patch edited + resubmitted for review; not for committing]

Hi Tom,

figuring that, on balance, you are in fact going to prefer to take a
potential future hit in duplicated work (in passing context in the fork/exec
case) over moving the client auth code to PostgresMain, I've just gone ahead
and made a patch that implements your BackendFork ideas...

Please let me know:

* if the changes to the BackendFork / SubPostmasterMain logic are more or
less what you envisaged, and if you are content with them [Note: we can also
roll BackendInit back into BackendFork, making BackendFork (now BackendRun?)
pretty much exactly as it was before the fork/exec changes began]

* if you are content with the above, whether or not you think I ought to do
the same for the SSDataBase logic. I'm hoping for a negative, as the #ifdef
logic is not as convoluted as that originally presented in BackendFork (ie.
to me, it looks like overkill in this case), but anticipating otherwise :-)

Also:
* are you ok with the pgstat changes (I'm guessing yes, as you haven't
mentioned them, and since these changes are pretty similar to what you
suggested for BackendFork)

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 6: Have you searched our list archives?

http://archives.postgresql.org

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
#12Bruce Momjian
bruce@momjian.us
In reply to: Claudio Natoli (#7)
Re: fork/exec patch: pre-CreateProcess finalization

Claudio, where are we on this patch? I see an even newer version in the
archives:

http://archives.postgresql.org/pgsql-patches/2003-12/msg00361.php

However, I have never seen that version, and Google doesn't show it
either:

http://groups.google.com/groups?hl=en&amp;lr=&amp;ie=UTF-8&amp;c2coff=1&amp;group=comp.databases.postgresql.patches

Anyway, Tom has looked at your newest patch and it looks good to him.

These are all marked not for application so we will just wait for you to
finalize it.

---------------------------------------------------------------------------

Claudio Natoli wrote:

[patch edited + resubmitted for review; not for committing]

Hi Tom,

figuring that, on balance, you are in fact going to prefer to take a
potential future hit in duplicated work (in passing context in the fork/exec
case) over moving the client auth code to PostgresMain, I've just gone ahead
and made a patch that implements your BackendFork ideas...

Please let me know:

* if the changes to the BackendFork / SubPostmasterMain logic are more or
less what you envisaged, and if you are content with them [Note: we can also
roll BackendInit back into BackendFork, making BackendFork (now BackendRun?)
pretty much exactly as it was before the fork/exec changes began]

* if you are content with the above, whether or not you think I ought to do
the same for the SSDataBase logic. I'm hoping for a negative, as the #ifdef
logic is not as convoluted as that originally presented in BackendFork (ie.
to me, it looks like overkill in this case), but anticipating otherwise :-)

Also:
* are you ok with the pgstat changes (I'm guessing yes, as you haven't
mentioned them, and since these changes are pretty similar to what you
suggested for BackendFork)

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 6: Have you searched our list archives?

http://archives.postgresql.org

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
#13Claudio Natoli
claudio.natoli@memetrics.com
In reply to: Bruce Momjian (#12)
Re: fork/exec patch: pre-CreateProcess finalization

Hi Bruce,

Claudio, where are we on this patch? I see an even newer version in the

archives:

http://archives.postgresql.org/pgsql-patches/2003-12/msg00361.php

[Weird you and Google groups "missed" it!]

Anyway, Tom has looked at your newest patch and it looks good to him.

I'm happy with the patch from the link above being committed if Tom has no
more comments. Was only waiting for a final nod from him.

Once it is in the source tree, give me a couple days and I'll fire off a
patch with the actual CreateProcess calls... and then we are off into Win32
signal land [shudder].

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>
#14Bruce Momjian
bruce@momjian.us
In reply to: Claudio Natoli (#13)
Re: fork/exec patch: pre-CreateProcess finalization

Claudio Natoli wrote:

Hi Bruce,

Claudio, where are we on this patch? I see an even newer version in the

archives:

http://archives.postgresql.org/pgsql-patches/2003-12/msg00361.php

[Weird you and Google groups "missed" it!]

No, seems only _I_ missed it. The google display for groups:

http://groups.google.com/groups?hl=en&amp;lr=&amp;ie=UTF-8&amp;group=comp.databases.postgresql.patches

Doesn't show individual messages but lists threads, _and_ it shows the
date of the last message in the thread, rather than the first. That's
how I missed it. How I missed it my mailbox, I have no idea. Sorry.

Anyway, Tom has looked at your newest patch and it looks good to him.

I'm happy with the patch from the link above being committed if Tom has no
more comments. Was only waiting for a final nod from him.

Thanks. Applied.

Once it is in the source tree, give me a couple days and I'll fire off a
patch with the actual CreateProcess calls... and then we are off into Win32
signal land [shudder].

Great.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
#15Jan Wieck
JanWieck@Yahoo.com
In reply to: Claudio Natoli (#13)
Re: fork/exec patch: pre-CreateProcess finalization

Claudio Natoli wrote:

Something after 2003/11/20 enhanced the query cancel handling. Namely,
CVS tip now responds to a query cancel with a postmaster restart
canceling all queries. Could the fork/exec stuff be responsible for this?

Jan

Hi Bruce,

Claudio, where are we on this patch? I see an even newer version in the

archives:

http://archives.postgresql.org/pgsql-patches/2003-12/msg00361.php

[Weird you and Google groups "missed" it!]

Anyway, Tom has looked at your newest patch and it looks good to him.

I'm happy with the patch from the link above being committed if Tom has no
more comments. Was only waiting for a final nod from him.

Once it is in the source tree, give me a couple days and I'll fire off a
patch with the actual CreateProcess calls... and then we are off into Win32
signal land [shudder].

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>

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck@Yahoo.com #

#16Tom Lane
tgl@sss.pgh.pa.us
In reply to: Jan Wieck (#15)
Re: fork/exec patch: pre-CreateProcess finalization

Jan Wieck <JanWieck@Yahoo.com> writes:

Something after 2003/11/20 enhanced the query cancel handling. Namely,
CVS tip now responds to a query cancel with a postmaster restart
canceling all queries. Could the fork/exec stuff be responsible for this?

Whoever changed this:

status = ProcessStartupPacket(port, false);

if (status != STATUS_OK)
return 0; /* cancel request processed, or error */

to this:

status = ProcessStartupPacket(port, false);

if (status != STATUS_OK)
{
ereport(LOG,
(errmsg("connection startup failed")));
proc_exit(status);
}

is responsible. May we have an explanation of the thought process,
if any?

regards, tom lane

#17Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#16)
Re: fork/exec patch: pre-CreateProcess finalization

Tom Lane wrote:

Jan Wieck <JanWieck@Yahoo.com> writes:

Something after 2003/11/20 enhanced the query cancel handling. Namely,
CVS tip now responds to a query cancel with a postmaster restart
canceling all queries. Could the fork/exec stuff be responsible for this?

Whoever changed this:

status = ProcessStartupPacket(port, false);

if (status != STATUS_OK)
return 0; /* cancel request processed, or error */

to this:

status = ProcessStartupPacket(port, false);

if (status != STATUS_OK)
{
ereport(LOG,
(errmsg("connection startup failed")));
proc_exit(status);
}

is responsible. May we have an explanation of the thought process,
if any?

My guess is that this used to proc_exit the postgres backend, but now
proc_exits the postmaster, but that is only a guess.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
#18Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#17)
Re: fork/exec patch: pre-CreateProcess finalization

Bruce Momjian <pgman@candle.pha.pa.us> writes:

My guess is that this used to proc_exit the postgres backend, but now
proc_exits the postmaster, but that is only a guess.

No. This is post-fork (and had better remain so). The change causes
the sub-postmaster that has just finished handling a cancel request
to exit with nonzero status, which the postmaster then interprets
(correctly) as a child process crash.

BTW, how are we going to do cancels in Windows-land? The sub-postmaster
isn't gonna have access to the postmaster's list of child PIDs and
cancel keys ...

regards, tom lane

#19Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#18)
Re: fork/exec patch: pre-CreateProcess finalization

Tom Lane wrote:

Bruce Momjian <pgman@candle.pha.pa.us> writes:

My guess is that this used to proc_exit the postgres backend, but now
proc_exits the postmaster, but that is only a guess.

No. This is post-fork (and had better remain so). The change causes
the sub-postmaster that has just finished handling a cancel request
to exit with nonzero status, which the postmaster then interprets
(correctly) as a child process crash.

BTW, how are we going to do cancels in Windows-land? The sub-postmaster
isn't gonna have access to the postmaster's list of child PIDs and
cancel keys ...

I think the postmaster will have access to the cancel key and pid. It
should work similar to Unix. However, I do have a win32 TODO item on
"test cancel key", so we will not forget about it.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
#20Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#18)
Re: fork/exec patch: pre-CreateProcess finalization

Tom Lane wrote:

Bruce Momjian <pgman@candle.pha.pa.us> writes:

My guess is that this used to proc_exit the postgres backend, but now
proc_exits the postmaster, but that is only a guess.

No. This is post-fork (and had better remain so). The change causes
the sub-postmaster that has just finished handling a cancel request
to exit with nonzero status, which the postmaster then interprets
(correctly) as a child process crash.

BTW, how are we going to do cancels in Windows-land? The sub-postmaster
isn't gonna have access to the postmaster's list of child PIDs and
cancel keys ...

When you say sub-postmaster, you mean we fork, then process the cancel
request? Seems we might need special handling in there, yea.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
#21Claudio Natoli
claudio.natoli@memetrics.com
In reply to: Bruce Momjian (#20)
#22Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#20)
#23Claudio Natoli
claudio.natoli@memetrics.com
In reply to: Tom Lane (#22)
#24Claudio Natoli
claudio.natoli@memetrics.com
In reply to: Claudio Natoli (#23)
#25Bruce Momjian
bruce@momjian.us
In reply to: Claudio Natoli (#23)
#26Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#25)
#27Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#26)
#28Jan Wieck
JanWieck@Yahoo.com
In reply to: Bruce Momjian (#27)
#29Jan Wieck
JanWieck@Yahoo.com
In reply to: Bruce Momjian (#27)
#30Tom Lane
tgl@sss.pgh.pa.us
In reply to: Jan Wieck (#28)
#31Jan Wieck
JanWieck@Yahoo.com
In reply to: Tom Lane (#30)
#32Claudio Natoli
claudio.natoli@memetrics.com
In reply to: Jan Wieck (#31)
#33Bruce Momjian
bruce@momjian.us
In reply to: Claudio Natoli (#32)
#34Claudio Natoli
claudio.natoli@memetrics.com
In reply to: Bruce Momjian (#33)
#35Bruce Momjian
bruce@momjian.us
In reply to: Claudio Natoli (#34)
#36Claudio Natoli
claudio.natoli@memetrics.com
In reply to: Bruce Momjian (#35)
#37Bruce Momjian
bruce@momjian.us
In reply to: Claudio Natoli (#36)
#38Tom Lane
tgl@sss.pgh.pa.us
In reply to: Claudio Natoli (#34)
#39Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#37)
#40Claudio Natoli
claudio.natoli@memetrics.com
In reply to: Tom Lane (#39)
#41Claudio Natoli
claudio.natoli@memetrics.com
In reply to: Claudio Natoli (#40)
#42Bruce Momjian
bruce@momjian.us
In reply to: Claudio Natoli (#40)
#43Claudio Natoli
claudio.natoli@memetrics.com
In reply to: Bruce Momjian (#42)
#44Tom Lane
tgl@sss.pgh.pa.us
In reply to: Claudio Natoli (#40)
#45Tom Lane
tgl@sss.pgh.pa.us
In reply to: Claudio Natoli (#41)
#46Tom Lane
tgl@sss.pgh.pa.us
In reply to: Claudio Natoli (#43)
#47Claudio Natoli
claudio.natoli@memetrics.com
In reply to: Tom Lane (#46)
#48Tom Lane
tgl@sss.pgh.pa.us
In reply to: Claudio Natoli (#47)
#49Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#16)
#50Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#16)
#51Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#50)
#52Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#51)