Skip to content

Commit

Permalink
JAMES-1999 Increase init waiting time for each retrying times
Browse files Browse the repository at this point in the history
  • Loading branch information
quynhn committed May 24, 2017
1 parent ed06af0 commit 58f0e72
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
Expand Up @@ -19,6 +19,7 @@
package org.apache.james.modules.mailbox; package org.apache.james.modules.mailbox;


import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.time.LocalDateTime;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
Expand Down Expand Up @@ -115,7 +116,7 @@ Cluster provideCluster(CassandraSessionConfiguration cassandraSessionConfigurati
} }


private RetryCallable<Cluster> getClusterRetryCallable(PropertiesConfiguration configuration, List<Host> servers, QueryLoggerConfiguration queryLoggerConfiguration) { private RetryCallable<Cluster> getClusterRetryCallable(PropertiesConfiguration configuration, List<Host> servers, QueryLoggerConfiguration queryLoggerConfiguration) {
LOGGER.info("Trying to connect to Cassandra service"); LOGGER.info("Trying to connect to Cassandra service at {}", LocalDateTime.now());


return context -> ClusterWithKeyspaceCreatedFactory return context -> ClusterWithKeyspaceCreatedFactory
.config(ClusterBuilder.builder() .config(ClusterBuilder.builder()
Expand Down
Expand Up @@ -20,6 +20,7 @@
package org.apache.james.modules.mailbox; package org.apache.james.modules.mailbox;


import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.time.LocalDateTime;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;


Expand Down Expand Up @@ -104,7 +105,7 @@ private Client createIndexAndMapping(Client client, PropertiesConfiguration prop
} }


private Client connectToCluster(PropertiesConfiguration propertiesReader) throws ConfigurationException { private Client connectToCluster(PropertiesConfiguration propertiesReader) throws ConfigurationException {
LOGGER.info("Trying to connect to ElasticSearch service"); LOGGER.info("Trying to connect to ElasticSearch service at {}", LocalDateTime.now());


return createIndexAndMapping(createClient(propertiesReader), propertiesReader); return createIndexAndMapping(createClient(propertiesReader), propertiesReader);
} }
Expand Down
Expand Up @@ -47,7 +47,7 @@ public PropertiesConfiguration getCassandraConfigurationForDocker() {
configuration.addProperty("cassandra.nodes", getIp() + ":" + CASSANDRA_PORT); configuration.addProperty("cassandra.nodes", getIp() + ":" + CASSANDRA_PORT);
configuration.addProperty("cassandra.keyspace", "apache_james"); configuration.addProperty("cassandra.keyspace", "apache_james");
configuration.addProperty("cassandra.replication.factor", 1); configuration.addProperty("cassandra.replication.factor", 1);
configuration.addProperty("cassandra.retryConnection.maxRetries", 10); configuration.addProperty("cassandra.retryConnection.maxRetries", 20);
configuration.addProperty("cassandra.retryConnection.minDelay", 5000); configuration.addProperty("cassandra.retryConnection.minDelay", 5000);


return configuration; return configuration;
Expand Down
Expand Up @@ -51,7 +51,7 @@ public PropertiesConfiguration getElasticSearchConfigurationForDocker() {
configuration.addProperty("elasticsearch.nb.shards", 1); configuration.addProperty("elasticsearch.nb.shards", 1);
configuration.addProperty("elasticsearch.nb.replica", 0); configuration.addProperty("elasticsearch.nb.replica", 0);
configuration.addProperty("elasticsearch.retryConnection.maxRetries", 7); configuration.addProperty("elasticsearch.retryConnection.maxRetries", 7);
configuration.addProperty("elasticsearch.retryConnection.minDelay", 30); configuration.addProperty("elasticsearch.retryConnection.minDelay", 3000);
configuration.addProperty("elasticsearch.indexAttachments", false); configuration.addProperty("elasticsearch.indexAttachments", false);
configuration.addProperty("elasticsearch.http.host", getIp()); configuration.addProperty("elasticsearch.http.host", getIp());
configuration.addProperty("elasticsearch.http.port", ELASTIC_SEARCH_HTTP_PORT); configuration.addProperty("elasticsearch.http.port", ELASTIC_SEARCH_HTTP_PORT);
Expand Down
Expand Up @@ -20,17 +20,21 @@
package org.apache.james.utils; package org.apache.james.utils;


import com.nurkiewicz.asyncretry.AsyncRetryExecutor; import com.nurkiewicz.asyncretry.AsyncRetryExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class RetryExecutorUtil { public class RetryExecutorUtil {
private static final Logger LOG = LoggerFactory.getLogger(RetryExecutorUtil.class);


public static final int INITIAL_DELAY_MILLIS = 500; private static final int INITIAL_DELAY_MILLIS = 500;
public static final int MULTIPLIER = 2; private static final int MULTIPLIER = 2;


public static AsyncRetryExecutor retryOnExceptions(AsyncRetryExecutor executor, int maxRetries, int minDelay, Class<? extends Throwable> clazz) { public static AsyncRetryExecutor retryOnExceptions(AsyncRetryExecutor executor, int maxRetries, int minDelay, Class<? extends Throwable>... clazz) {
LOG.info("The action should retry when {} and retry to {} times if needed", clazz, maxRetries);
return executor return executor
.retryOn(clazz)
.withExponentialBackoff(INITIAL_DELAY_MILLIS, MULTIPLIER) .withExponentialBackoff(INITIAL_DELAY_MILLIS, MULTIPLIER)
.withProportionalJitter() .withProportionalJitter()
.retryOn(clazz)
.withMaxRetries(maxRetries) .withMaxRetries(maxRetries)
.withMinDelay(minDelay); .withMinDelay(minDelay);
} }
Expand Down

0 comments on commit 58f0e72

Please sign in to comment.