Cache::Memcached 1.14 problem
Torsten Foertsch
torsten.foertsch at gmx.net
Sat Apr 8 19:43:57 UTC 2006
Hi,
I know there are 2 new Perl clients on the way. I am asking if they also
contain something like this function?
sub get_sock { # (key)
my Cache::Memcached $self = shift;
my ($key) = @_;
return $self->sock_to_host($self->{'_single_sock'}) if
$self->{'_single_sock'};
return undef unless $self->{'active'};
my $hv = ref $key ? int($key->[0]) : _hashfunc($key);
$self->init_buckets() unless $self->{'buckets'};
my $real_key = ref $key ? $key->[1] : $key;
my $tries = 0;
while ($tries++ < 20) {
my $host = $self->{'buckets'}->[$hv % $self->{'bucketcount'}];
my $sock = $self->sock_to_host($host);
return $sock if $sock;
return undef if $sock->{'no_rehash'};
$hv += _hashfunc($tries . $real_key); # stupid, but works
}
return undef;
}
The goal of the while-loop is to find another server if the first main one is
offline. Unfortunately, this will not always work. Try for example "5000" as
key and 2 servers. For the key itself and all 20 retries the hash function
gives an odd number. Hence, it points always to the same (offline) server.
Why not simply loop over all servers if the main one is offline?
Another problem with this code arises when the server that had been offline
comes online. A value stored in another server is not accessible anymore. It
would be good if set() would return the server or the hash value so it can be
passed the next time the value is accessed.
Torsten
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.danga.com/pipermail/memcached/attachments/20060408/01400a8a/attachment.pgp
More information about the memcached
mailing list