From 3abc6e458e5ec888374002a0e8adf9b739689762 Mon Sep 17 00:00:00 2001 From: Craig Ringer Date: Tue, 26 May 2015 17:51:55 +0800 Subject: [PATCH] Add bdr.bdr_apply_is_paused() information function This makes it possible to see whether replay is paused on a node. Also adds some tests for pause/resume. Closes #59 --- Makefile.in | 1 + bdr.c | 8 +++ doc/manual-functions.sgml | 17 +++++ expected/pause.out | 103 +++++++++++++++++++++++++++++ extsql/bdr--0.10.0.1--0.10.0.2.sql | 2 + extsql/bdr--0.9.0.4--0.9.0.5.sql | 2 + sql/pause.sql | 44 ++++++++++++ 7 files changed, 177 insertions(+) create mode 100644 expected/pause.out create mode 100644 sql/pause.sql diff --git a/Makefile.in b/Makefile.in index 52153c7c16..0917a4129e 100644 --- a/Makefile.in +++ b/Makefile.in @@ -257,6 +257,7 @@ REGRESSCHECKS= \ supervisordb \ upgrade \ identifier \ + pause \ $(DDLREGRESSCHECKS) \ dml/basic dml/contrib dml/delete_pk dml/extended dml/missing_pk dml/toasted \ $(REGRESSTEARDOWN) diff --git a/bdr.c b/bdr.c index e72f94644d..6f3b3bce5a 100644 --- a/bdr.c +++ b/bdr.c @@ -95,6 +95,7 @@ void _PG_init(void); PGDLLEXPORT Datum bdr_apply_pause(PG_FUNCTION_ARGS); PGDLLEXPORT Datum bdr_apply_resume(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum bdr_apply_is_paused(PG_FUNCTION_ARGS); PGDLLEXPORT Datum bdr_version(PG_FUNCTION_ARGS); PGDLLEXPORT Datum bdr_version_num(PG_FUNCTION_ARGS); PGDLLEXPORT Datum bdr_min_remote_version_num(PG_FUNCTION_ARGS); @@ -105,6 +106,7 @@ PGDLLEXPORT Datum bdr_format_slot_name_sql(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(bdr_apply_pause); PG_FUNCTION_INFO_V1(bdr_apply_resume); +PG_FUNCTION_INFO_V1(bdr_apply_is_paused); PG_FUNCTION_INFO_V1(bdr_version); PG_FUNCTION_INFO_V1(bdr_version_num); PG_FUNCTION_INFO_V1(bdr_min_remote_version_num); @@ -918,6 +920,12 @@ bdr_apply_resume(PG_FUNCTION_ARGS) PG_RETURN_VOID(); } +Datum +bdr_apply_is_paused(PG_FUNCTION_ARGS) +{ + PG_RETURN_BOOL(BdrWorkerCtl->pause_apply); +} + Datum bdr_version(PG_FUNCTION_ARGS) { diff --git a/doc/manual-functions.sgml b/doc/manual-functions.sgml index c7459f4f8f..b4f94bcb40 100644 --- a/doc/manual-functions.sgml +++ b/doc/manual-functions.sgml @@ -172,6 +172,23 @@ + + &bdr;/&udr; + + + bdr.bdr_apply_is_paused + + bdr.bdr_apply_is_paused() + + boolean + + Report whether replay is paused (e.g. with + bdr.bdr_apply_pause()). A false return + does not mean replay is actually progressing, only that + it's not intentionally paused. + + + &bdr;/&udr; diff --git a/expected/pause.out b/expected/pause.out new file mode 100644 index 0000000000..85e1ba5b0f --- /dev/null +++ b/expected/pause.out @@ -0,0 +1,103 @@ +\ccc regression +invalid command \ccc +SELECT bdr.bdr_apply_is_paused(); + bdr_apply_is_paused +--------------------- + f +(1 row) + +SELECT bdr.bdr_replicate_ddl_command('CREATE TABLE public.pause_test(x text primary key);'); + bdr_replicate_ddl_command +--------------------------- + +(1 row) + +INSERT INTO pause_test(x) VALUES ('before pause'); +SELECT pg_xlog_wait_remote_apply(pg_current_xlog_location(), 0); + pg_xlog_wait_remote_apply +--------------------------- + +(1 row) + +\cc postgres +invalid command \cc +SELECT bdr.bdr_apply_is_paused(); + bdr_apply_is_paused +--------------------- + f +(1 row) + +SELECT bdr.bdr_apply_pause(); + bdr_apply_pause +----------------- + +(1 row) + +SELECT bdr.bdr_apply_is_paused(); + bdr_apply_is_paused +--------------------- + t +(1 row) + +-- It's necessary to wait for a latch timeout on apply workers +-- until bdr_apply_pause gets taught to set their latches. +SELECT pg_sleep(6); + pg_sleep +---------- + +(1 row) + +\ccc regression +invalid command \ccc +INSERT INTO pause_test(x) VALUES ('after pause before resume'); +\cc postgres +invalid command \cc +-- Give more time for a row to replicate if it's going to +-- (it shouldn't) +SELECT pg_sleep(1); + pg_sleep +---------- + +(1 row) + +-- Pause state is preserved across sessions +SELECT bdr.bdr_apply_is_paused(); + bdr_apply_is_paused +--------------------- + t +(1 row) + +-- Must not see row from after pause +SELECT x FROM pause_test; + x +--------------------------- + before pause + after pause before resume +(2 rows) + +SELECT bdr.bdr_apply_resume(); + bdr_apply_resume +------------------ + +(1 row) + +\ccc regression +invalid command \ccc +INSERT INTO pause_test(x) VALUES ('after resume'); +SELECT pg_xlog_wait_remote_apply(pg_current_xlog_location(), 0); + pg_xlog_wait_remote_apply +--------------------------- + +(1 row) + +\cc postgres +invalid command \cc +-- Must see all three rows +SELECT x FROM pause_test; + x +--------------------------- + before pause + after pause before resume + after resume +(3 rows) + diff --git a/extsql/bdr--0.10.0.1--0.10.0.2.sql b/extsql/bdr--0.10.0.1--0.10.0.2.sql index 9d32af72ec..cd6390d213 100644 --- a/extsql/bdr--0.10.0.1--0.10.0.2.sql +++ b/extsql/bdr--0.10.0.1--0.10.0.2.sql @@ -9,6 +9,8 @@ SET bdr.skip_ddl_replication = true; ALTER FUNCTION bdr.table_set_replication_sets(p_relation regclass, p_sets text[]) SET bdr.permit_unsafe_ddl_commands = true; +CREATE OR REPLACE FUNCTION bdr.bdr_apply_is_paused() +RETURNS boolean LANGUAGE c AS 'MODULE_PATHNAME'; RESET bdr.permit_unsafe_ddl_commands; RESET bdr.skip_ddl_replication; diff --git a/extsql/bdr--0.9.0.4--0.9.0.5.sql b/extsql/bdr--0.9.0.4--0.9.0.5.sql index 9d32af72ec..cd6390d213 100644 --- a/extsql/bdr--0.9.0.4--0.9.0.5.sql +++ b/extsql/bdr--0.9.0.4--0.9.0.5.sql @@ -9,6 +9,8 @@ SET bdr.skip_ddl_replication = true; ALTER FUNCTION bdr.table_set_replication_sets(p_relation regclass, p_sets text[]) SET bdr.permit_unsafe_ddl_commands = true; +CREATE OR REPLACE FUNCTION bdr.bdr_apply_is_paused() +RETURNS boolean LANGUAGE c AS 'MODULE_PATHNAME'; RESET bdr.permit_unsafe_ddl_commands; RESET bdr.skip_ddl_replication; diff --git a/sql/pause.sql b/sql/pause.sql new file mode 100644 index 0000000000..792a30d8ac --- /dev/null +++ b/sql/pause.sql @@ -0,0 +1,44 @@ +\ccc regression + +SELECT bdr.bdr_apply_is_paused(); + +SELECT bdr.bdr_replicate_ddl_command('CREATE TABLE public.pause_test(x text primary key);'); +INSERT INTO pause_test(x) VALUES ('before pause'); +SELECT pg_xlog_wait_remote_apply(pg_current_xlog_location(), 0); + +\cc postgres + +SELECT bdr.bdr_apply_is_paused(); +SELECT bdr.bdr_apply_pause(); +SELECT bdr.bdr_apply_is_paused(); +-- It's necessary to wait for a latch timeout on apply workers +-- until bdr_apply_pause gets taught to set their latches. +SELECT pg_sleep(6); + +\ccc regression + +INSERT INTO pause_test(x) VALUES ('after pause before resume'); + +\cc postgres + +-- Give more time for a row to replicate if it's going to +-- (it shouldn't) +SELECT pg_sleep(1); + +-- Pause state is preserved across sessions +SELECT bdr.bdr_apply_is_paused(); + +-- Must not see row from after pause +SELECT x FROM pause_test; + +SELECT bdr.bdr_apply_resume(); + +\ccc regression + +INSERT INTO pause_test(x) VALUES ('after resume'); +SELECT pg_xlog_wait_remote_apply(pg_current_xlog_location(), 0); + +\cc postgres + +-- Must see all three rows +SELECT x FROM pause_test; -- 2.39.5