• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef TENSORFLOW_CORE_DATA_SERVICE_GRPC_UTIL_H_
17 #define TENSORFLOW_CORE_DATA_SERVICE_GRPC_UTIL_H_
18 
19 #include "grpcpp/grpcpp.h"
20 #include "tensorflow/core/platform/status.h"
21 
22 namespace tensorflow {
23 namespace data {
24 namespace grpc_util {
25 
26 // Wraps a grpc::Status in a tensorflow::Status with the given message.
27 Status WrapError(const std::string& message, const ::grpc::Status& status);
28 
29 // Retries the given function if the function produces UNAVAILABLE, ABORTED, or
30 // CANCELLED status codes. We retry these codes because they can all indicate
31 // preemption of a server. The retries continue until the deadline is exceeded
32 // or the `should_retry` callback returns false. `description` may be used to
33 // log that retries are happening. It should contain a description of the action
34 // being retried, e.g. "register dataset" The retry loop uses exponential
35 // backoff between retries. `deadline_micros` is interpreted as microseconds
36 // since the epoch.
37 Status Retry(const std::function<Status()>& f,
38              const std::function<bool()>& should_retry,
39              const std::string& description, int64_t deadline_micros);
40 
41 // Same as `Retry` above, but with a `should_retry` callback that always returns
42 // `true`.
43 Status Retry(const std::function<Status()>& f, const std::string& description,
44              int64_t deadline_micros);
45 
46 }  // namespace grpc_util
47 }  // namespace data
48 }  // namespace tensorflow
49 
50 #endif  // TENSORFLOW_CORE_DATA_SERVICE_GRPC_UTIL_H_
51