/
TestUpgradeXversion.pm
351 lines (251 loc) · 9.61 KB
/
TestUpgradeXversion.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
# Package Namespace is hardcoded. Modules must live in
# PGBuild::Modules
# NB: use of this module involves substantial persistent use of disk space.
# Don't even think about it unless you have a couple og GB extra (at least)
# you can devote to this module's storage.
# For now, only tests C locale upgrades.
package PGBuild::Modules::TestUpgradeXversion;
use PGBuild::Options;
use PGBuild::SCM;
use Data::Dumper;
use File::Copy;
use File::Path;
use File::Basename;
use strict;
use vars qw($VERSION); $VERSION = 'REL_4.7';
my $hooks = {
# 'checkout' => \&checkout,
# 'setup-target' => \&setup_target,
'need-run' => \&need_run,
# 'configure' => \&configure,
# 'build' => \&build,
'installcheck' => \&installcheck,
# 'check' => \&check,
# 'cleanup' => \&cleanup,
};
sub setup
{
my $class = __PACKAGE__;
my $buildroot = shift; # where we're building
my $branch = shift; # The branch of Postgres that's being built.
my $conf = shift; # ref to the whole config object
my $pgsql = shift; # postgres build dir
return unless ($branch eq 'HEAD' or $branch ge 'REL9_0');
my $upgrade_install_root = $conf->{upgrade_install_root};
die "No upgrade_install_root" unless $upgrade_install_root;
# could even set up several of these (e.g. for different branches)
my $self = {
buildroot => $buildroot,
pgbranch=> $branch,
bfconf => $conf,
pgsql => $pgsql,
upgrade_install_root => $upgrade_install_root,
};
bless($self, $class);
# for each instance you create, do:
main::register_module_hooks($self,$hooks);
}
sub need_run
{
my $self = shift;
my $need_run_ref = shift;
my $upgrade_install_root = $self->{upgrade_install_root};
my $upgrade_loc = "$upgrade_install_root/$self->{pgbranch}";
$$need_run_ref = 1 unless -d $upgrade_loc;
}
sub setinstenv
{
my $self = shift;
my $installdir = shift;
my $save_env = shift || {};
# first restore environment from what was saved
if (exists $save_env->{LD_LIBRARY_PATH})
{
$ENV{LD_LIBRARY_PATH} = $save_env->{LD_LIBRARY_PATH};
}
else
{
delete $ENV{LD_LIBRARY_PATH};
}
if (exists $save_env->{DYLD_LIBRARY_PATH})
{
$ENV{DYLD_LIBRARY_PATH} = $save_env->{DYLD_LIBRARY_PATH};
}
else
{
delete $ENV{DYLD_LIBRARY_PATH};
}
if (exists $save_env->{PATH})
{
$ENV{PATH} = $save_env->{PATH};
}
# now adjust it to point to new dir
if (my $ldpath = $ENV{LD_LIBRARY_PATH})
{
$ENV{LD_LIBRARY_PATH}="$installdir/lib:$ldpath";
}
else
{
$ENV{LD_LIBRARY_PATH}="$installdir/lib";
}
if (my $ldpath = $ENV{DYLD_LIBRARY_PATH})
{
$ENV{DYLD_LIBRARY_PATH}="$installdir/lib:$ldpath";
}
else
{
$ENV{DYLD_LIBRARY_PATH}="$installdir/lib";
}
if ($self->{pgconf}->{using_msvc})
{
$ENV{PATH} = "$installdir/bin;$ENV{PATH}";
}
else
{
$ENV{PATH} = "$installdir/bin:$ENV{PATH}";
}
}
sub installcheck
{
# this is called after base installcheck has run, which in turn
# is after both base install and base contrib install have run,
# so we have everything we should need.
my $self = shift;
my $locale = shift;
return unless $locale eq 'C';
return unless main::step_wanted('pg_upgrade-xversion-check');
# localize any environment changes so they don't leak to calling code.
my $save_env = eval Dumper(\%ENV);
local %ENV = %ENV;
print main::time_str(), "saving files for cross-version upgrade check\n" if $verbose;
my $upgrade_install_root = $self->{upgrade_install_root};
my $install_loc = "$self->{buildroot}/$self->{pgbranch}/inst";
my $upgrade_loc = "$upgrade_install_root/$self->{pgbranch}";
my $installdir = "$upgrade_loc/inst";
main::stop_db($locale);
mkdir $upgrade_install_root unless -d $upgrade_install_root;
rmtree($upgrade_loc);
mkdir $upgrade_loc;
system (qq{cp -r "$install_loc" "$installdir" >"$upgrade_loc/save.log" 2>&1});
# keep a copy of installed database
# not needed for HEAD since there is no later version
# to test it against, but we still need to move the regression
# libraries.
setinstenv($self, $installdir, $save_env);
# start the server
system("$installdir/bin/pg_ctl -D $installdir/data-C -o '-F' -l '$upgrade_loc/db.log' -w start >'$upgrade_loc/ctl.log' 2>&1");
# remove function that uses a setting that disappeared in 9.0
if ($self->{pgbranch} lt 'REL9_0')
{
my $sql = 'drop function myfunc(integer)';
system("$installdir/bin/psql -A -t -c '$sql' regression > '$upgrade_loc/fix.log' 2>&1");
}
# fix the regression database so its functions point to $libdir rather than
# the source directory, which won't persist past this build.
my $sql = 'select probin::text from pg_proc where probin not like $$$libdir%$$';
my @regresslibs = `psql -A -t -c '$sql' regression`;
chomp @regresslibs;
my %regresslibs = map { $_ => 1 } @regresslibs;
foreach my $lib (keys %regresslibs)
{
my $dest = "$installdir/lib/postgresql/" . basename($lib);
copy($lib,$dest);
die "cannot find $dest (from $lib)" unless -e $dest;
chmod 0755, $dest;
}
if ($self->{pgbranch} ne 'HEAD')
{
if ($self->{pgbranch} lt 'REL9_1')
{
$sql = 'set bytea_output to escape; update pg_proc set probin = regexp_replace(probin::text,$$.*/$$,$$$libdir/$$)::bytea where probin not like $$$libdir/%$$;';
}
else
{
$sql = 'update pg_proc set probin = regexp_replace(probin,$$.*/$$,$$$libdir/$$) where probin not like $$$libdir/%$$;';
}
system("$installdir/bin/psql -A -t -c '$sql' regression >> '$upgrade_loc/fix.log' 2>&1");
}
system("pg_ctl -D $installdir/data-C -w stop >> '$upgrade_loc/ctl.log' 2>&1");
if ($self->{pgbranch} eq 'HEAD')
{
# not needed for HEAD
rmtree("$installdir/data-C");
}
# ok, we now have the persistent copy of pre-HEAD branches we can use to test upgrading of
# plus the HEAD binaries
# 9.1 is the earliest branch we test upgrading to
if ($self->{pgbranch} lt 'REL9_1' && $self->{pgbranch} ne 'HEAD')
{
main::start_db($locale);
return;
}
my $dconfig = `$installdir/bin/pg_config --configure`;
my $dport = $dconfig =~ /--with-pgport=(\d+)/ ? $1 : 5432;
# %ENV = %$save_env;
foreach my $other_branch (glob("$upgrade_install_root/*"))
{
my $oversion = basename $other_branch;
next unless -d $other_branch;
next if $oversion eq $self->{pgbranch} || $oversion eq 'HEAD';
next unless (($self->{pgbranch} eq 'HEAD') || ($oversion lt $self->{pgbranch}));
print main::time_str(), "checking upgrade from $oversion to $self->{pgbranch} ...\n" if $verbose;
rmtree "$other_branch/inst/upgrade_test";
system qq{cp -r "$other_branch/inst/data-C" "$other_branch/inst/upgrade_test" > '$upgrade_loc/$oversion-copy.log' 2>&1};
setinstenv($self, "$other_branch/inst", $save_env);
my $sconfig = `$other_branch/inst/bin/pg_config --configure`;
my $sport = $sconfig =~ /--with-pgport=(\d+)/ ? $1 : 5432;
system("$other_branch/inst/bin/pg_ctl -D $other_branch/inst/upgrade_test -o '-F' -l $other_branch/inst/upgrade_log -w start >> '$upgrade_loc/ctl.log' 2>&1");
# use the NEW pg_dumpall so we're comparing apples with apples.
setinstenv($self, "$installdir", $save_env);
system("$installdir/bin/pg_dumpall -p $sport -f $upgrade_loc/origin-$oversion.sql >'$upgrade_loc/$oversion-dump1.log' 2>&1");
setinstenv($self, "$other_branch/inst", $save_env);
system("$other_branch/inst/bin/pg_ctl -D $other_branch/inst/upgrade_test -w stop >> '$upgrade_loc/ctl.log' 2>&1");
# %ENV = %$save_env;
setinstenv($self,$installdir, $save_env);
system("initdb -U buildfarm --locale=C $installdir/$oversion-upgrade > '$upgrade_loc/initdb.log' 2>&1");
system("cd $installdir && pg_upgrade --old-port=$sport --new-port=$dport --old-datadir=$other_branch/inst/upgrade_test --new-datadir=$installdir/$oversion-upgrade --old-bindir=$other_branch/inst/bin --new-bindir=$installdir/bin > '$upgrade_loc/upgrade.log' 2>&1" );
system("pg_ctl -D $installdir/$oversion-upgrade -l $installdir/upgrade_log -w start >> '$upgrade_loc/ctl.log' 2>&1");
system("cd $installdir && sh ./analyze_new_cluster.sh > '$upgrade_loc/$oversion-analyse.log' 2>&1 ") if -e "$installdir/analyze_new_cluster.sh";
system("pg_dumpall -f $upgrade_loc/converted-$oversion-to-$self->{pgbranch}.sql");
system("pg_ctl -D $installdir/$oversion-upgrade -w stop >> '$upgrade_loc/ctl.log'");
system("cd $installdir && sh ./delete_old_cluster.sh") if -e "$installdir/delete_old_cluster.sh";
=comment
[andrew@emma upgrade]$ find . -name dumpdiff* -print | xargs wc -l
11 ./HEAD/inst/dumpdiff-REL9_2_STABLE
11 ./HEAD/inst/dumpdiff-REL9_1_STABLE
125 ./HEAD/inst/dumpdiff-REL9_0_STABLE
0 ./REL9_2_STABLE/inst/dumpdiff-REL9_1_STABLE
116 ./REL9_2_STABLE/inst/dumpdiff-REL9_0_STABLE
116 ./REL9_1_STABLE/inst/dumpdiff-REL9_0_STABLE
=cut
#target source
my $expected_difflines = {
HEAD => {
REL9_0_STABLE => 125,
REL9_1_STABLE => 11,
REL9_2_STABLE => 11,
},
REL9_2_STABLE => {
REL9_1_STABLE => 0,
REL9_0_STABLE => 116,
},
REL9_1_STABLE => {
REL9_0_STABLE => 116,
}
};
system("diff -u $upgrade_loc/origin-$oversion.sql $upgrade_loc/converted-$oversion-to-$self->{pgbranch}.sql > $upgrade_loc/dumpdiff-$oversion 2>&1");
my $difflines = `wc -l < $upgrade_loc/dumpdiff-$oversion`;
my $expected = $expected_difflines->{$self->{pgbranch}}->{$oversion};
if ($difflines == $expected)
{
print "***SUCCESS!\n";
}
else
{
print "dumps $upgrade_loc/origin-$oversion.sql $upgrade_loc/converted-$oversion-to-$self->{pgbranch}.sql - expected $expected got $difflines of diff";
}
rmtree("$installdir/$oversion-upgrade");
}
main::start_db($locale);
}
1;