Skip to content

Commit 29bdf6d

Browse files
committed
fix bgwriter_checkpoint
1 parent 5249ebd commit 29bdf6d

2 files changed

Lines changed: 37 additions & 19 deletions

File tree

src/test/fsync/expected/bgwriter_checkpoint.out

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@ select gp_segment_id, pg_reload_conf() from gp_id union select gp_segment_id, pg
3030
(4 rows)
3131

3232
begin;
33+
create or replace function wait_until_dirty_buffer_flushed() returns text as $$
34+
begin
35+
for i in 1..60 loop
36+
if ((select count(*) = 0 from dirty_buffers_on_qes() as (tablespace oid, database oid, relfilenode int8, block int)) AND
37+
(select count(*) = 0 from dirty_buffers_on_qd() as (tablespace oid, database oid, relfilenode int8, block int))) then
38+
return 'OK'; /* in func */
39+
end if; /* in func */
40+
perform pg_sleep(0.1); /* in func */
41+
checkpoint; /* in func */
42+
end loop; /* in func */
43+
return 'Fail'; /* in func */
44+
end; /* in func */
45+
$$ language plpgsql;
3346
create function num_dirty_on_qes(relid oid) returns setof bigint as
3447
$$
3548
declare
@@ -99,6 +112,13 @@ select gp_inject_fault_infinite('all', 'reset', dbid) from gp_segment_configurat
99112

100113
-- Start with a clean slate (no dirty buffers).
101114
checkpoint;
115+
-- Ensure no buffers are dirty before we start.
116+
select wait_until_dirty_buffer_flushed();
117+
wait_until_dirty_buffer_flushed
118+
---------------------------------
119+
OK
120+
(1 row)
121+
102122
-- Skip checkpoints.
103123
select gp_inject_fault_infinite('checkpoint', 'skip', dbid)
104124
from gp_segment_configuration where role = 'p' and content > -1;
@@ -119,19 +139,6 @@ from gp_segment_configuration where role = 'p' and content > -1;
119139
Success:
120140
(3 rows)
121141

122-
-- Ensure no buffers are dirty before we start.
123-
select * from dirty_buffers_on_qd()
124-
as (tablespace oid, database oid, relfilenode int8, block int);
125-
tablespace | database | relfilenode | block
126-
------------+----------+-------------+-------
127-
(0 rows)
128-
129-
select * from dirty_buffers_on_qes()
130-
as (tablespace oid, database oid, relfilenode int8, block int);
131-
tablespace | database | relfilenode | block
132-
------------+----------+-------------+-------
133-
(0 rows)
134-
135142
-- Make buffers dirty. At least two relfiles must be sync'ed during
136143
-- next checkpoint.
137144
insert into fsync_test1 select i, i from generate_series(1,1000)i;

src/test/fsync/sql/bgwriter_checkpoint.sql

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ alter system set autovacuum = off;
2424
select gp_segment_id, pg_reload_conf() from gp_id union select gp_segment_id, pg_reload_conf() from gp_dist_random('gp_id');
2525

2626
begin;
27+
create or replace function wait_until_dirty_buffer_flushed() returns text as $$
28+
begin
29+
for i in 1..60 loop
30+
if ((select count(*) = 0 from dirty_buffers_on_qes() as (tablespace oid, database oid, relfilenode int8, block int)) AND
31+
(select count(*) = 0 from dirty_buffers_on_qd() as (tablespace oid, database oid, relfilenode int8, block int))) then
32+
return 'OK'; /* in func */
33+
end if; /* in func */
34+
perform pg_sleep(0.1); /* in func */
35+
checkpoint; /* in func */
36+
end loop; /* in func */
37+
return 'Fail'; /* in func */
38+
end; /* in func */
39+
$$ language plpgsql;
40+
2741
create function num_dirty_on_qes(relid oid) returns setof bigint as
2842
$$
2943
declare
@@ -86,6 +100,9 @@ select gp_inject_fault_infinite('all', 'reset', dbid) from gp_segment_configurat
86100
-- Start with a clean slate (no dirty buffers).
87101
checkpoint;
88102

103+
-- Ensure no buffers are dirty before we start.
104+
select wait_until_dirty_buffer_flushed();
105+
89106
-- Skip checkpoints.
90107
select gp_inject_fault_infinite('checkpoint', 'skip', dbid)
91108
from gp_segment_configuration where role = 'p' and content > -1;
@@ -94,12 +111,6 @@ from gp_segment_configuration where role = 'p' and content > -1;
94111
select gp_inject_fault_infinite('fault_in_background_writer_main', 'suspend', dbid)
95112
from gp_segment_configuration where role = 'p' and content > -1;
96113

97-
-- Ensure no buffers are dirty before we start.
98-
select * from dirty_buffers_on_qd()
99-
as (tablespace oid, database oid, relfilenode int8, block int);
100-
select * from dirty_buffers_on_qes()
101-
as (tablespace oid, database oid, relfilenode int8, block int);
102-
103114
-- Make buffers dirty. At least two relfiles must be sync'ed during
104115
-- next checkpoint.
105116
insert into fsync_test1 select i, i from generate_series(1,1000)i;

0 commit comments

Comments
 (0)