Changeset 564

Show
Ignore:
Timestamp:
06/18/07 17:50:53 (2 years ago)
Author:
bradfitz
Message:

fix from:
http://rt.cpan.org/Public/Bug/Display.html?id=27181

and remove the somewhat-half-done and documented hook support, which
is also unused and slows stuff down.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/api/perl/ChangeLog

    r558 r564  
    1         * Add hook support, and define a few hooks for use in gathering 
    2           statistics. 
     12007-06-18: version 1.22 
     2 
     3        * lost connection handling broken due to wrong %sock_map indexing 
     4          http://rt.cpan.org/Public/Bug/Display.html?id=27181 
     5          fix from RHESA 
    36 
    47        * let parser_class be configured as a constructor option, 
  • trunk/api/perl/lib/Cache/Memcached.pm

    r558 r564  
    2525    bucketcount _single_sock _stime 
    2626    connect_timeout cb_connect_fail 
    27     parser_class hooks 
     27    parser_class 
    2828}; 
    2929 
     
    3636 
    3737use vars qw($VERSION $HAVE_ZLIB $FLAG_NOSIGNAL); 
    38 $VERSION = "1.21"; 
     38$VERSION = "1.22"; 
    3939 
    4040BEGIN { 
     
    8383    $self->{namespace} = $args->{namespace} || ''; 
    8484    $self->{namespace_len} = length $self->{namespace}; 
    85     $self->{hooks} = {}; 
    8685 
    8786    return $self; 
     
    162161} 
    163162 
    164 my %sock_map;  # scalaraddr -> "$ip:$port"; 
     163my %sock_map;  # stringified-$sock -> "$ip:$port" 
    165164 
    166165sub _dead_sock { 
    167166    my ($sock, $ret, $dead_for) = @_; 
    168     if (my $ipport = $sock_map{\$sock}) { 
     167    if (my $ipport = $sock_map{$sock}) { 
    169168        my $now = time(); 
    170169        $host_dead{$ipport} = $now + $dead_for 
    171170            if $dead_for; 
    172171        delete $cache_sock{$ipport}; 
    173         delete $sock_map{\$sock}; 
     172        delete $sock_map{$sock}; 
    174173    } 
    175174    @buck2sock = (); 
     
    179178sub _close_sock { 
    180179    my ($sock) = @_; 
    181     if (my $ipport = $sock_map{\$sock}) { 
     180    if (my $ipport = $sock_map{$sock}) { 
    182181        close $sock; 
    183182        delete $cache_sock{$ipport}; 
    184         delete $sock_map{\$sock}; 
     183        delete $sock_map{$sock}; 
    185184    } 
    186185    @buck2sock = (); 
     
    413412    return 0 unless $sock; 
    414413 
    415     $self->run_hook('delete_start', $self); 
    416  
    417414    $self->{'stats'}->{"delete"}++; 
    418415    $key = ref $key ? $key->[1] : $key; 
     
    426423    } 
    427424 
    428     $self->run_hook('delete_end', $self); 
    429  
    430425    return $res eq "DELETED\r\n"; 
    431426} 
     
    452447    return 0 unless $sock; 
    453448 
    454     $self->run_hook('set_start', $self); 
    455  
    456449    use bytes; # return bytes from length() 
    457450 
     
    498491        $self->{'stat_callback'}->($stime, $etime, $sock, $cmdname); 
    499492    } 
    500  
    501     $self->run_hook('set_end', $self); 
    502493 
    503494    return $res eq "STORED\r\n"; 
     
    552543    $self->{'stats'}->{"get_multi"}++; 
    553544 
    554     $self->run_hook('get_start', $self); 
    555  
    556545    my %val;        # what we'll be returning a reference to (realkey -> value) 
    557546    my %sock_keys;  # sockref_as_scalar -> [ realkeys ] 
     
    561550        $sock = $self->sock_to_host($self->{'_single_sock'}); 
    562551        unless ($sock) { 
    563             $self->run_hook('get_start', $self); 
    564552            return {}; 
    565553        } 
     
    596584 
    597585    _load_multi($self, \%sock_keys, \%val); 
    598  
    599     $self->run_hook('get_end', $self); 
    600586 
    601587    if ($self->{'debug'}) { 
     
    920906} 
    921907 
    922 sub run_hook { 
    923     my Cache::Memcached $self = shift; 
    924     my $hookname = shift || return; 
    925  
    926     my $hook = $self->{hooks}->{$hookname}; 
    927     return unless $hook; 
    928  
    929     eval { $hook->(@_) }; 
    930  
    931     warn "Cache::Memcached hook '$hookname' threw error: $@\n" if $@; 
    932 } 
    933  
    934 sub add_hook { 
    935     my Cache::Memcached $self = shift; 
    936     my $hookname = shift || return; 
    937  
    938     if (@_) { 
    939         $self->{hooks}->{$hookname} = shift; 
    940     } else { 
    941         delete $self->{hooks}->{$hookname}; 
    942     } 
    943 } 
    944  
    9459081; 
    946909__END__