message: Declare local variables which represent a time interval as absl::Duration, and move any relevant conversions to the places those variables are referenced instead.
diff: @@ -127,10 +127,10 @@ class GrpcRemoteMaster : public MasterInterface {
  ::grpc::Status (MasterServiceStub::*pfunc)(
  ::grpc::ClientContext*, const Request&, Response*),
  string trace_string = {}) {
  - int64 timeout_in_ms = call_options->GetTimeout();
  - int64 expired_time_micros = Env::Default()->NowMicros();
  - if (timeout_in_ms > 0) {
  - expired_time_micros += (timeout_in_ms * 1000);
  + absl::Duration timeout = absl::Milliseconds(call_options->GetTimeout());
  + absl::Time expired_time = absl::FromUnixMicros(Env::Default()->NowMicros());
  + if (timeout > absl::ZeroDuration()) {
  + expired_time += timeout;
  }
  Status s;
  for (int num_retries = 0;; ++num_retries) {
  @@ -140,7 +140,7 @@ class GrpcRemoteMaster : public MasterInterface {
  trace.reset(NewTraceRpc(trace_string, &ctx));
  }
  ctx.set_fail_fast(false);
  - if (timeout_in_ms > 0) {
  + if (timeout > absl::ZeroDuration()) {
  // We do not modify the timeout here to match legacy behavior. However,
  // this could violate the contract of tensorflow::Session. If we retry
  // an RPC just before the deadline is exceeded, we will still set the
  @@ -148,8 +148,7 @@ class GrpcRemoteMaster : public MasterInterface {
  // being double what was expected.
  // TODO(b/117162170): investigate fixing this behavior for legacy and
  // gRPC RPC layers.
  - ctx.set_deadline(absl::ToChronoTime(absl::Now() +
  - absl::Milliseconds(timeout_in_ms)));
  + ctx.set_deadline(absl::ToChronoTime(absl::Now() + timeout));
  }
  s = FromGrpcStatus((stub_.get()->*pfunc)(&ctx, *request, response));
  if (!errors::IsUnavailable(s)) {
  @@ -164,20 +163,20 @@ class GrpcRemoteMaster : public MasterInterface {
  LOG(WARNING) << "Too many retries, returning last status: " << s;
  return s;
  }
  - const int64 now_micros = Env::Default()->NowMicros();
  - const int64 deadline_with_backoff_micros =
  - now_micros + ComputeBackoffMicroseconds(num_retries);
  + absl::Time now = absl::FromUnixMicros(Env::Default()->NowMicros());
  + const absl::Time deadline_with_backoff =
  + now + absl::Microseconds(ComputeBackoffMicroseconds(num_retries));
  // Wait for a short period of time before retrying the RPC. If our
  // backoff would put us past the RPC deadline, we truncate it to ensure
  // our RPC starts before the deadline.
  - const auto backoff_until =
  - (timeout_in_ms <= 0 ||
  - expired_time_micros > deadline_with_backoff_micros)
  - ? deadline_with_backoff_micros
  - : expired_time_micros;
  - Env::Default()->SleepForMicroseconds(backoff_until - now_micros);
  - const int64 now = Env::Default()->NowMicros();
  - if (now > expired_time_micros && timeout_in_ms > 0) {
  + const auto backoff_until = (timeout <= absl::ZeroDuration() ||
  + expired_time > deadline_with_backoff)
  + ? deadline_with_backoff
  + : expired_time;
  + Env::Default()->SleepForMicroseconds(
  + absl::ToInt64Microseconds(backoff_until - now));
  + now = absl::FromUnixMicros(Env::Default()->NowMicros());
  + if (now > expired_time && timeout > absl::ZeroDuration()) {
  // If timeout_in_ms is set, exit the retry loop on timeout.
  return errors::DeadlineExceeded(ctx.debug_error_string());
  }
  