jedis icon indicating copy to clipboard operation
jedis copied to clipboard

with or without ShardedJedisPool get diffrent shard result

Open jinghong opened this issue 15 years ago • 5 comments

With same JedisShardInfos, using ShardedJedisPool to set data, directly using ShardedJedis jedis = new ShardedJedis(shards); to get data, much keys missed, when using ShardedJedisPool to get data, that's all right.

jinghong avatar Feb 12 '11 10:02 jinghong

So you are saying that this test won't pass?

ShardedJedis jedis = new ShardedJedis(info); ShardedJedisPool pool = new ShardedJedisPool(new Config(), info);

assertEquals(jedis.getShard("somekey"), pool.getResource().getShard("somekey));

(assuming equals are correctly defined)

xetorthio avatar Feb 12 '11 22:02 xetorthio

please see my test program

package testshard; import java.util.ArrayList; import java.util.List; import org.apache.commons.pool.impl.GenericObjectPool.Config; import redis.clients.jedis.JedisShardInfo; import redis.clients.jedis.ShardedJedis; import redis.clients.jedis.ShardedJedisPool; public class TestShard { public static String[] ss = {"acs:user:jdjsak","acs:user:473892","acs:user:jd832","acs:user:kids88","acs:user:kjekKmmjmdj","acs:user:eiiw","acs:user:9mkkdk","acs:user:kkid","acs:user:wkdsl22"}; public static ShardedJedisPool pool; public static List shards = new ArrayList(); static { JedisShardInfo jsi0 = new JedisShardInfo("192.168.0.90", 6379, 2000); JedisShardInfo jsi1 = new JedisShardInfo("192.168.0.90", 6380, 2000); JedisShardInfo jsi2 = new JedisShardInfo("192.168.0.90", 6381, 2000); JedisShardInfo jsi3 = new JedisShardInfo("192.168.0.90", 6382, 2000); shards.add(jsi0); shards.add(jsi1); shards.add(jsi2); shards.add(jsi3);

    Config config = new Config();
    config.maxIdle=20;
    config.maxActive=20;
    config.maxWait=1000;
    config.testOnBorrow=true;
    config.testOnReturn=true;
    config.testWhileIdle=true;

    pool = new ShardedJedisPool(config, shards);
}

public static void main(String[] args) {
    insertPool();
    selectPool();
    System.out.println("--------");
    selectNoPool();
}

private static void insertPool(){
    ShardedJedis jedis = TestShard.pool.getResource();
    for(String s:ss){
        jedis.set(s, "test");
    }
    TestShard.pool.returnResource(jedis);
}
private static void selectPool(){
    ShardedJedis jedis = TestShard.pool.getResource();
    for(String s:ss){
        System.out.println(jedis.get(s));
    }
    TestShard.pool.returnResource(jedis);
}
private static void selectNoPool(){
    ShardedJedis jedis = new ShardedJedis(shards);
    for(String s:ss){
        System.out.println(jedis.get(s));
    }
}

}


result is test test test test test test test test

test

test null null test null test test null null

I think it should be all 'test', am I took something wrong?

jinghong avatar Feb 14 '11 02:02 jinghong

Ok perfect. This definitely a good way to start hunting down this bug. I will make some tests tomorrow and let you know. Btw sorry about the delay, lately work is crazy!

xetorthio avatar Feb 17 '11 04:02 xetorthio

ShardedJedis(shards) constructor uses murmur hash when ShardedJedisPool(config, shards) - md5 meaning impossible to fix for backwards compatibility reasons

grdmitro avatar Mar 25 '11 13:03 grdmitro

Oh damn! You are right, this is a stupid bug. I just pushed to master the fix so we are consistent. Everywhere we will default to Murmur. I know this is not backwards compatible, but next version of Jedis will be 1.6 which has a lot of incompatibilities, so it is a good opportunity to make these changes. Thanks for finding this, closing the issue now :)

xetorthio avatar Mar 25 '11 13:03 xetorthio