flush cache on exit

This commit is contained in:
Alexandre Bruyelles 2014-06-16 12:26:27 +02:00
parent 705e1687ff
commit 788bdc338f

View File

@ -88,6 +88,7 @@ sub REAPER {
sub TERM {
print "SIGTERM received\n";
flush_cache(1);
exit 0;
}
@ -627,7 +628,8 @@ sub handleflow {
}
sub flush_cache {
if ($childrunning || ((time - $ascache_lastflush) < $ascache_flush_interval)) {
my $force = shift;
if (!defined($force) && ($childrunning || ((time - $ascache_lastflush) < $ascache_flush_interval))) {
# can't/don't want to flush cache right now
return;
}
@ -641,17 +643,21 @@ sub flush_cache {
} elsif ($pid != 0) {
# in parent
$ascache_lastflush = time;
for (keys %$ascache) {
if ($_ % 10 == $ascache_flush_number % 10) {
delete $ascache->{$_};
if(!defined($force)){
for (keys %$ascache) {
if ($_ % 10 == $ascache_flush_number % 10) {
delete $ascache->{$_};
}
}
}else{
$ascache = ();
}
$ascache_flush_number++;
return;
}
while (my ($as, $cacheent) = each(%$ascache)) {
if ($as % 10 == $ascache_flush_number % 10) {
if (defined($force) || $as % 10 == $ascache_flush_number % 10) {
#print "$$: flushing data for AS $as ($cacheent->{updatets})\n";
my $rrdfile = getrrdfile($as, $cacheent->{updatets});