This is an automated email from the ASF dual-hosted git repository. rcordier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 72a388d2a65db187b47a60c3f314b573d974e05a Author: Benoit Tellier <btell...@linagora.com> AuthorDate: Tue Mar 10 17:31:53 2020 +0700 JAMES-3111 Use a retry policy to decrease consistency level when All --- .../backends/cassandra/init/ClusterFactory.java | 1 + .../init/NotConsistencyAllRetryPolicy.java | 69 ++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterFactory.java b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterFactory.java index a6bfc9e..350f8be 100644 --- a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterFactory.java +++ b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterFactory.java @@ -52,6 +52,7 @@ public class ClusterFactory { socketOptions.setReadTimeoutMillis(configuration.getReadTimeoutMillis()); socketOptions.setConnectTimeoutMillis(configuration.getConnectTimeoutMillis()); clusterBuilder.withSocketOptions(socketOptions); + clusterBuilder.withRetryPolicy(new NotConsistencyAllRetryPolicy()); configuration.getPoolingOptions().ifPresent(clusterBuilder::withPoolingOptions); if (configuration.useSsl()) { diff --git a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/NotConsistencyAllRetryPolicy.java b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/NotConsistencyAllRetryPolicy.java new file mode 100644 index 0000000..890e35e --- /dev/null +++ b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/NotConsistencyAllRetryPolicy.java @@ -0,0 +1,69 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.backends.cassandra.init; + +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.ConsistencyLevel; +import com.datastax.driver.core.Statement; +import com.datastax.driver.core.WriteType; +import com.datastax.driver.core.exceptions.DriverException; +import com.datastax.driver.core.policies.DefaultRetryPolicy; +import com.datastax.driver.core.policies.RetryPolicy; + +public class NotConsistencyAllRetryPolicy implements RetryPolicy { + @Override + public RetryDecision onReadTimeout(Statement statement, ConsistencyLevel cl, int requiredResponses, int receivedResponses, boolean dataRetrieved, int nbRetry) { + if (cl == ConsistencyLevel.ALL) { + return RetryDecision.retry(ConsistencyLevel.QUORUM); + } + return DefaultRetryPolicy.INSTANCE.onReadTimeout(statement, cl, requiredResponses, receivedResponses, dataRetrieved, nbRetry); + } + + @Override + public RetryDecision onWriteTimeout(Statement statement, ConsistencyLevel cl, WriteType writeType, int requiredAcks, int receivedAcks, int nbRetry) { + if (cl == ConsistencyLevel.ALL) { + return RetryDecision.retry(ConsistencyLevel.QUORUM); + } + return DefaultRetryPolicy.INSTANCE.onWriteTimeout(statement, cl, writeType, requiredAcks, receivedAcks, nbRetry); + } + + @Override + public RetryDecision onUnavailable(Statement statement, ConsistencyLevel cl, int requiredReplica, int aliveReplica, int nbRetry) { + if (cl == ConsistencyLevel.ALL) { + return RetryDecision.retry(ConsistencyLevel.QUORUM); + } + return DefaultRetryPolicy.INSTANCE.onUnavailable(statement, cl, requiredReplica, aliveReplica, nbRetry); + } + + @Override + public RetryDecision onRequestError(Statement statement, ConsistencyLevel cl, DriverException e, int nbRetry) { + return DefaultRetryPolicy.INSTANCE.onRequestError(statement, cl, e, nbRetry); + } + + @Override + public void init(Cluster cluster) { + + } + + @Override + public void close() { + + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org