diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc b/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc index 468c9d84591e1..85d1b0126964f 100644 --- a/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc @@ -575,7 +575,7 @@ class XdsLb : public LoadBalancingPolicy { OrphanablePtr pending_lb_chand_; // Timeout in milliseconds for the LB call. 0 means no deadline. - int lb_call_timeout_ms_ = 0; + const grpc_millis lb_call_timeout_ms_; // Whether the checks for fallback at startup are ALL pending. There are // several cases where this can be reset: @@ -587,7 +587,7 @@ class XdsLb : public LoadBalancingPolicy { bool fallback_at_startup_checks_pending_ = false; // Timeout in milliseconds for before using fallback backend addresses. // 0 means not using fallback. - int lb_fallback_timeout_ms_ = 0; + const grpc_millis lb_fallback_timeout_ms_; // The backend addresses from the resolver. ServerAddressList fallback_backend_addresses_; // Fallback timer. @@ -1705,7 +1705,13 @@ grpc_channel_args* BuildBalancerChannelArgs(const grpc_channel_args* args) { // XdsLb::XdsLb(Args args) - : LoadBalancingPolicy(std::move(args)), locality_map_(this) { + : LoadBalancingPolicy(std::move(args)), + lb_call_timeout_ms_(grpc_channel_args_find_integer( + args.args, GRPC_ARG_GRPCLB_CALL_TIMEOUT_MS, {0, 0, INT_MAX})), + lb_fallback_timeout_ms_(grpc_channel_args_find_integer( + args.args, GRPC_ARG_XDS_FALLBACK_TIMEOUT_MS, + {GRPC_XDS_DEFAULT_FALLBACK_TIMEOUT_MS, 0, INT_MAX})), + locality_map_(this) { // Record server name. const grpc_arg* arg = grpc_channel_args_find(args.args, GRPC_ARG_SERVER_URI); const char* server_uri = grpc_channel_arg_get_string(arg); @@ -1719,13 +1725,6 @@ XdsLb::XdsLb(Args args) server_name_); } grpc_uri_destroy(uri); - // Record LB call timeout. - arg = grpc_channel_args_find(args.args, GRPC_ARG_GRPCLB_CALL_TIMEOUT_MS); - lb_call_timeout_ms_ = grpc_channel_arg_get_integer(arg, {0, 0, INT_MAX}); - // Record fallback timeout. - arg = grpc_channel_args_find(args.args, GRPC_ARG_XDS_FALLBACK_TIMEOUT_MS); - lb_fallback_timeout_ms_ = grpc_channel_arg_get_integer( - arg, {GRPC_XDS_DEFAULT_FALLBACK_TIMEOUT_MS, 0, INT_MAX}); } XdsLb::~XdsLb() { diff --git a/src/core/lib/channel/channel_args.cc b/src/core/lib/channel/channel_args.cc index b629ac0e10732..60248f9d8fce2 100644 --- a/src/core/lib/channel/channel_args.cc +++ b/src/core/lib/channel/channel_args.cc @@ -257,6 +257,13 @@ int grpc_channel_arg_get_integer(const grpc_arg* arg, return arg->value.integer; } +int grpc_channel_args_find_integer(const grpc_channel_args* args, + const char* name, + const grpc_integer_options options) { + const grpc_arg* arg = grpc_channel_args_find(args, name); + return grpc_channel_arg_get_integer(arg, options); +} + char* grpc_channel_arg_get_string(const grpc_arg* arg) { if (arg == nullptr) return nullptr; if (arg->type != GRPC_ARG_STRING) { @@ -266,6 +273,12 @@ char* grpc_channel_arg_get_string(const grpc_arg* arg) { return arg->value.string; } +char* grpc_channel_args_find_string(const grpc_channel_args* args, + const char* name) { + const grpc_arg* arg = grpc_channel_args_find(args, name); + return grpc_channel_arg_get_string(arg); +} + bool grpc_channel_arg_get_bool(const grpc_arg* arg, bool default_value) { if (arg == nullptr) return default_value; if (arg->type != GRPC_ARG_INTEGER) { @@ -284,6 +297,12 @@ bool grpc_channel_arg_get_bool(const grpc_arg* arg, bool default_value) { } } +bool grpc_channel_args_find_bool(const grpc_channel_args* args, + const char* name, bool default_value) { + const grpc_arg* arg = grpc_channel_args_find(args, name); + return grpc_channel_arg_get_bool(arg, default_value); +} + bool grpc_channel_args_want_minimal_stack(const grpc_channel_args* args) { return grpc_channel_arg_get_bool( grpc_channel_args_find(args, GRPC_ARG_MINIMAL_STACK), false); diff --git a/src/core/lib/channel/channel_args.h b/src/core/lib/channel/channel_args.h index 2b698a66cfb33..5928802f288c2 100644 --- a/src/core/lib/channel/channel_args.h +++ b/src/core/lib/channel/channel_args.h @@ -73,16 +73,30 @@ typedef struct grpc_integer_options { int max_value; } grpc_integer_options; -/** Returns the value of \a arg, subject to the contraints in \a options. */ +/** Returns the value of \a arg, subject to the constraints in \a options. */ int grpc_channel_arg_get_integer(const grpc_arg* arg, const grpc_integer_options options); +/** Similar to the above, but needs to find the arg from \a args by the name + * first. */ +int grpc_channel_args_find_integer(const grpc_channel_args* args, + const char* name, + const grpc_integer_options options); /** Returns the value of \a arg if \a arg is of type GRPC_ARG_STRING. Otherwise, emits a warning log, and returns nullptr. If arg is nullptr, returns nullptr, and does not emit a warning. */ char* grpc_channel_arg_get_string(const grpc_arg* arg); - +/** Similar to the above, but needs to find the arg from \a args by the name + * first. */ +char* grpc_channel_args_find_string(const grpc_channel_args* args, + const char* name); +/** If \a arg is of type GRPC_ARG_INTEGER, returns true if it's non-zero. + * Returns \a default_value if \a arg is of other types. */ bool grpc_channel_arg_get_bool(const grpc_arg* arg, bool default_value); +/** Similar to the above, but needs to find the arg from \a args by the name + * first. */ +bool grpc_channel_args_find_bool(const grpc_channel_args* args, + const char* name, bool default_value); // Helpers for creating channel args. grpc_arg grpc_channel_arg_string_create(char* name, char* value);