Skip to content
Snippets Groups Projects
Commit 1a528958 authored by Michael Paquier's avatar Michael Paquier
Browse files

wal_utils: Rename functions into consistent names

This makes the whole module more consistent with its interface to the
user.
parent 4e7f166c
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -12,8 +12,8 @@ INSERT INTO history_data VALUES (
5 0/189BEB38 no recovery target specified
7 0/249BEB38 no recovery target specified
');
SELECT parse_wal_history(data) FROM history_data;
parse_wal_history
SELECT archive_parse_history(data) FROM history_data;
archive_parse_history
---------------------------
(1,,0/9D4F390)
(2,0/9D4F390,0/117BEB70)
Loading
Loading
@@ -27,13 +27,13 @@ SELECT parse_wal_history(data) FROM history_data;
-- Timeline number is not an integer.
TRUNCATE history_data;
INSERT INTO history_data VALUES ('not_integer_tli 0/249BEB38 string');
SELECT parse_wal_history(data) FROM history_data;
SELECT archive_parse_history(data) FROM history_data;
ERROR: syntax error in history file: not_integer_tli 0/249BEB38 string
HINT: Expected a numeric timeline ID.
-- Not three fields
TRUNCATE history_data;
INSERT INTO history_data VALUES ('1 not_lsn');
SELECT parse_wal_history(data) FROM history_data;
SELECT archive_parse_history(data) FROM history_data;
ERROR: syntax error in history file: 1 not_lsn
HINT: Expected a write-ahead log switchpoint location.
-- Timelines need to be increasing
Loading
Loading
@@ -42,7 +42,7 @@ INSERT INTO history_data VALUES (
'2 0/117BEB70 no recovery target specified
1 0/09D4F390 no recovery target specified
');
SELECT parse_wal_history(data) FROM history_data;
SELECT archive_parse_history(data) FROM history_data;
ERROR: invalid data in history file: 1 0/09D4F390 no recovery target specified
HINT: Timeline IDs must be in increasing sequence.
DROP TABLE history_data;
-- Tests for build of WAL segment list for multiple timelines
-- NULL checks
SELECT build_wal_segment_list(NULL, '0/0'::pg_lsn, 1, '0/0'::pg_lsn, NULL);
SELECT archive_build_segment_list(NULL, '0/0'::pg_lsn, 1, '0/0'::pg_lsn, NULL);
ERROR: origin or target data cannot be NULL
SELECT build_wal_segment_list(1, NULL, 1, '0/0'::pg_lsn, NULL);
SELECT archive_build_segment_list(1, NULL, 1, '0/0'::pg_lsn, NULL);
ERROR: origin or target data cannot be NULL
SELECT build_wal_segment_list(1, '0/0'::pg_lsn, NULL, '0/0'::pg_lsn, NULL);
SELECT archive_build_segment_list(1, '0/0'::pg_lsn, NULL, '0/0'::pg_lsn, NULL);
ERROR: origin or target data cannot be NULL
SELECT build_wal_segment_list(1, '0/0'::pg_lsn, 1, NULL, NULL);
SELECT archive_build_segment_list(1, '0/0'::pg_lsn, 1, NULL, NULL);
ERROR: origin or target data cannot be NULL
CREATE TABLE history_data (data text);
-- Load history file to use as a base with multiple timelines
Loading
Loading
@@ -18,22 +18,11 @@ INSERT INTO history_data VALUES (
5 0/189BEB38 no recovery target specified
7 0/249BEB38 no recovery target specified
');
SELECT parse_wal_history(data) FROM history_data;
parse_wal_history
---------------------------
(1,,0/9D4F390)
(2,0/9D4F390,0/117BEB70)
(3,0/117BEB70,0/187BEB38)
(4,0/187BEB38,0/188BEB38)
(5,0/188BEB38,0/189BEB38)
(7,0/189BEB38,0/249BEB38)
(6 rows)
-- Build full list of segments needed for recovery.
SELECT build_wal_segment_list(1, '0/06D4F389'::pg_lsn, 8, '0/259BEB38'::pg_lsn, data)
SELECT archive_build_segment_list(1, '0/06D4F389'::pg_lsn, 8, '0/259BEB38'::pg_lsn, data)
FROM history_data;
build_wal_segment_list
--------------------------
archive_build_segment_list
----------------------------
000000010000000000000006
000000010000000000000007
000000010000000000000008
Loading
Loading
@@ -69,10 +58,10 @@ SELECT build_wal_segment_list(1, '0/06D4F389'::pg_lsn, 8, '0/259BEB38'::pg_lsn,
(32 rows)
 
-- Partial list of segments
SELECT build_wal_segment_list(3, '0/177BEB38'::pg_lsn, 8, '0/259BEB38'::pg_lsn, data)
SELECT archive_build_segment_list(3, '0/177BEB38'::pg_lsn, 8, '0/259BEB38'::pg_lsn, data)
FROM history_data;
build_wal_segment_list
--------------------------
archive_build_segment_list
----------------------------
000000030000000000000017
000000070000000000000018
000000070000000000000019
Loading
Loading
@@ -91,9 +80,9 @@ SELECT build_wal_segment_list(3, '0/177BEB38'::pg_lsn, 8, '0/259BEB38'::pg_lsn,
(15 rows)
 
-- List of segments with same timeline for origin and target
SELECT build_wal_segment_list(1, '0/1D4F390', 1, '0/189BEB38'::pg_lsn, NULL);
build_wal_segment_list
--------------------------
SELECT archive_build_segment_list(1, '0/1D4F390', 1, '0/189BEB38'::pg_lsn, NULL);
archive_build_segment_list
----------------------------
000000010000000000000001
000000010000000000000002
000000010000000000000003
Loading
Loading
@@ -121,22 +110,22 @@ SELECT build_wal_segment_list(1, '0/1D4F390', 1, '0/189BEB38'::pg_lsn, NULL);
(24 rows)
 
-- error, target TLI older than origin TLI
SELECT build_wal_segment_list(2, '0/09D4F389'::pg_lsn, 1, '0/259BEB38'::pg_lsn, data)
SELECT archive_build_segment_list(2, '0/09D4F389'::pg_lsn, 1, '0/259BEB38'::pg_lsn, data)
FROM history_data;
ERROR: origin timeline 2 newer than target timeline 1
-- error, target LSN older than origin LSN
SELECT build_wal_segment_list(1, '0/09D4F389'::pg_lsn, 2, '0/08D4F389'::pg_lsn, data)
SELECT archive_build_segment_list(1, '0/09D4F389'::pg_lsn, 2, '0/08D4F389'::pg_lsn, data)
FROM history_data;
ERROR: origin LSN 0/9D4F389 newer than target LSN 0/8D4F389
-- error, target LSN older than last history file entry
SELECT build_wal_segment_list(1, '0/09D4F389'::pg_lsn, 2, '0/10D4F389'::pg_lsn, data)
SELECT archive_build_segment_list(1, '0/09D4F389'::pg_lsn, 2, '0/10D4F389'::pg_lsn, data)
FROM history_data;
ERROR: timeline of last history entry 7 newer than or equal to target timeline 2
-- error, timelines are not direct parents
SELECT build_wal_segment_list(6, '0/09D4F389'::pg_lsn, 9, '0/259BEB38'::pg_lsn, data)
SELECT archive_build_segment_list(6, '0/09D4F389'::pg_lsn, 9, '0/259BEB38'::pg_lsn, data)
FROM history_data;
ERROR: origin data not a direct parent of target
-- error, target and origin timelines have to match without history file
SELECT build_wal_segment_list(1, '0/1D4F390', 2, '0/189BEB38'::pg_lsn, NULL);
SELECT archive_build_segment_list(1, '0/1D4F390', 2, '0/189BEB38'::pg_lsn, NULL);
ERROR: origin and target timelines not matching without history file
DROP TABLE history_data;
Loading
Loading
@@ -14,23 +14,23 @@ INSERT INTO history_data VALUES (
5 0/189BEB38 no recovery target specified
7 0/249BEB38 no recovery target specified
');
SELECT parse_wal_history(data) FROM history_data;
SELECT archive_parse_history(data) FROM history_data;
 
-- Sanity checks with some failures
-- Timeline number is not an integer.
TRUNCATE history_data;
INSERT INTO history_data VALUES ('not_integer_tli 0/249BEB38 string');
SELECT parse_wal_history(data) FROM history_data;
SELECT archive_parse_history(data) FROM history_data;
-- Not three fields
TRUNCATE history_data;
INSERT INTO history_data VALUES ('1 not_lsn');
SELECT parse_wal_history(data) FROM history_data;
SELECT archive_parse_history(data) FROM history_data;
-- Timelines need to be increasing
TRUNCATE history_data;
INSERT INTO history_data VALUES (
'2 0/117BEB70 no recovery target specified
1 0/09D4F390 no recovery target specified
');
SELECT parse_wal_history(data) FROM history_data;
SELECT archive_parse_history(data) FROM history_data;
 
DROP TABLE history_data;
-- Tests for build of WAL segment list for multiple timelines
 
-- NULL checks
SELECT build_wal_segment_list(NULL, '0/0'::pg_lsn, 1, '0/0'::pg_lsn, NULL);
SELECT build_wal_segment_list(1, NULL, 1, '0/0'::pg_lsn, NULL);
SELECT build_wal_segment_list(1, '0/0'::pg_lsn, NULL, '0/0'::pg_lsn, NULL);
SELECT build_wal_segment_list(1, '0/0'::pg_lsn, 1, NULL, NULL);
SELECT archive_build_segment_list(NULL, '0/0'::pg_lsn, 1, '0/0'::pg_lsn, NULL);
SELECT archive_build_segment_list(1, NULL, 1, '0/0'::pg_lsn, NULL);
SELECT archive_build_segment_list(1, '0/0'::pg_lsn, NULL, '0/0'::pg_lsn, NULL);
SELECT archive_build_segment_list(1, '0/0'::pg_lsn, 1, NULL, NULL);
 
CREATE TABLE history_data (data text);
 
Loading
Loading
@@ -17,29 +17,28 @@ INSERT INTO history_data VALUES (
5 0/189BEB38 no recovery target specified
7 0/249BEB38 no recovery target specified
');
SELECT parse_wal_history(data) FROM history_data;
 
-- Build full list of segments needed for recovery.
SELECT build_wal_segment_list(1, '0/06D4F389'::pg_lsn, 8, '0/259BEB38'::pg_lsn, data)
SELECT archive_build_segment_list(1, '0/06D4F389'::pg_lsn, 8, '0/259BEB38'::pg_lsn, data)
FROM history_data;
-- Partial list of segments
SELECT build_wal_segment_list(3, '0/177BEB38'::pg_lsn, 8, '0/259BEB38'::pg_lsn, data)
SELECT archive_build_segment_list(3, '0/177BEB38'::pg_lsn, 8, '0/259BEB38'::pg_lsn, data)
FROM history_data;
-- List of segments with same timeline for origin and target
SELECT build_wal_segment_list(1, '0/1D4F390', 1, '0/189BEB38'::pg_lsn, NULL);
SELECT archive_build_segment_list(1, '0/1D4F390', 1, '0/189BEB38'::pg_lsn, NULL);
-- error, target TLI older than origin TLI
SELECT build_wal_segment_list(2, '0/09D4F389'::pg_lsn, 1, '0/259BEB38'::pg_lsn, data)
SELECT archive_build_segment_list(2, '0/09D4F389'::pg_lsn, 1, '0/259BEB38'::pg_lsn, data)
FROM history_data;
-- error, target LSN older than origin LSN
SELECT build_wal_segment_list(1, '0/09D4F389'::pg_lsn, 2, '0/08D4F389'::pg_lsn, data)
SELECT archive_build_segment_list(1, '0/09D4F389'::pg_lsn, 2, '0/08D4F389'::pg_lsn, data)
FROM history_data;
-- error, target LSN older than last history file entry
SELECT build_wal_segment_list(1, '0/09D4F389'::pg_lsn, 2, '0/10D4F389'::pg_lsn, data)
SELECT archive_build_segment_list(1, '0/09D4F389'::pg_lsn, 2, '0/10D4F389'::pg_lsn, data)
FROM history_data;
-- error, timelines are not direct parents
SELECT build_wal_segment_list(6, '0/09D4F389'::pg_lsn, 9, '0/259BEB38'::pg_lsn, data)
SELECT archive_build_segment_list(6, '0/09D4F389'::pg_lsn, 9, '0/259BEB38'::pg_lsn, data)
FROM history_data;
-- error, target and origin timelines have to match without history file
SELECT build_wal_segment_list(1, '0/1D4F390', 2, '0/189BEB38'::pg_lsn, NULL);
SELECT archive_build_segment_list(1, '0/1D4F390', 2, '0/189BEB38'::pg_lsn, NULL);
 
DROP TABLE history_data;
Loading
Loading
@@ -6,7 +6,7 @@
-- Parse a WAL history file, input is a buffer including the data of
-- a history file ready to be parsed. This returns a SQL representation
-- of a list of TimeLineHistoryEntry.
CREATE FUNCTION parse_wal_history(
CREATE FUNCTION archive_parse_history(
IN history_data text,
OUT timeline int,
OUT begin_lsn pg_lsn,
Loading
Loading
@@ -18,7 +18,7 @@ LANGUAGE C STRICT;
-- Build a list of WAL segments necessary to join the given origin LSN
-- and timeline to their targets. Note that the origin needs to be a
-- direct parent of the target as specified by the history data.
CREATE FUNCTION build_wal_segment_list(
CREATE FUNCTION archive_build_segment_list(
IN origin_tli int,
IN origin_lsn pg_lsn,
IN target_tli int,
Loading
Loading
Loading
Loading
@@ -32,8 +32,8 @@ static List *parseTimeLineHistory(char *buffer);
/*
* Set of SQL-callable functions.
*/
PG_FUNCTION_INFO_V1(parse_wal_history);
PG_FUNCTION_INFO_V1(build_wal_segment_list);
PG_FUNCTION_INFO_V1(archive_parse_history);
PG_FUNCTION_INFO_V1(archive_build_segment_list);
PG_FUNCTION_INFO_V1(archive_get_size);
PG_FUNCTION_INFO_V1(archive_get_data);
 
Loading
Loading
@@ -126,14 +126,14 @@ parseTimeLineHistory(char *buffer)
 
 
/*
* parse_wal_history
* archive_parse_history
*
* Parse input buffer of a history file and build a set of rows to
* give a SQL representation of TimeLineHistoryEntry entries part
* of a timeline history file.
*/
Datum
parse_wal_history(PG_FUNCTION_ARGS)
archive_parse_history(PG_FUNCTION_ARGS)
{
char *history_buf = TextDatumGetCString(PG_GETARG_DATUM(0));
TupleDesc tupdesc;
Loading
Loading
@@ -207,7 +207,7 @@ parse_wal_history(PG_FUNCTION_ARGS)
}
 
/*
* build_wal_segment_list
* archive_build_segment_list
*
* Taking in input an origin timeline and LSN, as well as a target timeline
* and LSN, build a list of WAL segments able to allow a standby pointing to
Loading
Loading
@@ -226,7 +226,7 @@ parse_wal_history(PG_FUNCTION_ARGS)
* timeline entry is higher than the target.
*/
Datum
build_wal_segment_list(PG_FUNCTION_ARGS)
archive_build_segment_list(PG_FUNCTION_ARGS)
{
TimeLineID origin_tli;
XLogRecPtr origin_lsn;
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment