Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cassandra:更改重试尝试次数和重试延迟_Cassandra_Reconnect_Retrypolicy - Fatal编程技术网

Cassandra:更改重试尝试次数和重试延迟

Cassandra:更改重试尝试次数和重试延迟,cassandra,reconnect,retrypolicy,Cassandra,Reconnect,Retrypolicy,我正在使用客户端向cassandra(api:com.datastax.driver.core)写入数据 如果在连接完成后我把卡桑德拉俱乐部弄下来。我的日志中出现以下错误 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 100

我正在使用客户端向cassandra(api:com.datastax.driver.core)写入数据 如果在连接完成后我把卡桑德拉俱乐部弄下来。我的日志中出现以下错误

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
2015-11-05 12:08:21667错误[Reconnection-1]com.datastax.driver.core.ControlConnection-[Control connection]无法连接到任何主机,计划在1000毫秒后重试
.
.
.
2015-11-05 14:15:24847调试[Reconnection-0]com.datastax.driver.core.Connection-连接[/10.75.43.251:9042-24,机上=0,关闭=false]连接到/10.75.43.251:9042时出错(连接被拒绝:/10.75.43.251:9042)
2015-11-05 14:15:24847调试[Reconnection-0]com.datastax.driver.core.Connection-与/10.75.43.251的连接已失效
com.datastax.driver.core.TransportException:[/10.75.43.251:9042]无法连接
位于com.datastax.driver.core.Connection.(Connection.java:104)
位于com.datastax.driver.core.Connection$Factory.open(Connection.java:544)
位于com.datastax.driver.core.Cluster$Manager$5.tryReconnect(Cluster.java:1652)
位于com.datastax.driver.core.AbstractReconnectionHandler.run(AbstractReconnectionHandler.java:124)
位于java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
在java.util.concurrent.FutureTask.run(FutureTask.java:262)处
位于java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)
位于java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)
位于java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
位于java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
运行(Thread.java:745)
原因:java.net.ConnectException:连接被拒绝:/10.75.43.251:9042
在sun.nio.ch.socketchannel.checkConnect(本机方法)
位于sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:739)
位于com.datastax.shaded.netty.channel.socket.nio.NioClientBoss.connect(NioClientBoss.java:150)
位于com.datastax.shaded.netty.channel.socket.nio.NioClientBoss.processSelectedKeys(NioClientBoss.java:105)
位于com.datastax.shaded.netty.channel.socket.nio.NioClientBoss.process(NioClientBoss.java:79)
位于com.datastax.shaded.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:318)
位于com.datastax.shaded.netty.channel.socket.nio.NioClientBoss.run(NioClientBoss.java:42)
位于com.datastax.shaded.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
位于com.datastax.shaded.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
... 3个以上
2015-11-05 14:15:24847调试[New I/O worker#8]com.datastax.driver.core.Connection-连接[/10.75.43.251:9042-24,机上=0,关闭=true]关闭连接
2015-11-05 14:15:24847调试[New I/O boss#9]com.datastax.driver.core.Connection-连接[/10.75.43.251:9042-24,机上=0,关闭=false]连接错误
java.net.ConnectException:连接被拒绝:/10.75.43.251:9042
在sun.nio.ch.socketchannel.checkConnect(本机方法)
位于sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:739)
位于com.datastax.shaded.netty.channel.socket.nio.NioClientBoss.connect(NioClientBoss.java:150)
位于com.datastax.shaded.netty.channel.socket.nio.NioClientBoss.processSelectedKeys(NioClientBoss.java:105)
位于com.datastax.shaded.netty.channel.socket.nio.NioClientBoss.process(NioClientBoss.java:79)
位于com.datastax.shaded.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:318)
位于com.datastax.shaded.netty.channel.socket.nio.NioClientBoss.run(NioClientBoss.java:42)
位于com.datastax.shaded.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
位于com.datastax.shaded.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
位于java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
位于java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
运行(Thread.java:745)
2015-11-05 14:15:24849调试[Reconnection-0]com.datastax.driver.core.Cluster-无法重新连接到/10.75.43.251:9042([/10.75.43.251:9042]无法连接),计划在600000毫秒后重试
2015-11-05 14:15:24849调试[Cassandra Java Driver worker-44]com.datastax.Driver.core.Cluster-Host/10.75.43.251:9042已关闭
2015-11-05 14:15:24849调试[Cassandra Java Driver worker-44]com.datastax.Driver.core.Cluster-中止onDown,因为主机上正在运行重新连接/10.75.43.251:9042
我尝试设置重新连接策略。这让我可以控制重试延迟。 但是重试尝试(表示我想要3次)仍然不在我的控制之下

我尝试了ConstantReconnectPolicy(它只提供重新连接延迟),这很有效。但我也希望重试尝试得到控制。 我正在尝试类似的东西

  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;
                // }
            }
        }

    }
private volatile int currentrycount;
类MyReconnectionPolicy实现重新连接策略{
@凌驾
公共重新连接计划新闻时间表(){
返回新的MyReconnectionSchedule();
}
}
类MyReconnectionSchedule实现重新连接计划{
@凌驾
公共长nextDelayMs(){
如果(++currentRetryCountprivate class CustomExponentialSchedule implements ReconnectionSchedule {

    private int attempts;

    @Override
    public long nextDelayMs() {

        // If totalReconnectionCount is zero, the application won't be never stopped.
        if (totalReconnectionCount != 0 && attempts == totalReconnectionCount) {
            // Kill the Java process.
            System.exit(1);
        }

        if (attempts > maxAttempts) {
            return maxDelayMs;
        }

        return Math.min(baseDelayMs * (1L << attempts++), maxDelayMs);
    }
}