views:

7

answers:

0

I wanted to know how OPT_SERVER_FAILURE_LIMIT constant (which I think is equivalent of MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT on libmemcached) works, so created a small code snippet like this:

#!/path/to/php533/bin/php
<?php
function debugging_set($memcached, $key, $value) {
  $code = '$memcached->set($key, $value)';
  var_dump(eval('return ' . $code . ';'));
  echo "Setting $key: " . $memcached->getResultMessage() . " (".$memcached->getResultCode().")\n";
}

function debugging_get($memcached, $key) {
  $code = '$memcached->get($key)';
  var_dump(eval('return ' . $code . ';'));
  echo "Getting $key: " . $memcached->getResultMessage() . " (".$memcached->getResultCode().")\n";
}

$memcached = new Memcached();

$memcached->setOption(Memcached::OPT_NO_BLOCK, true);
$memcached->setOption(Memcached::OPT_SERVER_FAILURE_LIMIT, $argv[1]);

$memcached->addServer("localhost", 12345);
$memcached->addServer("localhost", 12346);

debugging_set($m, "test", "test");
debugging_set($m, "test2", "test2");
debugging_set($m, "test3", "test3");

echo "\n";

debugging_get($m, "test");
debugging_get($m, "test2");
debugging_get($m, "test3");

... and I ran it with two Tokyo Tyrant servers on port 12345 (running) and 12346 (stopped using SIGSTOP).

I got following results (which are reasonable for me) in the case of argv is 0:

[me@host ~]$ ./test_memcached_2.php 0
bool(false)
Setting test: A TIMEOUT OCCURRED (31)
bool(false)
Setting test2: A TIMEOUT OCCURRED (31)
bool(true)
Setting test3: SUCCESS (0)

bool(false)
Getting test: A TIMEOUT OCCURRED (31)
bool(false)
Getting test2: A TIMEOUT OCCURRED (31)
string(5) "test3"
Getting test3: SUCCESS (0)

Also a reasonable result in the case of argv is 1:

[me@host ~]$ ./test_memcached_2.php 1
bool(false)
Setting test: A TIMEOUT OCCURRED (31)
bool(false)
Setting test2: SERVER IS MARKED DEAD (35)
bool(true)
Setting test3: SUCCESS (0)

bool(false)
Getting test: SERVER IS MARKED DEAD (35)
bool(false)
Getting test2: SERVER IS MARKED DEAD (35)
string(5) "test3"
Getting test3: SUCCESS (0)

But I don't know what is happening when argv[1] is 2.

[me@host ~]$ ./test_memcached_2.php 2
bool(false)
Setting test: A TIMEOUT OCCURRED (31)
bool(false)
Setting test2: A TIMEOUT OCCURRED (31)
bool(true)
Setting test3: SUCCESS (0)

bool(false)
Getting test: A TIMEOUT OCCURRED (31)
bool(false)
Getting test2: A TIMEOUT OCCURRED (31)
string(5) "test3"
Getting test3: SUCCESS (0)

I expect the first and second set() trial to be a timeout, but first trial of get() to be a "marked dead" error. But it seems that memcached client behaves just like OPT_SERVER_FAILURE_LIMIT is set to 0.

What's happening?