gpt4 book ai didi

cassandra - 如何使用 Hector 重新连接到 Cassandra?

转载 作者:行者123 更新时间:2023-12-03 10:31:44 29 4
gpt4 key购买 nike

我有以下代码:

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 ] Downed Host Retry service started with >queue size 128 and retry delay 5s [15:11:07] INFO [JmxMonitor ] Registering JMX >me.prettyprint.cassandra.service_ASG:ServiceType=hector,MonitorType=hector [15:11:17] ERROR [HThriftClient ] Could not flush transport (to be expected >if the pool is shutting down) in close for client: CassandraClient org.apache.thrift.transport.TTransportException: java.net.SocketException: Broken pipe at >org.apache.thrift.transport.TIOStreamTransport.write(TIOStreamTransport.java:147) at org.apache.thrift.transport.TFramedTransport.flush(TFramedTransport.java:156) at >me.prettyprint.cassandra.connection.client.HThriftClient.close(HThriftClient.java:98) at >me.prettyprint.cassandra.connection.client.HThriftClient.close(HThriftClient.java:26) at >me.prettyprint.cassandra.connection.HConnectionManager.closeClient(HConnectionManager.java:308) at >me.prettyprint.cassandra.connection.HConnectionManager.operateWithFailover(HConnectionManager.java:257) at >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) at com.app.App.main(App.java:40) Caused by: java.net.SocketException: Broken pipe at java.net.SocketOutputStream.socketWrite0(Native Method) at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109) at java.net.SocketOutputStream.write(SocketOutputStream.java:153) at >org.apache.thrift.transport.TIOStreamTransport.write(TIOStreamTransport.java:145) ... 9 more [15:11:17] ERROR [HConnectionManager ] MARK HOST AS DOWN TRIGGERED for host >localhost(127.0.0.1):9160 [15:11:17] ERROR [HConnectionManager ] Pool state on shutdown: >:{localhost(127.0.0.1):9160}; IsActive?: true; Active: 1; Blocked: 0; Idle: 15; NumBeforeExhausted: 49 [15:11:17] INFO [ConcurrentHClientPool ] Shutdown triggered on :{localhost(127.0.0.1):9160} [15:11:17] INFO [ConcurrentHClientPool ] Shutdown complete on :{localhost(127.0.0.1):9160} [15:11:17] INFO [CassandraHostRetryService ] Host detected as down was added to retry queue: localhost(127.0.0.1):9160 [15:11:17] WARN [HConnectionManager ] Could not fullfill request on this host CassandraClient [15:11:17] WARN [HConnectionManager ] Exception: me.prettyprint.hector.api.exceptions.HectorTransportException: org.apache.thrift.transport.TTransportException: java.net.SocketException: Broken pipe at >me.prettyprint.cassandra.connection.client.HThriftClient.getCassandra(HThriftClient.java:82) at >me.prettyprint.cassandra.connection.HConnectionManager.operateWithFailover(HConnectionManager.java:236) at >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) at com.app.App.main(App.java:40) Caused by: org.apache.thrift.transport.TTransportException: java.net.SocketException: Broken pipe at org.apache.thrift.transport.TIOStreamTransport.write(TIOStreamTransport.java:147) at org.apache.thrift.transport.TFramedTransport.flush(TFramedTransport.java:157) at org.apache.cassandra.thrift.Cassandra$Client.send_set_keyspace(Cassandra.java:466) at org.apache.cassandra.thrift.Cassandra$Client.set_keyspace(Cassandra.java:455) at >me.prettyprint.cassandra.connection.client.HThriftClient.getCassandra(HThriftClient.java:78) ... 5 more Caused by: java.net.SocketException: Broken pipe at java.net.SocketOutputStream.socketWrite0(Native Method) at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109) at java.net.SocketOutputStream.write(SocketOutputStream.java:153) at >org.apache.thrift.transport.TIOStreamTransport.write(TIOStreamTransport.java:145) ... 9 more [15:11:17] INFO [HConnectionManager ] Client CassandraClient released to inactive or dead pool. Closing. [15:11:17] INFO [HConnectionManager ] Client CassandraClient released to inactive or dead pool. Closing. [15:11:17] INFO [HConnectionManager ] Added host localhost(127.0.0.1):9160 to pool

最佳答案

你已经设置了-

conf.setRetryDownedHostsDelayInSeconds(5);

重启后尽量等待5秒以上。此外,您可能需要升级。

您设置的 thrift_max_message_length_in_mb 大小是多少?

亲切的问候。

关于cassandra - 如何使用 Hector 重新连接到 Cassandra?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10550391/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com