提交 e6addf3a 编写于 作者: P Paul Guo

Make test function wait_for_replication_replay() a common UDF.

We need that in more than one test.
Reviewed-by: Nxiong-gang <gxiong@pivotal.io>
(cherry picked from commit af942980)
上级 5b4c4f59
......@@ -21,12 +21,6 @@ CREATE
create extension if not exists gp_inject_fault;
CREATE
create or replace function wait_for_replication_replay (retries int) returns bool as $$ declare i int; /* in func */ result bool; /* in func */ begin /* in func */ i := 0; /* in func */ -- Wait until the mirror (content 0) has replayed up to flush location loop /* in func */ SELECT flush_location = replay_location INTO result from gp_stat_replication where gp_segment_id = 0; /* in func */ if result then /* in func */ return true; /* in func */ end if; /* in func */
if i >= retries then /* in func */ return false; /* in func */ end if; /* in func */ perform pg_sleep(0.1); /* in func */ i := i + 1; /* in func */ end loop; /* in func */ end; /* in func */ $$ language plpgsql;
CREATE
create table t_restart (a int);
CREATE
......@@ -70,7 +64,7 @@ CHECKPOINT
-- and then if the mirror is promoted it will panic like this:
-- FATAL","58P01","requested WAL segment pg_xlog/000000010000000000000003 has already been removed
-- The call stack is: StartupXLOG()->PrescanPreparedTransactions()...
select * from wait_for_replication_replay(5000);
select * from wait_for_replication_replay(0, 5000);
wait_for_replication_replay
-----------------------------
t
......
......@@ -8,10 +8,6 @@
include: helpers/server_helpers.sql;
CREATE
create or replace function wait_for_replication_replay (retries int) returns bool as $$ declare i int; /* in func */ result bool; /* in func */ begin /* in func */ i := 0; /* in func */ -- Wait until the mirror (content 0) has replayed up to flush location loop /* in func */ SELECT flush_location = replay_location INTO result from gp_stat_replication where gp_segment_id = 0; /* in func */ if result then /* in func */ return true; /* in func */ end if; /* in func */
if i >= retries then /* in func */ return false; /* in func */ end if; /* in func */ perform pg_sleep(0.1); /* in func */ i := i + 1; /* in func */ end loop; /* in func */ end; /* in func */ $$ language plpgsql;
CREATE
3:CREATE extension if NOT EXISTS gp_inject_fault;
CREATE
3:SELECT role, preferred_role, content, mode, status FROM gp_segment_configuration;
......@@ -643,7 +639,7 @@ VACUUM
-- Make sure mirror is able to successfully replay all the truncate
-- records generated and doesn't encounter the "WAL contains
-- references to invalid pages" PANIC.
6:SELECT * from wait_for_replication_replay(5000);
6:SELECT * from wait_for_replication_replay(0, 5000);
wait_for_replication_replay
-----------------------------
t
......
......@@ -165,3 +165,26 @@ begin
return 'Fail';
end;
$$ language plpgsql;
create or replace function wait_for_replication_replay (segid int, retries int) returns bool as
$$
declare
i int;
result bool;
begin
i := 0;
-- Wait until the mirror/standby has replayed up to flush location
loop
SELECT flush_location = replay_location INTO result from gp_stat_replication where gp_segment_id = segid;
if result then
return true;
end if;
if i >= retries then
return false;
end if;
perform pg_sleep(0.1);
i := i + 1;
end loop;
end;
$$ language plpgsql;
......@@ -14,31 +14,6 @@ include: helpers/server_helpers.sql;
!\retcode gpstop -u;
create extension if not exists gp_inject_fault;
create or replace function wait_for_replication_replay (retries int) returns bool as
$$
declare
i int; /* in func */
result bool; /* in func */
begin /* in func */
i := 0; /* in func */
-- Wait until the mirror (content 0) has replayed up to flush location
loop /* in func */
SELECT flush_location = replay_location INTO result from gp_stat_replication where gp_segment_id = 0; /* in func */
if result then /* in func */
return true; /* in func */
end if; /* in func */
if i >= retries then /* in func */
return false; /* in func */
end if; /* in func */
perform pg_sleep(0.1); /* in func */
i := i + 1; /* in func */
end loop; /* in func */
end; /* in func */
$$ language plpgsql;
create table t_restart (a int);
-- generate an orphaned prepare transaction.
......@@ -65,7 +40,7 @@ checkpoint;
-- and then if the mirror is promoted it will panic like this:
-- FATAL","58P01","requested WAL segment pg_xlog/000000010000000000000003 has already been removed
-- The call stack is: StartupXLOG()->PrescanPreparedTransactions()...
select * from wait_for_replication_replay(5000);
select * from wait_for_replication_replay(0, 5000);
-- shutdown primary and make sure the segment is down
-1U: select pg_ctl((SELECT datadir from gp_segment_configuration c
......
......@@ -7,29 +7,6 @@
-- end_matchsubs
include: helpers/server_helpers.sql;
create or replace function wait_for_replication_replay (retries int) returns bool as
$$
declare
i int; /* in func */
result bool; /* in func */
begin /* in func */
i := 0; /* in func */
-- Wait until the mirror (content 0) has replayed up to flush location
loop /* in func */
SELECT flush_location = replay_location INTO result from gp_stat_replication where gp_segment_id = 0; /* in func */
if result then /* in func */
return true; /* in func */
end if; /* in func */
if i >= retries then /* in func */
return false; /* in func */
end if; /* in func */
perform pg_sleep(0.1); /* in func */
i := i + 1; /* in func */
end loop; /* in func */
end; /* in func */
$$ language plpgsql;
3:CREATE extension if NOT EXISTS gp_inject_fault;
3:SELECT role, preferred_role, content, mode, status FROM gp_segment_configuration;
--
......@@ -216,5 +193,5 @@ where c.role='p' and c.content=0), 'restart');
-- Make sure mirror is able to successfully replay all the truncate
-- records generated and doesn't encounter the "WAL contains
-- references to invalid pages" PANIC.
6:SELECT * from wait_for_replication_replay(5000);
6:SELECT * from wait_for_replication_replay(0, 5000);
6:SELECT gp_inject_fault('fts_probe', 'reset', 1);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册