Changeset 103


Ignore:
Timestamp:
09/24/25 13:00:12 (38 hours ago)
Author:
Kris Deugau
Message:

/trunk/dnsbl

Refine DB transaction behaviour around addblock() based on glitches found
using it in earnest in updated production.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dnsbl/DNSBL.pm

    r95 r103  
    188188# JIC someone wants to close the db but not finish the script
    189189sub dbclose {
    190   $dbh->rollback;
    191190  $dbh->disconnect;
    192191}
     
    196195sub connect {
    197196  my $self = shift;
    198   ## want to NOT autocommit everything, it's unlikely we'll step on our own toes but...
     197  # after jumping a HUUUGE number of PG versions, AutoCommit => 0 produced some bizarre bugs
    199198  $dbh = DBI->connect("DBI:Pg:host=$self->{dbhost};dbname=$self->{dbname}", $self->{dbuser}, $self->{dbpass}, {
    200         AutoCommit => 0,
    201         PrintError => 1
     199        AutoCommit => 1,
     200        PrintError => 0
    202201        })
    203202        or die "database inaccessible: ".$DBI::errstr;
     
    250249  my $sth;
    251250  my $rows = 0;
     251
     252  local $dbh->{AutoCommit} = 0;
     253  local $dbh->{RaiseError} = 1;
     254
    252255  if ($rep =~ /^[\d.]+$/) {
    253256    # weesa gonna ASS-U-ME IP addresses are sanely formatted.
     
    363366  return "$blockin not a single CIDR range" if !$block;
    364367
    365 #  local $dbh->{AutoCommit} = 1;        # force autocommit
     368  local $dbh->{AutoCommit} = 0;
     369  local $dbh->{RaiseError} = 1;
    366370
    367371  my $sth;
     
    373377      ($parent) = $sth->fetchrow_array;
    374378    }
    375     $sth = $dbh->prepare("INSERT INTO blocks (block,orgid,level,parent,exclude,comments,ipcount) VALUES (?,?,?,?,?,?,".
    376         "(SELECT count(*) FROM iplist i JOIN blocks b ON b.block=i.parent WHERE i.ip << ? AND i.exclude='n' AND b.exclude='n'))");
    377     $sth->execute("$block",$orgid,$level,$parent,$exclude,$comment,"$block");
    378     $sth = $dbh->prepare("UPDATE iplist SET parent=? WHERE parent=? AND ip << ?");
    379     $sth->execute("$block",$parent,"$block");
     379    $dbh->do("INSERT INTO blocks (block,orgid,level,parent,exclude,comments,ipcount) VALUES (?,?,?,?,?,?,".
     380        "(SELECT count(*) FROM iplist i JOIN blocks b ON b.block=i.parent WHERE i.ip << ? AND i.exclude='n' AND b.exclude='n'))",
     381        undef, "$block",$orgid,$level,$parent,$exclude,$comment,"$block");
     382    $dbh->do("UPDATE iplist SET parent=? WHERE parent=? AND ip << ?", undef, "$block", $parent, "$block");
    380383    $dbh->commit;
    381384  };
Note: See TracChangeset for help on using the changeset viewer.