about a memcached extension's bug

From: Date: Sun, 09 Oct 2011 12:52:50 +0000
Subject: about a memcached extension's bug
Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-8676@lists.php.net to get a copy of this message
Hi, all: Today find a problem in memcached extension.
    <?php
    $mem = new Memcached;
$mem->addServers(array(array('10.8.8.32',11300,100),array('10.8.8.32',11301,0)));
    $mem->setOption(Memcached::OPT_DISTRIBUTION, Memcached::DISTRIBUTION_CONSISTENT);
    $mem->setOption(Memcached::OPT_HASH, Memcached::HASH_CRC);
    for ($i=0;$i<10;$i++){
        $key = "item_$i";
        $arr = $mem->getServerByKey($key);
        echo ($key.":\t".$arr['port']."\n");
    }
    print_r($mem->getServerList());
if we run above code, the key always distribute on single server. I dive into memcached extension and libmemcached's source code. The problem is in consistent distribute algrithm, the point's hash value is generated by DEFAULT hash algrithm but here, our key used crc hash algrithm, so, result is key always distribute on a single server. I suggest memcached extension add a option can modify the field named "hash_continuum" in "struct memcached_st" in libmemcached. God, I do not know whether the description is clear in my broken English

« previous php.pecl.dev (#8676) next »