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.2
	TIGRIS_703:1.2
	TIGRIS_702:1.2
	TIGRIS_701:1.2;
locks; strict;
comment	@# @;


1.5
date	2001.04.30.20.56.15;	author kmaples;	state dead;
branches;
next	1.4;

1.4
date	2001.01.30.22.16.26;	author kmaples;	state Exp;
branches
	1.4.6.1;
next	1.3;

1.3
date	2001.01.13.02.04.50;	author kmaples;	state Exp;
branches
	1.3.2.1;
next	1.2;

1.2
date	2000.10.05.21.50.37;	author kmaples;	state Exp;
branches
	1.2.4.1;
next	1.1;

1.1
date	2000.09.28.04.28.27;	author npm;	state Exp;
branches;
next	;

1.2.4.1
date	2001.05.23.17.36.27;	author kmaples;	state Exp;
branches;
next	;

1.3.2.1
date	2001.01.30.21.27.57;	author kmaples;	state Exp;
branches;
next	;

1.4.6.1
date	2001.08.03.00.34.39;	author jasonb;	state Exp;
branches;
next	;


desc
@@


1.5
log
@Issuezilla is now a separate module
@
text
@#!/usr/bin/perl
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is the Issuezilla Issue Tracking System.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s): Terry Weissman <terry@@mozilla.org>
#                 David Gardiner <david.gardiner@@unisa.edu.au>

#use diagnostics;
use strict;

require "globals.pl";
require "defparams.pl";

# Shut up misguided -w warnings about "used only once".  "use vars" just
# doesn't work for me.

sub sillyness {
    my $zz;
    $zz = $::db;
    $zz = $::dbwritesallowed;
}

my $verbose = 0;
my $syncall = 0;

sub Usage {
    print "Usage: syncshadowdb [-v] [-syncall]\n";
    exit;
}

foreach my $opt (@@ARGV) {
    if ($opt eq '-v') {
        $verbose = 1;
    } elsif ($opt eq '-syncall') {
        $syncall = 1;
        $verbose = 1;
    } else {
        Usage();
    }
}
$| = 1;

my $logtostderr = 0;

sub Verbose ($) {
    my ($str) = (@@_);
    if ($verbose) {
        if ($logtostderr) {
            print STDERR $str, "\n";
        } else {
            print $str, "\n";
        }
    }
}
    
my $db_name = "issues";
require "localconfig";

if (!Param("shadowdb")) {
    Verbose("We don't have shadow databases turned on; no syncing performed.");
    exit;
}

my $wasusing = Param("queryagainstshadowdb");

$::param{'queryagainstshadowdb'} = 1; # Force us to be able to use the
                                      # shadowdb, even if other processes
                                      # are not supposed to.


ConnectToDatabase(1);

Verbose("Aquiring lock.");
SendSQL("SELECT GET_LOCK('synclock', 1)");
if (!FetchOneColumn()) {
    Verbose("Couldn't get the lock to do the shadow database syncing.");
    exit;
}

my $shadowtable = "$db_name.shadowlog";

if (!$syncall) {
    Verbose("Looking for requests to sync the whole database.");
    SendSQL("SELECT id FROM $shadowtable " .
            "WHERE reflected = 0 AND command = 'SYNCUP'");
    if (FetchOneColumn()) {
        $syncall = 1;
    }
}

if ($syncall) {
    Verbose("Syncing up the shadow database by copying entire database in.");
    if ($wasusing) {
        $::param{'queryagainstshadowdb'} = 0;
        WriteParams();
        Verbose("Disabled reading from the shadowdb. Sleeping 10 seconds to let other procs catch up.");
        sleep(10);
        $::param{'queryagainstshadowdb'} = 1;
    }
    my @@tables;
    SendSQL("SHOW TABLES");
    my $query = "";
    while (MoreSQLData()) {
        my $table = FetchOneColumn();
        push(@@tables, $table);
        if ($query) {
            $query .= ", $table WRITE";
        } else {
            $query = "LOCK TABLES $table WRITE";
        }
    }
    if (@@tables) {
        Verbose("Locking entire shadow database");
        SendSQL($query);
        foreach my $table (@@tables) {
            Verbose("Dropping old shadow table $table");
            SendSQL("DROP TABLE $table");
        }
        SendSQL("UNLOCK TABLES");
    }    
    # Carefully lock the whole real database for reading, except for the
    # shadowlog table, which we lock for writing.  Then dump everything
    # into the shadowdb database.  Then mark everything in the shadowlog
    # as reflected.  Only then unlock everything.  This sequence causes
    # us to be sure not to miss anything or get something twice.
    SendSQL("USE $db_name");
    SendSQL("SHOW TABLES");
    @@tables = ();
    $query = "LOCK TABLES shadowlog WRITE";
    while (MoreSQLData()) {
        my $table = FetchOneColumn();
        if ($table ne "shadowlog") {
            $query .= ", $table READ";
            push(@@tables, $table);
        }
    }
    Verbose("Locking entire database");
    SendSQL($query);
    my $tablelist = join(' ', @@tables);
    my $tempfile = "$::data_dir/tmpsyncshadow.$$";
    Verbose("Dumping database to a temp file ($tempfile).");
    system("mysqldump -l -e --host=$db_host --port=$db_port $db_name $tablelist > $tempfile");
    Verbose("Restoring from tempfile into shadowdb");
    my $extra = "";
    if ($verbose) {
        $extra = "-v";
    }
    open(MYSQL, "cat $tempfile | mysql $extra " .
         Param("shadowdb") . "|") || die "Couldn't do db copy";
    my $count = 0;
    while (<MYSQL>) {
        print ".";
        $count++;
        if ($count % 70 == 0) {
            print "\n";
        }
    }
    close(MYSQL);
    unlink($tempfile);
    Verbose("");
    
    
    $::dbwritesallowed = 1;
#    SendSQL("UPDATE shadowlog SET reflected = 1 WHERE reflected = 0", 1);
    SendSQL("DELETE FROM shadowlog", 1);
    SendSQL("UNLOCK TABLES");
    if ($wasusing) {
        Verbose("Reenabling other processes to read from the shadow db");
        $::param{'queryagainstshadowdb'} = 1;
        WriteParams();
    }
    Verbose("OK, done.");
}

Verbose("Looking for commands to execute.");
$::dbwritesallowed = 1;

# Make us low priority, to not block anyone who is trying to actually use
# the shadowdb.  Note that this is carefully coded to ignore errors; we want
# to keep going even on older mysqld's that don't have the
# SQL_LOW_PRIORITY_UPDATES option.
$::db->do("SET OPTION SQL_LOW_PRIORITY_UPDATES = 1"); 

while (1) {
    SendSQL("SELECT id, command FROM $shadowtable WHERE reflected = 0 " .
            "ORDER BY id LIMIT 1");
    my ($id, $command) = (FetchSQLData());
    if (!$id) {
        last;
    }
    Verbose("Executing command in shadow db: $command");
    SendSQL($command, 1);
    SendSQL("UPDATE $shadowtable SET reflected = 1 WHERE id = $id", 1);
}

Verbose("Releasing lock.");
SendSQL("SELECT RELEASE_LOCK('synclock')");
@


1.4
log
@Removed -w warnings; commented out diagnostics
@
text
@@


1.4.6.1
log
@Solaris compatibility: Lots of changes:
- Changesand additions to the build files so that the system builds on Solaris.
- Changes to issuezilla so that it works on PERL 5.6.
- Changes to scripts so that they use bash as their interpreter explicitly.
- Changes to search/makeit.in so that the makeit script also runs on Solaris.
Issue number:
Obtained from:
Submitted by:
Reviewed by:
@
text
@d72 1
a72 1
$::db_name = "issues";
d96 1
a96 1
my $shadowtable = "$::db_name.shadowlog";
d142 1
a142 1
    SendSQL("USE $::db_name");
d158 1
a158 1
    system("mysqldump -l -e --host=$::db_host --port=$::db_port $::db_name $tablelist > $tempfile");
@


1.3
log
@First furtive attempts to support remote databases.
@
text
@d1 1
a1 1
#!/usr/bin/perl -w
d24 1
a24 1
use diagnostics;
@


1.3.2.1
log
@Removed -w flags and 'use diagnostics' calls
@
text
@d1 1
a1 1
#!/usr/bin/perl 
d24 1
a24 1
#use diagnostics;
@


1.2
log
@Initial checkin of scripts altered to support multiple databases segregated
by virtual host.
@
text
@d158 1
a158 1
    system("mysqldump -l -e $db_name $tablelist > $tempfile");
@


1.2.4.1
log
@Changed files to explicitly reference global database vars. - fixes problems
with package qualification in some cases.
@
text
@d72 1
a72 1
$::db_name = "issues";
d96 1
a96 1
my $shadowtable = "$::db_name.shadowlog";
d142 1
a142 1
    SendSQL("USE $::db_name");
d158 1
a158 1
    system("mysqldump -l -e $::db_name $tablelist > $tempfile");
@


1.1
log
@Notes on Bugzilla/IssueZilla.

--------------------

This is bugzilla straight outta CVS as of mid-september 2000.

Edited by NPM to work w/ tigris, qmail, etc

Further edited by NPM replacing most instances of "bugs"-->"issues"
"a issue" --> "an issue" etc.

NPM twiddled with query.cgi to lay things out more reasonably, and
add space for future enhancements/customizations.

NPM Removed bugs db column 'severity' and replaced it with 'issue-type'.
Severity seems silly and it's confusing/redundant with priority 'P1'-'P5'.
Some aspects of 'severity' are handled by 'issue-type', e.g.  you
distinguish between an enhancement, feature, task, or defect.

--------------------

To do an upgrade against mozilla.org, move all directories 'CVS' to 'CVS.bak',
e.g. (in tcsh)P:

| beral-5-.../sandbox/issuezilla> foreach i (`find . -name CVS`)
| foreach? mv $i $i.bak
| foreach? end

Then move all 'CVS.mozilla' to 'CVS':

| beral-6-.../sandbox/issuezilla> foreach i (`find . -name CVS.mozilla`)
| foreach? mv $i `dirname $i`/CVS
| foreach? end


Then to see what files might have changed, since this version was last
updated, do:

| beral-6-.../sandbox/issuezilla> cvs -qn update

Then you can either do 'cvs update' and be very careful to watch the output
of cvs, noting any conflicts between the issuezilla edits and mozilla.org's
edits... (files marked w/ 'C').

--------------------

Note the following files are to be instantiated by a tigris SANDBOX initialization script
which someone needs to write...

./data/params.in             ---> ./data/params
./localconfig.in	     ---> ./localconfig
./20issue-track.conf.in      ---> ./20issue-track.conf
@
text
@d156 1
a156 1
    my $tempfile = "data/tmpsyncshadow.$$";
@

