Concurrency bug in amcheck
Alexander Korotkov <a.korotkov@postgrespro.ru>
From: Alexander Korotkov <a.korotkov@postgrespro.ru>
To: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2020-04-21T09:54:27Z
Lists: pgsql-hackers
Attachments
- fix_amcheck_concurrency.patch (application/octet-stream) patch
Hi!
I found concurrency bug in amcheck running on replica. When
btree_xlog_unlink_page() replays changes to replica, deleted page is
left with no items. But if amcheck steps on such deleted page
palloc_btree_page() expects it would have items.
(lldb_on_primary) b btbulkdelete
primary=# drop table test;
primary=# create table test as (select random() x from
generate_series(1,1000000) i);
primary=# create index test_x_idx on test(x);
primary=# delete from test;
primary=# vacuum test;
(lldb_on_replica) b bt_check_level_from_leftmost
replica=# select bt_index_check('test_x_idx');
# skip to internal level
(lldb_on_replica) c
(lldb_on_replica) b palloc_btree_page
# skip to non-leftmost page
(lldb_on_replica) c
(lldb_on_replica) c
# concurrently delete btree pages
(lldb_on_primary) c
# continue with pages
(lldb_on_replica) c
Finally replica gets error.
ERROR: internal block 289 in index "test_x_idx" lacks high key and/or
at least one downlink
Proposed fix is attached. Spotted by Konstantin Knizhnik,
reproduction case and fix from me.
------
Alexander Korotkov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
Commits
-
Remove btree page items after page unlink
- f47b5e139579 14.0 landed
-
Fix amcheck for page checks concurrent to replay of btree page deletion
- b9a45d8dba4d 11.9 landed
- ae1f9b0a9bc3 12.4 landed
- 34dae902ca1c 13.0 landed