From 4ff34e9d3b747097a4bc88efd8171cae832a94e9 Mon Sep 17 00:00:00 2001 From: "terry%mozilla.org" <> Date: Fri, 18 Feb 2000 05:40:54 +0000 Subject: 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. --- globals.pl | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'globals.pl') 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 { -- cgit v1.2.1