Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0e42397

Browse files
committed
Fix pg_rewind when pg_xlog is a symlink.
pg_xlog is often a symlink, typically to a different filesystem. Don'tget confused and comlain about by that, and just always pretend that it's anormal directory, even if it's really a symlink.Also add a test case for this.Backpatch to 9.5.
1 parent69b7a35 commit0e42397

File tree

6 files changed

+107
-5
lines changed

6 files changed

+107
-5
lines changed

‎src/bin/pg_rewind/RewindTest.pm

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@ package RewindTest;
1313
#
1414
# 2. setup_cluster - creates a PostgreSQL cluster that runs as the master
1515
#
16-
# 3. create_standby - runs pg_basebackup to initialize a standby server, and
16+
# 3. start_master - starts the master server
17+
#
18+
# 4. create_standby - runs pg_basebackup to initialize a standby server, and
1719
# sets it up to follow the master.
1820
#
19-
#4. promote_standby - runs "pg_ctl promote" to promote the standby server.
21+
#5. promote_standby - runs "pg_ctl promote" to promote the standby server.
2022
# The old master keeps running.
2123
#
22-
#5. run_pg_rewind - stops the old master (if it's still running) and runs
24+
#6. run_pg_rewind - stops the old master (if it's still running) and runs
2325
# pg_rewind to synchronize it with the now-promoted standby server.
2426
#
25-
#6. clean_rewind_test - stops both servers used in the test, if they're
27+
#7. clean_rewind_test - stops both servers used in the test, if they're
2628
# still running.
2729
#
2830
# The test script can use the helper functions master_psql and standby_psql
@@ -56,6 +58,7 @@ our @EXPORT = qw(
5658
5759
init_rewind_test
5860
setup_cluster
61+
start_master
5962
create_standby
6063
promote_standby
6164
run_pg_rewind
@@ -182,7 +185,10 @@ max_connections = 10
182185

183186
# Accept replication connections on master
184187
configure_hba_for_replication$test_master_datadir;
188+
}
185189

190+
substart_master
191+
{
186192
system_or_bail('pg_ctl' ,'-w',
187193
'-D' ,$test_master_datadir,
188194
'-l',"$log_path/master.log",

‎src/bin/pg_rewind/filemap.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ process_source_file(const char *path, file_type_t type, size_t newsize,
7878
strcmp(path,"postmaster.opts")==0)
7979
return;
8080

81+
/*
82+
* Pretend that pg_xlog is a directory, even if it's really a symlink.
83+
* We don't want to mess with the symlink itself, nor complain if it's a
84+
* symlink in source but not in target or vice versa.
85+
*/
86+
if (strcmp(path,"pg_xlog")==0&&type==FILE_TYPE_SYMLINK)
87+
type=FILE_TYPE_DIRECTORY;
88+
8189
/*
8290
* Skip temporary files, .../pgsql_tmp/... and .../pgsql_tmp.* in source.
8391
* This has the effect that all temporary files in the destination will be
@@ -112,7 +120,7 @@ process_source_file(const char *path, file_type_t type, size_t newsize,
112120
switch (type)
113121
{
114122
caseFILE_TYPE_DIRECTORY:
115-
if (exists&& !S_ISDIR(statbuf.st_mode))
123+
if (exists&& !S_ISDIR(statbuf.st_mode)&&strcmp(path,"pg_xlog")!=0)
116124
{
117125
/* it's a directory in source, but not in target. Strange.. */
118126
pg_fatal("\"%s\" is not a directory\n",localpath);
@@ -285,6 +293,12 @@ process_target_file(const char *path, file_type_t type, size_t oldsize,
285293
strcmp(path,"postmaster.opts")==0)
286294
return;
287295

296+
/*
297+
* Like in process_source_file, pretend that xlog is always a directory.
298+
*/
299+
if (strcmp(path,"pg_xlog")==0&&type==FILE_TYPE_SYMLINK)
300+
type=FILE_TYPE_DIRECTORY;
301+
288302
key.path= (char*)path;
289303
key_ptr=&key;
290304
exists= (bsearch(&key_ptr,map->array,map->narray,sizeof(file_entry_t*),

‎src/bin/pg_rewind/t/001_basic.pl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ sub run_test
1010
my$test_mode =shift;
1111

1212
RewindTest::setup_cluster();
13+
RewindTest::start_master();
1314

1415
# Create a test table and insert a row in master.
1516
master_psql("CREATE TABLE tbl1 (d text)");

‎src/bin/pg_rewind/t/002_databases.pl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ sub run_test
1010
my$test_mode =shift;
1111

1212
RewindTest::setup_cluster();
13+
RewindTest::start_master();
1314

1415
# Create a database in master.
1516
master_psql('CREATE DATABASE inmaster');

‎src/bin/pg_rewind/t/003_extrafiles.pl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ sub run_test
1515
my$test_mode =shift;
1616

1717
RewindTest::setup_cluster();
18+
RewindTest::start_master();
1819

1920
my$test_master_datadir =$RewindTest::test_master_datadir;
2021

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#
2+
# Test pg_rewind when the target's pg_xlog directory is a symlink.
3+
#
4+
use strict;
5+
use warnings;
6+
use File::Copy;
7+
use File::Pathqw(remove_tree);
8+
use TestLib;
9+
use Test::More;
10+
if ($windows_os)
11+
{
12+
planskip_all=>'symlinks not supported on Windows';
13+
exit;
14+
}
15+
else
16+
{
17+
plantests=> 4;
18+
}
19+
20+
use RewindTest;
21+
22+
subrun_test
23+
{
24+
my$test_mode =shift;
25+
26+
my$master_xlogdir ="$tmp_check/xlog_master";
27+
28+
remove_tree($master_xlogdir);
29+
RewindTest::setup_cluster();
30+
31+
# turn pg_xlog into a symlink
32+
print("moving$test_master_datadir/pg_xlog to$master_xlogdir\n");
33+
move("$test_master_datadir/pg_xlog",$master_xlogdir)ordie;
34+
symlink($master_xlogdir,"$test_master_datadir/pg_xlog")ordie;
35+
36+
RewindTest::start_master();
37+
38+
# Create a test table and insert a row in master.
39+
master_psql("CREATE TABLE tbl1 (d text)");
40+
master_psql("INSERT INTO tbl1 VALUES ('in master')");
41+
42+
master_psql("CHECKPOINT");
43+
44+
RewindTest::create_standby();
45+
46+
# Insert additional data on master that will be replicated to standby
47+
master_psql("INSERT INTO tbl1 values ('in master, before promotion')");
48+
49+
master_psql('CHECKPOINT');
50+
51+
RewindTest::promote_standby();
52+
53+
# Insert a row in the old master. This causes the master and standby
54+
# to have "diverged", it's no longer possible to just apply the
55+
# standy's logs over master directory - you need to rewind.
56+
master_psql("INSERT INTO tbl1 VALUES ('in master, after promotion')");
57+
58+
# Also insert a new row in the standby, which won't be present in the
59+
# old master.
60+
standby_psql("INSERT INTO tbl1 VALUES ('in standby, after promotion')");
61+
62+
RewindTest::run_pg_rewind($test_mode);
63+
64+
check_query(
65+
'SELECT * FROM tbl1',
66+
qq(in master
67+
in master, before promotion
68+
in standby, after promotion
69+
),
70+
'table content');
71+
72+
RewindTest::clean_rewind_test();
73+
}
74+
75+
# Run the test in both modes
76+
run_test('local');
77+
run_test('remote');
78+
79+
exit(0);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp