X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2Fbin%2Ffreeside-torrus-srvderive;h=e83318fe89e9fa144cf5ac9175cb98ebc52f3690;hb=184cd3c86cccf8cb4710c25a871018361960906f;hp=f95029a5cfa20c36498aabebe394adaa0249070b;hpb=297bec469bf8c9257b58c57aabbcbd11a87e47c7;p=freeside.git diff --git a/FS/bin/freeside-torrus-srvderive b/FS/bin/freeside-torrus-srvderive index f95029a5c..e83318fe8 100644 --- a/FS/bin/freeside-torrus-srvderive +++ b/FS/bin/freeside-torrus-srvderive @@ -6,7 +6,7 @@ use Sys::SigAction qw( set_sig_handler ); use Date::Parse; use Date::Format; use FS::Daemon ':all'; #daemonize1 drop_root daemonize2 myexit logfile sig* -use FS::UID qw( adminsuidsetup dbh driver_name ); +use FS::UID qw( adminsuidsetup forksuidsetup dbh driver_name ); use FS::Record qw( qsearch str2time_sql str2time_sql_closing concat_sql ); use FS::torrus_srvderive; @@ -59,20 +59,22 @@ my $sql = " my $orderlimit = " ORDER BY srv_date, srv_time - LIMIT 50 -"; + LIMIT 100 +"; #50? our $kids = 0; -MAIN: while (1) { +#MAIN: while (1) { +while (1) { my $found = 0; - SERVICEID: foreach my $torrus_srvderive ( qsearch('torrus_srvderive', {}) ) { + #SERVICEID: foreach my $torrus_srvderive ( qsearch('torrus_srvderive', {}) ) { + foreach my $torrus_srvderive ( qsearch('torrus_srvderive', {}) ) { &reap_kids; if ( $kids >= $max_kids ) { - sleep 10; + sleep 5; redo; } @@ -95,7 +97,11 @@ MAIN: while (1) { my $serviceid = $torrus_srvderive->serviceid; my @serviceids = $torrus_srvderive->component_serviceids; - next unless @serviceids; #don't try to search for empty virtual ports + exit unless @serviceids; #don't try to search for empty virtual ports + + #nonlocking select statements; rows in this table never change + dbh->do('SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED') + if driver_name eq 'mysql'; my @in = (); for my $dir ('_IN', '_OUT') { @@ -118,7 +124,7 @@ MAIN: while (1) { die $error if $error; } else { warn "no initial last_srv_date for $serviceid; skipping\n" if $DEBUG; - next; + exit; } } @@ -142,24 +148,26 @@ MAIN: while (1) { eval { my $h = set_sig_handler( 'ALRM', sub { die "_timeout\n"; } ); - alarm(10*60); #5*60); #$torrus_srvderive->last_srv_date ? 5*60 : 15*60); + alarm(15*60); #5*60); #$torrus_srvderive->last_srv_date ? 5*60 : 15*60); $sth->execute($serviceid, $serviceid) or die $sth->errstr; alarm(0); }; alarm(0); if ( $@ && $@ eq "_timeout\n" ) { - warn "search timed out; reconnecting and restarting\n"; + #warn "search timed out; reconnecting and restarting\n"; + warn "search timed out\n"; dbh->clone()->do("KILL QUERY ". dbh->{"mysql_thread_id"}) if driver_name eq 'mysql'; dbh->rollback; #or die dbh->errstr; - adminsuidsetup($user); - next SERVICEID; #MAIN; + #adminsuidsetup($user); + #next SERVICEID; #MAIN; + exit; } elsif ( $@ ) { die $@; } - warn "search finished; checking results\n" if $DEBUG; + warn "search for $serviceid finished; checking results\n" if $DEBUG; my $prev = 0; while ( my $row = $sth->fetchrow_arrayref ) { @@ -200,11 +208,13 @@ MAIN: while (1) { #stupid mysql deadlocks all the time on insert, so we need to recover unless ( $isth->execute(@param) ) { - warn "Error inserting data for $serviceid$dir (restarting): ". - $isth->errstr; + #warn "Error inserting data for $serviceid$dir (restarting): ". + # $isth->errstr; + warn "Error inserting data for $serviceid$dir: ". $isth->errstr; dbh->rollback; #or die dbh->errstr; - sleep 5; - next SERVICEID; #MAIN; + #sleep 5; + #next SERVICEID; #MAIN; + exit; } }