Skip to content

Commit 9bdbaac

Browse files
committed
Bug 1986964 - Add new localconfig variables for the new dedicated replica to be used by the ETL cron job and possibly others
1 parent 4583179 commit 9bdbaac

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

Bugzilla.pm

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,26 @@ sub dbh_main {
459459
return request_cache->{dbh_main} ||= Bugzilla::DB::connect_main();
460460
}
461461

462+
sub switch_to_replica1_db {
463+
my $class = shift;
464+
465+
if (!request_cache->{dbh_replica1}) {
466+
if ($class->localconfig->db_replica1_name) {
467+
request_cache->{dbh_replica1} = Bugzilla::DB::connect_replica1();
468+
}
469+
elsif ($class->get_param_with_override('shadowdb')) {
470+
request_cache->{dbh_replica1} = Bugzilla::DB::connect_shadow();
471+
}
472+
else {
473+
request_cache->{dbh_replica1} = $class->dbh_main;
474+
}
475+
}
476+
477+
request_cache->{dbh} = request_cache->{dbh_replica1};
478+
479+
return $class->dbh;
480+
}
481+
462482
sub languages {
463483
return Bugzilla::Install::Util::supported_languages();
464484
}
@@ -1097,6 +1117,12 @@ Switch from using the main database to using the shadow database.
10971117
10981118
Change the database object to refer to the main database.
10991119
1120+
=item C<switch_to_replica1_db>
1121+
1122+
Switch from using the main database to using the replica1 database. This
1123+
will fall back to the shadow database, if one is configured, or the main
1124+
database as a last resort.
1125+
11001126
=item C<params>
11011127
11021128
The current Parameters of Bugzilla, as a hashref.

Bugzilla/DB.pm

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,20 @@ sub connect_main {
182182
return $main_dbh;
183183
}
184184

185+
sub connect_replica1 {
186+
state $replica1_dbh;
187+
return $replica1_dbh if $replica1_dbh;
188+
189+
my $connect_params = dclone(Bugzilla->localconfig);
190+
$connect_params->{db_host} = $connect_params->{db_replica1_host};
191+
$connect_params->{db_name} = $connect_params->{db_replica1_name};
192+
$connect_params->{db_user} = $connect_params->{db_replica1_user};
193+
$connect_params->{db_pass} = $connect_params->{db_replica1_pass};
194+
$connect_params->{db_port} = $connect_params->{db_replica1_port};
195+
196+
return $replica1_dbh = _connect($connect_params);
197+
}
198+
185199
sub _connect {
186200
my ($params) = @_;
187201

Bugzilla/Install/Localconfig.pm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ use constant LOCALCONFIG_VARS => (
105105
{name => 'shadowdb_pass', default => '',},
106106
{name => 'datadog_host', default => '',},
107107
{name => 'datadog_port', default => 8125,},
108+
{name => 'db_replica1_host', default => '',},
109+
{name => 'db_replica1_name', default => '',},
110+
{name => 'db_replica1_user', default => '',},
111+
{name => 'db_replica1_pass', default => '',},
112+
{name => 'db_replica1_port', default => 0,},
108113
);
109114

110115
sub _read_localconfig_from_env {

extensions/BMO/bin/export_bmo_etl.pl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@
6868
# Check to make sure another instance is not currently running
6969
check_and_set_lock();
7070

71-
# Use replica if available
72-
my $dbh = Bugzilla->switch_to_shadow_db();
71+
# Use dedicated replica1
72+
my $dbh = Bugzilla->switch_to_replica1_db;
7373

7474
my $ua = LWP::UserAgent::Determined->new(
7575
agent => 'Bugzilla',

0 commit comments

Comments
 (0)