diff options
| author | fukachan <fukachan> | 2003-03-16 07:26:20 +0000 |
|---|---|---|
| committer | fukachan <fukachan> | 2003-03-16 07:26:20 +0000 |
| commit | 65c05fbbc7c5d9e5ed3f59207ea2ce8ae50bdf7f (patch) | |
| tree | 8ef03af8c849588179f021da6ff190b1f2cd3a72 /fml | |
| parent | d0f972422c290576a8c22fede6468d72f816e96b (diff) | |
| download | fml8-65c05fbbc7c5d9e5ed3f59207ea2ce8ae50bdf7f.tar.gz fml8-65c05fbbc7c5d9e5ed3f59207ea2ce8ae50bdf7f.tar.bz2 fml8-65c05fbbc7c5d9e5ed3f59207ea2ce8ae50bdf7f.zip | |
clean up lock on error cache.
move lock mechanism into only FML::Error module.
XXX lock channel name is changed but hard-coded yet now.
Diffstat (limited to 'fml')
| -rw-r--r-- | fml/lib/FML/Error.pm | 90 | ||||
| -rw-r--r-- | fml/lib/FML/Process/Error.pm | 16 |
2 files changed, 93 insertions, 13 deletions
diff --git a/fml/lib/FML/Error.pm b/fml/lib/FML/Error.pm index 6395177f..dee10a02 100644 --- a/fml/lib/FML/Error.pm +++ b/fml/lib/FML/Error.pm @@ -4,7 +4,7 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: Error.pm,v 1.13 2003/02/09 12:31:40 fukachan Exp $ +# $FML: Error.pm,v 1.14 2003/02/18 15:57:46 fukachan Exp $ # package FML::Error; @@ -56,6 +56,55 @@ sub new } +# Descriptions: lock channel we should use to lock this object. +# Arguments: OBJ($self) +# Side Effects: lock "error_analyzer_cache_dir" channel +# Return Value: STR +sub get_lock_channel_name +{ + my ($self) = @_; + + # LOCK_CHANNEL: error_analyzer_cache_dir + return 'error_analyzer_cache_dir'; +} + + +=head1 LOCK ERROR DB ACCESS + +=cut + + +# Descriptions: lock +# Arguments: OBJ($self) +# Side Effects: none +# Return Value: none +sub lock +{ + my ($self) = @_; + my $curproc = $self->{ _curproc }; + my $channel = $self->get_lock_channel_name(); + $curproc->lock($channel); +} + + +# Descriptions: unlock +# Arguments: OBJ($self) +# Side Effects: none +# Return Value: none +sub unlock +{ + my ($self) = @_; + my $curproc = $self->{ _curproc }; + my $channel = $self->get_lock_channel_name(); + $curproc->unlock($channel); +} + + +=head1 Database + +=cut + + # Descriptions: open cache database. # Arguments: OBJ($self) # Side Effects: none @@ -66,7 +115,8 @@ sub db_open my $curproc = $self->{ _curproc }; use FML::Error::Cache; - return new FML::Error::Cache $curproc; + $self->{ _db } = new FML::Error::Cache $curproc; + return $self->{ _db }; } @@ -81,6 +131,35 @@ sub db_close } +=head2 add($info) + +add bounce info into cache. + +=cut + + +# Descriptions: add bounce info into cache. +# in fact, this is a wrapper of FML::Error::Cache::add() +# to clarify that we should lock. +# Arguments: OBJ($self) HASH_REF($info) +# Side Effects: update cache +# Return Value: none +sub add +{ + my ($self, $info) = @_; + my $db = $self->{ _db }; + + if (defined $db) { + $self->lock(); + $db->add($info); + $self->unlock(); + } + else { + LogError("db not open"); + } +} + + =head2 analyze() open error message cache and @@ -109,7 +188,11 @@ sub analyze use FML::Error::Analyze; my $analyzer = new FML::Error::Analyze $curproc; my $fp = $config->{ error_analyzer_function } || 'simple_count'; - my $list = $analyzer->$fp($curproc, $rdata); + + # critical region: access to db under locked. + $self->lock(); + my $list = $analyzer->$fp($curproc, $rdata); + $self->unlock(); $self->{ _analyzer } = $analyzer; @@ -163,6 +246,7 @@ sub remove_bouncers use FML::Restriction::Base; my $safe = new FML::Restriction::Base; + # XXX need no lock here since lock is done in FML::Command::* class. ADDR: for my $addr (@$list) { # check if $address is a safe string. diff --git a/fml/lib/FML/Process/Error.pm b/fml/lib/FML/Process/Error.pm index 8ef57ac8..59a23285 100644 --- a/fml/lib/FML/Process/Error.pm +++ b/fml/lib/FML/Process/Error.pm @@ -3,7 +3,7 @@ # Copyright (C) 2002,2003 Ken'ichi Fukamachi # All rights reserved. # -# $FML: Error.pm,v 1.27 2003/02/11 09:48:16 fukachan Exp $ +# $FML: Error.pm,v 1.28 2003/02/18 15:57:46 fukachan Exp $ # package FML::Process::Error; @@ -153,8 +153,8 @@ sub run $bouncer->analyze( $msg ); use FML::Error; - my $error_obj = new FML::Error $curproc; - my $errorcache = $error_obj->db_open(); + my $error = new FML::Error $curproc; + $error->db_open(); for my $address ( $bouncer->address_list ) { my $status = $bouncer->status( $address ); @@ -165,17 +165,17 @@ sub run Log("bounced: status=$status"); Log("bounced: reason=\"$reason\""); - $curproc->lock('errorcache'); - $errorcache->add({ + $error->add({ address => $address, status => $status, reason => $reason, }); - $curproc->unlock('errorcache'); $found++; } } + + $error->db_close(); }; LogError($@) if $@; @@ -206,11 +206,7 @@ sub _clean_up_bouncers eval q{ use FML::Error; my $error = new FML::Error $curproc; - - $curproc->lock('errorcache'); $error->analyze(); - $curproc->unlock('errorcache'); - $error->remove_bouncers(); }; LogError($@) if $@; |
