with or without ShardedJedisPool get diffrent shard result
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.
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)
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
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?
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!
ShardedJedis(shards) constructor uses murmur hash when ShardedJedisPool(config, shards) - md5 meaning impossible to fix for backwards compatibility reasons
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 :)