Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] eval command with RedisCluster::FAILOVER_DISTRIBUTE_SLAVES option will throw exception #1142

Closed
Barbery opened this issue Mar 31, 2017 · 3 comments · Fixed by #2459
Closed
Assignees

Comments

@Barbery
Copy link
Contributor

Barbery commented Mar 31, 2017

Info:
phpredis: lastest develop branch
redis-server: 3.2.1 and 3.0.7
system: ubuntu-14.04 64bit

If I use RedisCluster::FAILOVER_DISTRIBUTE option, that all is fine. But if I use RedisCluster::FAILOVER_DISTRIBUTE_SLAVES option, it will throw exception:

"Timed out attempting to find data in the correct node!"

Here is the example code, you can test it.

<?php
$servers = [
    '192.168.10.10:6383',
    '192.168.10.10:6384',
    '192.168.10.10:6385',
];
$readTimeout  = $timeout  = 3;
$persistent   = false;
$RedisCluster = new RedisCluster(null, $servers, $readTimeout, $timeout, $persistent);
$RedisCluster->setOption(RedisCluster::OPT_SLAVE_FAILOVER, RedisCluster::FAILOVER_DISTRIBUTE_SLAVES);
$lua = <<<'LUA'
local isSuccess = 1
local offset = 0
for i = 1, #KEYS, 1 do
    redis.call('setnx', KEYS[i], ARGV[i+offset+1])
    if redis.call('incrby', KEYS[i], math.abs(ARGV[i+offset])) > tonumber(ARGV[i+offset+2]) then
        isSuccess = 0
        break
    end
    offset = offset + 2
end

return isSuccess;
LUA;

for ($i = 0; $i < 100; $i++) {
    $RedisCluster->get($i);
    // if run the below code, all is fine
    // $RedisCluster->set($i, $i); 
}

try {
    $keys = ['counter:product:{1}:test'];
    $argv = [1, 10, 99];
    var_dump($RedisCluster->eval($lua, array_merge($keys, $argv), count($keys)));
} catch (Exception $e) {
    echo $e->getMessage();
}
@Barbery
Copy link
Contributor Author

Barbery commented Mar 31, 2017

I guess the problem is FAILOVER_DISTRIBUTE_SLAVES redirect the connection to the slave, then run eval it can't redirect to the right master node to execute the command

@piotr-lwks
Copy link

piotr-lwks commented Feb 6, 2023

I just encountered this too on a simple GET key request.
Can confirm that reverting it to FAILOVER_DISTRIBUTE fixes the problem.

@michael-grunder michael-grunder self-assigned this Feb 6, 2023
@michael-grunder
Copy link
Member

I'll take a look. I think we'll need to preclude distributing to replicas unless the command being invoked is EVAL_RO.

kjoe added a commit to kjoe/phpredis that referenced this issue Mar 17, 2024
When a node timeout occurs, then phpredis will try to connect to another
node, whose answer probably will be MOVED redirect. After this we need
more time to accomplish the redirection, otherwise we get "Timed out
attempting to find data in the correct node" error message.

Fixes phpredis#795 phpredis#888 phpredis#1142 phpredis#1385 phpredis#1633 phpredis#1707 phpredis#1811 phpredis#2407
michael-grunder pushed a commit that referenced this issue Mar 25, 2024
When a node timeout occurs, then phpredis will try to connect to another
node, whose answer probably will be MOVED redirect. After this we need
more time to accomplish the redirection, otherwise we get "Timed out
attempting to find data in the correct node" error message.

Fixes #795 #888 #1142 #1385 #1633 #1707 #1811 #2407
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants