Closed baoyongan closed 7 years ago
这个路径配的对么? '/zk/codis/db_test_codis_cluster/proxy/foo' 为什么最后有个'foo'?
我用zkCli.sh 查看了三台zookeeper 的路劲,我在代码上这样的curatorClient("66.0.34.24:2181,66.0.34.23:2181,66.0.34.217:2181",30000).zkProxyDir("/zk/codis/db_test_codis_cluster/proxy") 的所以我查看了ls /zk/codis/db_test_codis_cluster/proxy 下面是[proxy_1,proxy_2] 根本没有foo.所以我也很奇怪怎么会有个foo
import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory;
import redis.clients.jedis.JedisPoolConfig;
import com.wandoulabs.jodis.JedisResourcePool; import com.wandoulabs.jodis.RoundRobinJedisPool;
/**
*/ public class RedisPoolSingleInstance {
private JedisResourcePool pool = null; private String zkServerUri; // ZooKeeper服务URI private String zkProxyDir; // ZooKeeper管理的数据结构路劲 private int zkSessionTimeoutMs; //ZooKeeper session timeout in milliseconds private boolean blockWhenExhausted; // 连接耗尽时是否报异常,false 报异常,true 阻塞知道超时,默认是true private Long maxWaitMillis; // 获取连接等待最大毫秒数,-1永不超时。 private int maxIdle; // 最大空闲连接数,默认是8 private int minIdle; // 最小空闲连接数,默认0 private int maxTotal; // 最大连接数 private boolean testOnBorrow; // 获取连接时检测有效性,默认false
private final Log log = LogFactory.getLog(getClass());
private RedisPoolSingleInstance() { }
public synchronized JedisResourcePool getRedisPool() { if (null == pool) { pool = getJedisPo(); } return pool; }
private JedisResourcePool getJedisPo() {
try {
//创建jedis池 配置参数
JedisPoolConfig poolConfig = new JedisPoolConfig();
poolConfig.setBlockWhenExhausted(blockWhenExhausted);
poolConfig.setMaxIdle(maxIdle);
poolConfig.setMinIdle(minIdle);
poolConfig.setMaxTotal(maxTotal);
poolConfig.setMaxWaitMillis(maxWaitMillis);
poolConfig.setTestOnBorrow(testOnBorrow);
log.debug("ZookServer-->" +"zkServerUri: "+zkServerUri+"\r\nzkProxyDir: "+zkProxyDir);
log.debug("RedisPoolConfig-->" +"blockWhenExhausted: "+blockWhenExhausted+"\r\nmaxIdle: "+maxIdle+"\r\nminIdle: "+minIdle+"\r\nmaxTotal: "+maxTotal+"\r\nmaxWaitMillis: "+maxWaitMillis+"\r\ntestOnBorrow: "+testOnBorrow);
pool = RoundRobinJedisPool.create().curatorClient(zkServerUri,zkSessionTimeoutMs).zkProxyDir(zkProxyDir).poolConfig(poolConfig).build();
} catch (Exception e) {
log.error("RedisPoolSingleInstance: init pool error:", e);
}
return pool;
}
public void setBlockWhenExhausted(boolean blockWhenExhausted) { this.blockWhenExhausted = blockWhenExhausted; }
public void setMaxWaitMillis(Long maxWaitMillis) { this.maxWaitMillis = maxWaitMillis; }
public void setMaxIdle(int maxIdle) { this.maxIdle = maxIdle; }
public void setMinIdle(int minIdle) { this.minIdle = minIdle; }
public void setMaxTotal(int maxTotal) { this.maxTotal = maxTotal; }
public void setTestOnBorrow(boolean testOnBorrow) { this.testOnBorrow = testOnBorrow; }
public void setZkServerUri(String zkServerUri) { this.zkServerUri = zkServerUri; }
public void setZkProxyDir(String zkProxyDir) { this.zkProxyDir = zkProxyDir; }
public void setZkSessionTimeoutMs(int zkSessionTimeoutMs) { this.zkSessionTimeoutMs = zkSessionTimeoutMs; }
}
log.debug("ZookServer-->" +"zkServerUri: "+zkServerUri+"\r\nzkProxyDir: "+zkProxyDir);
log.debug("RedisPoolConfig-->" +"blockWhenExhausted: "+blockWhenExhausted+"\r\nmaxIdle: "+maxIdle+"\r\nminIdle: "+minIdle+"\r\nmaxTotal: "+maxTotal+"\r\nmaxWaitMillis: "+maxWaitMillis+"\r\ntestOnBorrow: "+testOnBorrow);
这两行日志输出的结果对么?
对的。。。跟我写的测试例子的参数一样,测试例子没有加设置poolConfig。 package com.baozi.test;
import redis.clients.jedis.Jedis;
import com.wandoulabs.jodis.JedisResourcePool; import com.wandoulabs.jodis.RoundRobinJedisPool;
public class TestJodis { public static void main(String[] args) { JedisResourcePool jedisPool = RoundRobinJedisPool.create().curatorClient("66.0.34.24:2181,66.0.34.23:2181,66.0.34.217:2181",10000).zkProxyDir("/zk/codis/db_test_codis_cluster/proxy").build(); Jedis jedis =jedisPool.getResource(); jedis.set("foo", "bar"); String value = jedis.get("foo"); jedis.del("foo"); jedis.close();
Jedis jedis1 =jedisPool.getResource();
jedis1.set("foo1", "barssss");
String value1 = jedis1.get("foo1");
System.out.println(value1);
jedis1.del("foo1");
jedis1.close();
Jedis jedis2 =jedisPool.getResource();
jedis2.set("foo1", "barssss");
String value2 = jedis2.get("foo1");
System.out.println(value2);
jedis2.del("foo1");
jedis2.close();
}
}
你把日志贴一下?
2016-03-15 16:19:50.102 [taskExecutor-7] DEBUG org.springframework.beans.CachedIntrospectionResults - Not strongly caching class [com.csii.rdb.mgmt.action.RedisCacheControl] because it is not cache-safe
2016-03-15 16:19:50.102 [taskExecutor-7] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Invoking init method 'createPool' on bean with name 'RedisCacheControl'
2016-03-15 16:19:50.104 [taskExecutor-7] DEBUG com.csii.rdb.mgmt.action.RedisPoolSingleInstance - ZookServer-->zkServerUri: 66.0.34.24:2181,66.0.34.23:2181,66.0.34.217:2181
zkProxyDir: /zk/codis/db_test_codis_cluster/proxy
2016-03-15 16:19:50.104 [taskExecutor-7] DEBUG com.csii.rdb.mgmt.action.RedisPoolSingleInstance - RedisPoolConfig-->blockWhenExhausted: true
maxIdle: 500
minIdle: 0
maxTotal: 100
maxWaitMillis: 1000
testOnBorrow: true
2016-03-15 16:20:51.926 [taskExecutor-7] ERROR com.csii.rdb.mgmt.action.RedisPoolSingleInstance - RedisPoolSingleInstance: init pool error:
redis.clients.jedis.exceptions.JedisException: org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /zk/codis/db_test_codis_cluster/proxy/foo
at com.wandoulabs.jodis.RoundRobinJedisPool.
你看着日志,有帮助吗
我用spring-DM 集成jodis之后,本地代码测试正常,服务器报错。开始以为环境问题,我用测试例子打了个执行jar包,在服务器执行没问题。环境上应该没有问题的。。可以帮看一下我的错误,给我一个查找错误的方向吗? 报错如下 Caused by: org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /zk/codis/db_test_codis_cluster/proxy/foo at org.apache.zookeeper.KeeperException.create(KeeperException.java:99) [null:na] at org.apache.zookeeper.KeeperException.create(KeeperException.java:51) [null:na] at org.apache.zookeeper.ZooKeeper.exists(ZooKeeper.java:1045) [null:na] at org.apache.curator.framework.imps.ExistsBuilderImpl$3.call(ExistsBuilderImpl.java:226) [null:na] at org.apache.curator.framework.imps.ExistsBuilderImpl$3.call(ExistsBuilderImpl.java:215) [null:na] at org.apache.curator.RetryLoop.callWithRetry(RetryLoop.java:107) [null:na] at org.apache.curator.framework.imps.ExistsBuilderImpl.pathInForegroundStandard(ExistsBuilderImpl.java:212) [null:na] at org.apache.curator.framework.imps.ExistsBuilderImpl.pathInForeground(ExistsBuilderImpl.java:205) [null:na] at org.apache.curator.framework.imps.ExistsBuilderImpl.forPath(ExistsBuilderImpl.java:168) [null:na] at org.apache.curator.framework.imps.ExistsBuilderImpl.forPath(ExistsBuilderImpl.java:39) [null:na] at org.apache.curator.framework.imps.CuratorFrameworkImpl.createContainers(CuratorFrameworkImpl.java:193) [null:na] at org.apache.curator.framework.recipes.cache.PathChildrenCache.ensurePath(PathChildrenCache.java:616) [null:na] at org.apache.curator.framework.recipes.cache.PathChildrenCache.rebuild(PathChildrenCache.java:322) [null:na] at org.apache.curator.framework.recipes.cache.PathChildrenCache.start(PathChildrenCache.java:299) [null:na] at com.wandoulabs.jodis.RoundRobinJedisPool.(RoundRobinJedisPool.java:242) [null:na]
... 56 common frames omitted