Fix primary crash continually with invalid checkpoint after promote

Поиск
Список
Период
Сортировка
От Zhao Rui
Тема Fix primary crash continually with invalid checkpoint after promote
Дата
Msg-id tencent_1D53DA1DFA2F5EF11B0D6B9DD24FF8BD4A08@qq.com
обсуждение исходный текст
Ответы Re: Fix primary crash continually with invalid checkpoint after promote  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Fix primary crash continually with invalid checkpoint after promote  (Nathan Bossart <nathandbossart@gmail.com>)
Re: Fix primary crash continually with invalid checkpoint after promote  (Nathan Bossart <nathandbossart@gmail.com>)
Список pgsql-hackers

Newly promoted primary may leave an invalid checkpoint.

In function CreateRestartPoint, control file is updated and old wals are removed. But in some situations, control file is not updated, old wals are still removed. Thus produces an invalid checkpoint with nonexistent wal. Crucial log: "invalid primary checkpoint record", "could not locate a valid checkpoint record".


The following timeline reproduces above situation:

tl1: standby begins to create restart point (time or wal triggered).

tl2: standby promotes and control file state is updated to DB_IN_PRODUCTION. Control file will not update (xlog.c:9690). But old wals are still removed (xlog.c:9719).

tl3: standby becomes primary. primary may crash before the next complete checkpoint (OOM in my situation). primary will crash continually with invalid checkpoint.


The attached patch reproduces this problem using standard postgresql perl test, you can run with 

./configure --enable-tap-tests; make -j; make -C src/test/recovery/ check PROVE_TESTS=t/027_invalid_checkpoint_after_promote.pl

The attached patch also fixes this problem by ensuring that remove old wals only after control file is updated.




Вложения

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Laurenz Albe
Дата:
Сообщение: Re: An attempt to avoid locally-committed-but-not-replicated-to-standby-transactions in synchronous replication
Следующее
От: vignesh C
Дата:
Сообщение: Re: Perform streaming logical transactions by background workers and parallel apply