File tree Expand file tree Collapse file tree 4 files changed +47
-2
lines changed
Expand file tree Collapse file tree 4 files changed +47
-2
lines changed Original file line number Diff line number Diff 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+
462482sub 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
10981118Change 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
11021128The current Parameters of Bugzilla, as a hashref.
Original file line number Diff line number Diff 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+
185199sub _connect {
186200 my ($params ) = @_ ;
187201
Original file line number Diff line number Diff 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
110115sub _read_localconfig_from_env {
Original file line number Diff line number Diff line change 6868# Check to make sure another instance is not currently running
6969check_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
7474my $ua = LWP::UserAgent::Determined-> new(
7575 agent => ' Bugzilla' ,
You can’t perform that action at this time.
0 commit comments