Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit de31e6f

Browse files
committed
BRIN: mask BRIN_EVACUATE_PAGE for WAL consistency checking
That bit is unlogged and therefore it's wrong to consider it in WAL page comparison. Add a test that tickles the case, as branch testing technology allows. This has been a problem ever since wal consistency checking was introduced (commit a507b86 for pg10), so backpatch to all supported branches. Author: 王海洋 (Haiyang Wang) <wanghaiyang.001@bytedance.com> Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com> Discussion: https://postgr.es/m/CACciXAD2UvLMOhc4jX9VvOKt7DtYLr3OYRBhvOZ-jRxtzc_7Jg@mail.gmail.com Discussion: https://postgr.es/m/CACciXADOfErX9Bx0nzE_SkdfXr6Bbpo5R=v_B6MUTEYW4ya+cg@mail.gmail.com
1 parent ad8ebcf commit de31e6f

File tree

3 files changed

+76
-1
lines changed

3 files changed

+76
-1
lines changed

src/backend/access/brin/brin_pageops.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,12 @@ brin_start_evacuating_page(Relation idxRel, Buffer buf)
541541
lp = PageGetItemId(page, off);
542542
if (ItemIdIsUsed(lp))
543543
{
544-
/* prevent other backends from adding more stuff to this page */
544+
/*
545+
* Prevent other backends from adding more stuff to this page:
546+
* BRIN_EVACUATE_PAGE informs br_page_get_freespace that this page
547+
* can no longer be used to add new tuples. Note that this flag
548+
* is not WAL-logged, except accidentally.
549+
*/
545550
BrinPageFlags(page) |= BRIN_EVACUATE_PAGE;
546551
MarkBufferDirtyHint(buf, true);
547552

src/backend/access/brin/brin_xlog.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,4 +358,10 @@ brin_mask(char *pagedata, BlockNumber blkno)
358358
{
359359
mask_unused_space(page);
360360
}
361+
362+
/*
363+
* BRIN_EVACUATE_PAGE is not WAL-logged, since it's of no use in recovery.
364+
* Mask it. See brin_start_evacuating_page() for details.
365+
*/
366+
BrinPageFlags(page) &= ~BRIN_EVACUATE_PAGE;
361367
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Copyright (c) 2021-2022, PostgreSQL Global Development Group
2+
3+
# Verify WAL consistency
4+
5+
use strict;
6+
use warnings;
7+
8+
use PostgreSQL::Test::Utils;
9+
use Test::More;
10+
use PostgreSQL::Test::Cluster;
11+
12+
# Set up primary
13+
my $whiskey = PostgreSQL::Test::Cluster->new('whiskey');
14+
$whiskey->init(allows_streaming => 1);
15+
$whiskey->append_conf('postgresql.conf', 'wal_consistency_checking = brin');
16+
$whiskey->start;
17+
$whiskey->safe_psql('postgres', 'create extension pageinspect');
18+
is( $whiskey->psql(
19+
'postgres',
20+
qq[SELECT pg_create_physical_replication_slot('standby_1');]),
21+
0,
22+
'physical slot created on primary');
23+
24+
# Take backup
25+
my $backup_name = 'brinbkp';
26+
$whiskey->backup($backup_name);
27+
28+
# Create streaming standby linking to primary
29+
my $charlie = PostgreSQL::Test::Cluster->new('charlie');
30+
$charlie->init_from_backup($whiskey, $backup_name, has_streaming => 1);
31+
$charlie->append_conf('postgresql.conf', 'primary_slot_name = standby_1');
32+
$charlie->start;
33+
34+
# Now write some WAL in the primary
35+
36+
$whiskey->safe_psql(
37+
'postgres', qq{
38+
create table tbl_timestamp0 (d1 timestamp(0) without time zone) with (fillfactor=10);
39+
create index on tbl_timestamp0 using brin (d1) with (pages_per_range = 1, autosummarize=false);
40+
});
41+
# Run a loop that will end when the second revmap page is created
42+
$whiskey->safe_psql(
43+
'postgres', q{
44+
do
45+
$$
46+
declare
47+
current timestamp with time zone := '2019-03-27 08:14:01.123456789 America/Punta_Arenas';
48+
begin
49+
loop
50+
insert into tbl_timestamp0 select i from
51+
generate_series(current, current + interval '1 day', '28 seconds') i;
52+
perform brin_summarize_new_values('tbl_timestamp0_d1_idx');
53+
if (brin_metapage_info(get_raw_page('tbl_timestamp0_d1_idx', 0))).lastrevmappage > 1 then
54+
exit;
55+
end if;
56+
current := current + interval '1 day';
57+
end loop;
58+
end
59+
$$;
60+
});
61+
62+
$whiskey->wait_for_catchup($charlie, 'replay', $whiskey->lsn('insert'));
63+
64+
done_testing();

0 commit comments

Comments
 (0)