Samunroyu commented on code in PR #1822: URL: https://github.com/apache/incubator-pegasus/pull/1822#discussion_r1508607544
########## java-client/src/main/java/org/apache/pegasus/client/retry/DefaultRetryPolicy.java: ########## @@ -0,0 +1,47 @@ +/* + * 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.pegasus.client.retry; + +import java.time.Duration; +import java.util.concurrent.TimeUnit; +import org.apache.pegasus.client.ClientOptions; + +/** + * The default retry policy, which is the only policy before we introduce the retry policy + * mechanism. It only considers the timeout value to calculate the retry delay, that's why we need + * to pass the {@code timeout} value in the {@link #shouldRetry(int, long, Duration)} method. + */ +public class DefaultRetryPolicy implements RetryPolicy { + public DefaultRetryPolicy(ClientOptions opts) { + // do nothing, just keep the constructor. + } + + @Override + public RetryAction shouldRetry(int retries, long deadlineNanos, Duration timeout) { + long now = System.nanoTime(); + if (now >= deadlineNanos) { + return new RetryAction(RetryDecision.FAIL, Duration.ZERO, "request deadline reached"); + } + long timeoutMs = timeout.toMillis(); + long retryDelayMs = + Math.min( + timeoutMs > 3 ? timeoutMs / 3 : 1, TimeUnit.NANOSECONDS.toMillis(deadlineNanos - now)); + return new RetryAction(RetryDecision.RETRY, Duration.ofMillis(retryDelayMs), ""); Review Comment: > If we change to use nanos here, then we do not need to change the code here if we allow users to specify timeouts with smaller unit than millis, like micros and nanos in the future. Whether to allow users to specify timeout with unit smaller than millis can be discussed later. I see. i already change the code.pls take a look one more time. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@pegasus.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@pegasus.apache.org For additional commands, e-mail: dev-h...@pegasus.apache.org