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

Commit e44dae0

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 d263ced commit e44dae0

File tree

4 files changed

+88
-2
lines changed

4 files changed

+88
-2
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
}

src/test/modules/brin/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# src/test/modules/brin/Makefile
22

3-
EXTRA_INSTALL = contrib/pageinspect
3+
EXTRA_INSTALL = contrib/pageinspect contrib/pg_walinspect
44

55
ISOLATION = summarization-and-inprogress-insertion
66
TAP_TESTS = 1
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
$whiskey->safe_psql('postgres', 'create extension pg_walinspect');
19+
is( $whiskey->psql(
20+
'postgres',
21+
qq[SELECT pg_create_physical_replication_slot('standby_1');]),
22+
0,
23+
'physical slot created on primary');
24+
25+
# Take backup
26+
my $backup_name = 'brinbkp';
27+
$whiskey->backup($backup_name);
28+
29+
# Create streaming standby linking to primary
30+
my $charlie = PostgreSQL::Test::Cluster->new('charlie');
31+
$charlie->init_from_backup($whiskey, $backup_name, has_streaming => 1);
32+
$charlie->append_conf('postgresql.conf', 'primary_slot_name = standby_1');
33+
$charlie->start;
34+
35+
# Now write some WAL in the primary
36+
37+
$whiskey->safe_psql(
38+
'postgres', qq{
39+
create table tbl_timestamp0 (d1 timestamp(0) without time zone) with (fillfactor=10);
40+
create index on tbl_timestamp0 using brin (d1) with (pages_per_range = 1, autosummarize=false);
41+
});
42+
my $start_lsn = $whiskey->lsn('insert');
43+
# Run a loop that will end when the second revmap page is created
44+
$whiskey->safe_psql(
45+
'postgres', q{
46+
do
47+
$$
48+
declare
49+
current timestamp with time zone := '2019-03-27 08:14:01.123456789 America/Punta_Arenas';
50+
begin
51+
loop
52+
insert into tbl_timestamp0 select i from
53+
generate_series(current, current + interval '1 day', '28 seconds') i;
54+
perform brin_summarize_new_values('tbl_timestamp0_d1_idx');
55+
if (brin_metapage_info(get_raw_page('tbl_timestamp0_d1_idx', 0))).lastrevmappage > 1 then
56+
exit;
57+
end if;
58+
current := current + interval '1 day';
59+
end loop;
60+
end
61+
$$;
62+
});
63+
my $end_lsn = $whiskey->lsn('insert');
64+
65+
my ($ret, $out, $err) = $whiskey->psql(
66+
'postgres', qq{
67+
select count(*) from pg_get_wal_records_info('$start_lsn', '$end_lsn')
68+
where resource_manager = 'BRIN' AND
69+
record_type ILIKE '%revmap%'
70+
});
71+
cmp_ok($out, '>=', 1);
72+
73+
$whiskey->wait_for_catchup($charlie, 'replay', $whiskey->lsn('insert'));
74+
75+
done_testing();

0 commit comments

Comments
 (0)