Comment 0 for bug 1158676

Revision history for this message
Denis Shashkov (bruzh2) wrote : ketama algorithm doesn't work?

All software is self-builded: PHP 5.3.10 + memcached extension 2.1.0, linked with libmemcached 1.0.14.
Running simple PHP-script:
<?php
$m = new Memcached();
$m->setOption(Memcached::OPT_COMPRESSION, false);
$m->setOption(Memcached::OPT_CONNECT_TIMEOUT, 10);
$m->setOption(Memcached::OPT_RETRY_TIMEOUT, 1);
// ketama options
$m->setOption(Memcached::OPT_DISTRIBUTION, Memcached::DISTRIBUTION_CONSISTENT);
$m->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE, true);
$m->setOption(Memcached::OPT_SERVER_FAILURE_LIMIT, 1);
$m->setOption(Memcached::OPT_REMOVE_FAILED_SERVERS, true);

$servers = array();
$servers[] = array('127.0.0.1', 11211, 100);
$servers[] = array('192.168.0.1', 11212, 100);
$m->addServers($servers);

for ( $i=0; $i<100; $i++ ) {
        sleep(1);
        var_dump($m->set('key', 1));
        if ($m->getResultCode() > 0) {
                if ($m->getResultCode() !== Memcached::RES_NOTFOUND ) {
                        echo $m->getResultMessage().PHP_EOL;
                }
        }
}
?>

After several successful cycles, dropping down second server (192.168.0.1).
Expected behavior:
1. After dropping connection and polling timeout, server will be marked as FAULTY.
2. After first connecting attempt, server will be marked as DEAD. Memcached ext./libmemcached will redistribute key to first memcached server (127.0.0.1).

Observed behavior:
1. After dropping connection and polling timeout, server is marked as FAULTY? (It's an assumption, cannot check).
2. Memcached ext./libmemcached open connection to first server (127.0.0.1), SUCCESSFULLY stores the key AND getResultMessage returns "SERVER IS MARKED DEAD". (It's normal)
3. At the next cycle, Memcached ext./libmemcached successfully stores the key. (It's normal, too)
4. At the next and further cycles, Memcached ext./libmemcached return FALSE on set() operation and getResultMessage returns "SERVER IS MARKED DEAD".

It's hard confusing. Why just using first server further?

I check memcached extension's sources and believe it pass ketama options to libmemcached well.
So I propose that unexpected behavior is a bug. Or maybe I use invalid option set with memcached extension/libmemcached?