You are viewing a plain text version of this content. The canonical link for it is here.
Posted to codereview@trafodion.apache.org by selvaganesang <gi...@git.apache.org> on 2018/01/08 19:55:46 UTC

[GitHub] trafodion pull request #1344: TRAFODION-2844 add strategy to dcsserver for r...

Github user selvaganesang commented on a diff in the pull request:

    https://github.com/apache/trafodion/pull/1344#discussion_r160235536
  
    --- Diff: dcs/src/main/java/org/trafodion/dcs/util/RetryCounter.java ---
    @@ -20,54 +20,94 @@
      */
     package org.trafodion.dcs.util;
     
    +import java.util.LinkedList;
    +import java.util.Queue;
     import java.util.concurrent.TimeUnit;
     
     import org.apache.commons.logging.Log;
     import org.apache.commons.logging.LogFactory;
     
     public class RetryCounter {
    -  private static final Log LOG = LogFactory.getLog(RetryCounter.class);
    -  private final int maxRetries;
    -  private int retriesRemaining;
    -  private final int retryIntervalMillis;
    -  private final TimeUnit timeUnit;
    +    private static final Log LOG = LogFactory.getLog(RetryCounter.class);
    +    private final int maxRetries;
    +    private int retriesRemaining;
    +    private int retryInterval;
    +    private Queue<Long> queue;
    +    private TimeUnit timeUnit;
     
    -  public RetryCounter(int maxRetries, 
    -  int retryIntervalMillis, TimeUnit timeUnit) {
    -    this.maxRetries = maxRetries;
    -    this.retriesRemaining = maxRetries;
    -    this.retryIntervalMillis = retryIntervalMillis;
    -    this.timeUnit = timeUnit;
    -  }
    +    public RetryCounter(int maxRetries, int retryInterval, TimeUnit timeUnit) {
    +        this.maxRetries = maxRetries;
    +        this.retriesRemaining = maxRetries;
    +        this.retryInterval = retryInterval;
    +        this.queue = new LinkedList<Long>();
    +        this.timeUnit = timeUnit;
    +    }
     
    -  public int getMaxRetries() {
    -    return maxRetries;
    -  }
    +    public int getMaxRetries() {
    +        return maxRetries;
    +    }
     
    -  /**
    -   * Sleep for a exponentially back off time
    -   * @throws InterruptedException
    -   */
    -  public void sleepUntilNextRetry() throws InterruptedException {
    -    int attempts = getAttemptTimes();
    -    long sleepTime = (long) (retryIntervalMillis * Math.log(attempts+15));
    -    LOG.info("Sleeping " + sleepTime + "ms before retry #" + attempts + "...");
    -    timeUnit.sleep(sleepTime);
    -  }
    +    /**
    +     * Sleep for a exponentially back off time
    +     * @throws InterruptedException
    +     */
    +    public void sleepUntilNextRetry() throws InterruptedException {
    +        int attempts = getAttemptTimes();
    +        long sleepTime = (long) (retryInterval * Math.log(attempts + 15));
    +        LOG.info("Sleeping " + sleepTime + "ms before retry #" + attempts + "...");
    +        timeUnit.sleep(sleepTime);
    --- End diff --
    
    Good catch It looks like earlier the sleep time was incorrect if the TimeUnit wasn't in milliseconds. 


---