java - spymemcached java客户端故障处理无法正常工作: membase server

标签 java spymemcached membase

我正在使用 aspymemcached java 客户端来评论 membase 服务器:

 public static void main(String[] args) throws Exception{
        MemcachedClient client = null;
        try {
            URI server1 = new URI("http://192.168.100.111:8091/pools");  //primary 
            URI server2 = new URI("http://127.0.0.1:8091/pools"); //secondry 
            ArrayList<URI> serverList = new ArrayList<URI>();
            serverList.add(server1);
            serverList.add(server2);
            client = new MemcachedClient(serverList, "bucketName", ""); 
            client.set("spoon", 50000, "Hello World!");  //after this line i am going to down server 1 (192.168.100.111:8091/pools)
            Thread.sleep(35000);
            Object obj = client.get("spoon"); // on excetuting this line value should returns from server 2
        }  catch (Exception e) {
            log.error("Exception in initializing membase connection:" + e.getMessage(), e);
        }
 }

我有 2 个 membase 服务器在复制上运行。现在,如果主(server1)节点出现故障,则客户端无法从辅助节点(server2)读取值,并且我收到以下错误:

2017-03-20 07:51:55,655 ERROR [stderr] (Memcached IO over {MemcachedConnection to /127.0.0.1:8091 /192.168.100.111:8091})   at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
2017-03-20 07:51:55,655 ERROR [stderr] (Memcached IO over {MemcachedConnection to /127.0.0.1:8091 /192.168.100.111:8091})   at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
2017-03-20 07:51:55,655 ERROR [stderr] (Memcached IO over {MemcachedConnection to /127.0.0.1:8091 /192.168.100.111:8091})   at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:407)
2017-03-20 07:51:55,655 ERROR [stderr] (Memcached IO over {MemcachedConnection to /127.0.0.1:8091 /192.168.100.111:8091})   at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:275)
2017-03-20 07:51:55,655 ERROR [stderr] (Memcached IO over {MemcachedConnection to /127.0.0.1:8091 /192.168.100.111:8091})   at net.spy.memcached.MemcachedClient.run(MemcachedClient.java:2030)
2017-03-20 07:51:55,656 ERROR [stderr] (Memcached IO over {MemcachedConnection to /127.0.0.1:8091 /192.168.100.111:8091}) 2017-03-20 07:51:55.656 WARN net.spy.memcached.MemcachedConnection:  Closing, and reopening {QA sa=/192.168.100.111:8091, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0}, attempt 5.
2017-03-20 07:52:04,549 ERROR [stderr] (Memcached IO over {MemcachedConnection to /127.0.0.1:8091 /192.168.100.111:8091}) 2017-03-20 07:52:04.549 INFO net.spy.memcached.MemcachedConnection:  Reconnecting {QA sa=/192.168.100.111:8091, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0}
2017-03-20 07:52:05,542 ERROR [stderr] (Memcached IO over {MemcachedConnection to /127.0.0.1:8091 /192.168.100.111:8091}) 2017-03-20 07:52:05.542 INFO net.spy.memcached.MemcachedConnection:  Connection state changed for sun.nio.ch.SelectionKeyImpl@58b50eaf
2017-03-20 07:52:05,542 ERROR [stderr] (Memcached IO over {MemcachedConnection to /127.0.0.1:8091 /192.168.100.111:8091}) 2017-03-20 07:52:05.542 INFO net.spy.memcached.MemcachedConnection:  Reconnecting due to failure to connect to {QA sa=/192.168.100.111:8091, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0}
2017-03-20 07:52:05,542 ERROR [stderr] (Memcached IO over {MemcachedConnection to /127.0.0.1:8091 /192.168.100.111:8091}) java.net.ConnectException: Connection refused: no further information
2017-03-20 07:52:05,542 ERROR [stderr] (Memcached IO over {MemcachedConnection to /127.0.0.1:8091 /192.168.100.111:8091})   at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
2017-03-20 07:52:05,542 ERROR [stderr] (Memcached IO over {MemcachedConnection to /127.0.0.1:8091 /192.168.100.111:8091})   at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
2017-03-20 07:52:05,542 ERROR [stderr] (Memcached IO over {MemcachedConnection to /127.0.0.1:8091 /192.168.100.111:8091})   at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:407)
2017-03-20 07:52:05,542 ERROR [stderr] (Memcached IO over {MemcachedConnection to /127.0.0.1:8091 /192.168.100.111:8091})   at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:275)
2017-03-20 07:52:05,543 ERROR [stderr] (Memcached IO over {MemcachedConnection to /127.0.0.1:8091 /192.168.100.111:8091})   at net.spy.memcached.MemcachedClient.run(MemcachedClient.java:2030)
2017-03-20 07:52:05,543 ERROR [stderr] (Memcached IO over {MemcachedConnection to /127.0.0.1:8091 /192.168.100.111:8091}) 2017-03-20 07:52:05.543 WARN net.spy.memcached.MemcachedConnection:  Closing, and reopening {QA sa=/192.168.100.111:8091, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0}, attempt 5.
2017-03-20 07:52:20,356 ERROR [stderr] (Memcached IO over {MemcachedConnection to /127.0.0.1:8091 /192.168.100.111:8091}) 2017-03-20 07:52:20.356 INFO net.spy.memcached.MemcachedConnection:  Reconnecting {QA sa=/192.168.100.111:8091, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0}
2017-03-20 07:52:21,356 ERROR [stderr] (Memcached IO over {MemcachedConnection to /127.0.0.1:8091 /192.168.100.111:8091}) 2017-03-20 07:52:21.356 INFO net.spy.memcached.MemcachedConnection:  Connection state changed for sun.nio.ch.SelectionKeyImpl@6fab717a
2017-03-20 07:52:21,356 ERROR [stderr] (Memcached IO over {MemcachedConnection to /127.0.0.1:8091 /192.168.100.111:8091}) 2017-03-20 07:52:21.356 INFO net.spy.memcached.MemcachedConnection:  Reconnecting due to failure to connect to {QA sa=/192.168.100.111:8091, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0}
2017-03-20 07:52:21,356 ERROR [stderr] (Memcached IO over {MemcachedConnection to /127.0.0.1:8091 /192.168.100.111:8091}) java.net.ConnectException: Connection refused: no further information
2017-03-20 07:52:21,356 ERROR [stderr] (Memcached IO over {MemcachedConnection to /127.0.0.1:8091 /192.168.100.111:8091})   at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
2017-03-20 07:52:21,356 ERROR [stderr] (Memcached IO over {MemcachedConnection to /127.0.0.1:8091 /192.168.100.111:8091})   at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
2017-03-20 07:52:21,356 ERROR [stderr] (Memcached IO over {MemcachedConnection to /127.0.0.1:8091 /192.168.100.111:8091})   at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:407)
2017-03-20 07:52:21,356 ERROR [stderr] (Memcached IO over {MemcachedConnection to /127.0.0.1:8091 /192.168.100.111:8091})   at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:275)
2017-03-20 07:52:21,356 ERROR [stderr] (Memcached IO over {MemcachedConnection to /127.0.0.1:8091 /192.168.100.111:8091})   at net.spy.memcached.MemcachedClient.run(MemcachedClient.java:2030)

我的预期行为是,客户端应该从辅助服务器(server2)读取值,而不是重新连接主服务器。

最佳答案

我们使用ConnectionObserver来处理它 看看我的answer

关于java - spymemcached java客户端故障处理无法正常工作: membase server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42920794/

相关文章:

java - Tomcat:java.io.IOException:无法创建目标 "xxx"目录”

java - 通过名称调用服务时,服务因空指针而失败,而在调用休息时则正常工作

java - 文本区 Jmeter 问题

java - Hibernate 4 二级缓存与memcached

java - memcache 无法在多个节点上运行

java - 如何使用 SpyMemcached 客户端关闭 tcp 连接?

spell-checking - 我如何使用 Membase 进行拼写检查?

mysql - 同步 mysql 和 memcached/membase

java - Buckminster 插件分辨率慢