我有以下代码:
StringSerializer ss = StringSerializer.get();
String cf = "TEST";
CassandraHostConfigurator conf = new CassandraHostConfigurator("localhost:9160");
conf.setCassandraThriftSocketTimeout(40000);
conf.setExhaustedPolicy(ExhaustedPolicy.WHEN_EXHAUSTED_BLOCK);
conf.setRetryDownedHostsDelayInSeconds(5);
conf.setRetryDownedHostsQueueSize(128);
conf.setRetryDownedHosts(true);
conf.setLoadBalancingPolicy(new LeastActiveBalancingPolicy());
String key = Long.toString(System.currentTimeMillis());
Cluster cluster = HFactory.getOrCreateCluster("TestCluster", conf);
Keyspace keyspace = HFactory.createKeyspace("TestCluster", cluster);
Mutator<String> mutator = HFactory.createMutator(keyspace, StringSerializer.get()); int count = 0;
while (!"q".equals(new Scanner( System.in).next())) {
try{
mutator.insert(key, cf, HFactory.createColumn("column_" + count, "v_" + count, ss, ss));
count++;
} catch (Exception e) {
e.printStackTrace();
}
}
我可以使用它写一些值,但是当我重新启动cassandra时,它会失败。这是日志:
[15:11:07] INFO [CassandraHostRetryService]已启动主机重试服务&gt;队列大小为128,重试延迟时间为5秒 [15:11:07] INFO [JmxMonitor]注册JMX&gt; me.prettyprint.cassandra.service_ASG:ServiceType = hector,MonitorType = hector [15:11:17]错误[HThriftClient]无法在客户端关闭时刷新传输(预期&gt;如果池正在关闭):CassandraClient org.apache.thrift.transport.TTransportException:java.net.SocketException:Broken pipe at&gt; org.apache.thrift.transport.TIOStreamTransport.write(TIOStreamTransport.java:147) 在org.apache.thrift.transport.TFramedTransport.flush(TFramedTransport.java:156) at&gt; me.prettyprint.cassandra.connection.client.HThriftClient.close(HThriftClient.java:98) at&gt; me.prettyprint.cassandra.connection.client.HThriftClient.close(HThriftClient.java:26) at&gt; me.prettyprint.cassandra.connection.HConnectionManager.closeClient(HConnectionManager.java:308) at&gt; me.prettyprint.cassandra.connection.HConnectionManager.operateWithFailover(HConnectionManager.java:257) at&gt; me.prettyprint.cassandra.model.ExecutingKeyspace.doExecuteOperation(ExecutingKeyspace.java:97) at me.prettyprint.cassandra.model.MutatorImpl.execute(MutatorImpl.java:243) at me.prettyprint.cassandra.model.MutatorImpl.insert(MutatorImpl.java:69) 在com.app.App.main(App.java:40) 引起:java.net.SocketException:管道损坏 at java.net.SocketOutputStream.socketWrite0(Native Method) 在java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109) 在java.net.SocketOutputStream.write(SocketOutputStream.java:153) at&gt; org.apache.thrift.transport.TIOStreamTransport.write(TIOStreamTransport.java:145) ......还有9个 [15:11:17] ERROR [HConnectionManager] MARK主机为主机&gt; localhost(127.0.0.1):9160向下触发 [15:11:17] ERROR [HConnectionManager]关闭时的池状态:&gt;:{localhost(127.0.0.1):9160}; IsActive?:是的;有效:1;被阻止:0;空闲:15; NumBeforeExhausted:49 [15:11:17] INFO [ConcurrentHClientPool]关闭时触发:{localhost(127.0.0.1):9160} [15:11:17] INFO [ConcurrentHClientPool]关闭完成:{localhost(127.0.0.1):9160} [15:11:17] INFO [CassandraHostRetryService]检测到关闭的主机被添加到重试队列:localhost(127.0.0.1):9160 [15:11:17]警告[HConnectionManager]无法在此主机上填写请求CassandraClient [15:11:17]警告[HConnectionManager]例外: me.prettyprint.hector.api.exceptions.HectorTransportException:org.apache.thrift.transport.TTransportException:java.net.SocketException:Broken pipe at&gt; me.prettyprint.cassandra.connection.client.HThriftClient.getCassandra(HThriftClient.java:82) at&gt; me.prettyprint.cassandra.connection.HConnectionManager.operateWithFailover(HConnectionManager.java:236) at&gt; me.prettyprint.cassandra.model.ExecutingKeyspace.doExecuteOperation(ExecutingKeyspace.java:97) at me.prettyprint.cassandra.model.MutatorImpl.execute(MutatorImpl.java:243) at me.prettyprint.cassandra.model.MutatorImpl.insert(MutatorImpl.java:69) 在com.app.App.main(App.java:40) 引起:org.apache.thrift.transport.TTransportException:java.net.SocketException:Broken pipe 在org.apache.thrift.transport.TIOStreamTransport.write(TIOStreamTransport.java:147) 在org.apache.thrift.transport.TFramedTransport.flush(TFramedTransport.java:157) 在org.apache.cassandra.thrift.Cassandra $ Client.send_set_keyspace(Cassandra.java:466) 在org.apache.cassandra.thrift.Cassandra $ Client.set_keyspace(Cassandra.java:455) at&gt; me.prettyprint.cassandra.connection.client.HThriftClient.getCassandra(HThriftClient.java:78) ......还有5个 引起:java.net.SocketException:管道损坏 at java.net.SocketOutputStream.socketWrite0(Native Method) 在java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109) 在java.net.SocketOutputStream.write(SocketOutputStream.java:153) at&gt; org.apache.thrift.transport.TIOStreamTransport.write(TIOStreamTransport.java:145) ......还有9个 [15:11:17] INFO [HConnectionManager]客户端CassandraClient发布到非活动或死池。关闭。 [15:11:17] INFO [HConnectionManager]客户端CassandraClient发布到非活动或死池。关闭。 [15:11:17] INFO [HConnectionManager]添加了主机localhost(127.0.0.1):9160到池
答案 0 :(得分:2)
你已经设置 -
conf.setRetryDownedHostsDelayInSeconds(5);
尝试在重启后等待超过5秒钟。 此外,您可能需要升级。
您设置的 thrift_max_message_length_in_mb 的大小是多少?
亲切的问候。