From 2e8920873d41b05a61378b1a1ea61f9ac051df15 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Fri, 23 Sep 2016 15:19:54 -0700 Subject: Add new files missed in last commit. --- src/core/ext/client_config/method_config.h | 85 ++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/core/ext/client_config/method_config.h (limited to 'src/core/ext/client_config/method_config.h') diff --git a/src/core/ext/client_config/method_config.h b/src/core/ext/client_config/method_config.h new file mode 100644 index 0000000000..9490e296b2 --- /dev/null +++ b/src/core/ext/client_config/method_config.h @@ -0,0 +1,85 @@ +// +// Copyright 2016, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// + +#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_METHOD_CONFIG_H +#define GRPC_CORE_EXT_CLIENT_CONFIG_METHOD_CONFIG_H + +#include + +#include + +#include "src/core/lib/transport/metadata.h" + +/// Per-method configuration. +typedef struct grpc_method_config grpc_method_config; + +/// Any parameter may be NULL to indicate that the value is unset. +grpc_method_config* grpc_method_config_create( + bool* wait_for_ready, gpr_timespec* timeout, + int32_t* max_request_message_bytes, int32_t* max_response_message_bytes); + +grpc_method_config* grpc_method_config_ref(grpc_method_config* method_config); +void grpc_method_config_unref(grpc_method_config* method_config); + +/// These methods return NULL if the requested field is unset. +/// The caller does NOT take ownership of the result. +bool* grpc_method_config_get_wait_for_ready(grpc_method_config* method_config); +gpr_timespec* grpc_method_config_get_timeout(grpc_method_config* method_config); +int32_t* grpc_method_config_get_max_request_message_bytes( + grpc_method_config* method_config); +int32_t* grpc_method_config_get_max_response_message_bytes( + grpc_method_config* method_config); + +/// A table of method configs. +typedef struct grpc_method_config_table grpc_method_config_table; + +grpc_method_config_table* grpc_method_config_table_create(); + +grpc_method_config_table* grpc_method_config_table_ref( + grpc_method_config_table* table); +void grpc_method_config_table_unref(grpc_method_config_table* table); + +/// Adds \a method_config to \a table. \a paths indicates the set of path +/// names for which this config applies. Each name is of one of the +/// following forms: +/// service/method -- specifies exact service and method name +/// service/* -- matches all methods for the specified service +/// Takes new references to all elements of \a paths and to \a method_config. +void grpc_method_config_table_add_method_config( + grpc_method_config_table* table, grpc_mdstr** paths, size_t num_paths, + grpc_method_config* method_config); + +/// Returns NULL if the method has no config. +/// Caller owns a reference to result. +grpc_method_config* grpc_method_config_table_get_method_config( + grpc_method_config_table* table, grpc_mdstr* path); + +#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_METHOD_CONFIG_H */ -- cgit v1.2.3 From 046cf7646918b19a8956e20f7e28e7422a6f29cd Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Mon, 26 Sep 2016 11:13:51 -0700 Subject: Encode method config table in channel args instead of in resolver result. --- src/core/ext/client_config/client_channel.c | 65 ++++++++++---------- src/core/ext/client_config/method_config.c | 71 ++++++++++++++++++++++ src/core/ext/client_config/method_config.h | 5 ++ src/core/ext/client_config/resolver_result.c | 11 +--- src/core/ext/client_config/resolver_result.h | 6 +- src/core/ext/lb_policy/grpclb/grpclb.c | 5 ++ src/core/ext/lb_policy/pick_first/pick_first.c | 1 + src/core/ext/lb_policy/round_robin/round_robin.c | 1 + src/core/ext/resolver/dns/native/dns_resolver.c | 2 +- src/core/ext/resolver/sockaddr/sockaddr_resolver.c | 2 +- src/core/lib/channel/channel_args.c | 10 +++ src/core/lib/channel/channel_args.h | 6 ++ 12 files changed, 137 insertions(+), 48 deletions(-) (limited to 'src/core/ext/client_config/method_config.h') diff --git a/src/core/ext/client_config/client_channel.c b/src/core/ext/client_config/client_channel.c index 73e62fcbbf..96c8c62c04 100644 --- a/src/core/ext/client_config/client_channel.c +++ b/src/core/ext/client_config/client_channel.c @@ -43,6 +43,7 @@ #include #include "src/core/ext/client_config/lb_policy_registry.h" +#include "src/core/ext/client_config/method_config.h" #include "src/core/ext/client_config/subchannel.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/connected_channel.h" @@ -70,15 +71,14 @@ typedef struct client_channel_channel_data { /** client channel factory */ grpc_client_channel_factory *client_channel_factory; - /** mutex protecting client configuration, including all - variables below in this data structure */ + /** mutex protecting all variables below in this data structure */ gpr_mu mu; - /** currently active load balancer - guarded by mu */ + /** currently active load balancer */ grpc_lb_policy *lb_policy; - /** incoming resolver result - set by resolver.next(), guarded by mu */ - grpc_resolver_result *incoming_resolver_result; - /** current resolver result */ - grpc_resolver_result *current_resolver_result; + /** method config table */ + grpc_method_config_table *method_config_table; + /** incoming resolver result - set by resolver.next() */ + grpc_resolver_result *resolver_result; /** a list of closures that are all waiting for config to come in */ grpc_closure_list waiting_for_config_closures; /** resolver callback */ @@ -176,23 +176,23 @@ static void on_resolver_result_changed(grpc_exec_ctx *exec_ctx, void *arg, channel_data *chand = arg; grpc_lb_policy *lb_policy = NULL; grpc_lb_policy *old_lb_policy; + grpc_method_config_table *method_config_table = NULL; grpc_connectivity_state state = GRPC_CHANNEL_TRANSIENT_FAILURE; bool exit_idle = false; grpc_error *state_error = GRPC_ERROR_CREATE("No load balancing policy"); - if (chand->incoming_resolver_result != NULL) { + if (chand->resolver_result != NULL) { grpc_lb_policy_args lb_policy_args; lb_policy_args.server_name = - grpc_resolver_result_get_server_name(chand->incoming_resolver_result); + grpc_resolver_result_get_server_name(chand->resolver_result); lb_policy_args.addresses = - grpc_resolver_result_get_addresses(chand->incoming_resolver_result); - lb_policy_args.additional_args = grpc_resolver_result_get_lb_policy_args( - chand->incoming_resolver_result); + grpc_resolver_result_get_addresses(chand->resolver_result); + lb_policy_args.additional_args = + grpc_resolver_result_get_lb_policy_args(chand->resolver_result); lb_policy_args.client_channel_factory = chand->client_channel_factory; lb_policy = grpc_lb_policy_create( exec_ctx, - grpc_resolver_result_get_lb_policy_name( - chand->incoming_resolver_result), + grpc_resolver_result_get_lb_policy_name(chand->resolver_result), &lb_policy_args); if (lb_policy != NULL) { GRPC_LB_POLICY_REF(lb_policy, "config_change"); @@ -200,11 +200,15 @@ static void on_resolver_result_changed(grpc_exec_ctx *exec_ctx, void *arg, state = grpc_lb_policy_check_connectivity(exec_ctx, lb_policy, &state_error); } - if (chand->current_resolver_result != NULL) { - grpc_resolver_result_unref(exec_ctx, chand->current_resolver_result); + const grpc_arg *channel_arg = grpc_channel_args_find( + lb_policy_args.additional_args, GRPC_ARG_SERVICE_CONFIG); + if (channel_arg != NULL) { + GPR_ASSERT(channel_arg->type == GRPC_ARG_POINTER); + method_config_table = grpc_method_config_table_ref( + (grpc_method_config_table *)channel_arg->value.pointer.p); } - chand->current_resolver_result = chand->incoming_resolver_result; - chand->incoming_resolver_result = NULL; + grpc_resolver_result_unref(exec_ctx, chand->resolver_result); + chand->resolver_result = NULL; } if (lb_policy != NULL) { @@ -215,6 +219,10 @@ static void on_resolver_result_changed(grpc_exec_ctx *exec_ctx, void *arg, gpr_mu_lock(&chand->mu); old_lb_policy = chand->lb_policy; chand->lb_policy = lb_policy; + if (chand->method_config_table != NULL) { + grpc_method_config_table_unref(chand->method_config_table); + } + chand->method_config_table = method_config_table; if (lb_policy != NULL) { grpc_exec_ctx_enqueue_list(exec_ctx, &chand->waiting_for_config_closures, NULL); @@ -238,8 +246,7 @@ static void on_resolver_result_changed(grpc_exec_ctx *exec_ctx, void *arg, watch_lb_policy(exec_ctx, chand, lb_policy, state); } GRPC_CHANNEL_STACK_REF(chand->owning_stack, "resolver"); - grpc_resolver_next(exec_ctx, chand->resolver, - &chand->incoming_resolver_result, + grpc_resolver_next(exec_ctx, chand->resolver, &chand->resolver_result, &chand->on_resolver_result_changed); gpr_mu_unlock(&chand->mu); } else { @@ -376,8 +383,8 @@ static void cc_destroy_channel_elem(grpc_exec_ctx *exec_ctx, chand->interested_parties); GRPC_LB_POLICY_UNREF(exec_ctx, chand->lb_policy, "channel"); } - if (chand->current_resolver_result != NULL) { - grpc_resolver_result_unref(exec_ctx, chand->current_resolver_result); + if (chand->method_config_table != NULL) { + grpc_method_config_table_unref(chand->method_config_table); } grpc_connectivity_state_destroy(exec_ctx, &chand->state_tracker); grpc_pollset_set_destroy(chand->interested_parties); @@ -512,11 +519,9 @@ static void subchannel_ready(grpc_exec_ctx *exec_ctx, void *arg, /* Get method config. */ // FIXME: need to actually use the config data! // FIXME: think about refcounting vs. atomicity here - grpc_method_config_table* table = grpc_resolver_result_get_method_configs( - chand->current_resolver_result); - if (table != NULL) { + if (chand->method_config_table != NULL) { calld->method_config = grpc_method_config_table_get_method_config( - table, calld->path); + chand->method_config_table, calld->path); } /* Create call on subchannel. */ grpc_subchannel_call *subchannel_call = NULL; @@ -626,8 +631,7 @@ static bool pick_subchannel(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, if (chand->resolver != NULL && !chand->started_resolving) { chand->started_resolving = true; GRPC_CHANNEL_STACK_REF(chand->owning_stack, "resolver"); - grpc_resolver_next(exec_ctx, chand->resolver, - &chand->incoming_resolver_result, + grpc_resolver_next(exec_ctx, chand->resolver, &chand->resolver_result, &chand->on_resolver_result_changed); } if (chand->resolver != NULL) { @@ -836,7 +840,7 @@ void grpc_client_channel_finish_initialization( chand->exit_idle_when_lb_policy_arrives) { chand->started_resolving = true; GRPC_CHANNEL_STACK_REF(chand->owning_stack, "resolver"); - grpc_resolver_next(exec_ctx, resolver, &chand->incoming_resolver_result, + grpc_resolver_next(exec_ctx, resolver, &chand->resolver_result, &chand->on_resolver_result_changed); } chand->client_channel_factory = client_channel_factory; @@ -858,8 +862,7 @@ grpc_connectivity_state grpc_client_channel_check_connectivity_state( if (!chand->started_resolving && chand->resolver != NULL) { GRPC_CHANNEL_STACK_REF(chand->owning_stack, "resolver"); chand->started_resolving = true; - grpc_resolver_next(exec_ctx, chand->resolver, - &chand->incoming_resolver_result, + grpc_resolver_next(exec_ctx, chand->resolver, &chand->resolver_result, &chand->on_resolver_result_changed); } } diff --git a/src/core/ext/client_config/method_config.c b/src/core/ext/client_config/method_config.c index e3589153fb..989f776967 100644 --- a/src/core/ext/client_config/method_config.c +++ b/src/core/ext/client_config/method_config.c @@ -33,9 +33,11 @@ #include +#include #include #include #include +#include #include "src/core/lib/transport/metadata.h" @@ -212,3 +214,72 @@ grpc_method_config* grpc_method_config_table_get_method_config( } return grpc_method_config_ref(method_config); } + +static void* copy_arg(void* p) { + return grpc_method_config_table_ref(p); +} + +static void destroy_arg(void* p) { + grpc_method_config_table_unref(p); +} + +static int cmp_arg(void* p1, void* p2) { + grpc_method_config_table* t1 = p1; + grpc_method_config_table* t2 = p2; + for (size_t i = 0; i < GPR_ARRAY_SIZE(t1->entries); ++i) { + grpc_method_config_table_entry* e1 = &t1->entries[i]; + grpc_method_config_table_entry* e2 = &t2->entries[i]; + // Compare paths by hash value. + if (e1->path->hash < e2->path->hash) return -1; + if (e1->path->hash > e2->path->hash) return 1; + // Compare wait_for_ready. + const bool wait_for_ready1 = + e1->method_config->wait_for_ready == NULL + ? false : *e1->method_config->wait_for_ready; + const bool wait_for_ready2 = + e2->method_config->wait_for_ready == NULL + ? false : *e2->method_config->wait_for_ready; + if (wait_for_ready1 < wait_for_ready2) return -1; + if (wait_for_ready1 > wait_for_ready2) return 1; + // Compare timeout. + const gpr_timespec timeout1 = + e1->method_config->timeout == NULL + ? gpr_inf_past(GPR_CLOCK_MONOTONIC) : *e1->method_config->timeout; + const gpr_timespec timeout2 = + e2->method_config->timeout == NULL + ? gpr_inf_past(GPR_CLOCK_MONOTONIC) : *e2->method_config->timeout; + const int timeout_result = gpr_time_cmp(timeout1, timeout2); + if (timeout_result != 0) return timeout_result; + // Compare max_request_message_bytes. + const int32_t max_request_message_bytes1 = + e1->method_config->max_request_message_bytes == NULL + ? -1 : *e1->method_config->max_request_message_bytes; + const int32_t max_request_message_bytes2 = + e2->method_config->max_request_message_bytes == NULL + ? -1 : *e2->method_config->max_request_message_bytes; + if (max_request_message_bytes1 < max_request_message_bytes2) return -1; + if (max_request_message_bytes1 > max_request_message_bytes2) return 1; + // Compare max_response_message_bytes. + const int32_t max_response_message_bytes1 = + e1->method_config->max_response_message_bytes == NULL + ? -1 : *e1->method_config->max_response_message_bytes; + const int32_t max_response_message_bytes2 = + e2->method_config->max_response_message_bytes == NULL + ? -1 : *e2->method_config->max_response_message_bytes; + if (max_response_message_bytes1 < max_response_message_bytes2) return -1; + if (max_response_message_bytes1 > max_response_message_bytes2) return 1; + } + return 0; +} + +static grpc_arg_pointer_vtable arg_vtable = {copy_arg, destroy_arg, cmp_arg}; + +grpc_arg grpc_method_config_table_create_channel_arg( + grpc_method_config_table* table) { + grpc_arg arg; + arg.type = GRPC_ARG_POINTER; + arg.key = GRPC_ARG_SERVICE_CONFIG; + arg.value.pointer.p = grpc_method_config_table_ref(table); + arg.value.pointer.vtable = &arg_vtable; + return arg; +} diff --git a/src/core/ext/client_config/method_config.h b/src/core/ext/client_config/method_config.h index 9490e296b2..2be0cd1006 100644 --- a/src/core/ext/client_config/method_config.h +++ b/src/core/ext/client_config/method_config.h @@ -35,6 +35,7 @@ #include #include +#include #include "src/core/lib/transport/metadata.h" @@ -82,4 +83,8 @@ void grpc_method_config_table_add_method_config( grpc_method_config* grpc_method_config_table_get_method_config( grpc_method_config_table* table, grpc_mdstr* path); +/// Returns a channel arg containing \a table. +grpc_arg grpc_method_config_table_create_channel_arg( + grpc_method_config_table* table); + #endif /* GRPC_CORE_EXT_CLIENT_CONFIG_METHOD_CONFIG_H */ diff --git a/src/core/ext/client_config/resolver_result.c b/src/core/ext/client_config/resolver_result.c index 5c5ffb2635..16d124d205 100644 --- a/src/core/ext/client_config/resolver_result.c +++ b/src/core/ext/client_config/resolver_result.c @@ -49,13 +49,11 @@ struct grpc_resolver_result { grpc_lb_addresses* addresses; char* lb_policy_name; grpc_channel_args* lb_policy_args; - grpc_method_config_table* method_configs; }; grpc_resolver_result* grpc_resolver_result_create( const char* server_name, grpc_lb_addresses* addresses, - const char* lb_policy_name, grpc_channel_args* lb_policy_args, - grpc_method_config_table* method_configs) { + const char* lb_policy_name, grpc_channel_args* lb_policy_args) { grpc_resolver_result* result = gpr_malloc(sizeof(*result)); memset(result, 0, sizeof(*result)); gpr_ref_init(&result->refs, 1); @@ -63,7 +61,6 @@ grpc_resolver_result* grpc_resolver_result_create( result->addresses = addresses; result->lb_policy_name = gpr_strdup(lb_policy_name); result->lb_policy_args = lb_policy_args; - result->method_configs = grpc_method_config_table_ref(method_configs); return result; } @@ -78,7 +75,6 @@ void grpc_resolver_result_unref(grpc_exec_ctx* exec_ctx, grpc_lb_addresses_destroy(result->addresses, NULL /* user_data_destroy */); gpr_free(result->lb_policy_name); grpc_channel_args_destroy(result->lb_policy_args); - grpc_method_config_table_unref(result->method_configs); gpr_free(result); } } @@ -101,8 +97,3 @@ grpc_channel_args* grpc_resolver_result_get_lb_policy_args( grpc_resolver_result* result) { return result->lb_policy_args; } - -grpc_method_config_table* grpc_resolver_result_get_method_configs( - grpc_resolver_result* result) { - return result->method_configs; -} diff --git a/src/core/ext/client_config/resolver_result.h b/src/core/ext/client_config/resolver_result.h index e6127f1d6d..707c8c2cf5 100644 --- a/src/core/ext/client_config/resolver_result.h +++ b/src/core/ext/client_config/resolver_result.h @@ -33,7 +33,6 @@ #define GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_RESULT_H #include "src/core/ext/client_config/lb_policy_factory.h" -#include "src/core/ext/client_config/method_config.h" #include "src/core/lib/iomgr/resolve_address.h" // TODO(roth, ctiller): In the long term, we are considering replacing @@ -52,8 +51,7 @@ typedef struct grpc_resolver_result grpc_resolver_result; /// Takes ownership of \a addresses, \a lb_policy_args. grpc_resolver_result* grpc_resolver_result_create( const char* server_name, grpc_lb_addresses* addresses, - const char* lb_policy_name, grpc_channel_args* lb_policy_args, - grpc_method_config_table* method_configs); + const char* lb_policy_name, grpc_channel_args* lb_policy_args); void grpc_resolver_result_ref(grpc_resolver_result* result); void grpc_resolver_result_unref(grpc_exec_ctx* exec_ctx, @@ -67,7 +65,5 @@ const char* grpc_resolver_result_get_lb_policy_name( grpc_resolver_result* result); grpc_channel_args* grpc_resolver_result_get_lb_policy_args( grpc_resolver_result* result); -grpc_method_config_table* grpc_resolver_result_get_method_configs( - grpc_resolver_result* result); #endif /* GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_RESULT_H */ diff --git a/src/core/ext/lb_policy/grpclb/grpclb.c b/src/core/ext/lb_policy/grpclb/grpclb.c index 8105c4415d..de3438be81 100644 --- a/src/core/ext/lb_policy/grpclb/grpclb.c +++ b/src/core/ext/lb_policy/grpclb/grpclb.c @@ -112,6 +112,7 @@ #include "src/core/ext/client_config/parse_address.h" #include "src/core/ext/lb_policy/grpclb/grpclb.h" #include "src/core/ext/lb_policy/grpclb/load_balancer_api.h" +#include "src/core/lib/channel/channel_args.h" #include "src/core/lib/iomgr/sockaddr.h" #include "src/core/lib/iomgr/sockaddr_utils.h" #include "src/core/lib/support/string.h" @@ -285,6 +286,7 @@ typedef struct glb_lb_policy { const char *server_name; grpc_client_channel_factory *cc_factory; + grpc_channel_args *args; /** for communicating with the LB server */ grpc_channel *lb_channel; @@ -442,6 +444,7 @@ static grpc_lb_policy *create_rr(grpc_exec_ctx *exec_ctx, args.server_name = glb_policy->server_name; args.client_channel_factory = glb_policy->cc_factory; args.addresses = process_serverlist(serverlist); + args.additional_args = glb_policy->args; grpc_lb_policy *rr = grpc_lb_policy_create(exec_ctx, "round_robin", &args); @@ -567,6 +570,7 @@ static grpc_lb_policy *glb_create(grpc_exec_ctx *exec_ctx, * Create a client channel over them to communicate with a LB service */ glb_policy->server_name = gpr_strdup(args->server_name); glb_policy->cc_factory = args->client_channel_factory; + glb_policy->args = grpc_channel_args_copy(args->additional_args); GPR_ASSERT(glb_policy->cc_factory != NULL); /* construct a target from the addresses in args, given in the form @@ -633,6 +637,7 @@ static void glb_destroy(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) { GPR_ASSERT(glb_policy->pending_picks == NULL); GPR_ASSERT(glb_policy->pending_pings == NULL); gpr_free((void *)glb_policy->server_name); + grpc_channel_args_destroy(glb_policy->args); grpc_channel_destroy(glb_policy->lb_channel); glb_policy->lb_channel = NULL; grpc_connectivity_state_destroy(exec_ctx, &glb_policy->state_tracker); diff --git a/src/core/ext/lb_policy/pick_first/pick_first.c b/src/core/ext/lb_policy/pick_first/pick_first.c index 466a0fdede..10030ef18b 100644 --- a/src/core/ext/lb_policy/pick_first/pick_first.c +++ b/src/core/ext/lb_policy/pick_first/pick_first.c @@ -470,6 +470,7 @@ static grpc_lb_policy *create_pick_first(grpc_exec_ctx *exec_ctx, sc_args.addr = (struct sockaddr *)(&args->addresses->addresses[i].address.addr); sc_args.addr_len = args->addresses->addresses[i].address.len; + sc_args.args = args->additional_args; grpc_subchannel *subchannel = grpc_client_channel_factory_create_subchannel( exec_ctx, args->client_channel_factory, &sc_args); diff --git a/src/core/ext/lb_policy/round_robin/round_robin.c b/src/core/ext/lb_policy/round_robin/round_robin.c index 037f180a9e..b6cfe8994d 100644 --- a/src/core/ext/lb_policy/round_robin/round_robin.c +++ b/src/core/ext/lb_policy/round_robin/round_robin.c @@ -633,6 +633,7 @@ static grpc_lb_policy *round_robin_create(grpc_exec_ctx *exec_ctx, sc_args.addr = (struct sockaddr *)(&args->addresses->addresses[i].address.addr); sc_args.addr_len = args->addresses->addresses[i].address.len; + sc_args.args = args->additional_args; grpc_subchannel *subchannel = grpc_client_channel_factory_create_subchannel( exec_ctx, args->client_channel_factory, &sc_args); diff --git a/src/core/ext/resolver/dns/native/dns_resolver.c b/src/core/ext/resolver/dns/native/dns_resolver.c index 879e26f7d9..e8ac1b12ae 100644 --- a/src/core/ext/resolver/dns/native/dns_resolver.c +++ b/src/core/ext/resolver/dns/native/dns_resolver.c @@ -181,7 +181,7 @@ static void dns_on_resolved(grpc_exec_ctx *exec_ctx, void *arg, } grpc_resolved_addresses_destroy(r->addresses); result = grpc_resolver_result_create(r->target_name, addresses, - r->lb_policy_name, NULL, NULL); + r->lb_policy_name, NULL); } else { gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); gpr_timespec next_try = gpr_backoff_step(&r->backoff_state, now); diff --git a/src/core/ext/resolver/sockaddr/sockaddr_resolver.c b/src/core/ext/resolver/sockaddr/sockaddr_resolver.c index 61be1b3c25..74d2015e5c 100644 --- a/src/core/ext/resolver/sockaddr/sockaddr_resolver.c +++ b/src/core/ext/resolver/sockaddr/sockaddr_resolver.c @@ -122,7 +122,7 @@ static void sockaddr_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx, r->published = true; *r->target_result = grpc_resolver_result_create( "", grpc_lb_addresses_copy(r->addresses, NULL /* user_data_copy */), - r->lb_policy_name, NULL, NULL); + r->lb_policy_name, NULL); grpc_exec_ctx_sched(exec_ctx, r->next_completion, GRPC_ERROR_NONE, NULL); r->next_completion = NULL; } diff --git a/src/core/lib/channel/channel_args.c b/src/core/lib/channel/channel_args.c index 3a56b1ff20..bab6fcd9fa 100644 --- a/src/core/lib/channel/channel_args.c +++ b/src/core/lib/channel/channel_args.c @@ -272,6 +272,16 @@ int grpc_channel_args_compare(const grpc_channel_args *a, return 0; } +const grpc_arg *grpc_channel_args_find(const grpc_channel_args *args, + const char *name) { + if (args != NULL) { + for (size_t i = 0; i < args->num_args; ++i) { + if (args->args[i].key == name) return &args->args[i]; + } + } + return NULL; +} + int grpc_channel_arg_get_integer(grpc_arg *arg, grpc_integer_options options) { if (arg->type != GRPC_ARG_INTEGER) { gpr_log(GPR_ERROR, "%s ignored: it must be an integer", arg->key); diff --git a/src/core/lib/channel/channel_args.h b/src/core/lib/channel/channel_args.h index 586a296d1f..38fb4c55d4 100644 --- a/src/core/lib/channel/channel_args.h +++ b/src/core/lib/channel/channel_args.h @@ -89,6 +89,12 @@ uint32_t grpc_channel_args_compression_algorithm_get_states( int grpc_channel_args_compare(const grpc_channel_args *a, const grpc_channel_args *b); +/** Returns the value of argument \a name from \a args, or NULL if not found. + Note: \a name is matched using pointer equality, so it must be the + same instance of the string used to create the grpc_arg key. */ +const grpc_arg *grpc_channel_args_find(const grpc_channel_args *args, + const char *name); + typedef struct grpc_integer_options { int default_value; // Return this if value is outside of expected bounds. int min_value; -- cgit v1.2.3 From 6600645135597fec4feaae81ca64fb02694d5f60 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Tue, 27 Sep 2016 10:13:56 -0700 Subject: Refactor hash table code into its own module and use it for method_config as well as method_config_table. --- BUILD | 12 + CMakeLists.txt | 5 + Makefile | 6 + binding.gyp | 1 + build.yaml | 2 + config.m4 | 1 + gRPC-Core.podspec | 3 + grpc.gemspec | 2 + package.xml | 2 + src/core/ext/client_config/method_config.c | 284 +++++++++++---------- src/core/ext/client_config/method_config.h | 29 ++- src/core/lib/transport/hashtable.c | 139 ++++++++++ src/core/lib/transport/hashtable.h | 82 ++++++ src/python/grpcio/grpc_core_dependencies.py | 1 + tools/doxygen/Doxyfile.c++.internal | 2 + tools/doxygen/Doxyfile.core.internal | 2 + tools/run_tests/sources_and_headers.json | 3 + vsprojects/vcxproj/grpc++/grpc++.vcxproj | 3 + vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters | 6 + .../grpc++_unsecure/grpc++_unsecure.vcxproj | 3 + .../grpc++_unsecure.vcxproj.filters | 6 + vsprojects/vcxproj/grpc/grpc.vcxproj | 3 + vsprojects/vcxproj/grpc/grpc.vcxproj.filters | 6 + .../vcxproj/grpc_test_util/grpc_test_util.vcxproj | 3 + .../grpc_test_util/grpc_test_util.vcxproj.filters | 6 + .../vcxproj/grpc_unsecure/grpc_unsecure.vcxproj | 3 + .../grpc_unsecure/grpc_unsecure.vcxproj.filters | 6 + 27 files changed, 470 insertions(+), 151 deletions(-) create mode 100644 src/core/lib/transport/hashtable.c create mode 100644 src/core/lib/transport/hashtable.h (limited to 'src/core/ext/client_config/method_config.h') diff --git a/BUILD b/BUILD index d542561ec8..46adf28f29 100644 --- a/BUILD +++ b/BUILD @@ -239,6 +239,7 @@ cc_library( "src/core/lib/surface/server.h", "src/core/lib/transport/byte_stream.h", "src/core/lib/transport/connectivity_state.h", + "src/core/lib/transport/hashtable.h", "src/core/lib/transport/metadata.h", "src/core/lib/transport/metadata_batch.h", "src/core/lib/transport/static_metadata.h", @@ -410,6 +411,7 @@ cc_library( "src/core/lib/surface/version.c", "src/core/lib/transport/byte_stream.c", "src/core/lib/transport/connectivity_state.c", + "src/core/lib/transport/hashtable.c", "src/core/lib/transport/metadata.c", "src/core/lib/transport/metadata_batch.c", "src/core/lib/transport/static_metadata.c", @@ -642,6 +644,7 @@ cc_library( "src/core/lib/surface/server.h", "src/core/lib/transport/byte_stream.h", "src/core/lib/transport/connectivity_state.h", + "src/core/lib/transport/hashtable.h", "src/core/lib/transport/metadata.h", "src/core/lib/transport/metadata_batch.h", "src/core/lib/transport/static_metadata.h", @@ -798,6 +801,7 @@ cc_library( "src/core/lib/surface/version.c", "src/core/lib/transport/byte_stream.c", "src/core/lib/transport/connectivity_state.c", + "src/core/lib/transport/hashtable.c", "src/core/lib/transport/metadata.c", "src/core/lib/transport/metadata_batch.c", "src/core/lib/transport/static_metadata.c", @@ -1000,6 +1004,7 @@ cc_library( "src/core/lib/surface/server.h", "src/core/lib/transport/byte_stream.h", "src/core/lib/transport/connectivity_state.h", + "src/core/lib/transport/hashtable.h", "src/core/lib/transport/metadata.h", "src/core/lib/transport/metadata_batch.h", "src/core/lib/transport/static_metadata.h", @@ -1148,6 +1153,7 @@ cc_library( "src/core/lib/surface/version.c", "src/core/lib/transport/byte_stream.c", "src/core/lib/transport/connectivity_state.c", + "src/core/lib/transport/hashtable.c", "src/core/lib/transport/metadata.c", "src/core/lib/transport/metadata_batch.c", "src/core/lib/transport/static_metadata.c", @@ -1355,6 +1361,7 @@ cc_library( "src/core/lib/surface/server.h", "src/core/lib/transport/byte_stream.h", "src/core/lib/transport/connectivity_state.h", + "src/core/lib/transport/hashtable.h", "src/core/lib/transport/metadata.h", "src/core/lib/transport/metadata_batch.h", "src/core/lib/transport/static_metadata.h", @@ -1480,6 +1487,7 @@ cc_library( "src/core/lib/surface/version.c", "src/core/lib/transport/byte_stream.c", "src/core/lib/transport/connectivity_state.c", + "src/core/lib/transport/hashtable.c", "src/core/lib/transport/metadata.c", "src/core/lib/transport/metadata_batch.c", "src/core/lib/transport/static_metadata.c", @@ -1765,6 +1773,7 @@ cc_library( "src/core/lib/surface/server.h", "src/core/lib/transport/byte_stream.h", "src/core/lib/transport/connectivity_state.h", + "src/core/lib/transport/hashtable.h", "src/core/lib/transport/metadata.h", "src/core/lib/transport/metadata_batch.h", "src/core/lib/transport/static_metadata.h", @@ -1885,6 +1894,7 @@ cc_library( "src/core/lib/surface/version.c", "src/core/lib/transport/byte_stream.c", "src/core/lib/transport/connectivity_state.c", + "src/core/lib/transport/hashtable.c", "src/core/lib/transport/metadata.c", "src/core/lib/transport/metadata_batch.c", "src/core/lib/transport/static_metadata.c", @@ -2274,6 +2284,7 @@ objc_library( "src/core/lib/surface/version.c", "src/core/lib/transport/byte_stream.c", "src/core/lib/transport/connectivity_state.c", + "src/core/lib/transport/hashtable.c", "src/core/lib/transport/metadata.c", "src/core/lib/transport/metadata_batch.c", "src/core/lib/transport/static_metadata.c", @@ -2485,6 +2496,7 @@ objc_library( "src/core/lib/surface/server.h", "src/core/lib/transport/byte_stream.h", "src/core/lib/transport/connectivity_state.h", + "src/core/lib/transport/hashtable.h", "src/core/lib/transport/metadata.h", "src/core/lib/transport/metadata_batch.h", "src/core/lib/transport/static_metadata.h", diff --git a/CMakeLists.txt b/CMakeLists.txt index 65a94bb995..39ea8906bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -376,6 +376,7 @@ add_library(grpc src/core/lib/surface/version.c src/core/lib/transport/byte_stream.c src/core/lib/transport/connectivity_state.c + src/core/lib/transport/hashtable.c src/core/lib/transport/metadata.c src/core/lib/transport/metadata_batch.c src/core/lib/transport/static_metadata.c @@ -636,6 +637,7 @@ add_library(grpc_cronet src/core/lib/surface/version.c src/core/lib/transport/byte_stream.c src/core/lib/transport/connectivity_state.c + src/core/lib/transport/hashtable.c src/core/lib/transport/metadata.c src/core/lib/transport/metadata_batch.c src/core/lib/transport/static_metadata.c @@ -868,6 +870,7 @@ add_library(grpc_unsecure src/core/lib/surface/version.c src/core/lib/transport/byte_stream.c src/core/lib/transport/connectivity_state.c + src/core/lib/transport/hashtable.c src/core/lib/transport/metadata.c src/core/lib/transport/metadata_batch.c src/core/lib/transport/static_metadata.c @@ -1127,6 +1130,7 @@ add_library(grpc++ src/core/lib/surface/version.c src/core/lib/transport/byte_stream.c src/core/lib/transport/connectivity_state.c + src/core/lib/transport/hashtable.c src/core/lib/transport/metadata.c src/core/lib/transport/metadata_batch.c src/core/lib/transport/static_metadata.c @@ -1481,6 +1485,7 @@ add_library(grpc++_unsecure src/core/lib/surface/version.c src/core/lib/transport/byte_stream.c src/core/lib/transport/connectivity_state.c + src/core/lib/transport/hashtable.c src/core/lib/transport/metadata.c src/core/lib/transport/metadata_batch.c src/core/lib/transport/static_metadata.c diff --git a/Makefile b/Makefile index 2a22923442..674fe91ee7 100644 --- a/Makefile +++ b/Makefile @@ -2613,6 +2613,7 @@ LIBGRPC_SRC = \ src/core/lib/surface/version.c \ src/core/lib/transport/byte_stream.c \ src/core/lib/transport/connectivity_state.c \ + src/core/lib/transport/hashtable.c \ src/core/lib/transport/metadata.c \ src/core/lib/transport/metadata_batch.c \ src/core/lib/transport/static_metadata.c \ @@ -2891,6 +2892,7 @@ LIBGRPC_CRONET_SRC = \ src/core/lib/surface/version.c \ src/core/lib/transport/byte_stream.c \ src/core/lib/transport/connectivity_state.c \ + src/core/lib/transport/hashtable.c \ src/core/lib/transport/metadata.c \ src/core/lib/transport/metadata_batch.c \ src/core/lib/transport/static_metadata.c \ @@ -3158,6 +3160,7 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/lib/surface/version.c \ src/core/lib/transport/byte_stream.c \ src/core/lib/transport/connectivity_state.c \ + src/core/lib/transport/hashtable.c \ src/core/lib/transport/metadata.c \ src/core/lib/transport/metadata_batch.c \ src/core/lib/transport/static_metadata.c \ @@ -3351,6 +3354,7 @@ LIBGRPC_UNSECURE_SRC = \ src/core/lib/surface/version.c \ src/core/lib/transport/byte_stream.c \ src/core/lib/transport/connectivity_state.c \ + src/core/lib/transport/hashtable.c \ src/core/lib/transport/metadata.c \ src/core/lib/transport/metadata_batch.c \ src/core/lib/transport/static_metadata.c \ @@ -3693,6 +3697,7 @@ LIBGRPC++_SRC = \ src/core/lib/surface/version.c \ src/core/lib/transport/byte_stream.c \ src/core/lib/transport/connectivity_state.c \ + src/core/lib/transport/hashtable.c \ src/core/lib/transport/metadata.c \ src/core/lib/transport/metadata_batch.c \ src/core/lib/transport/static_metadata.c \ @@ -4322,6 +4327,7 @@ LIBGRPC++_UNSECURE_SRC = \ src/core/lib/surface/version.c \ src/core/lib/transport/byte_stream.c \ src/core/lib/transport/connectivity_state.c \ + src/core/lib/transport/hashtable.c \ src/core/lib/transport/metadata.c \ src/core/lib/transport/metadata_batch.c \ src/core/lib/transport/static_metadata.c \ diff --git a/binding.gyp b/binding.gyp index 8aa153b878..88acd1786b 100644 --- a/binding.gyp +++ b/binding.gyp @@ -651,6 +651,7 @@ 'src/core/lib/surface/version.c', 'src/core/lib/transport/byte_stream.c', 'src/core/lib/transport/connectivity_state.c', + 'src/core/lib/transport/hashtable.c', 'src/core/lib/transport/metadata.c', 'src/core/lib/transport/metadata_batch.c', 'src/core/lib/transport/static_metadata.c', diff --git a/build.yaml b/build.yaml index fe2558eed3..7e95837ee9 100644 --- a/build.yaml +++ b/build.yaml @@ -243,6 +243,7 @@ filegroups: - src/core/lib/surface/server.h - src/core/lib/transport/byte_stream.h - src/core/lib/transport/connectivity_state.h + - src/core/lib/transport/hashtable.h - src/core/lib/transport/metadata.h - src/core/lib/transport/metadata_batch.h - src/core/lib/transport/static_metadata.h @@ -336,6 +337,7 @@ filegroups: - src/core/lib/surface/version.c - src/core/lib/transport/byte_stream.c - src/core/lib/transport/connectivity_state.c + - src/core/lib/transport/hashtable.c - src/core/lib/transport/metadata.c - src/core/lib/transport/metadata_batch.c - src/core/lib/transport/static_metadata.c diff --git a/config.m4 b/config.m4 index 6ee121df4e..f65f617f9a 100644 --- a/config.m4 +++ b/config.m4 @@ -170,6 +170,7 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/surface/version.c \ src/core/lib/transport/byte_stream.c \ src/core/lib/transport/connectivity_state.c \ + src/core/lib/transport/hashtable.c \ src/core/lib/transport/metadata.c \ src/core/lib/transport/metadata_batch.c \ src/core/lib/transport/static_metadata.c \ diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 4581762bdf..ffa7ca0825 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -326,6 +326,7 @@ Pod::Spec.new do |s| 'src/core/lib/surface/server.h', 'src/core/lib/transport/byte_stream.h', 'src/core/lib/transport/connectivity_state.h', + 'src/core/lib/transport/hashtable.h', 'src/core/lib/transport/metadata.h', 'src/core/lib/transport/metadata_batch.h', 'src/core/lib/transport/static_metadata.h', @@ -501,6 +502,7 @@ Pod::Spec.new do |s| 'src/core/lib/surface/version.c', 'src/core/lib/transport/byte_stream.c', 'src/core/lib/transport/connectivity_state.c', + 'src/core/lib/transport/hashtable.c', 'src/core/lib/transport/metadata.c', 'src/core/lib/transport/metadata_batch.c', 'src/core/lib/transport/static_metadata.c', @@ -701,6 +703,7 @@ Pod::Spec.new do |s| 'src/core/lib/surface/server.h', 'src/core/lib/transport/byte_stream.h', 'src/core/lib/transport/connectivity_state.h', + 'src/core/lib/transport/hashtable.h', 'src/core/lib/transport/metadata.h', 'src/core/lib/transport/metadata_batch.h', 'src/core/lib/transport/static_metadata.h', diff --git a/grpc.gemspec b/grpc.gemspec index 2d4a8ddbcf..44cd7dd7f7 100755 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -246,6 +246,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/surface/server.h ) s.files += %w( src/core/lib/transport/byte_stream.h ) s.files += %w( src/core/lib/transport/connectivity_state.h ) + s.files += %w( src/core/lib/transport/hashtable.h ) s.files += %w( src/core/lib/transport/metadata.h ) s.files += %w( src/core/lib/transport/metadata_batch.h ) s.files += %w( src/core/lib/transport/static_metadata.h ) @@ -421,6 +422,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/surface/version.c ) s.files += %w( src/core/lib/transport/byte_stream.c ) s.files += %w( src/core/lib/transport/connectivity_state.c ) + s.files += %w( src/core/lib/transport/hashtable.c ) s.files += %w( src/core/lib/transport/metadata.c ) s.files += %w( src/core/lib/transport/metadata_batch.c ) s.files += %w( src/core/lib/transport/static_metadata.c ) diff --git a/package.xml b/package.xml index 8720216260..bf452c3b16 100644 --- a/package.xml +++ b/package.xml @@ -253,6 +253,7 @@ + @@ -428,6 +429,7 @@ + diff --git a/src/core/ext/client_config/method_config.c b/src/core/ext/client_config/method_config.c index 989f776967..553a7be496 100644 --- a/src/core/ext/client_config/method_config.c +++ b/src/core/ext/client_config/method_config.c @@ -39,165 +39,214 @@ #include #include +#include "src/core/lib/transport/hashtable.h" #include "src/core/lib/transport/metadata.h" // // grpc_method_config // +// bool vtable + +static void* bool_copy(void* valuep) { + bool value = *(bool*)valuep; + bool* new_value = gpr_malloc(sizeof(bool)); + *new_value = value; + return new_value; +} + +static int bool_cmp(void* v1, void* v2) { + bool b1 = *(bool*)v1; + bool b2 = *(bool*)v2; + if (!b1 && b2) return -1; + if (b1 && !b2) return 1; + return 0; +} + +static grpc_hash_table_vtable bool_vtable = {gpr_free, bool_copy, bool_cmp}; + +// timespec vtable + +static void* timespec_copy(void* valuep) { + gpr_timespec value = *(gpr_timespec*)valuep; + gpr_timespec* new_value = gpr_malloc(sizeof(gpr_timespec)); + *new_value = value; + return new_value; +} + +static int timespec_cmp(void* v1, void* v2) { + return gpr_time_cmp(*(gpr_timespec*)v1, *(gpr_timespec*)v2); +} + +static grpc_hash_table_vtable timespec_vtable = { + gpr_free, timespec_copy, timespec_cmp}; + +// int32 vtable + +static void* int32_copy(void* valuep) { + int32_t value = *(int32_t*)valuep; + int32_t* new_value = gpr_malloc(sizeof(int32_t)); + *new_value = value; + return new_value; +} + +static int int32_cmp(void* v1, void* v2) { + int32_t i1 = *(int32_t*)v1; + int32_t i2 = *(int32_t*)v2; + if (i1 < i2) return -1; + if (i1 > i2) return 1; + return 0; +} + +static grpc_hash_table_vtable int32_vtable = {gpr_free, int32_copy, int32_cmp}; + +// Hash table keys. +#define GRPC_METHOD_CONFIG_WAIT_FOR_READY "grpc.wait_for_ready" // bool +#define GRPC_METHOD_CONFIG_TIMEOUT "grpc.timeout" // gpr_timespec +#define GRPC_METHOD_CONFIG_MAX_REQUEST_MESSAGE_BYTES \ + "grpc.max_request_message_bytes" // int32 +#define GRPC_METHOD_CONFIG_MAX_RESPONSE_MESSAGE_BYTES \ + "grpc.max_response_message_bytes" // int32 + struct grpc_method_config { - gpr_refcount refs; - bool* wait_for_ready; - gpr_timespec* timeout; - int32_t* max_request_message_bytes; - int32_t* max_response_message_bytes; + grpc_hash_table* table; + grpc_mdstr* wait_for_ready_key; + grpc_mdstr* timeout_key; + grpc_mdstr* max_request_message_bytes_key; + grpc_mdstr* max_response_message_bytes_key; }; grpc_method_config* grpc_method_config_create( bool* wait_for_ready, gpr_timespec* timeout, int32_t* max_request_message_bytes, int32_t* max_response_message_bytes) { - grpc_method_config* config = gpr_malloc(sizeof(*config)); - memset(config, 0, sizeof(*config)); - gpr_ref_init(&config->refs, 1); + grpc_method_config* method_config = gpr_malloc(sizeof(grpc_method_config)); + memset(method_config, 0, sizeof(grpc_method_config)); + grpc_hash_table_entry entries[4]; + size_t num_entries = 0; if (wait_for_ready != NULL) { - config->wait_for_ready = gpr_malloc(sizeof(*wait_for_ready)); - *config->wait_for_ready = *wait_for_ready; + method_config->wait_for_ready_key = + grpc_mdstr_from_string(GRPC_METHOD_CONFIG_WAIT_FOR_READY); + entries[num_entries].key = method_config->wait_for_ready_key; + entries[num_entries].value = wait_for_ready; + entries[num_entries].vtable = &bool_vtable; + ++num_entries; } if (timeout != NULL) { - config->timeout = gpr_malloc(sizeof(*timeout)); - *config->timeout = *timeout; + method_config->timeout_key = + grpc_mdstr_from_string(GRPC_METHOD_CONFIG_TIMEOUT); + entries[num_entries].key = method_config->timeout_key; + entries[num_entries].value = timeout; + entries[num_entries].vtable = ×pec_vtable; + ++num_entries; } if (max_request_message_bytes != NULL) { - config->max_request_message_bytes = - gpr_malloc(sizeof(*max_request_message_bytes)); - *config->max_request_message_bytes = *max_request_message_bytes; + method_config->max_request_message_bytes_key = + grpc_mdstr_from_string(GRPC_METHOD_CONFIG_MAX_REQUEST_MESSAGE_BYTES); + entries[num_entries].key = method_config->max_request_message_bytes_key; + entries[num_entries].value = max_request_message_bytes; + entries[num_entries].vtable = &int32_vtable; + ++num_entries; } if (max_response_message_bytes != NULL) { - config->max_response_message_bytes = - gpr_malloc(sizeof(*max_response_message_bytes)); - *config->max_response_message_bytes = *max_response_message_bytes; + method_config->max_response_message_bytes_key = + grpc_mdstr_from_string(GRPC_METHOD_CONFIG_MAX_RESPONSE_MESSAGE_BYTES); + entries[num_entries].key = method_config->max_response_message_bytes_key; + entries[num_entries].value = max_response_message_bytes; + entries[num_entries].vtable = &int32_vtable; + ++num_entries; } - return config; + method_config->table = grpc_hash_table_create(num_entries, entries); + return method_config; } grpc_method_config* grpc_method_config_ref(grpc_method_config* method_config) { - gpr_ref(&method_config->refs); + grpc_hash_table_ref(method_config->table); return method_config; } void grpc_method_config_unref(grpc_method_config* method_config) { - if (gpr_unref(&method_config->refs)) { - gpr_free(method_config->wait_for_ready); - gpr_free(method_config->timeout); - gpr_free(method_config->max_request_message_bytes); - gpr_free(method_config->max_response_message_bytes); - gpr_free(method_config); + if (grpc_hash_table_unref(method_config->table)) { + GRPC_MDSTR_UNREF(method_config->wait_for_ready_key); + GRPC_MDSTR_UNREF(method_config->timeout_key); + GRPC_MDSTR_UNREF(method_config->max_request_message_bytes_key); + GRPC_MDSTR_UNREF(method_config->max_response_message_bytes_key); } } +int grpc_method_config_cmp(grpc_method_config* method_config1, + grpc_method_config* method_config2) { + return grpc_hash_table_cmp(method_config1->table, method_config2->table); +} + bool* grpc_method_config_get_wait_for_ready(grpc_method_config* method_config) { - return method_config->wait_for_ready; + return grpc_hash_table_get(method_config->table, + method_config->wait_for_ready_key); } gpr_timespec* grpc_method_config_get_timeout( grpc_method_config* method_config) { - return method_config->timeout; + return grpc_hash_table_get(method_config->table, method_config->timeout_key); } int32_t* grpc_method_config_get_max_request_message_bytes( grpc_method_config* method_config) { - return method_config->max_request_message_bytes; + return grpc_hash_table_get(method_config->table, + method_config->max_request_message_bytes_key); } int32_t* grpc_method_config_get_max_response_message_bytes( grpc_method_config* method_config) { - return method_config->max_response_message_bytes; + return grpc_hash_table_get(method_config->table, + method_config->max_response_message_bytes_key); } // // grpc_method_config_table // -typedef struct grpc_method_config_table_entry { - grpc_mdstr* path; - grpc_method_config* method_config; -} grpc_method_config_table_entry; - -#define METHOD_CONFIG_TABLE_SIZE 128 -struct grpc_method_config_table { - gpr_refcount refs; - grpc_method_config_table_entry entries[METHOD_CONFIG_TABLE_SIZE]; -}; - -grpc_method_config_table* grpc_method_config_table_create() { - grpc_method_config_table* table = gpr_malloc(sizeof(*table)); - memset(table, 0, sizeof(*table)); - gpr_ref_init(&table->refs, 1); - return table; +static void method_config_unref(void* valuep) { + grpc_method_config_unref(valuep); } -grpc_method_config_table* grpc_method_config_table_ref( - grpc_method_config_table* table) { - if (table != NULL) gpr_ref(&table->refs); - return table; +static void* method_config_ref(void* valuep) { + return grpc_method_config_ref(valuep); } -void grpc_method_config_table_unref(grpc_method_config_table* table) { - if (table != NULL && gpr_unref(&table->refs)) { - for (size_t i = 0; i < GPR_ARRAY_SIZE(table->entries); ++i) { - grpc_method_config_table_entry* entry = &table->entries[i]; - if (entry->path != NULL) { - GRPC_MDSTR_UNREF(entry->path); - grpc_method_config_unref(entry->method_config); - } - } - } +static int method_config_cmp(void* valuep1, void* valuep2) { + return grpc_method_config_cmp(valuep1, valuep2); } -// Helper function for insert and get operations that performs quadratic -// probing (https://en.wikipedia.org/wiki/Quadratic_probing). -static size_t grpc_method_config_table_find_index( - grpc_method_config_table* table, grpc_mdstr* path, bool find_empty) { - for (size_t i = 0; i < GPR_ARRAY_SIZE(table->entries); ++i) { - const size_t idx = (path->hash + i * i) % GPR_ARRAY_SIZE(table->entries); - if (table->entries[idx].path == NULL) - return find_empty ? idx : GPR_ARRAY_SIZE(table->entries); - if (table->entries[idx].path == path) return idx; +static const grpc_hash_table_vtable method_config_table_vtable = { + method_config_unref, method_config_ref, method_config_cmp}; + +grpc_method_config_table* grpc_method_config_table_create( + size_t num_entries, grpc_method_config_table_entry* entries) { + grpc_hash_table_entry hash_table_entries[num_entries]; + for (size_t i = 0; i < num_entries; ++i) { + hash_table_entries[i].key = entries[i].method_name; + hash_table_entries[i].value = entries[i].method_config; + hash_table_entries[i].vtable = &method_config_table_vtable; } - return GPR_ARRAY_SIZE(table->entries) + 1; // Not found. + return grpc_hash_table_create(num_entries, hash_table_entries); } -static void grpc_method_config_table_insert(grpc_method_config_table* table, - grpc_mdstr* path, - grpc_method_config* config) { - const size_t idx = - grpc_method_config_table_find_index(table, path, true /* find_empty */); - // This can happen if the table is full. - GPR_ASSERT(idx != GPR_ARRAY_SIZE(table->entries)); - grpc_method_config_table_entry* entry = &table->entries[idx]; - entry->path = GRPC_MDSTR_REF(path); - entry->method_config = grpc_method_config_ref(config); +grpc_method_config_table* grpc_method_config_table_ref( + grpc_method_config_table* table) { + return grpc_hash_table_ref(table); } -static grpc_method_config* grpc_method_config_table_get( - grpc_method_config_table* table, grpc_mdstr* path) { - const size_t idx = - grpc_method_config_table_find_index(table, path, false /* find_empty */); - if (idx == GPR_ARRAY_SIZE(table->entries)) return NULL; // Not found. - return table->entries[idx].method_config; +void grpc_method_config_table_unref(grpc_method_config_table* table) { + grpc_hash_table_unref(table); } -void grpc_method_config_table_add_method_config( - grpc_method_config_table* table, grpc_mdstr** paths, size_t num_paths, - grpc_method_config* method_config) { - for (size_t i = 0; i < num_paths; ++i) { - grpc_method_config_table_insert(table, paths[i], method_config); - } +int grpc_method_config_table_cmp(grpc_method_config_table* table1, + grpc_method_config_table* table2) { + return grpc_hash_table_cmp(table1, table2); } grpc_method_config* grpc_method_config_table_get_method_config( grpc_method_config_table* table, grpc_mdstr* path) { - grpc_method_config* method_config = grpc_method_config_table_get(table, path); + grpc_method_config* method_config = grpc_hash_table_get(table, path); // If we didn't find a match for the path, try looking for a wildcard // entry (i.e., change "/service/method" to "/service/*"). if (method_config == NULL) { @@ -209,7 +258,7 @@ grpc_method_config* grpc_method_config_table_get_method_config( buf[len] = '*'; buf[len + 1] = '\0'; grpc_mdstr* wildcard_path = grpc_mdstr_from_string(buf); - method_config = grpc_method_config_table_get(table, wildcard_path); + method_config = grpc_hash_table_get(table, wildcard_path); GRPC_MDSTR_UNREF(wildcard_path); } return grpc_method_config_ref(method_config); @@ -224,52 +273,7 @@ static void destroy_arg(void* p) { } static int cmp_arg(void* p1, void* p2) { - grpc_method_config_table* t1 = p1; - grpc_method_config_table* t2 = p2; - for (size_t i = 0; i < GPR_ARRAY_SIZE(t1->entries); ++i) { - grpc_method_config_table_entry* e1 = &t1->entries[i]; - grpc_method_config_table_entry* e2 = &t2->entries[i]; - // Compare paths by hash value. - if (e1->path->hash < e2->path->hash) return -1; - if (e1->path->hash > e2->path->hash) return 1; - // Compare wait_for_ready. - const bool wait_for_ready1 = - e1->method_config->wait_for_ready == NULL - ? false : *e1->method_config->wait_for_ready; - const bool wait_for_ready2 = - e2->method_config->wait_for_ready == NULL - ? false : *e2->method_config->wait_for_ready; - if (wait_for_ready1 < wait_for_ready2) return -1; - if (wait_for_ready1 > wait_for_ready2) return 1; - // Compare timeout. - const gpr_timespec timeout1 = - e1->method_config->timeout == NULL - ? gpr_inf_past(GPR_CLOCK_MONOTONIC) : *e1->method_config->timeout; - const gpr_timespec timeout2 = - e2->method_config->timeout == NULL - ? gpr_inf_past(GPR_CLOCK_MONOTONIC) : *e2->method_config->timeout; - const int timeout_result = gpr_time_cmp(timeout1, timeout2); - if (timeout_result != 0) return timeout_result; - // Compare max_request_message_bytes. - const int32_t max_request_message_bytes1 = - e1->method_config->max_request_message_bytes == NULL - ? -1 : *e1->method_config->max_request_message_bytes; - const int32_t max_request_message_bytes2 = - e2->method_config->max_request_message_bytes == NULL - ? -1 : *e2->method_config->max_request_message_bytes; - if (max_request_message_bytes1 < max_request_message_bytes2) return -1; - if (max_request_message_bytes1 > max_request_message_bytes2) return 1; - // Compare max_response_message_bytes. - const int32_t max_response_message_bytes1 = - e1->method_config->max_response_message_bytes == NULL - ? -1 : *e1->method_config->max_response_message_bytes; - const int32_t max_response_message_bytes2 = - e2->method_config->max_response_message_bytes == NULL - ? -1 : *e2->method_config->max_response_message_bytes; - if (max_response_message_bytes1 < max_response_message_bytes2) return -1; - if (max_response_message_bytes1 > max_response_message_bytes2) return 1; - } - return 0; + return grpc_method_config_table_cmp(p1, p2); } static grpc_arg_pointer_vtable arg_vtable = {copy_arg, destroy_arg, cmp_arg}; diff --git a/src/core/ext/client_config/method_config.h b/src/core/ext/client_config/method_config.h index 2be0cd1006..e95a5583be 100644 --- a/src/core/ext/client_config/method_config.h +++ b/src/core/ext/client_config/method_config.h @@ -37,6 +37,7 @@ #include #include +#include "src/core/lib/transport/hashtable.h" #include "src/core/lib/transport/metadata.h" /// Per-method configuration. @@ -50,6 +51,9 @@ grpc_method_config* grpc_method_config_create( grpc_method_config* grpc_method_config_ref(grpc_method_config* method_config); void grpc_method_config_unref(grpc_method_config* method_config); +int grpc_method_config_cmp(grpc_method_config* method_config1, + grpc_method_config* method_config2); + /// These methods return NULL if the requested field is unset. /// The caller does NOT take ownership of the result. bool* grpc_method_config_get_wait_for_ready(grpc_method_config* method_config); @@ -60,23 +64,26 @@ int32_t* grpc_method_config_get_max_response_message_bytes( grpc_method_config* method_config); /// A table of method configs. -typedef struct grpc_method_config_table grpc_method_config_table; +typedef grpc_hash_table grpc_method_config_table; + +typedef struct grpc_method_config_table_entry { + /// The name is of one of the following forms: + /// service/method -- specifies exact service and method name + /// service/* -- matches all methods for the specified service + grpc_mdstr* method_name; + grpc_method_config* method_config; +} grpc_method_config_table_entry; -grpc_method_config_table* grpc_method_config_table_create(); +/// Takes new references to all keys and values in \a entries. +grpc_method_config_table* grpc_method_config_table_create( + size_t num_entries, grpc_method_config_table_entry* entries); grpc_method_config_table* grpc_method_config_table_ref( grpc_method_config_table* table); void grpc_method_config_table_unref(grpc_method_config_table* table); -/// Adds \a method_config to \a table. \a paths indicates the set of path -/// names for which this config applies. Each name is of one of the -/// following forms: -/// service/method -- specifies exact service and method name -/// service/* -- matches all methods for the specified service -/// Takes new references to all elements of \a paths and to \a method_config. -void grpc_method_config_table_add_method_config( - grpc_method_config_table* table, grpc_mdstr** paths, size_t num_paths, - grpc_method_config* method_config); +int grpc_method_config_table_cmp(grpc_method_config_table* table1, + grpc_method_config_table* table2); /// Returns NULL if the method has no config. /// Caller owns a reference to result. diff --git a/src/core/lib/transport/hashtable.c b/src/core/lib/transport/hashtable.c new file mode 100644 index 0000000000..89e2640969 --- /dev/null +++ b/src/core/lib/transport/hashtable.c @@ -0,0 +1,139 @@ +// +// Copyright 2016, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// + +#include "src/core/lib/transport/hashtable.h" + +#include +#include + +#include +#include + +#include "src/core/lib/transport/metadata.h" + +struct grpc_hash_table { + gpr_refcount refs; + size_t num_entries; + grpc_hash_table_entry* entries; +}; + +// Helper function for insert and get operations that performs quadratic +// probing (https://en.wikipedia.org/wiki/Quadratic_probing). +static size_t grpc_hash_table_find_index( + grpc_hash_table* table, grpc_mdstr* key, bool find_empty) { + for (size_t i = 0; i < table->num_entries; ++i) { + const size_t idx = (key->hash + i * i) % table->num_entries; + if (table->entries[idx].key == NULL) + return find_empty ? idx : table->num_entries; + if (table->entries[idx].key == key) return idx; + } + return table->num_entries; // Not found. +} + +static void grpc_hash_table_add(grpc_hash_table* table, grpc_mdstr* key, + void* value, + const grpc_hash_table_vtable* vtable) { + GPR_ASSERT(value != NULL); + const size_t idx = + grpc_hash_table_find_index(table, key, true /* find_empty */); + // This can happen if the table is full. + GPR_ASSERT(idx != table->num_entries); + grpc_hash_table_entry* entry = &table->entries[idx]; + entry->key = GRPC_MDSTR_REF(key); + entry->value = vtable->copy_value(value); + entry->vtable = vtable; +} + +grpc_hash_table* grpc_hash_table_create(size_t num_entries, + grpc_hash_table_entry* entries) { + grpc_hash_table* table = gpr_malloc(sizeof(*table)); + memset(table, 0, sizeof(*table)); + gpr_ref_init(&table->refs, 1); + // Quadratic chaining gets best performance when the table is no more + // than half full. + table->num_entries = num_entries * 2; + const size_t entry_size = sizeof(grpc_hash_table_entry) * table->num_entries; + table->entries = gpr_malloc(entry_size); + memset(table->entries, 0, entry_size); + for (size_t i = 0; i < num_entries; ++i) { + grpc_hash_table_entry* entry = &entries[i]; + grpc_hash_table_add(table, entry->key, entry->value, entry->vtable); + } + return table; +} + +grpc_hash_table* grpc_hash_table_ref(grpc_hash_table* table) { + if (table != NULL) gpr_ref(&table->refs); + return table; +} + +int grpc_hash_table_unref(grpc_hash_table* table) { + if (table != NULL && gpr_unref(&table->refs)) { + for (size_t i = 0; i < table->num_entries; ++i) { + grpc_hash_table_entry* entry = &table->entries[i]; + if (entry->key != NULL) { + GRPC_MDSTR_UNREF(entry->key); + entry->vtable->destroy_value(entry->value); + } + } + gpr_free(table->entries); + gpr_free(table); + return 1; + } + return 0; +} + +void* grpc_hash_table_get(grpc_hash_table* table, grpc_mdstr* key) { + const size_t idx = + grpc_hash_table_find_index(table, key, false /* find_empty */); + if (idx == table->num_entries) return NULL; // Not found. + return table->entries[idx].value; +} + +int grpc_hash_table_cmp(grpc_hash_table* table1, grpc_hash_table* table2) { + // Compare by num_entries. + if (table1->num_entries < table2->num_entries) return -1; + if (table1->num_entries > table2->num_entries) return 1; + for (size_t i = 0; i < table1->num_entries; ++i) { + grpc_hash_table_entry* e1 = &table1->entries[i]; + grpc_hash_table_entry* e2 = &table2->entries[i]; + // Compare keys by hash value. + if (e1->key->hash < e2->key->hash) return -1; + if (e1->key->hash > e2->key->hash) return 1; + // Compare by vtable (pointer equality). + if (e1->vtable < e2->vtable) return -1; + if (e1->vtable > e2->vtable) return 1; + // Compare values via vtable. + const int value_result = e1->vtable->compare_value(e1->value, e2->value); + if (value_result != 0) return value_result; + } + return 0; +} diff --git a/src/core/lib/transport/hashtable.h b/src/core/lib/transport/hashtable.h new file mode 100644 index 0000000000..93f0642c17 --- /dev/null +++ b/src/core/lib/transport/hashtable.h @@ -0,0 +1,82 @@ +/* + * Copyright 2016, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef GRPC_CORE_LIB_TRANSPORT_HASHTABLE_H +#define GRPC_CORE_LIB_TRANSPORT_HASHTABLE_H + +#include "src/core/lib/transport/metadata.h" + +/** Hash table implementation. + * + * This implementation uses open addressing + * (https://en.wikipedia.org/wiki/Open_addressing) with quadratic + * probing (https://en.wikipedia.org/wiki/Quadratic_probing). + * This means that the hash table is of fixed size and cannot contain + * more than that number of elements. + * + * The keys are grpc_mdstr objects. The values are arbitrary pointers + * with a common vtable. + * + * Hash tables are intentionally immutable, to avoid the need for locking. + */ + +typedef struct grpc_hash_table grpc_hash_table; + +typedef struct grpc_hash_table_vtable { + void (*destroy_value)(void* value); + void* (*copy_value)(void* value); + int (*compare_value)(void* value1, void* value2); +} grpc_hash_table_vtable; + +typedef struct grpc_hash_table_entry { + grpc_mdstr* key; + void* value; /* Must not be NULL. */ + const grpc_hash_table_vtable* vtable; +} grpc_hash_table_entry; + +/** Creates a new hash table of containing \a entries, which is an array + of length \a num_entries. + Creates its own copy of all keys and values from \a entries. */ +grpc_hash_table* grpc_hash_table_create(size_t num_entries, + grpc_hash_table_entry* entries); + +grpc_hash_table* grpc_hash_table_ref(grpc_hash_table* table); +/** Returns 1 when \a table is destroyed. */ +int grpc_hash_table_unref(grpc_hash_table* table); + +/** Returns the value from \a table associated with \a key. + Returns NULL if \a key is not found. */ +void* grpc_hash_table_get(grpc_hash_table* table, grpc_mdstr* key); + +/** Compares two hash tables. */ +int grpc_hash_table_cmp(grpc_hash_table* table1, grpc_hash_table* table2); + +#endif /* GRPC_CORE_LIB_TRANSPORT_HASHTABLE_H */ diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index f9308ba7a5..315d469a15 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -164,6 +164,7 @@ CORE_SOURCE_FILES = [ 'src/core/lib/surface/version.c', 'src/core/lib/transport/byte_stream.c', 'src/core/lib/transport/connectivity_state.c', + 'src/core/lib/transport/hashtable.c', 'src/core/lib/transport/metadata.c', 'src/core/lib/transport/metadata_batch.c', 'src/core/lib/transport/static_metadata.c', diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index ce21a4ea00..1619194d4a 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -947,6 +947,7 @@ src/core/lib/surface/lame_client.h \ src/core/lib/surface/server.h \ src/core/lib/transport/byte_stream.h \ src/core/lib/transport/connectivity_state.h \ +src/core/lib/transport/hashtable.h \ src/core/lib/transport/metadata.h \ src/core/lib/transport/metadata_batch.h \ src/core/lib/transport/static_metadata.h \ @@ -1072,6 +1073,7 @@ src/core/lib/surface/validate_metadata.c \ src/core/lib/surface/version.c \ src/core/lib/transport/byte_stream.c \ src/core/lib/transport/connectivity_state.c \ +src/core/lib/transport/hashtable.c \ src/core/lib/transport/metadata.c \ src/core/lib/transport/metadata_batch.c \ src/core/lib/transport/static_metadata.c \ diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 9ea6695f24..c9317396f6 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -863,6 +863,7 @@ src/core/lib/surface/lame_client.h \ src/core/lib/surface/server.h \ src/core/lib/transport/byte_stream.h \ src/core/lib/transport/connectivity_state.h \ +src/core/lib/transport/hashtable.h \ src/core/lib/transport/metadata.h \ src/core/lib/transport/metadata_batch.h \ src/core/lib/transport/static_metadata.h \ @@ -1038,6 +1039,7 @@ src/core/lib/surface/validate_metadata.c \ src/core/lib/surface/version.c \ src/core/lib/transport/byte_stream.c \ src/core/lib/transport/connectivity_state.c \ +src/core/lib/transport/hashtable.c \ src/core/lib/transport/metadata.c \ src/core/lib/transport/metadata_batch.c \ src/core/lib/transport/static_metadata.c \ diff --git a/tools/run_tests/sources_and_headers.json b/tools/run_tests/sources_and_headers.json index f6889c8f3a..0fe6cdf6b9 100644 --- a/tools/run_tests/sources_and_headers.json +++ b/tools/run_tests/sources_and_headers.json @@ -6049,6 +6049,7 @@ "src/core/lib/surface/server.h", "src/core/lib/transport/byte_stream.h", "src/core/lib/transport/connectivity_state.h", + "src/core/lib/transport/hashtable.h", "src/core/lib/transport/metadata.h", "src/core/lib/transport/metadata_batch.h", "src/core/lib/transport/static_metadata.h", @@ -6229,6 +6230,8 @@ "src/core/lib/transport/byte_stream.h", "src/core/lib/transport/connectivity_state.c", "src/core/lib/transport/connectivity_state.h", + "src/core/lib/transport/hashtable.c", + "src/core/lib/transport/hashtable.h", "src/core/lib/transport/metadata.c", "src/core/lib/transport/metadata.h", "src/core/lib/transport/metadata_batch.c", diff --git a/vsprojects/vcxproj/grpc++/grpc++.vcxproj b/vsprojects/vcxproj/grpc++/grpc++.vcxproj index 88ddecf426..92a7e02e52 100644 --- a/vsprojects/vcxproj/grpc++/grpc++.vcxproj +++ b/vsprojects/vcxproj/grpc++/grpc++.vcxproj @@ -447,6 +447,7 @@ + @@ -693,6 +694,8 @@ + + diff --git a/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters b/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters index a6616449d3..9282b52eef 100644 --- a/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters +++ b/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters @@ -358,6 +358,9 @@ src\core\lib\transport + + src\core\lib\transport + src\core\lib\transport @@ -944,6 +947,9 @@ src\core\lib\transport + + src\core\lib\transport + src\core\lib\transport diff --git a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj index 99cee2830a..0270fe4836 100644 --- a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj +++ b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj @@ -443,6 +443,7 @@ + @@ -679,6 +680,8 @@ + + diff --git a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters index e1b6b2f327..8863237f43 100644 --- a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters +++ b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters @@ -343,6 +343,9 @@ src\core\lib\transport + + src\core\lib\transport + src\core\lib\transport @@ -917,6 +920,9 @@ src\core\lib\transport + + src\core\lib\transport + src\core\lib\transport diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj b/vsprojects/vcxproj/grpc/grpc.vcxproj index ba2174f429..b2352d74f4 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj @@ -372,6 +372,7 @@ + @@ -636,6 +637,8 @@ + + diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters index ee3e7a85d3..ee7825ae88 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters @@ -262,6 +262,9 @@ src\core\lib\transport + + src\core\lib\transport + src\core\lib\transport @@ -902,6 +905,9 @@ src\core\lib\transport + + src\core\lib\transport + src\core\lib\transport diff --git a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj index 21d9fc9529..f09be1528b 100644 --- a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj +++ b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj @@ -264,6 +264,7 @@ + @@ -480,6 +481,8 @@ + + diff --git a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters index 09a32482cd..7be3b76d23 100644 --- a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters +++ b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters @@ -313,6 +313,9 @@ src\core\lib\transport + + src\core\lib\transport + src\core\lib\transport @@ -680,6 +683,9 @@ src\core\lib\transport + + src\core\lib\transport + src\core\lib\transport diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj index be02a4fa92..09a1e2386d 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj @@ -362,6 +362,7 @@ + @@ -604,6 +605,8 @@ + + diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters index 482da9b984..df7a9b9b43 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters @@ -265,6 +265,9 @@ src\core\lib\transport + + src\core\lib\transport + src\core\lib\transport @@ -812,6 +815,9 @@ src\core\lib\transport + + src\core\lib\transport + src\core\lib\transport -- cgit v1.2.3 From d51e0352c5460a0c050a026dd4d2c1b498ddb57f Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Fri, 30 Sep 2016 08:23:30 -0700 Subject: Various fixes and clean-ups. --- src/core/ext/client_config/client_channel.c | 4 +++- src/core/ext/client_config/method_config.c | 19 ++++++++++--------- src/core/ext/client_config/method_config.h | 2 +- src/core/ext/client_config/resolver_result.c | 5 ----- src/core/ext/client_config/resolver_result.h | 2 +- src/core/lib/channel/channel_args.c | 4 +++- src/core/lib/channel/channel_args.h | 4 +--- src/core/lib/transport/hashtable.c | 2 +- 8 files changed, 20 insertions(+), 22 deletions(-) (limited to 'src/core/ext/client_config/method_config.h') diff --git a/src/core/ext/client_config/client_channel.c b/src/core/ext/client_config/client_channel.c index 3860f65f95..026d3a51b8 100644 --- a/src/core/ext/client_config/client_channel.c +++ b/src/core/ext/client_config/client_channel.c @@ -811,7 +811,9 @@ static grpc_error *cc_init_call_elem(grpc_exec_ctx *exec_ctx, *wait_for_ready ? WAIT_FOR_READY_TRUE : WAIT_FOR_READY_FALSE; } } - grpc_method_config_table_unref(chand->method_config_table); + if (method_config_table != NULL) { + grpc_method_config_table_unref(method_config_table); + } calld->deadline = args->deadline; calld->path = GRPC_MDSTR_REF(args->path); calld->cancel_error = GRPC_ERROR_NONE; diff --git a/src/core/ext/client_config/method_config.c b/src/core/ext/client_config/method_config.c index 553a7be496..95efe492a9 100644 --- a/src/core/ext/client_config/method_config.c +++ b/src/core/ext/client_config/method_config.c @@ -121,35 +121,35 @@ grpc_method_config* grpc_method_config_create( int32_t* max_request_message_bytes, int32_t* max_response_message_bytes) { grpc_method_config* method_config = gpr_malloc(sizeof(grpc_method_config)); memset(method_config, 0, sizeof(grpc_method_config)); + method_config->wait_for_ready_key = + grpc_mdstr_from_string(GRPC_METHOD_CONFIG_WAIT_FOR_READY); + method_config->timeout_key = + grpc_mdstr_from_string(GRPC_METHOD_CONFIG_TIMEOUT); + method_config->max_request_message_bytes_key = + grpc_mdstr_from_string(GRPC_METHOD_CONFIG_MAX_REQUEST_MESSAGE_BYTES); + method_config->max_response_message_bytes_key = + grpc_mdstr_from_string(GRPC_METHOD_CONFIG_MAX_RESPONSE_MESSAGE_BYTES); grpc_hash_table_entry entries[4]; size_t num_entries = 0; if (wait_for_ready != NULL) { - method_config->wait_for_ready_key = - grpc_mdstr_from_string(GRPC_METHOD_CONFIG_WAIT_FOR_READY); entries[num_entries].key = method_config->wait_for_ready_key; entries[num_entries].value = wait_for_ready; entries[num_entries].vtable = &bool_vtable; ++num_entries; } if (timeout != NULL) { - method_config->timeout_key = - grpc_mdstr_from_string(GRPC_METHOD_CONFIG_TIMEOUT); entries[num_entries].key = method_config->timeout_key; entries[num_entries].value = timeout; entries[num_entries].vtable = ×pec_vtable; ++num_entries; } if (max_request_message_bytes != NULL) { - method_config->max_request_message_bytes_key = - grpc_mdstr_from_string(GRPC_METHOD_CONFIG_MAX_REQUEST_MESSAGE_BYTES); entries[num_entries].key = method_config->max_request_message_bytes_key; entries[num_entries].value = max_request_message_bytes; entries[num_entries].vtable = &int32_vtable; ++num_entries; } if (max_response_message_bytes != NULL) { - method_config->max_response_message_bytes_key = - grpc_mdstr_from_string(GRPC_METHOD_CONFIG_MAX_RESPONSE_MESSAGE_BYTES); entries[num_entries].key = method_config->max_response_message_bytes_key; entries[num_entries].value = max_response_message_bytes; entries[num_entries].vtable = &int32_vtable; @@ -170,6 +170,7 @@ void grpc_method_config_unref(grpc_method_config* method_config) { GRPC_MDSTR_UNREF(method_config->timeout_key); GRPC_MDSTR_UNREF(method_config->max_request_message_bytes_key); GRPC_MDSTR_UNREF(method_config->max_response_message_bytes_key); + gpr_free(method_config); } } @@ -261,7 +262,7 @@ grpc_method_config* grpc_method_config_table_get_method_config( method_config = grpc_hash_table_get(table, wildcard_path); GRPC_MDSTR_UNREF(wildcard_path); } - return grpc_method_config_ref(method_config); + return method_config; } static void* copy_arg(void* p) { diff --git a/src/core/ext/client_config/method_config.h b/src/core/ext/client_config/method_config.h index e95a5583be..65b34a768a 100644 --- a/src/core/ext/client_config/method_config.h +++ b/src/core/ext/client_config/method_config.h @@ -86,7 +86,7 @@ int grpc_method_config_table_cmp(grpc_method_config_table* table1, grpc_method_config_table* table2); /// Returns NULL if the method has no config. -/// Caller owns a reference to result. +/// Caller does NOT own a reference to the result. grpc_method_config* grpc_method_config_table_get_method_config( grpc_method_config_table* table, grpc_mdstr* path); diff --git a/src/core/ext/client_config/resolver_result.c b/src/core/ext/client_config/resolver_result.c index 16d124d205..63480d152b 100644 --- a/src/core/ext/client_config/resolver_result.c +++ b/src/core/ext/client_config/resolver_result.c @@ -36,13 +36,8 @@ #include #include -#include "src/core/lib/transport/metadata.h" #include "src/core/lib/channel/channel_args.h" -// -// grpc_resolver_result -// - struct grpc_resolver_result { gpr_refcount refs; char* server_name; diff --git a/src/core/ext/client_config/resolver_result.h b/src/core/ext/client_config/resolver_result.h index 707c8c2cf5..a7ea7c0f4b 100644 --- a/src/core/ext/client_config/resolver_result.h +++ b/src/core/ext/client_config/resolver_result.h @@ -48,7 +48,7 @@ /// Results reported from a grpc_resolver. typedef struct grpc_resolver_result grpc_resolver_result; -/// Takes ownership of \a addresses, \a lb_policy_args. +/// Takes ownership of \a addresses and \a lb_policy_args. grpc_resolver_result* grpc_resolver_result_create( const char* server_name, grpc_lb_addresses* addresses, const char* lb_policy_name, grpc_channel_args* lb_policy_args); diff --git a/src/core/lib/channel/channel_args.c b/src/core/lib/channel/channel_args.c index bab6fcd9fa..2957d2c818 100644 --- a/src/core/lib/channel/channel_args.c +++ b/src/core/lib/channel/channel_args.c @@ -276,7 +276,9 @@ const grpc_arg *grpc_channel_args_find(const grpc_channel_args *args, const char *name) { if (args != NULL) { for (size_t i = 0; i < args->num_args; ++i) { - if (args->args[i].key == name) return &args->args[i]; + if (strcmp(args->args[i].key, name) == 0) { + return &args->args[i]; + } } } return NULL; diff --git a/src/core/lib/channel/channel_args.h b/src/core/lib/channel/channel_args.h index 38fb4c55d4..a80340c0fa 100644 --- a/src/core/lib/channel/channel_args.h +++ b/src/core/lib/channel/channel_args.h @@ -89,9 +89,7 @@ uint32_t grpc_channel_args_compression_algorithm_get_states( int grpc_channel_args_compare(const grpc_channel_args *a, const grpc_channel_args *b); -/** Returns the value of argument \a name from \a args, or NULL if not found. - Note: \a name is matched using pointer equality, so it must be the - same instance of the string used to create the grpc_arg key. */ +/** Returns the value of argument \a name from \a args, or NULL if not found. */ const grpc_arg *grpc_channel_args_find(const grpc_channel_args *args, const char *name); diff --git a/src/core/lib/transport/hashtable.c b/src/core/lib/transport/hashtable.c index 89e2640969..3e0e0bd6c6 100644 --- a/src/core/lib/transport/hashtable.c +++ b/src/core/lib/transport/hashtable.c @@ -77,7 +77,7 @@ grpc_hash_table* grpc_hash_table_create(size_t num_entries, grpc_hash_table* table = gpr_malloc(sizeof(*table)); memset(table, 0, sizeof(*table)); gpr_ref_init(&table->refs, 1); - // Quadratic chaining gets best performance when the table is no more + // Quadratic probing gets best performance when the table is no more // than half full. table->num_entries = num_entries * 2; const size_t entry_size = sizeof(grpc_hash_table_entry) * table->num_entries; -- cgit v1.2.3 From c1c38586dedfb4368372a2de03df1645a2a9ee7f Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Tue, 11 Oct 2016 11:03:27 -0700 Subject: Code review changes. --- src/core/ext/client_config/client_channel.c | 25 +++++++++++++++---------- src/core/ext/client_config/method_config.c | 25 +++++++++++++------------ src/core/ext/client_config/method_config.h | 24 +++++++++++++----------- src/core/lib/channel/message_size_filter.c | 4 ++-- src/core/lib/transport/hashtable.c | 9 +++++---- src/core/lib/transport/hashtable.h | 5 +++-- 6 files changed, 51 insertions(+), 41 deletions(-) (limited to 'src/core/ext/client_config/method_config.h') diff --git a/src/core/ext/client_config/client_channel.c b/src/core/ext/client_config/client_channel.c index 0d243768ef..0594c0b3ac 100644 --- a/src/core/ext/client_config/client_channel.c +++ b/src/core/ext/client_config/client_channel.c @@ -663,9 +663,13 @@ static bool pick_subchannel(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, // If the application explicitly set wait_for_ready, use that. // Otherwise, if the service config specified a value for this // method, use that. - if ((initial_metadata_flags & - GRPC_INITIAL_METADATA_WAIT_FOR_READY_EXPLICITLY_SET) == 0 && - calld->wait_for_ready_from_service_config != WAIT_FOR_READY_UNSET) { + const bool wait_for_ready_set_from_api = + initial_metadata_flags & + GRPC_INITIAL_METADATA_WAIT_FOR_READY_EXPLICITLY_SET; + const bool wait_for_ready_set_from_service_config = + calld->wait_for_ready_from_service_config != WAIT_FOR_READY_UNSET; + if (!wait_for_ready_set_from_api && + wait_for_ready_set_from_service_config) { if (calld->wait_for_ready_from_service_config == WAIT_FOR_READY_TRUE) { initial_metadata_flags |= GRPC_INITIAL_METADATA_WAIT_FOR_READY; } else { @@ -676,8 +680,9 @@ static bool pick_subchannel(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, const grpc_lb_policy_pick_args inputs = { calld->pollent, initial_metadata, initial_metadata_flags, &calld->lb_token_mdelem, gpr_inf_future(GPR_CLOCK_MONOTONIC)}; - bool result = grpc_lb_policy_pick(exec_ctx, lb_policy, &inputs, - connected_subchannel, NULL, on_ready); + const bool result = + grpc_lb_policy_pick(exec_ctx, lb_policy, &inputs, + connected_subchannel, NULL, on_ready); GRPC_LB_POLICY_UNREF(exec_ctx, lb_policy, "pick_subchannel"); GPR_TIMER_END("pick_subchannel", 0); return result; @@ -836,13 +841,13 @@ static void read_service_config(grpc_exec_ctx *exec_ctx, void *arg, gpr_mu_unlock(&chand->mu); // If the method config table was present, use it. if (method_config_table != NULL) { - grpc_method_config *method_config = + const grpc_method_config *method_config = grpc_method_config_table_get_method_config(method_config_table, calld->path); if (method_config != NULL) { - gpr_timespec *per_method_timeout = + const gpr_timespec *per_method_timeout = grpc_method_config_get_timeout(method_config); - bool *wait_for_ready = + const bool *wait_for_ready = grpc_method_config_get_wait_for_ready(method_config); if (per_method_timeout != NULL || wait_for_ready != NULL) { gpr_mu_lock(&calld->mu); @@ -907,14 +912,14 @@ static grpc_error *cc_init_call_elem(grpc_exec_ctx *exec_ctx, grpc_method_config_table_get_method_config(method_config_table, args->path); if (method_config != NULL) { - gpr_timespec *per_method_timeout = + const gpr_timespec *per_method_timeout = grpc_method_config_get_timeout(method_config); if (per_method_timeout != NULL) { gpr_timespec per_method_deadline = gpr_time_add(calld->call_start_time, *per_method_timeout); calld->deadline = gpr_time_min(calld->deadline, per_method_deadline); } - bool *wait_for_ready = + const bool *wait_for_ready = grpc_method_config_get_wait_for_ready(method_config); if (wait_for_ready != NULL) { calld->wait_for_ready_from_service_config = diff --git a/src/core/ext/client_config/method_config.c b/src/core/ext/client_config/method_config.c index a112355ff5..3699c22810 100644 --- a/src/core/ext/client_config/method_config.c +++ b/src/core/ext/client_config/method_config.c @@ -174,29 +174,30 @@ void grpc_method_config_unref(grpc_method_config* method_config) { } } -int grpc_method_config_cmp(grpc_method_config* method_config1, - grpc_method_config* method_config2) { +int grpc_method_config_cmp(const grpc_method_config* method_config1, + const grpc_method_config* method_config2) { return grpc_hash_table_cmp(method_config1->table, method_config2->table); } -bool* grpc_method_config_get_wait_for_ready(grpc_method_config* method_config) { +const bool* grpc_method_config_get_wait_for_ready( + const grpc_method_config* method_config) { return grpc_hash_table_get(method_config->table, method_config->wait_for_ready_key); } -gpr_timespec* grpc_method_config_get_timeout( - grpc_method_config* method_config) { +const gpr_timespec* grpc_method_config_get_timeout( + const grpc_method_config* method_config) { return grpc_hash_table_get(method_config->table, method_config->timeout_key); } -int32_t* grpc_method_config_get_max_request_message_bytes( - grpc_method_config* method_config) { +const int32_t* grpc_method_config_get_max_request_message_bytes( + const grpc_method_config* method_config) { return grpc_hash_table_get(method_config->table, method_config->max_request_message_bytes_key); } -int32_t* grpc_method_config_get_max_response_message_bytes( - grpc_method_config* method_config) { +const int32_t* grpc_method_config_get_max_response_message_bytes( + const grpc_method_config* method_config) { return grpc_hash_table_get(method_config->table, method_config->max_response_message_bytes_key); } @@ -244,13 +245,13 @@ void grpc_method_config_table_unref(grpc_method_config_table* table) { grpc_hash_table_unref(table); } -int grpc_method_config_table_cmp(grpc_method_config_table* table1, - grpc_method_config_table* table2) { +int grpc_method_config_table_cmp(const grpc_method_config_table* table1, + const grpc_method_config_table* table2) { return grpc_hash_table_cmp(table1, table2); } grpc_method_config* grpc_method_config_table_get_method_config( - grpc_method_config_table* table, grpc_mdstr* path) { + const grpc_method_config_table* table, const grpc_mdstr* path) { grpc_method_config* method_config = grpc_hash_table_get(table, path); // If we didn't find a match for the path, try looking for a wildcard // entry (i.e., change "/service/method" to "/service/*"). diff --git a/src/core/ext/client_config/method_config.h b/src/core/ext/client_config/method_config.h index 65b34a768a..04e6bc8141 100644 --- a/src/core/ext/client_config/method_config.h +++ b/src/core/ext/client_config/method_config.h @@ -51,17 +51,19 @@ grpc_method_config* grpc_method_config_create( grpc_method_config* grpc_method_config_ref(grpc_method_config* method_config); void grpc_method_config_unref(grpc_method_config* method_config); -int grpc_method_config_cmp(grpc_method_config* method_config1, - grpc_method_config* method_config2); +int grpc_method_config_cmp(const grpc_method_config* method_config1, + const grpc_method_config* method_config2); /// These methods return NULL if the requested field is unset. /// The caller does NOT take ownership of the result. -bool* grpc_method_config_get_wait_for_ready(grpc_method_config* method_config); -gpr_timespec* grpc_method_config_get_timeout(grpc_method_config* method_config); -int32_t* grpc_method_config_get_max_request_message_bytes( - grpc_method_config* method_config); -int32_t* grpc_method_config_get_max_response_message_bytes( - grpc_method_config* method_config); +const bool* grpc_method_config_get_wait_for_ready( + const grpc_method_config* method_config); +const gpr_timespec* grpc_method_config_get_timeout( + const grpc_method_config* method_config); +const int32_t* grpc_method_config_get_max_request_message_bytes( + const grpc_method_config* method_config); +const int32_t* grpc_method_config_get_max_response_message_bytes( + const grpc_method_config* method_config); /// A table of method configs. typedef grpc_hash_table grpc_method_config_table; @@ -82,13 +84,13 @@ grpc_method_config_table* grpc_method_config_table_ref( grpc_method_config_table* table); void grpc_method_config_table_unref(grpc_method_config_table* table); -int grpc_method_config_table_cmp(grpc_method_config_table* table1, - grpc_method_config_table* table2); +int grpc_method_config_table_cmp(const grpc_method_config_table* table1, + const grpc_method_config_table* table2); /// Returns NULL if the method has no config. /// Caller does NOT own a reference to the result. grpc_method_config* grpc_method_config_table_get_method_config( - grpc_method_config_table* table, grpc_mdstr* path); + const grpc_method_config_table* table, const grpc_mdstr* path); /// Returns a channel arg containing \a table. grpc_arg grpc_method_config_table_create_channel_arg( diff --git a/src/core/lib/channel/message_size_filter.c b/src/core/lib/channel/message_size_filter.c index dbd8afd465..1382f19945 100644 --- a/src/core/lib/channel/message_size_filter.c +++ b/src/core/lib/channel/message_size_filter.c @@ -137,14 +137,14 @@ static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, grpc_method_config_table_get_method_config(chand->method_config_table, args->path); if (method_config != NULL) { - int32_t* max_request_message_bytes = + const int32_t* max_request_message_bytes = grpc_method_config_get_max_request_message_bytes(method_config); if (max_request_message_bytes != NULL && (*max_request_message_bytes < calld->max_send_size || calld->max_send_size < 0)) { calld->max_send_size = *max_request_message_bytes; } - int32_t* max_response_message_bytes = + const int32_t* max_response_message_bytes = grpc_method_config_get_max_response_message_bytes(method_config); if (max_response_message_bytes != NULL && (*max_response_message_bytes < calld->max_recv_size || diff --git a/src/core/lib/transport/hashtable.c b/src/core/lib/transport/hashtable.c index 838fe1026e..d127f17a37 100644 --- a/src/core/lib/transport/hashtable.c +++ b/src/core/lib/transport/hashtable.c @@ -47,8 +47,8 @@ struct grpc_hash_table { // Helper function for insert and get operations that performs quadratic // probing (https://en.wikipedia.org/wiki/Quadratic_probing). -static size_t grpc_hash_table_find_index(grpc_hash_table* table, - grpc_mdstr* key, bool find_empty) { +static size_t grpc_hash_table_find_index( + const grpc_hash_table* table, const grpc_mdstr* key, bool find_empty) { for (size_t i = 0; i < table->num_entries; ++i) { const size_t idx = (key->hash + i * i) % table->num_entries; if (table->entries[idx].key == NULL) @@ -111,14 +111,15 @@ int grpc_hash_table_unref(grpc_hash_table* table) { return 0; } -void* grpc_hash_table_get(grpc_hash_table* table, grpc_mdstr* key) { +void* grpc_hash_table_get(const grpc_hash_table* table, const grpc_mdstr* key) { const size_t idx = grpc_hash_table_find_index(table, key, false /* find_empty */); if (idx == table->num_entries) return NULL; // Not found. return table->entries[idx].value; } -int grpc_hash_table_cmp(grpc_hash_table* table1, grpc_hash_table* table2) { +int grpc_hash_table_cmp(const grpc_hash_table* table1, + const grpc_hash_table* table2) { // Compare by num_entries. if (table1->num_entries < table2->num_entries) return -1; if (table1->num_entries > table2->num_entries) return 1; diff --git a/src/core/lib/transport/hashtable.h b/src/core/lib/transport/hashtable.h index 3ec48dce3a..0ce51383c7 100644 --- a/src/core/lib/transport/hashtable.h +++ b/src/core/lib/transport/hashtable.h @@ -74,9 +74,10 @@ int grpc_hash_table_unref(grpc_hash_table* table); /** Returns the value from \a table associated with \a key. Returns NULL if \a key is not found. */ -void* grpc_hash_table_get(grpc_hash_table* table, grpc_mdstr* key); +void* grpc_hash_table_get(const grpc_hash_table* table, const grpc_mdstr* key); /** Compares two hash tables. */ -int grpc_hash_table_cmp(grpc_hash_table* table1, grpc_hash_table* table2); +int grpc_hash_table_cmp(const grpc_hash_table* table1, + const grpc_hash_table* table2); #endif /* GRPC_CORE_LIB_TRANSPORT_HASHTABLE_H */ -- cgit v1.2.3 From 070a2873c5b19a86a3054c295cba4c20a8640d5d Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Wed, 12 Oct 2016 08:09:30 -0700 Subject: Improve documentation in method_config.h. --- src/core/ext/client_config/method_config.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/core/ext/client_config/method_config.h') diff --git a/src/core/ext/client_config/method_config.h b/src/core/ext/client_config/method_config.h index 04e6bc8141..d228b97948 100644 --- a/src/core/ext/client_config/method_config.h +++ b/src/core/ext/client_config/method_config.h @@ -43,7 +43,18 @@ /// Per-method configuration. typedef struct grpc_method_config grpc_method_config; +/// Creates a grpc_method_config with the specified parameters. /// Any parameter may be NULL to indicate that the value is unset. +/// +/// \a wait_for_ready indicates whether the client should wait until the +/// request deadline for the channel to become ready, even if there is a +/// temporary failure before the deadline while attempting to connect. +/// +/// \a timeout indicates the timeout for calls. +/// +/// \a max_request_message_bytes and \a max_response_message_bytes +/// indicate the maximum sizes of the request (checked when sending) and +/// response (checked when receiving) messages. grpc_method_config* grpc_method_config_create( bool* wait_for_ready, gpr_timespec* timeout, int32_t* max_request_message_bytes, int32_t* max_response_message_bytes); @@ -51,6 +62,8 @@ grpc_method_config* grpc_method_config_create( grpc_method_config* grpc_method_config_ref(grpc_method_config* method_config); void grpc_method_config_unref(grpc_method_config* method_config); +/// Compares two grpc_method_configs. +/// The sort order is stable but undefined. int grpc_method_config_cmp(const grpc_method_config* method_config1, const grpc_method_config* method_config2); @@ -84,9 +97,13 @@ grpc_method_config_table* grpc_method_config_table_ref( grpc_method_config_table* table); void grpc_method_config_table_unref(grpc_method_config_table* table); +/// Compares two grpc_method_config_tables. +/// The sort order is stable but undefined. int grpc_method_config_table_cmp(const grpc_method_config_table* table1, const grpc_method_config_table* table2); +/// Gets the method config for the specified \a path, which should be of +/// the form "/service/method". /// Returns NULL if the method has no config. /// Caller does NOT own a reference to the result. grpc_method_config* grpc_method_config_table_get_method_config( -- cgit v1.2.3 From 6a721b5b3f253b86eac3f34c66e6b2d47bb08c9e Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Fri, 14 Oct 2016 12:43:34 -0700 Subject: Rename grpc_hash_table to grpc_mdstr_hash_table. --- BUILD | 16 +-- CMakeLists.txt | 6 +- Makefile | 8 +- binding.gyp | 2 +- build.yaml | 4 +- config.m4 | 2 +- gRPC-Core.podspec | 6 +- grpc.gemspec | 4 +- package.xml | 4 +- src/core/ext/client_config/method_config.c | 58 +++++---- src/core/ext/client_config/method_config.h | 4 +- src/core/lib/transport/hashtable.c | 140 -------------------- src/core/lib/transport/hashtable.h | 82 ------------ src/core/lib/transport/mdstr_hash_table.c | 142 +++++++++++++++++++++ src/core/lib/transport/mdstr_hash_table.h | 83 ++++++++++++ src/python/grpcio/grpc_core_dependencies.py | 2 +- tools/doxygen/Doxyfile.core.internal | 4 +- tools/run_tests/sources_and_headers.json | 6 +- vsprojects/vcxproj/grpc/grpc.vcxproj | 4 +- vsprojects/vcxproj/grpc/grpc.vcxproj.filters | 4 +- .../vcxproj/grpc_test_util/grpc_test_util.vcxproj | 4 +- .../grpc_test_util/grpc_test_util.vcxproj.filters | 4 +- .../vcxproj/grpc_unsecure/grpc_unsecure.vcxproj | 4 +- .../grpc_unsecure/grpc_unsecure.vcxproj.filters | 4 +- 24 files changed, 302 insertions(+), 295 deletions(-) delete mode 100644 src/core/lib/transport/hashtable.c delete mode 100644 src/core/lib/transport/hashtable.h create mode 100644 src/core/lib/transport/mdstr_hash_table.c create mode 100644 src/core/lib/transport/mdstr_hash_table.h (limited to 'src/core/ext/client_config/method_config.h') diff --git a/BUILD b/BUILD index a1be967ee4..4128ea6bf6 100644 --- a/BUILD +++ b/BUILD @@ -239,7 +239,7 @@ cc_library( "src/core/lib/surface/server.h", "src/core/lib/transport/byte_stream.h", "src/core/lib/transport/connectivity_state.h", - "src/core/lib/transport/hashtable.h", + "src/core/lib/transport/mdstr_hash_table.h", "src/core/lib/transport/metadata.h", "src/core/lib/transport/metadata_batch.h", "src/core/lib/transport/static_metadata.h", @@ -411,7 +411,7 @@ cc_library( "src/core/lib/surface/version.c", "src/core/lib/transport/byte_stream.c", "src/core/lib/transport/connectivity_state.c", - "src/core/lib/transport/hashtable.c", + "src/core/lib/transport/mdstr_hash_table.c", "src/core/lib/transport/metadata.c", "src/core/lib/transport/metadata_batch.c", "src/core/lib/transport/static_metadata.c", @@ -644,7 +644,7 @@ cc_library( "src/core/lib/surface/server.h", "src/core/lib/transport/byte_stream.h", "src/core/lib/transport/connectivity_state.h", - "src/core/lib/transport/hashtable.h", + "src/core/lib/transport/mdstr_hash_table.h", "src/core/lib/transport/metadata.h", "src/core/lib/transport/metadata_batch.h", "src/core/lib/transport/static_metadata.h", @@ -801,7 +801,7 @@ cc_library( "src/core/lib/surface/version.c", "src/core/lib/transport/byte_stream.c", "src/core/lib/transport/connectivity_state.c", - "src/core/lib/transport/hashtable.c", + "src/core/lib/transport/mdstr_hash_table.c", "src/core/lib/transport/metadata.c", "src/core/lib/transport/metadata_batch.c", "src/core/lib/transport/static_metadata.c", @@ -1004,7 +1004,7 @@ cc_library( "src/core/lib/surface/server.h", "src/core/lib/transport/byte_stream.h", "src/core/lib/transport/connectivity_state.h", - "src/core/lib/transport/hashtable.h", + "src/core/lib/transport/mdstr_hash_table.h", "src/core/lib/transport/metadata.h", "src/core/lib/transport/metadata_batch.h", "src/core/lib/transport/static_metadata.h", @@ -1153,7 +1153,7 @@ cc_library( "src/core/lib/surface/version.c", "src/core/lib/transport/byte_stream.c", "src/core/lib/transport/connectivity_state.c", - "src/core/lib/transport/hashtable.c", + "src/core/lib/transport/mdstr_hash_table.c", "src/core/lib/transport/metadata.c", "src/core/lib/transport/metadata_batch.c", "src/core/lib/transport/static_metadata.c", @@ -1918,7 +1918,7 @@ objc_library( "src/core/lib/surface/version.c", "src/core/lib/transport/byte_stream.c", "src/core/lib/transport/connectivity_state.c", - "src/core/lib/transport/hashtable.c", + "src/core/lib/transport/mdstr_hash_table.c", "src/core/lib/transport/metadata.c", "src/core/lib/transport/metadata_batch.c", "src/core/lib/transport/static_metadata.c", @@ -2130,7 +2130,7 @@ objc_library( "src/core/lib/surface/server.h", "src/core/lib/transport/byte_stream.h", "src/core/lib/transport/connectivity_state.h", - "src/core/lib/transport/hashtable.h", + "src/core/lib/transport/mdstr_hash_table.h", "src/core/lib/transport/metadata.h", "src/core/lib/transport/metadata_batch.h", "src/core/lib/transport/static_metadata.h", diff --git a/CMakeLists.txt b/CMakeLists.txt index 21c38baba3..366480eb00 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -376,7 +376,7 @@ add_library(grpc src/core/lib/surface/version.c src/core/lib/transport/byte_stream.c src/core/lib/transport/connectivity_state.c - src/core/lib/transport/hashtable.c + src/core/lib/transport/mdstr_hash_table.c src/core/lib/transport/metadata.c src/core/lib/transport/metadata_batch.c src/core/lib/transport/static_metadata.c @@ -637,7 +637,7 @@ add_library(grpc_cronet src/core/lib/surface/version.c src/core/lib/transport/byte_stream.c src/core/lib/transport/connectivity_state.c - src/core/lib/transport/hashtable.c + src/core/lib/transport/mdstr_hash_table.c src/core/lib/transport/metadata.c src/core/lib/transport/metadata_batch.c src/core/lib/transport/static_metadata.c @@ -870,7 +870,7 @@ add_library(grpc_unsecure src/core/lib/surface/version.c src/core/lib/transport/byte_stream.c src/core/lib/transport/connectivity_state.c - src/core/lib/transport/hashtable.c + src/core/lib/transport/mdstr_hash_table.c src/core/lib/transport/metadata.c src/core/lib/transport/metadata_batch.c src/core/lib/transport/static_metadata.c diff --git a/Makefile b/Makefile index 44738bd20c..4892ae98fb 100644 --- a/Makefile +++ b/Makefile @@ -2624,7 +2624,7 @@ LIBGRPC_SRC = \ src/core/lib/surface/version.c \ src/core/lib/transport/byte_stream.c \ src/core/lib/transport/connectivity_state.c \ - src/core/lib/transport/hashtable.c \ + src/core/lib/transport/mdstr_hash_table.c \ src/core/lib/transport/metadata.c \ src/core/lib/transport/metadata_batch.c \ src/core/lib/transport/static_metadata.c \ @@ -2903,7 +2903,7 @@ LIBGRPC_CRONET_SRC = \ src/core/lib/surface/version.c \ src/core/lib/transport/byte_stream.c \ src/core/lib/transport/connectivity_state.c \ - src/core/lib/transport/hashtable.c \ + src/core/lib/transport/mdstr_hash_table.c \ src/core/lib/transport/metadata.c \ src/core/lib/transport/metadata_batch.c \ src/core/lib/transport/static_metadata.c \ @@ -3172,7 +3172,7 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/lib/surface/version.c \ src/core/lib/transport/byte_stream.c \ src/core/lib/transport/connectivity_state.c \ - src/core/lib/transport/hashtable.c \ + src/core/lib/transport/mdstr_hash_table.c \ src/core/lib/transport/metadata.c \ src/core/lib/transport/metadata_batch.c \ src/core/lib/transport/static_metadata.c \ @@ -3367,7 +3367,7 @@ LIBGRPC_UNSECURE_SRC = \ src/core/lib/surface/version.c \ src/core/lib/transport/byte_stream.c \ src/core/lib/transport/connectivity_state.c \ - src/core/lib/transport/hashtable.c \ + src/core/lib/transport/mdstr_hash_table.c \ src/core/lib/transport/metadata.c \ src/core/lib/transport/metadata_batch.c \ src/core/lib/transport/static_metadata.c \ diff --git a/binding.gyp b/binding.gyp index 88acd1786b..60e2278cd9 100644 --- a/binding.gyp +++ b/binding.gyp @@ -651,7 +651,7 @@ 'src/core/lib/surface/version.c', 'src/core/lib/transport/byte_stream.c', 'src/core/lib/transport/connectivity_state.c', - 'src/core/lib/transport/hashtable.c', + 'src/core/lib/transport/mdstr_hash_table.c', 'src/core/lib/transport/metadata.c', 'src/core/lib/transport/metadata_batch.c', 'src/core/lib/transport/static_metadata.c', diff --git a/build.yaml b/build.yaml index 9cec3aeab4..c167ebf990 100644 --- a/build.yaml +++ b/build.yaml @@ -243,7 +243,7 @@ filegroups: - src/core/lib/surface/server.h - src/core/lib/transport/byte_stream.h - src/core/lib/transport/connectivity_state.h - - src/core/lib/transport/hashtable.h + - src/core/lib/transport/mdstr_hash_table.h - src/core/lib/transport/metadata.h - src/core/lib/transport/metadata_batch.h - src/core/lib/transport/static_metadata.h @@ -337,7 +337,7 @@ filegroups: - src/core/lib/surface/version.c - src/core/lib/transport/byte_stream.c - src/core/lib/transport/connectivity_state.c - - src/core/lib/transport/hashtable.c + - src/core/lib/transport/mdstr_hash_table.c - src/core/lib/transport/metadata.c - src/core/lib/transport/metadata_batch.c - src/core/lib/transport/static_metadata.c diff --git a/config.m4 b/config.m4 index f65f617f9a..c3f2e20c20 100644 --- a/config.m4 +++ b/config.m4 @@ -170,7 +170,7 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/surface/version.c \ src/core/lib/transport/byte_stream.c \ src/core/lib/transport/connectivity_state.c \ - src/core/lib/transport/hashtable.c \ + src/core/lib/transport/mdstr_hash_table.c \ src/core/lib/transport/metadata.c \ src/core/lib/transport/metadata_batch.c \ src/core/lib/transport/static_metadata.c \ diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index ffa7ca0825..0712e6de9f 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -326,7 +326,7 @@ Pod::Spec.new do |s| 'src/core/lib/surface/server.h', 'src/core/lib/transport/byte_stream.h', 'src/core/lib/transport/connectivity_state.h', - 'src/core/lib/transport/hashtable.h', + 'src/core/lib/transport/mdstr_hash_table.h', 'src/core/lib/transport/metadata.h', 'src/core/lib/transport/metadata_batch.h', 'src/core/lib/transport/static_metadata.h', @@ -502,7 +502,7 @@ Pod::Spec.new do |s| 'src/core/lib/surface/version.c', 'src/core/lib/transport/byte_stream.c', 'src/core/lib/transport/connectivity_state.c', - 'src/core/lib/transport/hashtable.c', + 'src/core/lib/transport/mdstr_hash_table.c', 'src/core/lib/transport/metadata.c', 'src/core/lib/transport/metadata_batch.c', 'src/core/lib/transport/static_metadata.c', @@ -703,7 +703,7 @@ Pod::Spec.new do |s| 'src/core/lib/surface/server.h', 'src/core/lib/transport/byte_stream.h', 'src/core/lib/transport/connectivity_state.h', - 'src/core/lib/transport/hashtable.h', + 'src/core/lib/transport/mdstr_hash_table.h', 'src/core/lib/transport/metadata.h', 'src/core/lib/transport/metadata_batch.h', 'src/core/lib/transport/static_metadata.h', diff --git a/grpc.gemspec b/grpc.gemspec index e547811332..e3834f2127 100755 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -246,7 +246,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/surface/server.h ) s.files += %w( src/core/lib/transport/byte_stream.h ) s.files += %w( src/core/lib/transport/connectivity_state.h ) - s.files += %w( src/core/lib/transport/hashtable.h ) + s.files += %w( src/core/lib/transport/mdstr_hash_table.h ) s.files += %w( src/core/lib/transport/metadata.h ) s.files += %w( src/core/lib/transport/metadata_batch.h ) s.files += %w( src/core/lib/transport/static_metadata.h ) @@ -422,7 +422,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/surface/version.c ) s.files += %w( src/core/lib/transport/byte_stream.c ) s.files += %w( src/core/lib/transport/connectivity_state.c ) - s.files += %w( src/core/lib/transport/hashtable.c ) + s.files += %w( src/core/lib/transport/mdstr_hash_table.c ) s.files += %w( src/core/lib/transport/metadata.c ) s.files += %w( src/core/lib/transport/metadata_batch.c ) s.files += %w( src/core/lib/transport/static_metadata.c ) diff --git a/package.xml b/package.xml index bf452c3b16..49b71eef0f 100644 --- a/package.xml +++ b/package.xml @@ -253,7 +253,7 @@ - + @@ -429,7 +429,7 @@ - + diff --git a/src/core/ext/client_config/method_config.c b/src/core/ext/client_config/method_config.c index 3699c22810..f8a82323e7 100644 --- a/src/core/ext/client_config/method_config.c +++ b/src/core/ext/client_config/method_config.c @@ -39,7 +39,7 @@ #include #include -#include "src/core/lib/transport/hashtable.h" +#include "src/core/lib/transport/mdstr_hash_table.h" #include "src/core/lib/transport/metadata.h" // @@ -63,7 +63,8 @@ static int bool_cmp(void* v1, void* v2) { return 0; } -static grpc_hash_table_vtable bool_vtable = {gpr_free, bool_copy, bool_cmp}; +static grpc_mdstr_hash_table_vtable bool_vtable = {gpr_free, bool_copy, + bool_cmp}; // timespec vtable @@ -78,8 +79,8 @@ static int timespec_cmp(void* v1, void* v2) { return gpr_time_cmp(*(gpr_timespec*)v1, *(gpr_timespec*)v2); } -static grpc_hash_table_vtable timespec_vtable = {gpr_free, timespec_copy, - timespec_cmp}; +static grpc_mdstr_hash_table_vtable timespec_vtable = {gpr_free, timespec_copy, + timespec_cmp}; // int32 vtable @@ -98,7 +99,8 @@ static int int32_cmp(void* v1, void* v2) { return 0; } -static grpc_hash_table_vtable int32_vtable = {gpr_free, int32_copy, int32_cmp}; +static grpc_mdstr_hash_table_vtable int32_vtable = {gpr_free, int32_copy, + int32_cmp}; // Hash table keys. #define GRPC_METHOD_CONFIG_WAIT_FOR_READY "grpc.wait_for_ready" // bool @@ -109,7 +111,7 @@ static grpc_hash_table_vtable int32_vtable = {gpr_free, int32_copy, int32_cmp}; "grpc.max_response_message_bytes" // int32 struct grpc_method_config { - grpc_hash_table* table; + grpc_mdstr_hash_table* table; grpc_mdstr* wait_for_ready_key; grpc_mdstr* timeout_key; grpc_mdstr* max_request_message_bytes_key; @@ -129,7 +131,7 @@ grpc_method_config* grpc_method_config_create( grpc_mdstr_from_string(GRPC_METHOD_CONFIG_MAX_REQUEST_MESSAGE_BYTES); method_config->max_response_message_bytes_key = grpc_mdstr_from_string(GRPC_METHOD_CONFIG_MAX_RESPONSE_MESSAGE_BYTES); - grpc_hash_table_entry entries[4]; + grpc_mdstr_hash_table_entry entries[4]; size_t num_entries = 0; if (wait_for_ready != NULL) { entries[num_entries].key = method_config->wait_for_ready_key; @@ -155,17 +157,17 @@ grpc_method_config* grpc_method_config_create( entries[num_entries].vtable = &int32_vtable; ++num_entries; } - method_config->table = grpc_hash_table_create(num_entries, entries); + method_config->table = grpc_mdstr_hash_table_create(num_entries, entries); return method_config; } grpc_method_config* grpc_method_config_ref(grpc_method_config* method_config) { - grpc_hash_table_ref(method_config->table); + grpc_mdstr_hash_table_ref(method_config->table); return method_config; } void grpc_method_config_unref(grpc_method_config* method_config) { - if (grpc_hash_table_unref(method_config->table)) { + if (grpc_mdstr_hash_table_unref(method_config->table)) { GRPC_MDSTR_UNREF(method_config->wait_for_ready_key); GRPC_MDSTR_UNREF(method_config->timeout_key); GRPC_MDSTR_UNREF(method_config->max_request_message_bytes_key); @@ -176,30 +178,32 @@ void grpc_method_config_unref(grpc_method_config* method_config) { int grpc_method_config_cmp(const grpc_method_config* method_config1, const grpc_method_config* method_config2) { - return grpc_hash_table_cmp(method_config1->table, method_config2->table); + return grpc_mdstr_hash_table_cmp(method_config1->table, + method_config2->table); } const bool* grpc_method_config_get_wait_for_ready( const grpc_method_config* method_config) { - return grpc_hash_table_get(method_config->table, - method_config->wait_for_ready_key); + return grpc_mdstr_hash_table_get(method_config->table, + method_config->wait_for_ready_key); } const gpr_timespec* grpc_method_config_get_timeout( const grpc_method_config* method_config) { - return grpc_hash_table_get(method_config->table, method_config->timeout_key); + return grpc_mdstr_hash_table_get(method_config->table, + method_config->timeout_key); } const int32_t* grpc_method_config_get_max_request_message_bytes( const grpc_method_config* method_config) { - return grpc_hash_table_get(method_config->table, - method_config->max_request_message_bytes_key); + return grpc_mdstr_hash_table_get( + method_config->table, method_config->max_request_message_bytes_key); } const int32_t* grpc_method_config_get_max_response_message_bytes( const grpc_method_config* method_config) { - return grpc_hash_table_get(method_config->table, - method_config->max_response_message_bytes_key); + return grpc_mdstr_hash_table_get( + method_config->table, method_config->max_response_message_bytes_key); } // @@ -218,41 +222,41 @@ static int method_config_cmp(void* valuep1, void* valuep2) { return grpc_method_config_cmp(valuep1, valuep2); } -static const grpc_hash_table_vtable method_config_table_vtable = { +static const grpc_mdstr_hash_table_vtable method_config_table_vtable = { method_config_unref, method_config_ref, method_config_cmp}; grpc_method_config_table* grpc_method_config_table_create( size_t num_entries, grpc_method_config_table_entry* entries) { - grpc_hash_table_entry* hash_table_entries = - gpr_malloc(sizeof(grpc_hash_table_entry) * num_entries); + grpc_mdstr_hash_table_entry* hash_table_entries = + gpr_malloc(sizeof(grpc_mdstr_hash_table_entry) * num_entries); for (size_t i = 0; i < num_entries; ++i) { hash_table_entries[i].key = entries[i].method_name; hash_table_entries[i].value = entries[i].method_config; hash_table_entries[i].vtable = &method_config_table_vtable; } grpc_method_config_table* method_config_table = - grpc_hash_table_create(num_entries, hash_table_entries); + grpc_mdstr_hash_table_create(num_entries, hash_table_entries); gpr_free(hash_table_entries); return method_config_table; } grpc_method_config_table* grpc_method_config_table_ref( grpc_method_config_table* table) { - return grpc_hash_table_ref(table); + return grpc_mdstr_hash_table_ref(table); } void grpc_method_config_table_unref(grpc_method_config_table* table) { - grpc_hash_table_unref(table); + grpc_mdstr_hash_table_unref(table); } int grpc_method_config_table_cmp(const grpc_method_config_table* table1, const grpc_method_config_table* table2) { - return grpc_hash_table_cmp(table1, table2); + return grpc_mdstr_hash_table_cmp(table1, table2); } grpc_method_config* grpc_method_config_table_get_method_config( const grpc_method_config_table* table, const grpc_mdstr* path) { - grpc_method_config* method_config = grpc_hash_table_get(table, path); + grpc_method_config* method_config = grpc_mdstr_hash_table_get(table, path); // If we didn't find a match for the path, try looking for a wildcard // entry (i.e., change "/service/method" to "/service/*"). if (method_config == NULL) { @@ -265,7 +269,7 @@ grpc_method_config* grpc_method_config_table_get_method_config( buf[len + 1] = '\0'; grpc_mdstr* wildcard_path = grpc_mdstr_from_string(buf); gpr_free(buf); - method_config = grpc_hash_table_get(table, wildcard_path); + method_config = grpc_mdstr_hash_table_get(table, wildcard_path); GRPC_MDSTR_UNREF(wildcard_path); } return method_config; diff --git a/src/core/ext/client_config/method_config.h b/src/core/ext/client_config/method_config.h index d228b97948..1302ac425d 100644 --- a/src/core/ext/client_config/method_config.h +++ b/src/core/ext/client_config/method_config.h @@ -37,7 +37,7 @@ #include #include -#include "src/core/lib/transport/hashtable.h" +#include "src/core/lib/transport/mdstr_hash_table.h" #include "src/core/lib/transport/metadata.h" /// Per-method configuration. @@ -79,7 +79,7 @@ const int32_t* grpc_method_config_get_max_response_message_bytes( const grpc_method_config* method_config); /// A table of method configs. -typedef grpc_hash_table grpc_method_config_table; +typedef grpc_mdstr_hash_table grpc_method_config_table; typedef struct grpc_method_config_table_entry { /// The name is of one of the following forms: diff --git a/src/core/lib/transport/hashtable.c b/src/core/lib/transport/hashtable.c deleted file mode 100644 index a016daa0ec..0000000000 --- a/src/core/lib/transport/hashtable.c +++ /dev/null @@ -1,140 +0,0 @@ -// -// Copyright 2016, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// - -#include "src/core/lib/transport/hashtable.h" - -#include -#include - -#include -#include - -#include "src/core/lib/transport/metadata.h" - -struct grpc_hash_table { - gpr_refcount refs; - size_t num_entries; - grpc_hash_table_entry* entries; -}; - -// Helper function for insert and get operations that performs quadratic -// probing (https://en.wikipedia.org/wiki/Quadratic_probing). -static size_t grpc_hash_table_find_index(const grpc_hash_table* table, - const grpc_mdstr* key, - bool find_empty) { - for (size_t i = 0; i < table->num_entries; ++i) { - const size_t idx = (key->hash + i * i) % table->num_entries; - if (table->entries[idx].key == NULL) - return find_empty ? idx : table->num_entries; - if (table->entries[idx].key == key) return idx; - } - return table->num_entries; // Not found. -} - -static void grpc_hash_table_add(grpc_hash_table* table, grpc_mdstr* key, - void* value, - const grpc_hash_table_vtable* vtable) { - GPR_ASSERT(value != NULL); - const size_t idx = - grpc_hash_table_find_index(table, key, true /* find_empty */); - GPR_ASSERT(idx != table->num_entries); // Table should never be full. - grpc_hash_table_entry* entry = &table->entries[idx]; - entry->key = GRPC_MDSTR_REF(key); - entry->value = vtable->copy_value(value); - entry->vtable = vtable; -} - -grpc_hash_table* grpc_hash_table_create(size_t num_entries, - grpc_hash_table_entry* entries) { - grpc_hash_table* table = gpr_malloc(sizeof(*table)); - memset(table, 0, sizeof(*table)); - gpr_ref_init(&table->refs, 1); - // Quadratic probing gets best performance when the table is no more - // than half full. - table->num_entries = num_entries * 2; - const size_t entry_size = sizeof(grpc_hash_table_entry) * table->num_entries; - table->entries = gpr_malloc(entry_size); - memset(table->entries, 0, entry_size); - for (size_t i = 0; i < num_entries; ++i) { - grpc_hash_table_entry* entry = &entries[i]; - grpc_hash_table_add(table, entry->key, entry->value, entry->vtable); - } - return table; -} - -grpc_hash_table* grpc_hash_table_ref(grpc_hash_table* table) { - if (table != NULL) gpr_ref(&table->refs); - return table; -} - -int grpc_hash_table_unref(grpc_hash_table* table) { - if (table != NULL && gpr_unref(&table->refs)) { - for (size_t i = 0; i < table->num_entries; ++i) { - grpc_hash_table_entry* entry = &table->entries[i]; - if (entry->key != NULL) { - GRPC_MDSTR_UNREF(entry->key); - entry->vtable->destroy_value(entry->value); - } - } - gpr_free(table->entries); - gpr_free(table); - return 1; - } - return 0; -} - -void* grpc_hash_table_get(const grpc_hash_table* table, const grpc_mdstr* key) { - const size_t idx = - grpc_hash_table_find_index(table, key, false /* find_empty */); - if (idx == table->num_entries) return NULL; // Not found. - return table->entries[idx].value; -} - -int grpc_hash_table_cmp(const grpc_hash_table* table1, - const grpc_hash_table* table2) { - // Compare by num_entries. - if (table1->num_entries < table2->num_entries) return -1; - if (table1->num_entries > table2->num_entries) return 1; - for (size_t i = 0; i < table1->num_entries; ++i) { - grpc_hash_table_entry* e1 = &table1->entries[i]; - grpc_hash_table_entry* e2 = &table2->entries[i]; - // Compare keys by hash value. - if (e1->key->hash < e2->key->hash) return -1; - if (e1->key->hash > e2->key->hash) return 1; - // Compare by vtable (pointer equality). - if (e1->vtable < e2->vtable) return -1; - if (e1->vtable > e2->vtable) return 1; - // Compare values via vtable. - const int value_result = e1->vtable->compare_value(e1->value, e2->value); - if (value_result != 0) return value_result; - } - return 0; -} diff --git a/src/core/lib/transport/hashtable.h b/src/core/lib/transport/hashtable.h deleted file mode 100644 index d5f40a2cf7..0000000000 --- a/src/core/lib/transport/hashtable.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2016, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef GRPC_CORE_LIB_TRANSPORT_HASHTABLE_H -#define GRPC_CORE_LIB_TRANSPORT_HASHTABLE_H - -#include "src/core/lib/transport/metadata.h" - -/** Hash table implementation. - * - * This implementation uses open addressing - * (https://en.wikipedia.org/wiki/Open_addressing) with quadratic - * probing (https://en.wikipedia.org/wiki/Quadratic_probing). - * - * The keys are \a grpc_mdstr objects. The values are arbitrary pointers - * with a common vtable. - * - * Hash tables are intentionally immutable, to avoid the need for locking. - */ - -typedef struct grpc_hash_table grpc_hash_table; - -typedef struct grpc_hash_table_vtable { - void (*destroy_value)(void* value); - void* (*copy_value)(void* value); - int (*compare_value)(void* value1, void* value2); -} grpc_hash_table_vtable; - -typedef struct grpc_hash_table_entry { - grpc_mdstr* key; - void* value; /* Must not be NULL. */ - const grpc_hash_table_vtable* vtable; -} grpc_hash_table_entry; - -/** Creates a new hash table of containing \a entries, which is an array - of length \a num_entries. - Creates its own copy of all keys and values from \a entries. */ -grpc_hash_table* grpc_hash_table_create(size_t num_entries, - grpc_hash_table_entry* entries); - -grpc_hash_table* grpc_hash_table_ref(grpc_hash_table* table); -/** Returns 1 when \a table is destroyed. */ -int grpc_hash_table_unref(grpc_hash_table* table); - -/** Returns the value from \a table associated with \a key. - Returns NULL if \a key is not found. */ -void* grpc_hash_table_get(const grpc_hash_table* table, const grpc_mdstr* key); - -/** Compares two hash tables. - The sort order is stable but undefined. */ -int grpc_hash_table_cmp(const grpc_hash_table* table1, - const grpc_hash_table* table2); - -#endif /* GRPC_CORE_LIB_TRANSPORT_HASHTABLE_H */ diff --git a/src/core/lib/transport/mdstr_hash_table.c b/src/core/lib/transport/mdstr_hash_table.c new file mode 100644 index 0000000000..4be0536dd7 --- /dev/null +++ b/src/core/lib/transport/mdstr_hash_table.c @@ -0,0 +1,142 @@ +// +// Copyright 2016, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// + +#include "src/core/lib/transport/mdstr_hash_table.h" + +#include +#include + +#include +#include + +#include "src/core/lib/transport/metadata.h" + +struct grpc_mdstr_hash_table { + gpr_refcount refs; + size_t num_entries; + grpc_mdstr_hash_table_entry* entries; +}; + +// Helper function for insert and get operations that performs quadratic +// probing (https://en.wikipedia.org/wiki/Quadratic_probing). +static size_t grpc_mdstr_hash_table_find_index( + const grpc_mdstr_hash_table* table, const grpc_mdstr* key, + bool find_empty) { + for (size_t i = 0; i < table->num_entries; ++i) { + const size_t idx = (key->hash + i * i) % table->num_entries; + if (table->entries[idx].key == NULL) + return find_empty ? idx : table->num_entries; + if (table->entries[idx].key == key) return idx; + } + return table->num_entries; // Not found. +} + +static void grpc_mdstr_hash_table_add( + grpc_mdstr_hash_table* table, grpc_mdstr* key, void* value, + const grpc_mdstr_hash_table_vtable* vtable) { + GPR_ASSERT(value != NULL); + const size_t idx = + grpc_mdstr_hash_table_find_index(table, key, true /* find_empty */); + GPR_ASSERT(idx != table->num_entries); // Table should never be full. + grpc_mdstr_hash_table_entry* entry = &table->entries[idx]; + entry->key = GRPC_MDSTR_REF(key); + entry->value = vtable->copy_value(value); + entry->vtable = vtable; +} + +grpc_mdstr_hash_table* grpc_mdstr_hash_table_create( + size_t num_entries, grpc_mdstr_hash_table_entry* entries) { + grpc_mdstr_hash_table* table = gpr_malloc(sizeof(*table)); + memset(table, 0, sizeof(*table)); + gpr_ref_init(&table->refs, 1); + // Quadratic probing gets best performance when the table is no more + // than half full. + table->num_entries = num_entries * 2; + const size_t entry_size = + sizeof(grpc_mdstr_hash_table_entry) * table->num_entries; + table->entries = gpr_malloc(entry_size); + memset(table->entries, 0, entry_size); + for (size_t i = 0; i < num_entries; ++i) { + grpc_mdstr_hash_table_entry* entry = &entries[i]; + grpc_mdstr_hash_table_add(table, entry->key, entry->value, entry->vtable); + } + return table; +} + +grpc_mdstr_hash_table* grpc_mdstr_hash_table_ref(grpc_mdstr_hash_table* table) { + if (table != NULL) gpr_ref(&table->refs); + return table; +} + +int grpc_mdstr_hash_table_unref(grpc_mdstr_hash_table* table) { + if (table != NULL && gpr_unref(&table->refs)) { + for (size_t i = 0; i < table->num_entries; ++i) { + grpc_mdstr_hash_table_entry* entry = &table->entries[i]; + if (entry->key != NULL) { + GRPC_MDSTR_UNREF(entry->key); + entry->vtable->destroy_value(entry->value); + } + } + gpr_free(table->entries); + gpr_free(table); + return 1; + } + return 0; +} + +void* grpc_mdstr_hash_table_get(const grpc_mdstr_hash_table* table, + const grpc_mdstr* key) { + const size_t idx = + grpc_mdstr_hash_table_find_index(table, key, false /* find_empty */); + if (idx == table->num_entries) return NULL; // Not found. + return table->entries[idx].value; +} + +int grpc_mdstr_hash_table_cmp(const grpc_mdstr_hash_table* table1, + const grpc_mdstr_hash_table* table2) { + // Compare by num_entries. + if (table1->num_entries < table2->num_entries) return -1; + if (table1->num_entries > table2->num_entries) return 1; + for (size_t i = 0; i < table1->num_entries; ++i) { + grpc_mdstr_hash_table_entry* e1 = &table1->entries[i]; + grpc_mdstr_hash_table_entry* e2 = &table2->entries[i]; + // Compare keys by hash value. + if (e1->key->hash < e2->key->hash) return -1; + if (e1->key->hash > e2->key->hash) return 1; + // Compare by vtable (pointer equality). + if (e1->vtable < e2->vtable) return -1; + if (e1->vtable > e2->vtable) return 1; + // Compare values via vtable. + const int value_result = e1->vtable->compare_value(e1->value, e2->value); + if (value_result != 0) return value_result; + } + return 0; +} diff --git a/src/core/lib/transport/mdstr_hash_table.h b/src/core/lib/transport/mdstr_hash_table.h new file mode 100644 index 0000000000..52e5b023db --- /dev/null +++ b/src/core/lib/transport/mdstr_hash_table.h @@ -0,0 +1,83 @@ +/* + * Copyright 2016, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef GRPC_CORE_LIB_TRANSPORT_MDSTR_HASH_TABLE_H +#define GRPC_CORE_LIB_TRANSPORT_MDSTR_HASH_TABLE_H + +#include "src/core/lib/transport/metadata.h" + +/** Hash table implementation. + * + * This implementation uses open addressing + * (https://en.wikipedia.org/wiki/Open_addressing) with quadratic + * probing (https://en.wikipedia.org/wiki/Quadratic_probing). + * + * The keys are \a grpc_mdstr objects. The values are arbitrary pointers + * with a common vtable. + * + * Hash tables are intentionally immutable, to avoid the need for locking. + */ + +typedef struct grpc_mdstr_hash_table grpc_mdstr_hash_table; + +typedef struct grpc_mdstr_hash_table_vtable { + void (*destroy_value)(void* value); + void* (*copy_value)(void* value); + int (*compare_value)(void* value1, void* value2); +} grpc_mdstr_hash_table_vtable; + +typedef struct grpc_mdstr_hash_table_entry { + grpc_mdstr* key; + void* value; /* Must not be NULL. */ + const grpc_mdstr_hash_table_vtable* vtable; +} grpc_mdstr_hash_table_entry; + +/** Creates a new hash table of containing \a entries, which is an array + of length \a num_entries. + Creates its own copy of all keys and values from \a entries. */ +grpc_mdstr_hash_table* grpc_mdstr_hash_table_create( + size_t num_entries, grpc_mdstr_hash_table_entry* entries); + +grpc_mdstr_hash_table* grpc_mdstr_hash_table_ref(grpc_mdstr_hash_table* table); +/** Returns 1 when \a table is destroyed. */ +int grpc_mdstr_hash_table_unref(grpc_mdstr_hash_table* table); + +/** Returns the value from \a table associated with \a key. + Returns NULL if \a key is not found. */ +void* grpc_mdstr_hash_table_get(const grpc_mdstr_hash_table* table, + const grpc_mdstr* key); + +/** Compares two hash tables. + The sort order is stable but undefined. */ +int grpc_mdstr_hash_table_cmp(const grpc_mdstr_hash_table* table1, + const grpc_mdstr_hash_table* table2); + +#endif /* GRPC_CORE_LIB_TRANSPORT_MDSTR_HASH_TABLE_H */ diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 315d469a15..98bbe6f742 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -164,7 +164,7 @@ CORE_SOURCE_FILES = [ 'src/core/lib/surface/version.c', 'src/core/lib/transport/byte_stream.c', 'src/core/lib/transport/connectivity_state.c', - 'src/core/lib/transport/hashtable.c', + 'src/core/lib/transport/mdstr_hash_table.c', 'src/core/lib/transport/metadata.c', 'src/core/lib/transport/metadata_batch.c', 'src/core/lib/transport/static_metadata.c', diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index c9317396f6..0a2a3456f1 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -863,7 +863,7 @@ src/core/lib/surface/lame_client.h \ src/core/lib/surface/server.h \ src/core/lib/transport/byte_stream.h \ src/core/lib/transport/connectivity_state.h \ -src/core/lib/transport/hashtable.h \ +src/core/lib/transport/mdstr_hash_table.h \ src/core/lib/transport/metadata.h \ src/core/lib/transport/metadata_batch.h \ src/core/lib/transport/static_metadata.h \ @@ -1039,7 +1039,7 @@ src/core/lib/surface/validate_metadata.c \ src/core/lib/surface/version.c \ src/core/lib/transport/byte_stream.c \ src/core/lib/transport/connectivity_state.c \ -src/core/lib/transport/hashtable.c \ +src/core/lib/transport/mdstr_hash_table.c \ src/core/lib/transport/metadata.c \ src/core/lib/transport/metadata_batch.c \ src/core/lib/transport/static_metadata.c \ diff --git a/tools/run_tests/sources_and_headers.json b/tools/run_tests/sources_and_headers.json index 2ca9ed6000..e0b8a0902a 100644 --- a/tools/run_tests/sources_and_headers.json +++ b/tools/run_tests/sources_and_headers.json @@ -6463,7 +6463,7 @@ "src/core/lib/surface/server.h", "src/core/lib/transport/byte_stream.h", "src/core/lib/transport/connectivity_state.h", - "src/core/lib/transport/hashtable.h", + "src/core/lib/transport/mdstr_hash_table.h", "src/core/lib/transport/metadata.h", "src/core/lib/transport/metadata_batch.h", "src/core/lib/transport/static_metadata.h", @@ -6645,8 +6645,8 @@ "src/core/lib/transport/byte_stream.h", "src/core/lib/transport/connectivity_state.c", "src/core/lib/transport/connectivity_state.h", - "src/core/lib/transport/hashtable.c", - "src/core/lib/transport/hashtable.h", + "src/core/lib/transport/mdstr_hash_table.c", + "src/core/lib/transport/mdstr_hash_table.h", "src/core/lib/transport/metadata.c", "src/core/lib/transport/metadata.h", "src/core/lib/transport/metadata_batch.c", diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj b/vsprojects/vcxproj/grpc/grpc.vcxproj index b2352d74f4..2297e81fbf 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj @@ -372,7 +372,7 @@ - + @@ -637,7 +637,7 @@ - + diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters index ee7825ae88..3e8632daa5 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters @@ -262,7 +262,7 @@ src\core\lib\transport - + src\core\lib\transport @@ -905,7 +905,7 @@ src\core\lib\transport - + src\core\lib\transport diff --git a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj index c7375431c8..f9602d0349 100644 --- a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj +++ b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj @@ -265,7 +265,7 @@ - + @@ -484,7 +484,7 @@ - + diff --git a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters index 18cdaa5819..412af4d5af 100644 --- a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters +++ b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters @@ -316,7 +316,7 @@ src\core\lib\transport - + src\core\lib\transport @@ -689,7 +689,7 @@ src\core\lib\transport - + src\core\lib\transport diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj index 09a1e2386d..730d17beee 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj @@ -362,7 +362,7 @@ - + @@ -605,7 +605,7 @@ - + diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters index df7a9b9b43..235dc993f1 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters @@ -265,7 +265,7 @@ src\core\lib\transport - + src\core\lib\transport @@ -815,7 +815,7 @@ src\core\lib\transport - + src\core\lib\transport -- cgit v1.2.3