Re: [PATCHES] patches for 6.2.1p6
Hi hackers,
I have old patches for version 6.2.1p6 which fix some problems and add
new features. Here is a short description of each patch file:assert.patch
adds a switch to turn on/off the assert checking if enabled at compile
time. You can now compile postgres with assert checking and disable it
at runtime in a production environment.async-unlisten.patch
declares Async_Unlisten() external so that it can be called by user
modules.exec-limit.patch
removes the #ifdef NOT_USED around ExecutorLimit(). It is used.
exitpg.patch
limits recursive calls to exitpg() preventing an infinite loop
if an error is found inside exitpg.libpgtcl-listen.patch
Just a change from upper to lowercase of an sql command in libpgtcl,
totally harmless.new-locks.patch
After long studying and many debugging sessions I have finally
understood how the low level locks work.
I have completely rewritten lock.c cleaning up the code and adding
better assert checking. I have also added some fields to the lock
and xid tags for better support of user locks. This patch includes
also a patch submitted by Bruce Momjian which changes the handling
of lock priorities. It can however be disabled if an option is set
in pg_options, see tprintf.patch (Bruce patch works by building
the queue in reverse priority order, my old patch kept the queue in
decreasing order and traversed it from the other side).pg-flush.patch
removes an unnecessary flush in libpq reducing network traffic and
increasing performance.relname.patch
an utility which returns the relname corresponding to a given oid.
Useful for debug messages (see vacum.patch).sequence.patch
added a setval() function which enables othe owner of a sequence
to set its value without need to delete and recreate it.sinval.patch
fixes a problem in SI cache which causes table overflow if some
backend is idle for a long time while other backends keep adding
entries.
It uses the new signal handling implemented in tprintf.patch.
I have also increacasesed the max number of backends from 32 to 64 and
the table size from 1000 to 5000.spin-lock.patch
I'm not sure if this is really useful, but it seems stupid to have
a backend wasting cpu cycles in a busy loop while the process which
should release the lock is waiting for the cpu. So I added a call
to process_yield() if the spin lock can't obtained.
This has been implemented and tested only on Linux. I don't know if
other OS have process_yield(). If someone can check please do it.tprintf.patch
adds functions and macros which implement a conditional trace package
with the ability to change flags and numeric options of running
backends at runtime.
Options/flags can be specified in the command line and/or read from
the file pg_options in the data directory.
Running backends can be forced to update their options from this file
by sending them a SIGHUP signal (this is the convention used by most
unix daemons so I changed the meaning of SIGHUP).
Options can be debugging flags used by the trace package or any other
numeric value used by the backend, for example the deadlock_timeout.
Having flags and options specified at runtime and changed while the
backends are running can greatly simplify the debugging and tuning
of the database. New options can be defined in utils/misc/trace.c and
include/utils/trace.h. As an example of the usage of this package
see lock.c and proc.c which make use of new runtime options.Old files using int flags or variables can be easily changed to
use the new package by substituting the old variable with a #define
like in the following example:/* int my_flag = 0; */
#include "trace.h"
#define my_flag pg_options[OPT_MYFLAG]I have done it in postgres.c and some other files and now I can turn
on/off any single debug flag on the fly with a simple shell script.
I have removed the IpcConfigTip() from ipc.c, it should better be
described in the postgres manual instead of being printed on stderr.This patch provides also a new format of debugging messages which
are always in a single line with a timestamp and the backend pid:#timestamp #pid #message
980127.17:52:14.173 [29271] StartTransactionCommand
980127.17:52:14.174 [29271] ProcessUtility: drop table t;
980127.17:52:14.186 [29271] SIIncNumEntries: table is 70% full
980127.17:52:14.186 [29286] Async_NotifyHandler
980127.17:52:14.186 [29286] Waking up sleeping backend process
980127.19:52:14.292 [29286] Async_NotifyFrontEnd
980127.19:52:14.413 [29286] Async_NotifyFrontEnd done
980127.19:52:14.466 [29286] Async_NotifyHandler doneThis improves the readability of the log and allows one to understand
exactly which backend is doing what and at which time. It also makes
easier to write simple awk or perl scripts which monitor the log to
detect database errors or problem, or to compute transaction times.The patch changes also the meaning of signals used by postgres, as
described by the following table:postmaster backend
SIGHUP kill(*,sighup) read_pg_options
SIGINT kill(*,sigint), die die
SIGCHLD reaper -
SIGTTIN ignored -
SIGTTOU ignored -
SIGQUIT die handle_warn
SIGTERM kill(*,sigterm), kill(*,9), die die
SIGCONT dumpstatus -
SIGPIPE ignored die
SIGFPE - FloatExceptionHandler
SIGTSTP - ignored (alive test)
SIGUSR1 kill(*,sigusr1), die quickdie
SIGUSR2 kill(*,sigusr2) Async_NotifyHandler
(also SI buffer flush)The main changes to the old implementation are SIGQUIT instead of
SIGHUP to handle warns, SIGHUP to reread pg_options and redirection
to all backends of SIGHUP, SIGINT, SIGTERM, SIGUSR1 and SIGUSR2.
In this way some of the signals sent to the postmaster can be sent
automatically to all the backends. To shut down postgres one needs
only to send a SIGTERM to postmaster and it will stop automatically
all the backends. This new signal handling mechanism is also used
to prevent SI cache table overflows: when a backend detects the SI
table full at 70% it simply sends a signal to the postmaster which
will wake up all idle backends and make them flush the cache.vacuum.patch
adds a debug message to vacuum that prints the name of a table or
index *before* vacuuming it, if the verbose keyword is set.
This is useful to know which table is causing troubles if a
vacuum all crashes. Currently table information is printed only
at the end of each vacuum operation and is never printed if the
vacuum crashes.--
Massimo Dal Zotto
Massimo, now that 6.3 is released, any chance of getting these patches
against the 6.3 source code?
--
Bruce Momjian | 830 Blythe Avenue
maillist@candle.pha.pa.us | Drexel Hill, Pennsylvania 19026
+ If your life is a hard drive, | (610) 353-9879(w)
+ Christ can be your backup. | (610) 853-3000(h)
Import Notes
Reply to msg id not found: 199802132233.XAA01003@nikita.wizard.it
Hi hackers,
I have old patches for version 6.2.1p6 which fix some problems and add
new features. Here is a short description of each patch file:
spin-lock.patch
I'm not sure if this is really useful, but it seems stupid to have
a backend wasting cpu cycles in a busy loop while the process which
should release the lock is waiting for the cpu. So I added a call
to process_yield() if the spin lock can't obtained.
This has been implemented and tested only on Linux. I don't know if
other OS have process_yield(). If someone can check please do it.
The generic way to do this is
select( NULL_FDSET, NULL_FDSET, NULL_FDSET, &delaytime, NULL);
Delay time may be 0, but a random value between 0 and say 30 msec seems
to be optimal. Hard busy wait spinlocks cause huge performance problems with
heavily loaded systems and lots of postgres backends. Basically one backend
ends up with the lock and gets scheduled out holding it, every else queues
up busywaiting behind this one. But the backend holding the lock cannot
release it until all the other backeds waiting on the lock exhaust a full
timeslice busywaiting. Get 20 of these guys going (like on a busy website) and
the system pretty much stops doing any work at all.
I say we should get this in as soon as we can.
--
Massimo Dal ZottoMassimo, now that 6.3 is released, any chance of getting these patches
against the 6.3 source code?--
Bruce Momjian | 830 Blythe Avenue
maillist@candle.pha.pa.us | Drexel Hill, Pennsylvania 19026
-dg
David Gould dg@illustra.com 510.628.3783 or 510.305.9468
Informix Software (No, really) 300 Lakeside Drive Oakland, CA 94612
- I realize now that irony has no place in business communications.
On Mon, 16 Mar 1998, David Gould wrote:
The generic way to do this is
select( NULL_FDSET, NULL_FDSET, NULL_FDSET, &delaytime, NULL);
Delay time may be 0, but a random value between 0 and say 30 msec seems
to be optimal. Hard busy wait spinlocks cause huge performance problems with
heavily loaded systems and lots of postgres backends. Basically one backend
ends up with the lock and gets scheduled out holding it, every else queues
up busywaiting behind this one. But the backend holding the lock cannot
release it until all the other backeds waiting on the lock exhaust a full
timeslice busywaiting. Get 20 of these guys going (like on a busy website) and
the system pretty much stops doing any work at all.I say we should get this in as soon as we can.
Can you submit an appropriate patch that can be included in the mega-patch
to be created on Sunday?
Thanks...
Marc G. Fournier
Systems Administrator @ hub.org
primary: scrappy@hub.org secondary: scrappy@{freebsd|postgresql}.org
On Mon, 16 Mar 1998, David Gould wrote:
The generic way to do this is
select( NULL_FDSET, NULL_FDSET, NULL_FDSET, &delaytime, NULL);
Delay time may be 0, but a random value between 0 and say 30 msec seems
to be optimal. Hard busy wait spinlocks cause huge performance problems with
heavily loaded systems and lots of postgres backends. Basically one backend
ends up with the lock and gets scheduled out holding it, every else queues
up busywaiting behind this one. But the backend holding the lock cannot
release it until all the other backeds waiting on the lock exhaust a full
timeslice busywaiting. Get 20 of these guys going (like on a busy website) and
the system pretty much stops doing any work at all.I say we should get this in as soon as we can.
Can you submit an appropriate patch that can be included in the mega-patch
to be created on Sunday?
Just a warning that this is not going to be easy. We have OS-specific
code for spinlocks in include/storage/s_lock.h and
backend/storage/buffer/s_lock.c. So each S_LOCK macro call has to have
its test-and-set logic de-coupled with its while-lock-fail-try-again
logic. Most of them are easy, but some like VAX:
#define S_LOCK(addr) __asm__("1: bbssi $0,(%0),1b": :"r"(addr))
are hard to de-couple. Now, I did not know we supported NetBSD on VAX.
Does it work, anyone? Can I remove it?
This is going to be pretty tough to test on every platform we support,
so if it is done now, it will have to be done carefully.
--
Bruce Momjian | 830 Blythe Avenue
maillist@candle.pha.pa.us | Drexel Hill, Pennsylvania 19026
+ If your life is a hard drive, | (610) 353-9879(w)
+ Christ can be your backup. | (610) 853-3000(h)
Can you submit an appropriate patch that can be included in the
mega-patch to be created on Sunday?Just a warning that this is not going to be easy. We have OS-specific
code for spinlocks in include/storage/s_lock.h and
backend/storage/buffer/s_lock.c. So each S_LOCK macro call has to
have its test-and-set logic de-coupled with its
while-lock-fail-try-again logic.
Most of them are easy, but some like VAX:#define S_LOCK(addr) __asm__("1: bbssi $0,(%0),1b": :"r"(addr))
are hard to de-couple. Now, I did not know we supported NetBSD on
VAX. Does it work, anyone? Can I remove it?
NetBSD on VAX in on our supported list, and was verified for v6.3 by Tom
Helbekkmo.
This is going to be pretty tough to test on every platform we support,
so if it is done now, it will have to be done carefully.
Is this behavior in v6.2.x? In any case, if it is anything but minimally
trivial, it should be given a test on every supported platform, since it
hits the heart of the platform-specific code, doesn't it? Seems like it
should be put into the CVS tree and shaken out until the next release...
- Tom
On Tue, 17 Mar 1998, Thomas G. Lockhart wrote:
This is going to be pretty tough to test on every platform we support,
so if it is done now, it will have to be done carefully.Is this behavior in v6.2.x? In any case, if it is anything but minimally
trivial, it should be given a test on every supported platform, since it
hits the heart of the platform-specific code, doesn't it? Seems like it
should be put into the CVS tree and shaken out until the next release...
Not realizing what was involved, I have to agree here...*after* I
get a post-release patch out on Sunday? :)
Marc G. Fournier
Systems Administrator @ hub.org
primary: scrappy@hub.org secondary: scrappy@{freebsd|postgresql}.org
Can you submit an appropriate patch that can be included in the
mega-patch to be created on Sunday?
are hard to de-couple. Now, I did not know we supported NetBSD on
VAX. Does it work, anyone? Can I remove it?NetBSD on VAX in on our supported list, and was verified for v6.3 by Tom
Helbekkmo.This is going to be pretty tough to test on every platform we support,
so if it is done now, it will have to be done carefully.Is this behavior in v6.2.x? In any case, if it is anything but minimally
trivial, it should be given a test on every supported platform, since it
hits the heart of the platform-specific code, doesn't it? Seems like it
should be put into the CVS tree and shaken out until the next release...
Yea, that is what I was hinting at.
--
Bruce Momjian | 830 Blythe Avenue
maillist@candle.pha.pa.us | Drexel Hill, Pennsylvania 19026
+ If your life is a hard drive, | (610) 353-9879(w)
+ Christ can be your backup. | (610) 853-3000(h)
Can you submit an appropriate patch that can be included in the
mega-patch to be created on Sunday?are hard to de-couple. Now, I did not know we supported NetBSD on
VAX. Does it work, anyone? Can I remove it?NetBSD on VAX in on our supported list, and was verified for v6.3 by Tom
Helbekkmo.This is going to be pretty tough to test on every platform we support,
so if it is done now, it will have to be done carefully.Is this behavior in v6.2.x? In any case, if it is anything but minimally
trivial, it should be given a test on every supported platform, since it
hits the heart of the platform-specific code, doesn't it? Seems like it
should be put into the CVS tree and shaken out until the next release...Yea, that is what I was hinting at.
--
Bruce Momjian | 830 Blythe Avenue
maillist@candle.pha.pa.us | Drexel Hill, Pennsylvania 19026
I tend to agree but am willing to compromise.
Can we do only the easy platforms at this time and then fix the others later?
Since S_LOCK is a macro, it could be
#define S_LOCK s_lock_with_backoff
on the easy platforms and
#define S_LOCK original_definition
on the tricky or hard to test platforms
If this will work, I am willing to hack this together tomorrow.
What is the time frame for accepting a patch like this?
-dg
David Gould dg@illustra.com 510.628.3783 or 510.305.9468
Informix Software (No, really) 300 Lakeside Drive Oakland, CA 94612
- I realize now that irony has no place in business communications.
David Gould wrote:
Can you submit an appropriate patch that can be included in the
mega-patch to be created on Sunday?are hard to de-couple. Now, I did not know we supported NetBSD on
VAX. Does it work, anyone? Can I remove it?NetBSD on VAX in on our supported list, and was verified for v6.3 by Tom
Helbekkmo.This is going to be pretty tough to test on every platform we support,
so if it is done now, it will have to be done carefully.Is this behavior in v6.2.x? In any case, if it is anything but minimally
trivial, it should be given a test on every supported platform, since it
hits the heart of the platform-specific code, doesn't it? Seems like it
should be put into the CVS tree and shaken out until the next release...Yea, that is what I was hinting at.
--
Bruce Momjian | 830 Blythe Avenue
maillist@candle.pha.pa.us | Drexel Hill, Pennsylvania 19026I tend to agree but am willing to compromise.
Can we do only the easy platforms at this time
If this will work, I am willing to hack this together tomorrow.
What is the time frame for accepting a patch like this?
What do you think it would take to exercise the patch heavily enough on
any of the affected platforms to ensure that it behaves no worse than
the current code? Is a test case easy to set up and run? If so, you can
probably get ~5 platforms tested in the next few days, and reduce the
risk of including this in the mega-patch.
Alternatively, we could do this the day _after_ the mega-patch, so that
the two are decoupled, and have a nice "slock patch" a few days later.
At the moment, there aren't any large backend patches waiting to go (I
think Vadim is still sleeping to recover from v6.3 :)
- Tom
On Mon, 16 Mar 1998, David Gould wrote:
If this will work, I am willing to hack this together tomorrow.
What is the time frame for accepting a patch like this?
Assuming that its *clean* (clean meaning that Bruce fully approves
of it, as this is his area of the code...well, one of them
*grin*)...tomorrow would be great :) If Bruce has *any* doubts though, it
doesn't go in until after I do the patch I want to do...
Marc G. Fournier
Systems Administrator @ hub.org
primary: scrappy@hub.org secondary: scrappy@{freebsd|postgresql}.org
David Gould wrote:
Can you submit an appropriate patch that can be included in the
mega-patch to be created on Sunday?are hard to de-couple. Now, I did not know we supported NetBSD on
VAX. Does it work, anyone? Can I remove it?NetBSD on VAX in on our supported list, and was verified for v6.3 by Tom
Helbekkmo.This is going to be pretty tough to test on every platform we support,
so if it is done now, it will have to be done carefully.Is this behavior in v6.2.x? In any case, if it is anything but minimally
trivial, it should be given a test on every supported platform, since it
hits the heart of the platform-specific code, doesn't it? Seems like it
should be put into the CVS tree and shaken out until the next release...Yea, that is what I was hinting at.
--
Bruce Momjian | 830 Blythe Avenue
maillist@candle.pha.pa.us | Drexel Hill, Pennsylvania 19026I tend to agree but am willing to compromise.
Can we do only the easy platforms at this time
If this will work, I am willing to hack this together tomorrow.
What is the time frame for accepting a patch like this?What do you think it would take to exercise the patch heavily enough on
any of the affected platforms to ensure that it behaves no worse than
the current code? Is a test case easy to set up and run? If so, you can
probably get ~5 platforms tested in the next few days, and reduce the
risk of including this in the mega-patch.
Simple but clumsy test:
Multiple backends all doing single row inserts into private tables. Run it
for a fixed time period and add up the total number of rows. Do this for both
a small (eg 2) and large (eg 20 or 40) number of backends.
psuedo perl /sh / sql follows
# driver <number of users> <delay time> <run time>
synchtime = timenow
starttime = synctime + delaytime;
endtime = starttime + runtime
for user 1 to number of users
singleuser synchtime delay_time run_time
# singleuser <userno> <starttime> <endtime>
exec sql 'create table user$user (i int);'
sleep until start time
n = 1;
while timenow < endtime
exec sql "insert into user$user values($n);"
print "user $user inserted $n"
The figure of merit is the total number of inserts. Oh and that the system
does not fall over.
But, it may be best to leave this until after the mega patch. I am not sure
I want to share the blame ;-).
Just to fill me in, where does the mega patch fall in with the next release
snapshot? That is, if this misses the mega patch is it waiting until 6.4?
-dg
David Gould dg@illustra.com 510.628.3783 or 510.305.9468
Informix Software (No, really) 300 Lakeside Drive Oakland, CA 94612
- I realize now that irony has no place in business communications.
On Mon, 16 Mar 1998, David Gould wrote:
Just to fill me in, where does the mega patch fall in with the next release
snapshot? That is, if this misses the mega patch is it waiting until 6.4?
That is pretty much up to you, actually. There is nothing wrong
with a clean patch for this being placed in the patches directory, if it
can be done shortly after the post-release patch. Basically, starting
April 1st (or so), development basically starts up again, so backtracking
a patch from v6.4-alpha to v6.3 release can prove difficult :(
Marc G. Fournier
Systems Administrator @ hub.org
primary: scrappy@hub.org secondary: scrappy@{freebsd|postgresql}.org
On Mon, 16 Mar 1998, David Gould wrote:
If this will work, I am willing to hack this together tomorrow.
What is the time frame for accepting a patch like this?Assuming that its *clean* (clean meaning that Bruce fully approves
of it, as this is his area of the code...well, one of them
*grin*)...tomorrow would be great :) If Bruce has *any* doubts though, it
doesn't go in until after I do the patch I want to do...
David, go for it. The code is all local in two files, and I think you
can basically change all the do{test-and-set} while(lock-is-false)
loops to:
do{test-and-set} while(lock-is-false && select ())
Pretty easy. No need to test multiple platforms. The ones where the
loop is integrated into the asm(), leave them for later.
--
Bruce Momjian | 830 Blythe Avenue
maillist@candle.pha.pa.us | Drexel Hill, Pennsylvania 19026
+ If your life is a hard drive, | (610) 353-9879(w)
+ Christ can be your backup. | (610) 853-3000(h)
But, it may be best to leave this until after the mega patch. I am not
sure I want to share the blame ;-).Just to fill me in, where does the mega patch fall in with the next
release snapshot? That is, if this misses the mega patch is it waiting
until 6.4?
I would guess that we could post a separate patch any time soon,
especially since the changes are apparently isolated to only a few
places in the code. In the last release, we posted ~7 patches, each
independent of the others, and generated on our local source trees. Each
of the patches was, however, fairly simple, quite often only one or a
few lines of change, and were intended as bug fixes. Also, they were
easily tested. In any case, at a minimum the regression test should be
run (and passed!).
- Tom
* Bruce Momjian
|
| Just a warning that this is not going to be easy. We have OS-specific
| code for spinlocks in include/storage/s_lock.h and
| backend/storage/buffer/s_lock.c. So each S_LOCK macro call has to have
| its test-and-set logic de-coupled with its while-lock-fail-try-again
| logic. Most of them are easy, but some like VAX:
|
| #define S_LOCK(addr) __asm__("1: bbssi $0,(%0),1b": :"r"(addr))
|
| are hard to de-couple. Now, I did not know we supported NetBSD on VAX.
| Does it work, anyone? Can I remove it?
Yes, it works. No, please don't break it. Heck, I only just got it
in in time for 6.3! :-) The not-so-busy-waiting-spinlock stuff can be
put in on a platform at a time -- I'll expand the VAX version to do
the right thing once someone has done another platform, so I can see
what's the preferred way of doing it.
-tih
--
Popularity is the hallmark of mediocrity. --Niles Crane, "Frasier"
* Bruce Momjian
| Just a warning that this is not going to be easy. We have OS-specific
| code for spinlocks in include/storage/s_lock.h and
| backend/storage/buffer/s_lock.c. So each S_LOCK macro call has to have
| its test-and-set logic de-coupled with its while-lock-fail-try-again
| logic. Most of them are easy, but some like VAX:
|
| #define S_LOCK(addr) __asm__("1: bbssi $0,(%0),1b": :"r"(addr))
|
| are hard to de-couple. Now, I did not know we supported NetBSD on VAX.
| Does it work, anyone? Can I remove it?Yes, it works. No, please don't break it. Heck, I only just got it
in in time for 6.3! :-) The not-so-busy-waiting-spinlock stuff can be
put in on a platform at a time -- I'll expand the VAX version to do
the right thing once someone has done another platform, so I can see
what's the preferred way of doing it.-tih
I won't. I hope.
Seriously, if you want to, please create a function to emulate the following:
/*
* tas(lock)
*
* Access to platform specific test_and_set functionality. Given pointer to
* lock attempts to acquire the lock atomically.
*
* Returns 0 for success, nonzero for failure.
*/
typedef slock_t unsigned char; /* or whatever works on the platform */
int tas(slock_t *lock)
{
slock_t tmp;
/* atomic, interlocked */
tmp = *lock;
*lock = -1; /* any nonzero will do here */
return (tmp != 0);
}
Given this, I can fold the VAX right into the grand scheme, just like a
normal computer (;-)).
-dg
David Gould dg@illustra.com 510.628.3783 or 510.305.9468
Informix Software (No, really) 300 Lakeside Drive Oakland, CA 94612
- I realize now that irony has no place in business communications.
* Bruce Momjian
|
| Just a warning that this is not going to be easy. We have OS-specific
| code for spinlocks in include/storage/s_lock.h and
| backend/storage/buffer/s_lock.c. So each S_LOCK macro call has to have
| its test-and-set logic de-coupled with its while-lock-fail-try-again
| logic. Most of them are easy, but some like VAX:
|
| #define S_LOCK(addr) __asm__("1: bbssi $0,(%0),1b": :"r"(addr))
|
| are hard to de-couple. Now, I did not know we supported NetBSD on VAX.
| Does it work, anyone? Can I remove it?Yes, it works. No, please don't break it. Heck, I only just got it
in in time for 6.3! :-) The not-so-busy-waiting-spinlock stuff can be
put in on a platform at a time -- I'll expand the VAX version to do
the right thing once someone has done another platform, so I can see
what's the preferred way of doing it.
OK, now I know that the VAX stuff is still used and supported. Good.
We don't have good platform-specific information on NetBSD and Linux
ports.
--
Bruce Momjian | 830 Blythe Avenue
maillist@candle.pha.pa.us | Drexel Hill, Pennsylvania 19026
+ If your life is a hard drive, | (610) 353-9879(w)
+ Christ can be your backup. | (610) 853-3000(h)
OK, now I know that the VAX stuff is still used and supported. Good.
We don't have good platform-specific information on NetBSD and Linux
ports.
??
Have you checked the hardcopy or html versions of the "Supported
Platforms" section in the Administrator's Guide? _Every_ entry in this
was updated and refreshed at the end of February.
What other info should we be collecting for this?
- Tom
Right now, there is not much chance of catching a signal while waiting for
a spinlock. This is good, cause the code that waits for spinlocks tends to
be doing funny things with buffers and locks and shared stuff like that.
We don't catch signals because we don't make syscalls. But, once this goes in,
we will be calling select() a _lot_ and so it kinda becomes the likely place
for a signal to get delivered. Without thinking about it and looking at the
code a bit longer, I am not sure it is prudent to rush this in. I still want
it in as soon a possible, but possible includes free from harmful side effects.
Well, signals are handled in the backend by tcop/postgres.c. In
most/all? cases, a signal causes a longjump() out of the code and
releases locks and aborts the transaction.
I was afraid that would be the answer. Basically, this never worked. The
problem is that in an indeterminate number of places the code manipulates
multiple distinct but related structures in a sequence. To leave the server
in a consistant state all these updates need to be done in the right order
so that if the sequence in interrupted by a signal the partially updated
state is consistant. Unhappily, the original coders did not always have this
in mind. An example:
cleaning up after a scan
1 - release buffer pointed by scan descriptor
2 - release scan descriptor
If a signal is taken just after one, the abort code will see the scan
descriptor and call the cleanup for it resulting in:
cleaning up after a scan (take 2)
1 - release buffer pointed by scan descriptor
- Whoopsie, buffer already released!
2 - release scan descriptor
These sequences either _all_ have to identified and fixed, or made atomic
somehow, which is a biggish job.
Or the system has to acknowledge signals at only clearly defined points.
My preference is to have signal handlers only set a global flag to indicate
that a signal was seen. Then one just sprinkles check_for_interrupts() calls
in all the likely places: step to next node, fetch next page, call function,
etc.
The way this shows up in real life is strange unreproduceable errors on busy
systems, especially when backends are killed or transactions are forced to
abort.
Fixing this is a bit of a project, but the result is that a lot of mystery
bugs go away.
I considered the possibility that your select() could return EINTR, so I
was thinking of suggesting something likedo { } while (lock-no-set && (select(),true) )
or something like that so the return value of select is always true. I
also recommend making a S_LOCK macro, and inside the while loop, call
the OS-specific lock stuff, so you don't have to code the select() for
each platform. So you have two macros, the S_LOCK macro with the while,
and inside the while, you call S_LOCK_SPIN() which is defined for each
platform. More centralized and less error-prone.
You may like what I have done then. S_LOCK() becomes a function:
S_LOCK(lock)
{
do {
while (!S_LOCK_FREE(lock)) /* non interlocked test to avoid */
{ /* hammering the bus and caches */
select( a_semi_random_time_delay_with_backoff );
}
} while (TAS(lock)); /* TAS: test and set
}
S_LOCK_FREE(), and TAS() are platform specific macros that invoke the
platform specific implementation. There are default implementations for
all the platform interface macros, so most of the time all that is needed
is to create a tas() function in asm and the rest falls into place.
Now I have to go home and test it.
Btw, feel free to forward this to the list if you feel it is of interest. I
didn't because I didn't want to quote you from private mail.
-dg
David Gould dg@illustra.com 510.628.3783 or 510.305.9468
Informix Software (No, really) 300 Lakeside Drive Oakland, CA 94612
- I realize now that irony has no place in business communications.
Import Notes
Reply to msg id not found: 199803190234.VAA28806@candle.pha.pa.us | Resolved by subject fallback
OK, now I know that the VAX stuff is still used and supported. Good.
We don't have good platform-specific information on NetBSD and Linux
ports.??
Have you checked the hardcopy or html versions of the "Supported
Platforms" section in the Administrator's Guide? _Every_ entry in this
was updated and refreshed at the end of February.What other info should we be collecting for this?
- Tom
Sorry, haven't looked there yet.
--
Bruce Momjian | 830 Blythe Avenue
maillist@candle.pha.pa.us | Drexel Hill, Pennsylvania 19026
+ If your life is a hard drive, | (610) 353-9879(w)
+ Christ can be your backup. | (610) 853-3000(h)