我正在使用客户端写入cassandra(api:com.datastax.driver.core) 如果在连接完成后关闭cassandra clustures。我的日志中出现以下错误Cassandra:更改重试尝试次数和重试延迟
2015-11-05 12:08:21,667 ERROR [Reconnection-1] com.datastax.driver.core.ControlConnection - [Control connection] Cannot connect to any host, scheduling retry in 1000 milliseconds
.
.
.
2015-11-05 14:15:24,847 DEBUG [Reconnection-0] com.datastax.driver.core.Connection - Connection[/10.75.43.251:9042-24, inFlight=0, closed=false] Error connecting to /10.75.43.251:9042 (Connection refused: /10.75.43.251:9042)
2015-11-05 14:15:24,847 DEBUG [Reconnection-0] com.datastax.driver.core.Connection - Defuncting connection to /10.75.43.251:9042
com.datastax.driver.core.TransportException: [/10.75.43.251:9042] Cannot connect
at com.datastax.driver.core.Connection.<init>(Connection.java:104)
at com.datastax.driver.core.Connection$Factory.open(Connection.java:544)
at com.datastax.driver.core.Cluster$Manager$5.tryReconnect(Cluster.java:1652)
at com.datastax.driver.core.AbstractReconnectionHandler.run(AbstractReconnectionHandler.java:124)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.ConnectException: Connection refused: /10.75.43.251:9042
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:739)
at com.datastax.shaded.netty.channel.socket.nio.NioClientBoss.connect(NioClientBoss.java:150)
at com.datastax.shaded.netty.channel.socket.nio.NioClientBoss.processSelectedKeys(NioClientBoss.java:105)
at com.datastax.shaded.netty.channel.socket.nio.NioClientBoss.process(NioClientBoss.java:79)
at com.datastax.shaded.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:318)
at com.datastax.shaded.netty.channel.socket.nio.NioClientBoss.run(NioClientBoss.java:42)
at com.datastax.shaded.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
at com.datastax.shaded.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
... 3 more
2015-11-05 14:15:24,847 DEBUG [New I/O worker #8] com.datastax.driver.core.Connection - Connection[/10.75.43.251:9042-24, inFlight=0, closed=true] closing connection
2015-11-05 14:15:24,847 DEBUG [New I/O boss #9] com.datastax.driver.core.Connection - Connection[/10.75.43.251:9042-24, inFlight=0, closed=false] connection error
java.net.ConnectException: Connection refused: /10.75.43.251:9042
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:739)
at com.datastax.shaded.netty.channel.socket.nio.NioClientBoss.connect(NioClientBoss.java:150)
at com.datastax.shaded.netty.channel.socket.nio.NioClientBoss.processSelectedKeys(NioClientBoss.java:105)
at com.datastax.shaded.netty.channel.socket.nio.NioClientBoss.process(NioClientBoss.java:79)
at com.datastax.shaded.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:318)
at com.datastax.shaded.netty.channel.socket.nio.NioClientBoss.run(NioClientBoss.java:42)
at com.datastax.shaded.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
at com.datastax.shaded.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
2015-11-05 14:15:24,849 DEBUG [Reconnection-0] com.datastax.driver.core.Cluster - Failed reconnection to /10.75.43.251:9042 ([/10.75.43.251:9042] Cannot connect), scheduling retry in 600000 milliseconds
2015-11-05 14:15:24,849 DEBUG [Cassandra Java Driver worker-44] com.datastax.driver.core.Cluster - Host /10.75.43.251:9042 is DOWN
2015-11-05 14:15:24,849 DEBUG [Cassandra Java Driver worker-44] com.datastax.driver.core.Cluster - Aborting onDown because a reconnection is running on DOWN host /10.75.43.251:9042
我试着设置ReconnectionPolicy。这使我可以控制重试延迟。 但是重试尝试(说我想要3)仍然不在我的控制之下。
我试图ConstantReconnectPolicy(其中仅给出reconnectDelay来提供,其中的工作。但我也希望重试被控制。 我试图像
private volatile int currentRetryCount;
class MyReconnectionPolicy implements ReconnectionPolicy {
@Override
public ReconnectionSchedule newSchedule() {
return new MyReconnectionSchedule();
}
}
class MyReconnectionSchedule implements ReconnectionSchedule {
@Override
public long nextDelayMs() {
if (++currentRetryCount < maxReconnectAttempts) {
return retryIntervalInMilliSec;
} else {
// try {
throw new Error("Exception Occurred. Retry limits exhausted.");
// } catch (Exception e) {
// logger.error("Exception Occurred!");
// return Long.MAX_VALUE;
// }
}
}
}
某事,这也没有这个例外不会传播到主程序中,因为它不会抛出异常。
什么可能是api(如果暴露)或开放的bug(如果有的话,找不到)。
谢谢!
我试图关闭连接。但nextDelayMs()方法不允许我抛出异常,因此在返回Long.MAX_VAL的catch中。 – nandini
不要抛出异常,直接返回值。 –