- add config options for using a read-only database in parallel
- use read-only database for major reporting queries (coverage, freeform search,daily/testday reports)
This commit is contained in:
ccooper%deadsquid.com 2007-08-28 18:38:41 +00:00
Родитель 84ca6926e5
Коммит ae6c859abe
11 изменённых файлов: 49 добавлений и 16 удалений

Просмотреть файл

@ -82,6 +82,19 @@ our %AUDIT_ACTIONS_TO_IGNORE = (
],
);
our $user_cookiename = "litmus_login";
our $sysconfig_cookiename = "litmustestingconfiguration";
our $sendmail_path = '/usr/sbin/sendmail';
our @nightly_report_recipients = ();
# We allow for a separate database that is optimized for read-only queries.
# These vars can be set in localconfig, but will default to the same values
# as for the regular database if not set.
our ($db_host, $db_port, $db_name, $db_user, $db_pass);
our ($db_host_ro, $db_port_ro, $db_name_ro, $db_user_ro, $db_pass_ro);
our $localconfig = litmus_locations()->{'localconfig'};
do $localconfig;
@ -93,5 +106,4 @@ our $disabled = 0;
# Set/unset this to display inline debugging value/code.
our $DEBUG = 0;
1;

Просмотреть файл

@ -123,7 +123,7 @@ sub coverage() {
if ($community_only) {
$sql .= " AND t.community_enabled=1";
}
my $dbh = $self->db_Main();
my $dbh = $self->db_ReadOnly();
my $sth = $dbh->prepare_cached($sql);
$sth->execute(
$self->{'subgroup_id'},

Просмотреть файл

@ -65,7 +65,7 @@ Litmus::DB::TestRun->set_sql('daterange' => qq {
sub getCriteria() {
my $self = shift;
my $dbh = __PACKAGE__->db_Main();
my $dbh = __PACKAGE__->db_ReadOnly();
my $sql = "SELECT trc.build_id, trc.platform_id, trc.opsys_id,
pl.name AS platform_name, o.name AS opsys_name
FROM test_run_criteria trc
@ -286,7 +286,7 @@ sub getTestRuns() {
$sql .= " LIMIT $limit";
}
my $dbh = __PACKAGE__->db_Main();
my $dbh = __PACKAGE__->db_ReadOnly();
my $sth = $dbh->prepare($sql);
$sth->execute();
my @test_run_ids;
@ -360,7 +360,7 @@ $sql .= " WHERE
$sql .= $self->getCriteriaSql();
my $dbh = __PACKAGE__->db_Main();
my $dbh = __PACKAGE__->db_ReadOnly();
my $sth = $dbh->prepare($sql);
$sth->execute($self->test_run_id);
my ($num_testcases_with_results) = $sth->fetchrow_array;
@ -425,7 +425,7 @@ $sql .= " WHERE
$sql .= $self->getCriteriaSql();
my $dbh = __PACKAGE__->db_Main();
my $dbh = __PACKAGE__->db_ReadOnly();
my $sth = $dbh->prepare($sql);
$sth->execute($self->test_run_id,$status_id);
my ($num_results) = $sth->fetchrow_array;
@ -482,7 +482,7 @@ $sql .= " WHERE
$sql .= $self->getCriteriaSql();
my $dbh = __PACKAGE__->db_Main();
my $dbh = __PACKAGE__->db_ReadOnly();
my $sth = $dbh->prepare($sql);
$sth->execute($self->test_run_id);
my ($num_results) = $sth->fetchrow_array;

Просмотреть файл

@ -202,7 +202,7 @@ sub coverage() {
my $user = shift; # optional
my $trusted = shift; # optional
my $dbh = __PACKAGE__->db_Main();
my $dbh = __PACKAGE__->db_ReadOnly();
my $select = "SELECT tr.testresult_id, trsl.class_name";
my $from = " FROM test_results tr, users u, opsyses o, test_result_status_lookup trsl";
my $where = " WHERE tr.testcase_id=" . quotemeta($self->{'testcase_id'}) . " AND tr.user_id=u.user_id AND tr.opsys_id=o.opsys_id AND tr.result_status_id=trsl.result_status_id";

Просмотреть файл

@ -380,7 +380,7 @@ sub getTestResults($\@\@$) {
}
my $sql = "$select $from $where $group_by $order_by $limit";
my $dbh = Litmus::DBI->db_Main();
my $dbh = Litmus::DBI->db_ReadOnly();
my $sth = $dbh->prepare($sql);
$sth->execute();
my @rows = $self->sth_to_objects($sth);

Просмотреть файл

@ -83,7 +83,7 @@ sub search_full_text {
my $realname = shift;
my @groups = shift;
my $dbh = Litmus::DBI->db_Main();
my $dbh = Litmus::DBI->db_ReadOnly();
my @args;
my $sql = q{

Просмотреть файл

@ -151,6 +151,7 @@ use strict;
use warnings;
use Litmus::Config;
use Litmus::Memoize;
use DBI;
use base 'Class::DBI::mysql';
@ -159,12 +160,24 @@ use constant MP2 => ( exists $ENV{MOD_PERL_API_VERSION} and
use constant MP1 => ( exists $ENV{MOD_PERL} and
! exists $ENV{MOD_PERL_API_VERSION});
our $dsn = "dbi:mysql(RootClass=AuditDBI):database=$Litmus::Config::db_name;host=$Litmus::Config::db_host;port=3306";
our $dsn = "dbi:mysql(RootClass=AuditDBI):database=$Litmus::Config::db_name;host=$Litmus::Config::db_host;port=$Litmus::Config::db_port";
Litmus::DBI->connection($dsn,
$Litmus::Config::db_user,
$Litmus::Config::db_pass);
our $readonly_dbh;
if (defined $Litmus::Config::db_host_ro and
$Litmus::Config::db_host_ro ne $Litmus::Config::db_host) {
my $readonly_dsn = "dbi:mysql:database=$Litmus::Config::db_name_ro;host=$Litmus::Config::db_host_ro;port=$Litmus::Config::db_port_ro";
$readonly_dbh = DBI->connect($readonly_dsn,
$Litmus::Config::db_user_ro,
$Litmus::Config::db_pass_ro,
{ReadOnly => 1}
);
}
our %column_aliases;
Litmus::DBI->autoupdate(0);
@ -241,5 +254,13 @@ sub _auto_increment_value {
if (! defined $id) { return $self->SUPER::_auto_increment_value() }
return $id;
}
sub db_ReadOnly() {
my $class = shift;
return $readonly_dbh if ($readonly_dbh);
return $class->db_Main();
}
1;

Просмотреть файл

@ -55,7 +55,7 @@ sub _init {
return 1;
}
$self->{_dbh} = Litmus::DBI->db_Main;
$self->{_dbh} = Litmus::DBI->db_ReadOnly;
if ($args{testday_id}) {
my $testday = Litmus::DB::TestDay->retrieve($args{testday_id});

Просмотреть файл

@ -46,7 +46,7 @@ my $template = "reporting/aggregate_results.tmpl";
my $title = "Test Results Submitted by Testgroup";
my $results;
my $dbh = Litmus::DBI->db_Main();
my $dbh = Litmus::DBI->db_ReadOnly();
my $sql = "SELECT tg.name AS testgroup_name,pr.name AS product_name,b.name AS branch_name,count(tr.testresult_id) AS num_results
FROM testgroups tg, products pr, branches b, subgroup_testgroups sgtg, testcase_subgroups tcsg, testcases tc, test_results tr
WHERE tg.branch_id=b.branch_id AND tg.product_id=pr.product_id AND tg.enabled=1 AND tg.testgroup_id=sgtg.testgroup_id AND sgtg.subgroup_id=tcsg.subgroup_id AND tcsg.testcase_id=tc.testcase_id AND tc.testcase_id=tr.testcase_id AND tc.enabled=1 AND tr.branch_id=tc.branch_id AND tc.product_id=tg.product_id

Просмотреть файл

@ -68,7 +68,7 @@ if (
die;
}
$dbh = Litmus::DBI->db_Main;
$dbh = Litmus::DBI->db_ReadOnly;
if (!$dbh) {
die "Unable to connect to database!";
}

Просмотреть файл

@ -46,7 +46,7 @@ END {
}
}
$litmus_dbh = Litmus::DBI->db_Main() or die;
$litmus_dbh = Litmus::DBI->db_ReadOnly() or die;
my ($sql,$sth);