Skip to content

Commit

Permalink
Make delete_accesslog support a BLACKHOLE master->normal slave
Browse files Browse the repository at this point in the history
The DELETEs sent to the log master don't replicate to the slave if the
master is ENGINE=BLACKHOLE and the slave is (obviously) not.  This checks
for that situation by testing whether an id exists on the master, and
if not, sends the DELETEs directly to the slave.
  • Loading branch information
jamiemccarthy committed Jun 3, 2008
1 parent 45c892f commit 74f0756
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions themes/slashcode/tasks/delete_accesslog.pl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
$task{$me}{timespec} = '22 * * * *'; # Normally run once an hour
$task{$me}{timespec_panic_1} = '20 1,2,3,4,5,6 * * *'; # Just run at night if an issue pops up
$task{$me}{timespec_panic_2} = ''; # In a pinch don't do anything
$task{$me}{resource_locks} = { logdb => 1 };
$task{$me}{resource_locks} = { logdb => 1, log_slave => 1 };
$task{$me}{fork} = SLASHD_NOWAIT;
$task{$me}{code} = sub {
my($virtual_user, $constants, $slashdb, $user) = @_;
Expand All @@ -37,21 +37,28 @@
return "nothing to do";
}

# If the log master is ENGINE=BLACKHOLE, we can't delete from there;
# delete from the log slave instead.
my $delete_db = $logdb;
if (! $logdb->sqlSelect('id', 'accesslog' "id=$id") {
$delete_db = $log_slave;
}

my $rows;
my $total = 0;
my $limit = 100_000;

my $last_err = "";
my $done = 0;
MAINLOOP: while (!$done) {
while ($rows = $logdb->sqlDelete("accesslog", "id < $id", $limit)) {
while ($rows = $delete_db->sqlDelete("accesslog", "id < $id", $limit)) {
$total += $rows;
last if $rows eq "0E0";
slashdLog("deleted so far $total of $limit rows");
sleep 10;
}
my $err = "";
if ( $counter >= $failures || !($err = $logdb->sqlError()) ) {
if ( $counter >= $failures || !($err = $delete_db->sqlError()) ) {
# If either we're giving up because there are too many
# failures, or the last attempt was successful, then
# break out of the loop, we're done.
Expand Down

0 comments on commit 74f0756

Please sign in to comment.