@@ -442,6 +442,8 @@ sub should_use_specific_version
442442}
443443
444444my $n1OldVersionBinDir = " " ;
445+ my @n1OldExtensionFiles = ();
446+ my $n1ExtensionBackupDir = catfile($TMP_CHECKDIR , " n1_extension_backup_current" );
445447
446448# Prepare an isolated PostgreSQL installation directory for N-1 nodes and
447449# set the bindir used by those nodes.
@@ -476,9 +478,6 @@ sub prepare_n1_isolated_pg_home_dir
476478
477479 my $oldPkglibdir = ` $n1OldVersionBinDir /pg_config --pkglibdir` ;
478480 chomp $oldPkglibdir ;
479- my $oldSharedir = ` $n1OldVersionBinDir /pg_config --sharedir` ;
480- chomp $oldSharedir ;
481-
482481 # accept both .../lib and parent layouts for CITUSLIBDIR
483482 my @libSearchDirs = ($citusLibdir , catfile($citusLibdir , " lib" ));
484483 my @libFiles = ();
@@ -510,15 +509,62 @@ sub prepare_n1_isolated_pg_home_dir
510509
511510 if (@extensionFiles )
512511 {
513- system (" cp" , (" -f" , @extensionFiles , catfile($oldSharedir , " extension" ))) == 0
514- or die " Could not copy Citus extension files into " . catfile($oldSharedir , " extension" );
512+ @n1OldExtensionFiles = @extensionFiles ;
515513 }
516514 else
517515 {
518516 die " Could not find Citus extension files anywhere under $citusLibdir " ;
519517 }
520518}
521519
520+ sub backup_current_extension_files_for_n1
521+ {
522+ my $currentSharedir = ` $pgConfig --sharedir` ;
523+ chomp $currentSharedir ;
524+ my $currentExtensionDir = catfile($currentSharedir , " extension" );
525+
526+ my @currentFiles = glob (catfile($currentExtensionDir , " citus*" ));
527+ return unless @currentFiles ;
528+
529+ if (-e $n1ExtensionBackupDir )
530+ {
531+ remove_tree($n1ExtensionBackupDir ) or die " Could not remove extension backup dir $n1ExtensionBackupDir " ;
532+ }
533+
534+ make_path($n1ExtensionBackupDir ) or die " Could not create extension backup dir $n1ExtensionBackupDir " ;
535+ system (" cp" , (" -f" , @currentFiles , $n1ExtensionBackupDir )) == 0
536+ or die " Could not backup current Citus extension files into $n1ExtensionBackupDir " ;
537+ }
538+
539+ sub apply_old_extension_files_for_n1
540+ {
541+ return unless @n1OldExtensionFiles ;
542+
543+ backup_current_extension_files_for_n1();
544+
545+ my $currentSharedir = ` $pgConfig --sharedir` ;
546+ chomp $currentSharedir ;
547+ my $currentExtensionDir = catfile($currentSharedir , " extension" );
548+
549+ system (" cp" , (" -f" , @n1OldExtensionFiles , $currentExtensionDir )) == 0
550+ or die " Could not copy Citus extension files into $currentExtensionDir " ;
551+ }
552+
553+ sub restore_current_extension_files_after_n1
554+ {
555+ return unless -d $n1ExtensionBackupDir ;
556+
557+ my @backupFiles = glob (catfile($n1ExtensionBackupDir , " citus*" ));
558+ return unless @backupFiles ;
559+
560+ my $currentSharedir = ` $pgConfig --sharedir` ;
561+ chomp $currentSharedir ;
562+ my $currentExtensionDir = catfile($currentSharedir , " extension" );
563+
564+ system (" cp" , (" -f" , @backupFiles , $currentExtensionDir )) == 0
565+ or die " Could not restore current Citus extension files into $currentExtensionDir " ;
566+ }
567+
522568sub node_bindir
523569{
524570 my ($nodeType , $workerIndex ) = @_ ;
9881034{
9891035 my $saved_status = $? ;
9901036
1037+ restore_current_extension_files_after_n1();
9911038 restore_original(catfile($psqlLibdir , " citus.so" )) if defined $psqlLibdir ;
9921039
9931040 if (!$conninfo && $serversAreShutdown eq " FALSE" )
@@ -1245,6 +1292,15 @@ END
12451292 ($firstLib =~ m / ^citus$ / )
12461293 or die " Could not find citus as first library in shared_preload_libraries on worker $port ." ;
12471294
1295+ if (should_use_alternative_libdir(" worker" , $workeroff ))
1296+ {
1297+ apply_old_extension_files_for_n1();
1298+ }
1299+ else
1300+ {
1301+ restore_current_extension_files_after_n1();
1302+ }
1303+
12481304 for my $extension (@extensions )
12491305 {
12501306 if ($extension eq " citus" && should_use_specific_version(" worker" , $workeroff ))
@@ -1279,6 +1335,11 @@ END
12791335 or die " Could not create foreign data wrapper $fdw on worker port $port " ;
12801336 }
12811337 }
1338+
1339+ if (!should_use_alternative_libdir(" coordinator" ))
1340+ {
1341+ restore_current_extension_files_after_n1();
1342+ }
12821343}
12831344else
12841345{
@@ -1335,9 +1396,26 @@ END
13351396# explicit VERSION.
13361397if (!$conninfo && should_use_specific_version(" coordinator" ))
13371398{
1399+ if (should_use_alternative_libdir(" coordinator" ))
1400+ {
1401+ apply_old_extension_files_for_n1();
1402+ }
1403+
13381404 create_coordinator_database_and_extensions();
1405+
1406+ if (should_use_alternative_libdir(" coordinator" ))
1407+ {
1408+ restore_current_extension_files_after_n1();
1409+ }
1410+
13391411 push (@arguments , " --use-existing" );
13401412}
1413+ elsif (!$conninfo && should_use_alternative_libdir(" coordinator" ))
1414+ {
1415+ # pg_regress will create coordinator extension; ensure it sees old control/sql
1416+ # files while coordinator is running old Citus library.
1417+ apply_old_extension_files_for_n1();
1418+ }
13411419
13421420my $startTime = time ();
13431421
0 commit comments