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

Commit e79a57b

Browse files
committed
Fix copydir hook. Add tap test. Update readme
1 parent 305ec6f commit e79a57b

File tree

6 files changed

+212
-33
lines changed

6 files changed

+212
-33
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ install:
1212
- docker-compose build
1313

1414
script:
15-
# - docker-compose run tests
1615
- docker-compose run $(bash <(curl -s https://codecov.io/env)) tests
1716

1817
notifications:

Makefile

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,9 @@ endif
2424
$(EXTENSION)--$(EXTVERSION).sql: ptrack.sql
2525
cat $^ > $@
2626

27-
# check: isolationcheck
28-
29-
# ISOLATIONCHECKS=corner_cases
30-
31-
# submake-isolation:
32-
# $(MAKE) -C $(top_builddir)/src/test/isolation all
33-
34-
# isolationcheck: | submake-isolation temp-install
35-
# $(MKDIR_P) isolation_output
36-
# $(pg_isolation_regress_check) \
37-
# --temp-config $(top_srcdir)/contrib/pg_query_state/test.conf \
38-
# --outputdir=isolation_output \
39-
# $(ISOLATIONCHECKS)
40-
41-
# isolationcheck-install-force: all | submake-isolation temp-install
42-
# $(MKDIR_P) isolation_output
43-
# $(pg_isolation_regress_installcheck) \
44-
# --outputdir=isolation_output \
45-
# $(ISOLATIONCHECKS)
27+
temp-install: EXTRA_INSTALL=contrib/ptrack
4628

47-
# .PHONY: isolationcheck isolationcheck-install-force check
29+
check-tap: temp-install
30+
$(prove_check)
4831

49-
temp-install: EXTRA_INSTALL=contrib/ptrack
32+
check: check-tap

README.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,33 @@ CREATE EXTENSION ptrack;
4545

4646
## Public SQL API
4747

48-
* ptrack_version() — returns ptrack version string (2.0 currently).
49-
* ptrack_get_pagemapset('LSN') — returns a set of changed data files with bitmaps of changed blocks since specified LSN.
48+
* ptrack_version() — returns ptrack version string.
5049
* ptrack_init_lsn() — returns LSN of the last ptrack map initialization.
50+
* ptrack_get_pagemapset('LSN') — returns a set of changed data files with bitmaps of changed blocks since specified LSN.
51+
52+
Usage example:
53+
54+
```sql
55+
postgres=# SELECT ptrack_version();
56+
ptrack_version
57+
----------------
58+
2.1
59+
(1 row)
60+
61+
postgres=# SELECT ptrack_init_lsn();
62+
ptrack_init_lsn
63+
-----------------
64+
0/1814408
65+
(1 row)
66+
67+
postgres=# SELECT ptrack_get_pagemapset('0/186F4C8');
68+
ptrack_get_pagemapset
69+
-------------------------------------------
70+
(global/1262,"\\x0100000000000000000000")
71+
(global/2672,"\\x0200000000000000000000")
72+
(global/2671,"\\x0200000000000000000000")
73+
(3 rows)
74+
```
5175

5276
## Architecture
5377

patches/REL_12_STABLE-ptrack-core.diff

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ index 3bc26568eb7..aa282bfe0ab 100644
2929
{"config_exec_params", true},
3030
#endif
3131
diff --git a/src/backend/storage/file/copydir.c b/src/backend/storage/file/copydir.c
32-
index 30f6200a86f..4b3a7c4cd75 100644
32+
index 30f6200a86f..53e3b22c3e4 100644
3333
--- a/src/backend/storage/file/copydir.c
3434
+++ b/src/backend/storage/file/copydir.c
3535
@@ -27,6 +27,8 @@
@@ -41,16 +41,16 @@ index 30f6200a86f..4b3a7c4cd75 100644
4141
/*
4242
* copydir: copy a directory
4343
*
44-
@@ -118,6 +120,9 @@ copydir(char *fromdir, char *todir, bool recurse)
45-
* it's been true for ext3 and other filesystems in the past.
46-
*/
47-
fsync_fname(todir, true);
48-
+
44+
@@ -78,6 +80,9 @@ copydir(char *fromdir, char *todir, bool recurse)
45+
}
46+
FreeDir(xldir);
47+
4948
+ if (copydir_hook)
5049
+ copydir_hook(todir);
51-
}
52-
53-
/*
50+
+
51+
/*
52+
* Be paranoid here and fsync all files to ensure the copy is really done.
53+
* But if fsync is disabled, we're done.
5454
diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c
5555
index 050cee5f9a9..75cf67d464f 100644
5656
--- a/src/backend/storage/smgr/md.c

run_tests.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,15 @@ if [ "$MODE" = "basic" ]; then
8383
fi
8484

8585
if [ "$TEST_CASE" = "all" ]; then
86+
# Run all pg_probackup ptrack tests
8687
python -m unittest -v tests.ptrack || status=$?
8788

8889
# Get back to testdir
8990
cd ..
9091

92+
# Run tap tests
93+
make USE_PGXS=1 check || status=$?
94+
9195
# Something went wrong, exit with code 1 now
9296
if [ $status -ne 0 ]; then exit 1; fi
9397

t/001_basic.pl

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
#
2+
# Here we mostly do sanity checks and verify, that ptrack public API works
3+
# as expected. Data integrity after incremental backups taken via ptrack
4+
# is tested on the pg_probackup side.
5+
#
6+
7+
use strict;
8+
use warnings;
9+
use PostgresNode;
10+
use TestLib;
11+
use Test::More;
12+
13+
plan tests => 23;
14+
15+
my $node;
16+
my $res;
17+
my $res_stdout;
18+
my $res_stderr;
19+
20+
# Initialize node
21+
$node = get_new_node('node');
22+
$node->init;
23+
$node->start;
24+
25+
# Could not load ptrack module after postmaster start
26+
($res, $res_stdout, $res_stderr) = $node->psql("postgres", "CREATE EXTENSION ptrack");
27+
is($res, 3, 'errors out without shared_preload_libraries = \'ptrack\'');
28+
like(
29+
$res_stderr,
30+
qr/ptrack module must be initialized by Postmaster/,
31+
'errors out without shared_preload_libraries = \'ptrack\'');
32+
33+
# Load ptrack library
34+
$node->append_conf(
35+
'postgresql.conf', q{
36+
wal_level = 'minimal'
37+
shared_preload_libraries = 'ptrack'
38+
log_min_messages = debug1
39+
});
40+
$node->restart;
41+
42+
$node->safe_psql("postgres", "CREATE EXTENSION ptrack");
43+
44+
# Check some static functions
45+
$node->safe_psql("postgres", "SELECT ptrack_version()");
46+
47+
# Could not use ptrack if disabled
48+
($res, $res_stdout, $res_stderr) = $node->psql("postgres", "SELECT ptrack_get_pagemapset('0/0')");
49+
is($res, 3, 'errors out if ptrack is disabled');
50+
like(
51+
$res_stderr,
52+
qr/ptrack is disabled/,
53+
'errors out if ptrack is disabled');
54+
($res, $res_stdout, $res_stderr) = $node->psql("postgres", "SELECT ptrack_init_lsn()");
55+
is($res, 0, 'only warning if ptrack is disabled');
56+
like(
57+
$res_stdout,
58+
qr/0\/0/,
59+
'should print init LSN 0/0 if disabled');
60+
like(
61+
$res_stderr,
62+
qr/ptrack is disabled/,
63+
'warning if ptrack is disabled');
64+
65+
# Actually enable ptrack
66+
$node->append_conf(
67+
'postgresql.conf', q{
68+
ptrack.map_size = 13
69+
});
70+
$node->stop;
71+
$res = $node->start(fail_ok => 1);
72+
is($res, 0, 'could not start with wal_level = \'minimal\'');
73+
$node->append_conf(
74+
'postgresql.conf', q{
75+
wal_level = 'replica'
76+
});
77+
$node->start;
78+
79+
# Do checkpoint (test ptrack hook)
80+
$node->safe_psql("postgres", "CHECKPOINT");
81+
82+
# Remember pg_current_wal_flush_lsn() value
83+
my $flush_lsn = $node->safe_psql("postgres", "SELECT pg_current_wal_flush_lsn()");
84+
85+
# Remember ptrack init_lsn
86+
my $init_lsn = $node->safe_psql("postgres", "SELECT ptrack_init_lsn()");
87+
unlike(
88+
$init_lsn,
89+
qr/0\/0/,
90+
'ptrack init LSN should not be 0/0 after CHECKPOINT');
91+
92+
# Ptrack map should survive crash
93+
$node->stop('immediate');
94+
$node->start;
95+
$res_stdout = $node->safe_psql("postgres", "SELECT ptrack_init_lsn()");
96+
is($res_stdout, $init_lsn, 'ptrack init_lsn should be the same after crash recovery');
97+
98+
# Do some stuff, which hits ptrack
99+
$node->safe_psql("postgres", "CREATE DATABASE ptrack_test");
100+
$node->safe_psql("postgres", "CREATE TABLE ptrack_test AS SELECT i AS id FROM generate_series(0, 1000) i");
101+
102+
# Remember DB and relation oids
103+
my $db_oid = $node->safe_psql("postgres", "SELECT oid FROM pg_database WHERE datname = 'ptrack_test'");
104+
my $rel_oid = $node->safe_psql("postgres", "SELECT relfilenode FROM pg_class WHERE relname = 'ptrack_test'");
105+
106+
# Data should survive clean restart
107+
$node->restart;
108+
$res_stdout = $node->safe_psql("postgres", "SELECT ptrack_get_pagemapset('$flush_lsn')");
109+
like(
110+
$res_stdout,
111+
qr/base\/$db_oid/,
112+
'ptrack pagemapset should contain new database oid');
113+
like(
114+
$res_stdout,
115+
qr/$rel_oid/,
116+
'ptrack pagemapset should contain new relation oid');
117+
118+
# We should be able to change ptrack map size (but loose all changes)
119+
$node->append_conf(
120+
'postgresql.conf', q{
121+
ptrack.map_size = 14
122+
});
123+
$node->restart;
124+
125+
$node->safe_psql("postgres", "CHECKPOINT");
126+
$res_stdout = $node->safe_psql("postgres", "SELECT ptrack_init_lsn()");
127+
unlike(
128+
$res_stdout,
129+
qr/0\/0/,
130+
'ptrack init LSN should not be 0/0 after CHECKPOINT');
131+
ok($res_stdout ne $init_lsn, 'ptrack init_lsn should not be the same after map resize');
132+
$res_stdout = $node->safe_psql("postgres", "SELECT ptrack_get_pagemapset('$flush_lsn')");
133+
unlike(
134+
$res_stdout,
135+
qr/base\/$db_oid/,
136+
'we should loose changes after ptrack map resize');
137+
138+
# We should be able to turn off ptrack and clean up all files by stting ptrack.map_size = 0
139+
$node->append_conf(
140+
'postgresql.conf', q{
141+
ptrack.map_size = 0
142+
});
143+
$node->restart;
144+
145+
# Check that we have lost everything
146+
ok(! -f $node->data_dir . "/global/ptrack.map", "ptrack.map should be cleaned up");
147+
ok(! -f $node->data_dir . "/global/ptrack.map.tmp", "ptrack.map.tmp should be cleaned up");
148+
ok(! -f $node->data_dir . "/global/ptrack.map.mmap", "ptrack.map.mmap should be cleaned up");
149+
150+
($res, $res_stdout, $res_stderr) = $node->psql("postgres", "SELECT ptrack_get_pagemapset('0/0')");
151+
is($res, 3, 'errors out if ptrack is disabled');
152+
like(
153+
$res_stderr,
154+
qr/ptrack is disabled/,
155+
'errors out if ptrack is disabled');
156+
($res, $res_stdout, $res_stderr) = $node->psql("postgres", "SELECT ptrack_init_lsn()");
157+
is($res, 0, 'only warning if ptrack is disabled');
158+
like(
159+
$res_stdout,
160+
qr/0\/0/,
161+
'should print init LSN 0/0 if disabled');
162+
like(
163+
$res_stderr,
164+
qr/ptrack is disabled/,
165+
'warning if ptrack is disabled');
166+
167+
$node->stop;
168+
169+
done_testing;

0 commit comments

Comments
 (0)