CodisLabs / jodis

A java client for codis based on Jedis and Curator
MIT License
217 stars 97 forks source link

使用jodis报错,很奇怪,用命令行连接codis写入操作没有问题 #36

Closed wy1981105 closed 7 years ago

wy1981105 commented 7 years ago

JedisResourcePool jedisPool = RoundRobinJedisPool.create() .curatorClient("127.0.0.1:19000", 30000).zkProxyDir("/Users/lili/Documents/jodis").build(); try (Jedis jedis = jedisPool.getResource()) { jedis.set("foo", "bar"); String value = jedis.get("foo"); System.out.println(value); } 提示如下错误 [main-SendThread(127.0.0.1:19000)] INFO org.apache.zookeeper.ClientCnxn - Opening socket connection to server 127.0.0.1/127.0.0.1:19000. Will not attempt to authenticate using SASL (unknown error) [main-SendThread(127.0.0.1:19000)] INFO org.apache.zookeeper.ClientCnxn - Socket connection established to 127.0.0.1/127.0.0.1:19000, initiating session [main] ERROR org.apache.curator.ConnectionState - Connection timed out for connection string (127.0.0.1:19000) and timeout (15000) / elapsed (15086) org.apache.curator.CuratorConnectionLossException: KeeperErrorCode = ConnectionLoss at org.apache.curator.ConnectionState.checkTimeouts(ConnectionState.java:195) at org.apache.curator.ConnectionState.getZooKeeper(ConnectionState.java:87) at org.apache.curator.CuratorZookeeperClient.getZooKeeper(CuratorZookeeperClient.java:115) at io.codis.jodis.TestMain.main(TestMain.java:11) [main-SendThread(127.0.0.1:19000)] WARN org.apache.zookeeper.ClientCnxn - Client session timed out, have not heard from server in 30002ms for sessionid 0x0

但是我用命令行操作 ./redis-cli -h 127.0.0.1 -p 19000 127.0.0.1:19000> get ju "xian" 127.0.0.1:19000> get ju "xian" 127.0.0.1:19000> get ju "xian" 是没有问题

我的zookeeper是用的是3.4.10版本 libs目录里commons-pool2-2.3 curator-client-2.9.1 curator-framework-2.9.1 curator-recipes-2.9.1 guava-16.0.1 jackson-annotations-2.8.8 jackson-core-2.8.8 jackson-databind-2.8.8 jedis-2.8.0 jsr305-1.3.9 slf4j-api-1.7.25 slf4j-simple-1.7.25 zookeeper-3.4.10 的jar包

请牛人看看

Apache9 commented 7 years ago

所以你19000端口上启动的是codis proxy?

curatorClient("xxx", 30000), xxx那里写的是zk的地址,不是codis proxy的地址

wy1981105 commented 7 years ago

改成2181,但是报如下错误 [main-SendThread(127.0.0.1:2181)] INFO org.apache.zookeeper.ClientCnxn - Opening socket connection to server 127.0.0.1/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error) [main-SendThread(127.0.0.1:2181)] INFO org.apache.zookeeper.ClientCnxn - Socket connection established to 127.0.0.1/127.0.0.1:2181, initiating session [main-SendThread(127.0.0.1:2181)] INFO org.apache.zookeeper.ClientCnxn - Session establishment complete on server 127.0.0.1/127.0.0.1:2181, sessionid = 0x15b64c01d4c0007, negotiated timeout = 30000 [main-EventThread] INFO org.apache.curator.framework.state.ConnectionStateManager - State change: CONNECTED Exception in thread "main" redis.clients.jedis.exceptions.JedisException: Proxy list empty at io.codis.jodis.RoundRobinJedisPool.getResource(RoundRobinJedisPool.java:199) at io.codis.jodis.TestMain.main(TestMain.java:12)

Apache9 commented 7 years ago

那个proxyDir传的对嘛?那个是codis proxy在zk上注册的路径

echokk11 commented 7 years ago

我也遇到这个问题 zk注册地址是 /codis3/codis-demo/proxy JedisResourcePool jedisPool = RoundRobinJedisPool.create() .curatorClient("x.x.x.x:2181", 30000).zkProxyDir("/codis3/codis-demo/proxy").build(); 但是返回Exception in thread "main" redis.clients.jedis.exceptions.JedisException: Proxy list empty ip地址是对的 我用zkCli可以连 也看到proxy下面有节点

Apache9 commented 7 years ago

这是parse节点内容出错了,把那个节点里的内容贴一下?

echokk11 commented 7 years ago

[zk: x.x.x.x:2181(CONNECTED) 18] get /codis3/codis-demo/proxy/proxy-310bb7d8889d16620478fb24717427df { "id": 1, "token": "310bb7d8889d16620478fb24717427df", "start_time": "2017-04-11 15:16:50.658110625 +0800 CST", "admin_addr": "iZ23d155t9zZ:11080", "proto_type": "tcp4", "proxy_addr": "iZ23d155t9zZ:19000", "product_name": "codis-demo", "pid": 23313, "pwd": "/alidata/codis/gopath/src/github.com/CodisLabs/codis", "sys": "Linux iZ23d155t9zZ 2.6.32-642.11.1.el6.x86_64 #1 SMP Fri Nov 18 19:25:05 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux", "hostname": "iZ23d155t9zZ", "datacenter": "" }

echokk11 commented 7 years ago

一直都是返回 Exception in thread "main" java.io.IOException: Proxy list empty at com.wandoulabs.nedis.codis.RoundRobinNedisClientPool.acquire(RoundRobinNedisClientPool.java:229) at com.wandoulabs.nedis.util.NedisUtils$Invoker.invoke(NedisUtils.java:220) at com.sun.proxy.$Proxy5.set(Unknown Source)

Apache9 commented 7 years ago

@spinlock 这个应该是codis proxy没有打开jodis兼容导致的?

wy1981105 commented 7 years ago

@Apache9

[zk: 127.0.0.1:2181(CONNECTED) 3] ls /codis3/codis-demo/proxy [proxy-503d4bf48dce7b2672467e7825ed98e1]

JedisResourcePool jedisPool = RoundRobinJedisPool.create() .curatorClient("127.0.0.1:2181", 30000).zkProxyDir("/codis3/codis-demo/proxy").build(); try (Jedis jedis = jedisPool.getResource()) { jedis.set("foo", "bar"); String value = jedis.get("foo"); System.out.println(value); }

在proxy.toml文件中 odis_name = "zookeeper" jodis_addr = "127.0.0.1:2181" jodis_timeout = "20s" jodis_compatible = false

是这样设置的

但是运行结果是 ] INFO org.apache.zookeeper.ZooKeeper - Initiating client connection, connectString=127.0.0.1:2181 sessionTimeout=30000 watcher=org.apache.curator.ConnectionState@49fc609f [main-SendThread(127.0.0.1:2181)] INFO org.apache.zookeeper.ClientCnxn - Opening socket connection to server 127.0.0.1/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error) [main-SendThread(127.0.0.1:2181)] INFO org.apache.zookeeper.ClientCnxn - Socket connection established to 127.0.0.1/127.0.0.1:2181, initiating session [main-SendThread(127.0.0.1:2181)] INFO org.apache.zookeeper.ClientCnxn - Session establishment complete on server 127.0.0.1/127.0.0.1:2181, sessionid = 0x15b64c01d4c0017, negotiated timeout = 30000 [main-EventThread] INFO org.apache.curator.framework.state.ConnectionStateManager - State change: CONNECTED Exception in thread "main" redis.clients.jedis.exceptions.JedisException: Proxy list empty at io.codis.jodis.RoundRobinJedisPool.getResource(RoundRobinJedisPool.java:199) at io.codis.jodis.TestMain.main(TestMain.java:12)

[zk: 127.0.0.1:2181(CONNECTED) 4] get /codis3/codis-demo/proxy/proxy-503d4bf48dce7b2672467e7825ed98e1 { "id": 1, "token": "503d4bf48dce7b2672467e7825ed98e1", "start_time": "2017-04-13 12:10:36.81957486 +0800 CST", "admin_addr": "192.168.3.109:11080", "proto_type": "tcp4", "proxy_addr": "192.168.3.109:19000", "jodis_path": "/jodis/codis-demo/proxy-503d4bf48dce7b2672467e7825ed98e1", "product_name": "codis-demo", "pid": 1478, "pwd": "/Users/wangyue/go/src/github.com/CodisLabs/codis",

"datacenter": ""

} cZxid = 0x1d23 ctime = Thu Apr 13 12:11:14 CST 2017 mZxid = 0x1d24 mtime = Thu Apr 13 12:11:14 CST 2017 pZxid = 0x1d23 cversion = 0 dataVersion = 1 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 650 numChildren = 0 [zk: 127.0.0.1:2181(CONNECTED) 5]

spinlock commented 7 years ago

不是。

/codis3 路径是用来做集群管理的,服务发现是 /jodis 开始的 路径或者 /zk 开始的。在 jodis 项目首页 readme 写了例子。

On Thu, Apr 13, 2017 at 12:42 Apache9 notifications@github.com wrote:

@spinlock https://github.com/spinlock 这个应该是codis proxy没有打开jodis兼容导致的?

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/CodisLabs/jodis/issues/36#issuecomment-293771367, or mute the thread https://github.com/notifications/unsubscribe-auth/AAsHpc3THQiY5MdvbAqPSrBGTkLFs05-ks5rvZnCgaJpZM4M8NDH .

wy1981105 commented 7 years ago

@spinlock 需要在/目录下建立zk或者jodis目录吗 在根目录下没有发现,只有这几个目录 Applications etc Library home Network installer.failurerequests System net Users opt Volumes private bin sbin cores tmp data usr dev var

wy1981105 commented 7 years ago

已经解决的确需要在根目录下建立/jodis/XX的目录 xx这里是codis-demo.才能发送,接收。 请在文档里详细写明,这个含糊有点问题,还有zookeeper的jar包与服务端要保持一致等。

echokk11 commented 7 years ago

@wy1981105 是在文件系统中建立目录还是zk下面建立啊 我问题依旧

wy1981105 commented 7 years ago

在proxy.toml文件中 odis_name = "zookeeper" jodis_addr = "127.0.0.1:2181" jodis_timeout = "20s" jodis_compatible = false 要设置

echokk11 commented 7 years ago

3q,已经解决。

spinlock commented 7 years ago

两个项目的 readme 我记得都写了的。

On Thu, Apr 13, 2017 at 14:53 codeopps notifications@github.com wrote:

3q,已经解决。

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/CodisLabs/jodis/issues/36#issuecomment-293789153, or mute the thread https://github.com/notifications/unsubscribe-auth/AAsHpRchqrvT3HI0fT7q5Nlz6vxXUfKmks5rvbhRgaJpZM4M8NDH .

jxdw commented 6 years ago

创建了jodis目录,还是报.JedisException: Proxy list empty [zk: localhost:2181(CONNECTED) 7] create /jodis/codis-demo/proxy "10.2.1.31:19000" Created /jodis/codis-demo/proxy