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

Commit 37f1e1b

Browse files
committed
Merge branch 'PGPROEE10_test_xid-64' into PGPROEE10
2 parents 2e7f99d + 79d3a33 commit 37f1e1b

File tree

6 files changed

+233
-1
lines changed

6 files changed

+233
-1
lines changed

src/test/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ subdir = src/test
1212
top_builddir = ../..
1313
include $(top_builddir)/src/Makefile.global
1414

15-
SUBDIRS = perl regress isolation modules authentication recovery subscription default_collation
15+
SUBDIRS = perl regress isolation modules authentication recovery subscription default_collation xid-64
1616

1717
# We don't build or execute examples/, locale/, or thread/ by default,
1818
# but we do want "make clean" etc to recurse into them. Likewise for ssl/,

src/test/xid-64/Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#-------------------------------------------------------------------------
2+
#
3+
# Makefile for src/test/xid-64
4+
#
5+
# Copyright (c) 2018, Postgres Professional
6+
#
7+
# src/test/xid-64/Makefile
8+
#
9+
#-------------------------------------------------------------------------
10+
11+
subdir = src/test/xid-64
12+
top_builddir = ../../..
13+
include $(top_builddir)/src/Makefile.global
14+
15+
check:
16+
$(prove_check)
17+
18+
clean distclean maintainer-clean:
19+
rm -rf tmp_check

src/test/xid-64/README

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
src/test/xid-64/README
2+
3+
Regression tests for 64-bit XIDs
4+
=============================================
5+
6+
This directory contains a test suite for 64-bit xids.
7+
8+
Running the tests
9+
=================
10+
11+
make check
12+
13+
NOTE: This creates a temporary installation, and some tests may
14+
create one or multiple nodes.
15+
16+
NOTE: This requires the --enable-tap-tests argument to configure.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Tests for large xid values
2+
use strict;
3+
use warnings;
4+
use PostgresNode;
5+
use TestLib;
6+
use Test::More tests => 9;
7+
8+
use bigint;
9+
10+
sub command_output
11+
{
12+
my ($cmd) = @_;
13+
my ($stdout, $stderr);
14+
print("# Running: " . join(" ", @{$cmd}) . "\n");
15+
my $result = IPC::Run::run $cmd, '>', \$stdout, '2>', \$stderr;
16+
ok($result, "@$cmd exit code 0");
17+
is($stderr, '', "@$cmd no stderr");
18+
return $stdout;
19+
}
20+
21+
my $START_VAL = 2**32;
22+
my $MAX_VAL = 2**62;
23+
24+
my $ixid = $START_VAL + rand($MAX_VAL - $START_VAL);
25+
my $imxid = $START_VAL + rand($MAX_VAL - $START_VAL);
26+
my $imoff = $START_VAL + rand($MAX_VAL - $START_VAL);
27+
28+
# Initialize master node with the random xid-related parameters
29+
my $node = get_new_node('master');
30+
$node->init(extra => [ "--xid=$ixid", "--multixact-id=$imxid", "--multixact-offset=$imoff" ]);
31+
$node->start;
32+
33+
# Initialize master node and check the xid-related parameters
34+
my $pgcd_output = command_output(
35+
[ 'pg_controldata', '-D', $node->data_dir ] );
36+
print($pgcd_output); print('\n');
37+
ok($pgcd_output =~ qr/Latest checkpoint's NextXID:\s*(\d+)/, "XID found");
38+
my ($nextxid) = ($1);
39+
ok($nextxid >= $ixid && $nextxid < $ixid + 1000,
40+
"Latest checkpoint's NextXID ($nextxid) is close to the initial xid ($ixid).");
41+
ok($pgcd_output =~ qr/Latest checkpoint's NextMultiXactId:\s*(\d+)/, "MultiXactId found");
42+
my ($nextmxid) = ($1);
43+
ok($nextmxid >= $imxid && $nextmxid < $imxid + 1000,
44+
"Latest checkpoint's NextMultiXactId ($nextmxid) is close to the initial multiXactId ($imxid).");
45+
ok($pgcd_output =~ qr/Latest checkpoint's NextMultiOffset:\s*(\d+)/, "MultiOffset found");
46+
my ($nextmoff) = ($1);
47+
ok($nextmoff >= $imoff && $nextmoff < $imoff + 1000,
48+
"Latest checkpoint's NextMultiOffset ($nextmoff) is close to the initial multiOffset ($imoff).");
49+
50+
# Run pgbench to check whether the database is working properly
51+
$node->command_ok(
52+
[ qw(pgbench --initialize --no-vacuum --scale=10) ],
53+
'pgbench finished without errors');

src/test/xid-64/t/002_test_gucs.pl

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Tests for guc boundary values
2+
use strict;
3+
use warnings;
4+
use PostgresNode;
5+
use TestLib;
6+
use Test::More tests => 19;
7+
8+
use bigint;
9+
10+
sub command_output
11+
{
12+
my ($cmd) = @_;
13+
my ($stdout, $stderr);
14+
print("# Running: " . join(" ", @{$cmd}) . "\n");
15+
my $result = IPC::Run::run $cmd, '>', \$stdout, '2>', \$stderr;
16+
ok($result, "@$cmd exit code 0");
17+
is($stderr, '', "@$cmd no stderr");
18+
return $stdout;
19+
}
20+
21+
sub set_guc
22+
{
23+
my ($node, $guc, $val) = @_;
24+
print("SET $guc = $val\n");
25+
$node->safe_psql('postgres', "ALTER SYSTEM SET $guc = $val");
26+
$node->restart();
27+
}
28+
29+
sub test_pgbench
30+
{
31+
my ($node) = @_;
32+
$node->command_ok(
33+
[ qw(pgbench --progress=5 --transactions=1000 --jobs=5 --client=5) ],
34+
'pgbench finished without errors');
35+
}
36+
37+
my @guc_vals = (
38+
[ "autovacuum_freeze_max_age", 100000, 2**63 - 1 ],
39+
[ "autovacuum_multixact_freeze_max_age", 10000, 2**63 - 1 ],
40+
[ "vacuum_freeze_min_age", 0, 2**63 - 1 ],
41+
[ "vacuum_freeze_table_age", 0, 2**63 - 1 ],
42+
[ "vacuum_multixact_freeze_min_age", 0, 2**63 - 1 ],
43+
[ "vacuum_multixact_freeze_table_age", 0, 2**63 -1 ]
44+
);
45+
46+
my $START_VAL = 2**32;
47+
my $MAX_VAL = 2**62;
48+
49+
my $ixid = $START_VAL + rand($MAX_VAL - $START_VAL);
50+
my $imxid = $START_VAL + rand($MAX_VAL - $START_VAL);
51+
my $imoff = $START_VAL + rand($MAX_VAL - $START_VAL);
52+
53+
# Initialize master node
54+
my $node = get_new_node('master');
55+
$node->init(extra => [ "--xid=$ixid", "--multixact-id=$imxid", "--multixact-offset=$imoff" ]);
56+
$node->start;
57+
58+
# Fill the test database with the pgbench data
59+
$node->command_ok(
60+
[ qw(pgbench --initialize --scale=10) ],
61+
'pgbench finished without errors');
62+
63+
# Test all GUCs with minimum, maximum and random value inbetween
64+
# (run pgbench for every configuration setting)
65+
foreach my $gi (0 .. $#guc_vals) {
66+
print($guc_vals[$gi][0]); print("\n");
67+
my $guc = $guc_vals[$gi][0];
68+
my $minval = $guc_vals[$gi][1];
69+
my $maxval = $guc_vals[$gi][2];
70+
set_guc($node, $guc, $minval);
71+
test_pgbench($node);
72+
set_guc($node, $guc, $maxval);
73+
test_pgbench($node);
74+
set_guc($node, $guc, $minval + rand($maxval - $minval));
75+
test_pgbench($node);
76+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Tests for checking integrity
2+
use strict;
3+
use warnings;
4+
use PostgresNode;
5+
use TestLib;
6+
use Test::More tests => 5;
7+
use File::Compare;
8+
9+
my $tempdir = TestLib::tempdir;
10+
use bigint;
11+
12+
sub command_output
13+
{
14+
my ($cmd) = @_;
15+
my ($stdout, $stderr);
16+
print("# Running: " . join(" ", @{$cmd}) . "\n");
17+
my $exit;
18+
my $result = IPC::Run::run $cmd, '>', \$stdout, '2>', \$stderr;
19+
print("exit code: $?\n\n");
20+
ok($result, "@$cmd exit code 0");
21+
is($stderr, '', "@$cmd no stderr");
22+
return $stdout;
23+
}
24+
25+
my $START_VAL = 2**32;
26+
my $MAX_VAL = 2**62;
27+
28+
my $ixid = $START_VAL + rand($MAX_VAL - $START_VAL);
29+
my $imxid = $START_VAL + rand($MAX_VAL - $START_VAL);
30+
my $imoff = $START_VAL + rand($MAX_VAL - $START_VAL);
31+
32+
# Initialize master node
33+
my $node = get_new_node('master');
34+
$node->init();
35+
$node->start;
36+
37+
# Create a database and fill it with pgbench data
38+
$node->safe_psql('postgres', "CREATE DATABASE pgbench_db");
39+
$node->command_ok(
40+
[ qw(pgbench --initialize --scale=2 pgbench_db) ],
41+
'pgbench finished without errors');
42+
# Dump the database and stop the server
43+
$node->command_ok(
44+
[ "pg_dump", "-w", "--inserts", "--file=$tempdir/pgbench.sql", "pgbench_db" ],
45+
'pgdump finished without errors');
46+
$node->stop('fast');
47+
48+
# Initialize second node
49+
my $node2 = get_new_node('master2');
50+
$node2->init(extra => [ "--xid=$ixid", "--multixact-id=$imxid", "--multixact-offset=$imoff" ]);
51+
$node2->start;
52+
53+
# Create a database and restore the previous dump
54+
$node2->safe_psql('postgres', "CREATE DATABASE pgbench_db");
55+
my $txid0 = $node2->safe_psql('pgbench_db', 'SELECT txid_current()');
56+
print("# Initial txid_current: $txid0\n");
57+
$node2->command_ok(["psql", "-q", "-f", "$tempdir/pgbench.sql", "pgbench_db"]);
58+
59+
# Get current txid and compare it with the initial one
60+
my $txid1 = $node2->safe_psql('pgbench_db', 'SELECT txid_current()');
61+
print("# Final txid_current: $txid1\n");
62+
print("# Number of transactions: " . ($txid1 - $txid0) . "\n");
63+
64+
# Dump the database and compare the dumped content with the previous
65+
$node2->command_ok(
66+
[ "pg_dump", "-w", "--inserts", "--file=$tempdir/pgbench2.sql", "pgbench_db" ],
67+
'pgdump finished without errors');
68+
ok(File::Compare::compare_text("$tempdir/pgbench.sql", "$tempdir/pgbench2.sql") == 0, "no differences detected");

0 commit comments

Comments
 (0)