Обсуждение: pgsql: Repair a low-probability race condition identified by Qingqing

Поиск
Список
Период
Сортировка

pgsql: Repair a low-probability race condition identified by Qingqing

От
tgl@postgresql.org (Tom Lane)
Дата:
Log Message:
-----------
Repair a low-probability race condition identified by Qingqing Zhou.
If a process abandons a wait in LockBufferForCleanup (in practice,
only happens if someone cancels a VACUUM) just before someone else
sends it a signal indicating the buffer is available, it was possible
for the wakeup to remain in the process' semaphore, causing misbehavior
next time the process waited for an lmgr lock.  Rather than try to
prevent the race condition directly, it seems best to make the lock
manager robust against leftover wakeups, by having it repeat waiting
on the semaphore if the lock has not actually been granted or denied
yet.

Modified Files:
--------------
    pgsql/src/backend/storage/buffer:
        bufmgr.c (r1.206 -> r1.207)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/storage/buffer/bufmgr.c.diff?r1=1.206&r2=1.207)
    pgsql/src/backend/storage/lmgr:
        lock.c (r1.163 -> r1.164)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/storage/lmgr/lock.c.diff?r1=1.163&r2=1.164)
        proc.c (r1.173 -> r1.174)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/storage/lmgr/proc.c.diff?r1=1.173&r2=1.174)
    pgsql/src/include:
        c.h (r1.199 -> r1.200)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/include/c.h.diff?r1=1.199&r2=1.200)
    pgsql/src/include/storage:
        proc.h (r1.87 -> r1.88)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/include/storage/proc.h.diff?r1=1.87&r2=1.88)

Re: pgsql: Repair a low-probability race condition identified by Qingqing

От
"Qingqing Zhou"
Дата:
"Tom Lane" <tgl@postgresql.org> wrote
> Rather than try to prevent the race condition directly, it seems best
> to make the lock manager robust against leftover wakeups, by having it
> repeat waiting on the semaphore if the lock has not actually been granted
> or denied yet.
>

IMHO the lmgr will not be the murdered by the leftover wakeup, but what
about the next LockBufferForCleanUp()? It is possible that the the leftover
wakeup is still there (e.g. get the lock without any waiting) and it will
wake up prematurely?

Regards,
Qingqing



Re: pgsql: Repair a low-probability race condition identified by Qingqing

От
Tom Lane
Дата:
"Qingqing Zhou" <zhouqq@cs.toronto.edu> writes:
> IMHO the lmgr will not be the murdered by the leftover wakeup, but what
> about the next LockBufferForCleanUp()?

What about it?  It has a loop already.

            regards, tom lane

Re: pgsql: Repair a low-probability race condition identified by Qingqing

От
"Qingqing Zhou"
Дата:
"Tom Lane" <tgl@sss.pgh.pa.us> wrote
> "Qingqing Zhou" <zhouqq@cs.toronto.edu> writes:
> > IMHO the lmgr will not be the murdered by the leftover wakeup, but what
> > about the next LockBufferForCleanUp()?
>
> What about it?  It has a loop already.
>

Oh, right.

Regards,
Qingqing