2013-04-18 Sancho Lerena <slerena@artica.es>
* util/pandora_db.pl: Added a usleep() inside loops to aliviate SQL transactions. This should help to improve performance and avoid lockings. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@8014 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
c3e5805834
commit
702cb84227
|
@ -1,3 +1,9 @@
|
|||
2013-04-18 Sancho Lerena <slerena@artica.es>
|
||||
|
||||
* util/pandora_db.pl: Added a usleep() inside loops to aliviate
|
||||
SQL transactions. This should help to improve performance and
|
||||
avoid lockings.
|
||||
|
||||
2013-04-18 Miguel de Dios <miguel.dedios@artica.es>
|
||||
|
||||
* lib/PandoraFMS/Core.pm: cleaned source code style.
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
###############################################################################
|
||||
# Pandora FMS DB Management
|
||||
###############################################################################
|
||||
# Copyright (c) 2005-2012 Artica Soluciones Tecnologicas S.L
|
||||
# Copyright (c) 2005-2013 Artica Soluciones Tecnologicas S.L
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
|
@ -23,6 +23,7 @@ use Time::Local; # DateTime basic manipulation
|
|||
use DBI; # DB interface with MySQL
|
||||
use POSIX qw(strftime);
|
||||
use File::Path qw (rmtree);
|
||||
use Time::HiRes qw/usleep/;
|
||||
|
||||
# Default lib dir for RPM and DEB packages
|
||||
use lib '/usr/lib/perl5';
|
||||
|
@ -31,7 +32,7 @@ use PandoraFMS::Tools;
|
|||
use PandoraFMS::DB;
|
||||
|
||||
# version: define current version
|
||||
my $version = "5.0dev PS130228";
|
||||
my $version = "5.0dev PS130418";
|
||||
|
||||
# Pandora server configuration
|
||||
my %conf;
|
||||
|
@ -105,6 +106,9 @@ sub pandora_purgedb ($$) {
|
|||
for (my $ax = 1; $ax <= $BIG_OPERATION_STEP; $ax++){
|
||||
db_do ($dbh, "DELETE FROM tagente_datos WHERE utimestamp < ". ($first_mark + ($purge_steps * $ax)) . " AND utimestamp >= ". $first_mark );
|
||||
print "[PURGE] Data deletion Progress %$ax .. \r";
|
||||
|
||||
# Do a nanosleep here for 0,01 sec
|
||||
usleep (10000);
|
||||
}
|
||||
print "\n";
|
||||
} else {
|
||||
|
@ -138,6 +142,8 @@ sub pandora_purgedb ($$) {
|
|||
for (my $ax = 1; $ax <= $BIG_OPERATION_STEP; $ax++){
|
||||
db_do ($dbh, "DELETE FROM tagente_datos_inventory WHERE utimestamp < ". ($first_mark + ($purge_steps * $ax)) . " AND utimestamp >= ". $first_mark );
|
||||
print "[PURGE] Inventory data deletion Progress %$ax .. \r";
|
||||
# Do a nanosleep here for 0,01 sec
|
||||
usleep (10000);
|
||||
}
|
||||
print "\n";
|
||||
} else {
|
||||
|
@ -157,6 +163,8 @@ sub pandora_purgedb ($$) {
|
|||
for (my $ax = 1; $ax <= $BIG_OPERATION_STEP; $ax++){
|
||||
db_do ($dbh, "DELETE FROM tagente_datos_log4x WHERE utimestamp < ". ($first_mark + ($purge_steps * $ax)) . " AND utimestamp >= ". $first_mark );
|
||||
print "[PURGE] Log4x data deletion progress %$ax .. \r";
|
||||
# Do a nanosleep here for 0,01 sec
|
||||
usleep (10000);
|
||||
}
|
||||
print "\n";
|
||||
} else {
|
||||
|
@ -302,6 +310,8 @@ sub pandora_purgedb ($$) {
|
|||
for (my $ax = 1; $ax <= $BIG_OPERATION_STEP; $ax++){
|
||||
db_do ($dbh, "DELETE FROM tagent_access WHERE utimestamp < ". ( $first_mark + ($purge_steps * $ax)) . " AND utimestamp >= ". $first_mark);
|
||||
print "[PURGE] Agent access deletion progress %$ax .. \r";
|
||||
# Do a nanosleep here for 0,01 sec
|
||||
usleep (10000);
|
||||
}
|
||||
print "\n";
|
||||
} else {
|
||||
|
@ -471,6 +481,7 @@ sub pandora_compactdb ($$) {
|
|||
delete($count_hash{$key});
|
||||
}
|
||||
|
||||
usleep (1000); # Very small usleep, just to don't burn the DB
|
||||
# Move to the next interval
|
||||
$start_utime = $stop_utime;
|
||||
}
|
||||
|
@ -587,6 +598,9 @@ sub pandora_checkdb_integrity {
|
|||
# Delete all non-used IP addresses from taddress
|
||||
db_do ($dbh, 'DELETE FROM taddress WHERE id_a NOT IN (SELECT id_a FROM taddress_agent)');
|
||||
|
||||
# Do a nanosleep here for 0,01 sec
|
||||
usleep (10000);
|
||||
|
||||
print "[INTEGRITY] Deleting orphan alerts \n";
|
||||
|
||||
# Delete alerts assigned to inexistant modules
|
||||
|
@ -602,10 +616,7 @@ sub pandora_checkdb_integrity {
|
|||
|
||||
# Delete orphan data_inc reference records
|
||||
db_do ($dbh, 'DELETE FROM tagente_datos_inc WHERE id_agente_modulo NOT IN (SELECT id_agente_modulo FROM tagente_modulo)');
|
||||
|
||||
# Delete all non-used IP addresses from taddress
|
||||
db_do ($dbh, 'DELETE FROM taddress WHERE id_a NOT IN (SELECT id_a FROM taddress_agent)');
|
||||
|
||||
|
||||
# Check enterprise tables
|
||||
enterprise_hook ('pandora_checkdb_integrity_enterprise', [$dbh]);
|
||||
}
|
||||
|
@ -638,6 +649,9 @@ sub pandora_checkdb_consistency {
|
|||
# Delete the module
|
||||
db_do ($dbh, 'DELETE FROM tagente_modulo WHERE id_agente_modulo = ?', $id_agente_modulo);
|
||||
|
||||
# Do a nanosleep here for 0,001 sec
|
||||
usleep (100000);
|
||||
|
||||
# Delete any alerts associated to the module
|
||||
db_do ($dbh, 'DELETE FROM talert_template_modules WHERE id_agent_module = ?', $id_agente_modulo);
|
||||
}
|
||||
|
@ -657,6 +671,9 @@ sub pandora_checkdb_consistency {
|
|||
|
||||
# Delete any alerts associated to the module
|
||||
db_do ($dbh, 'DELETE FROM talert_template_modules WHERE id_agent_module = ? AND NOT EXISTS (SELECT id_agente_modulo FROM tagente_modulo WHERE id_agente_modulo = ?)', $id_agente_modulo, $id_agente_modulo);
|
||||
|
||||
# Do a nanosleep here for 0,001 sec
|
||||
usleep (100000);
|
||||
}
|
||||
}
|
||||
print "[CHECKDB] Checking database consistency (Missing status)... \n";
|
||||
|
@ -686,6 +703,10 @@ sub pandora_checkdb_consistency {
|
|||
next if (defined ($count) && $count > 0);
|
||||
|
||||
db_do ($dbh, 'DELETE FROM tagente_estado WHERE id_agente_modulo = ?', $id_agente_modulo);
|
||||
|
||||
# Do a nanosleep here for 0,001 sec
|
||||
usleep (100000);
|
||||
|
||||
print "[CHECKDB] Deleting non-existing module $id_agente_modulo in state table \n";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue