summaryrefslogtreecommitdiffstats
path: root/globals.pl
diff options
context:
space:
mode:
authorterry%mozilla.org <>2000-02-18 06:40:54 +0100
committerterry%mozilla.org <>2000-02-18 06:40:54 +0100
commit4ff34e9d3b747097a4bc88efd8171cae832a94e9 (patch)
tree680a7889e3432e5b5dfe2580a2de9f019fa4c0f3 /globals.pl
parent870be34704d0679153de40192b326b076343ba7d (diff)
downloadbugzilla-4ff34e9d3b747097a4bc88efd8171cae832a94e9.tar.gz
bugzilla-4ff34e9d3b747097a4bc88efd8171cae832a94e9.tar.xz
Added an optional ability to keep a read-only shadow database, so that
bug queries can be run against it, so that these slow queries won't be able to tie up the rest of the system.
Diffstat (limited to 'globals.pl')
-rw-r--r--globals.pl31
1 files changed, 29 insertions, 2 deletions
diff --git a/globals.pl b/globals.pl
index 820749769..00e1cfd25 100644
--- a/globals.pl
+++ b/globals.pl
@@ -74,10 +74,17 @@ $::dontchange = "--do_not_change--";
$::chooseone = "--Choose_one:--";
$::defaultqueryname = "(Default query)";
$::unconfirmedstate = "UNCONFIRMED";
+$::dbwritesallowed = 1;
sub ConnectToDatabase {
+ my ($useshadow) = (@_);
if (!defined $::db) {
- $::db = Mysql->Connect($db_host, $db_name, $db_user, $db_pass)
+ my $name = $db_name;
+ if ($useshadow) {
+ $name = Param("shadowdb");
+ $::dbwritesallowed = 0;
+ }
+ $::db = Mysql->Connect($db_host, $name, $db_user, $db_pass)
|| die "Can't connect to database server.";
}
}
@@ -100,11 +107,31 @@ sub SqlLog {
sub SendSQL {
- my ($str) = (@_);
+ my ($str, $dontshadow) = (@_);
+ my $iswrite = ($str =~ /^(INSERT|REPLACE|UPDATE|DELETE)/i);
+ if ($iswrite && !$::dbwritesallowed) {
+ die "Evil code attempted to write stuff to the shadow database.";
+ }
+ if ($str =~ /^LOCK TABLES/ && $str !~ /shadowlog/) {
+ $str =~ s/^LOCK TABLES/LOCK TABLES shadowlog WRITE, /;
+ }
SqlLog($str);
$::currentquery = $::db->query($str)
|| die "$str: $::db_errstr";
SqlLog("Done");
+ if (!$dontshadow && $iswrite && Param("shadowdb")) {
+ my $q = SqlQuote($str);
+ my $insertid;
+ if ($str =~ /^(INSERT|REPLACE)/i) {
+ SendSQL("SELECT LAST_INSERT_ID()");
+ $insertid = FetchOneColumn();
+ }
+ SendSQL("INSERT INTO shadowlog (command) VALUES ($q)", 1);
+ if ($insertid) {
+ SendSQL("SET LAST_INSERT_ID = $insertid");
+ }
+ system("./syncshadowdb &");
+ }
}
sub MoreSQLData {