diff options
Diffstat (limited to 'src')
45 files changed, 1912 insertions, 1576 deletions
diff --git a/src/core/ext/filters/client_channel/http_proxy.cc b/src/core/ext/filters/client_channel/http_proxy.cc index 037c65822a..7c5f79fb30 100644 --- a/src/core/ext/filters/client_channel/http_proxy.cc +++ b/src/core/ext/filters/client_channel/http_proxy.cc @@ -115,6 +115,7 @@ static bool proxy_mapper_map_name(grpc_proxy_mapper* mapper, "unable to split host and port, not checking no_proxy list for " "host '%s'", server_uri); + gpr_free(no_proxy_str); } else { size_t uri_len = strlen(server_host); char** no_proxy_hosts; @@ -139,6 +140,7 @@ static bool proxy_mapper_map_name(grpc_proxy_mapper* mapper, gpr_free(no_proxy_hosts); gpr_free(server_host); gpr_free(server_port); + gpr_free(no_proxy_str); if (!use_proxy) goto no_use_proxy; } } diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc index 1708d81e61..4596f90745 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc @@ -69,11 +69,13 @@ static grpc_error* init_call_elem(grpc_call_element* elem, call_data* calld = (call_data*)elem->call_data; // Get stats object from context and take a ref. GPR_ASSERT(args->context != nullptr); - GPR_ASSERT(args->context[GRPC_GRPCLB_CLIENT_STATS].value != nullptr); - calld->client_stats = grpc_grpclb_client_stats_ref( - (grpc_grpclb_client_stats*)args->context[GRPC_GRPCLB_CLIENT_STATS].value); - // Record call started. - grpc_grpclb_client_stats_add_call_started(calld->client_stats); + if (args->context[GRPC_GRPCLB_CLIENT_STATS].value != nullptr) { + calld->client_stats = grpc_grpclb_client_stats_ref( + (grpc_grpclb_client_stats*)args->context[GRPC_GRPCLB_CLIENT_STATS] + .value); + // Record call started. + grpc_grpclb_client_stats_add_call_started(calld->client_stats); + } return GRPC_ERROR_NONE; } @@ -81,36 +83,40 @@ static void destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { call_data* calld = (call_data*)elem->call_data; - // Record call finished, optionally setting client_failed_to_send and - // received. - grpc_grpclb_client_stats_add_call_finished( - !calld->send_initial_metadata_succeeded /* client_failed_to_send */, - calld->recv_initial_metadata_succeeded /* known_received */, - calld->client_stats); - // All done, so unref the stats object. - grpc_grpclb_client_stats_unref(calld->client_stats); + if (calld->client_stats != nullptr) { + // Record call finished, optionally setting client_failed_to_send and + // received. + grpc_grpclb_client_stats_add_call_finished( + !calld->send_initial_metadata_succeeded /* client_failed_to_send */, + calld->recv_initial_metadata_succeeded /* known_received */, + calld->client_stats); + // All done, so unref the stats object. + grpc_grpclb_client_stats_unref(calld->client_stats); + } } static void start_transport_stream_op_batch( grpc_call_element* elem, grpc_transport_stream_op_batch* batch) { call_data* calld = (call_data*)elem->call_data; GPR_TIMER_BEGIN("clr_start_transport_stream_op_batch", 0); - // Intercept send_initial_metadata. - if (batch->send_initial_metadata) { - calld->original_on_complete_for_send = batch->on_complete; - GRPC_CLOSURE_INIT(&calld->on_complete_for_send, on_complete_for_send, calld, - grpc_schedule_on_exec_ctx); - batch->on_complete = &calld->on_complete_for_send; - } - // Intercept recv_initial_metadata. - if (batch->recv_initial_metadata) { - calld->original_recv_initial_metadata_ready = - batch->payload->recv_initial_metadata.recv_initial_metadata_ready; - GRPC_CLOSURE_INIT(&calld->recv_initial_metadata_ready, - recv_initial_metadata_ready, calld, - grpc_schedule_on_exec_ctx); - batch->payload->recv_initial_metadata.recv_initial_metadata_ready = - &calld->recv_initial_metadata_ready; + if (calld->client_stats != nullptr) { + // Intercept send_initial_metadata. + if (batch->send_initial_metadata) { + calld->original_on_complete_for_send = batch->on_complete; + GRPC_CLOSURE_INIT(&calld->on_complete_for_send, on_complete_for_send, + calld, grpc_schedule_on_exec_ctx); + batch->on_complete = &calld->on_complete_for_send; + } + // Intercept recv_initial_metadata. + if (batch->recv_initial_metadata) { + calld->original_recv_initial_metadata_ready = + batch->payload->recv_initial_metadata.recv_initial_metadata_ready; + GRPC_CLOSURE_INIT(&calld->recv_initial_metadata_ready, + recv_initial_metadata_ready, calld, + grpc_schedule_on_exec_ctx); + batch->payload->recv_initial_metadata.recv_initial_metadata_ready = + &calld->recv_initial_metadata_ready; + } } // Chain to next filter. grpc_call_next_op(elem, batch); diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc index 06ae79041e..1709e5622e 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc @@ -169,25 +169,78 @@ struct pending_ping { } // namespace -struct glb_lb_policy { - /** base policy: must be first */ +typedef struct glb_lb_call_data { + struct glb_lb_policy* glb_policy; + // TODO(juanlishen): c++ize this struct. + gpr_refcount refs; + + /** The streaming call to the LB server. Always non-NULL. */ + grpc_call* lb_call; + + /** The initial metadata received from the LB server. */ + grpc_metadata_array lb_initial_metadata_recv; + + /** The message sent to the LB server. It's used to query for backends (the + * value may vary if the LB server indicates a redirect) or send client load + * report. */ + grpc_byte_buffer* send_message_payload; + /** The callback after the initial request is sent. */ + grpc_closure lb_on_sent_initial_request; + + /** The response received from the LB server, if any. */ + grpc_byte_buffer* recv_message_payload; + /** The callback to process the response received from the LB server. */ + grpc_closure lb_on_response_received; + bool seen_initial_response; + + /** The callback to process the status received from the LB server, which + * signals the end of the LB call. */ + grpc_closure lb_on_server_status_received; + /** The trailing metadata from the LB server. */ + grpc_metadata_array lb_trailing_metadata_recv; + /** The call status code and details. */ + grpc_status_code lb_call_status; + grpc_slice lb_call_status_details; + + /** The stats for client-side load reporting associated with this LB call. + * Created after the first serverlist is received. */ + grpc_grpclb_client_stats* client_stats; + /** The interval and timer for next client load report. */ + grpc_millis client_stats_report_interval; + grpc_timer client_load_report_timer; + bool client_load_report_timer_callback_pending; + bool last_client_load_report_counters_were_zero; + bool client_load_report_is_due; + /** The closure used for either the load report timer or the callback for + * completion of sending the load report. */ + grpc_closure client_load_report_closure; +} glb_lb_call_data; + +typedef struct glb_lb_policy { + /** Base policy: must be first. */ grpc_lb_policy base; - /** who the client is trying to communicate with */ + /** Who the client is trying to communicate with. */ const char* server_name; + + /** Channel related data that will be propagated to the internal RR policy. */ grpc_client_channel_factory* cc_factory; grpc_channel_args* args; - /** timeout in milliseconds for the LB call. 0 means no deadline. */ - int lb_call_timeout_ms; - - /** timeout in milliseconds for before using fallback backend addresses. + /** Timeout in milliseconds for before using fallback backend addresses. * 0 means not using fallback. */ int lb_fallback_timeout_ms; - /** for communicating with the LB server */ + /** The channel for communicating with the LB server. */ grpc_channel* lb_channel; + /** The data associated with the current LB call. It holds a ref to this LB + * policy. It's initialized every time we query for backends. It's reset to + * NULL whenever the current LB call is no longer needed (e.g., the LB policy + * is shutting down, or the LB call has ended). A non-NULL lb_calld always + * contains a non-NULL lb_call. */ + glb_lb_call_data* lb_calld; + /** response generator to inject address updates into \a lb_channel */ grpc_fake_resolver_response_generator* response_generator; @@ -225,9 +278,6 @@ struct glb_lb_policy { bool shutting_down; - /** are we currently updating lb_call? */ - bool updating_lb_call; - /** are we already watching the LB channel's connectivity? */ bool watching_lb_channel; @@ -243,65 +293,70 @@ struct glb_lb_policy { /************************************************************/ /* client data associated with the LB server communication */ /************************************************************/ - /* Finished sending initial request. */ - grpc_closure lb_on_sent_initial_request; - - /* Status from the LB server has been received. This signals the end of the LB - * call. */ - grpc_closure lb_on_server_status_received; - - /* A response from the LB server has been received. Process it */ - grpc_closure lb_on_response_received; - - /* LB call retry timer callback. */ - grpc_closure lb_on_call_retry; - - /* LB fallback timer callback. */ - grpc_closure lb_on_fallback; - - grpc_call* lb_call; /* streaming call to the LB server, */ - - grpc_metadata_array lb_initial_metadata_recv; /* initial MD from LB server */ - grpc_metadata_array - lb_trailing_metadata_recv; /* trailing MD from LB server */ - - /* what's being sent to the LB server. Note that its value may vary if the LB - * server indicates a redirect. */ - grpc_byte_buffer* lb_request_payload; - - /* response the LB server, if any. Processed in lb_on_response_received() */ - grpc_byte_buffer* lb_response_payload; - - /* call status code and details, set in lb_on_server_status_received() */ - grpc_status_code lb_call_status; - grpc_slice lb_call_status_details; /** LB call retry backoff state */ grpc_core::ManualConstructor<grpc_core::BackOff> lb_call_backoff; + /** timeout in milliseconds for the LB call. 0 means no deadline. */ + int lb_call_timeout_ms; + /** LB call retry timer */ grpc_timer lb_call_retry_timer; + /** LB call retry timer callback */ + grpc_closure lb_on_call_retry; /** LB fallback timer */ grpc_timer lb_fallback_timer; + /** LB fallback timer callback */ + grpc_closure lb_on_fallback; +} glb_lb_policy; - bool initial_request_sent; - bool seen_initial_response; +static void glb_lb_call_data_ref(glb_lb_call_data* lb_calld, + const char* reason) { + gpr_ref_non_zero(&lb_calld->refs); + if (grpc_lb_glb_trace.enabled()) { + const gpr_atm count = gpr_atm_acq_load(&lb_calld->refs.count); + gpr_log(GPR_DEBUG, "[%s %p] lb_calld %p REF %lu->%lu (%s)", + grpc_lb_glb_trace.name(), lb_calld->glb_policy, lb_calld, + (unsigned long)(count - 1), (unsigned long)count, reason); + } +} - /* Stats for client-side load reporting. Should be unreffed and - * recreated whenever lb_call is replaced. */ - grpc_grpclb_client_stats* client_stats; - /* Interval and timer for next client load report. */ - grpc_millis client_stats_report_interval; - grpc_timer client_load_report_timer; - bool client_load_report_timer_callback_pending; - bool last_client_load_report_counters_were_zero; - /* Closure used for either the load report timer or the callback for - * completion of sending the load report. */ - grpc_closure client_load_report_closure; - /* Client load report message payload. */ - grpc_byte_buffer* client_load_report_payload; -}; +static void glb_lb_call_data_unref(glb_lb_call_data* lb_calld, + const char* reason) { + const bool done = gpr_unref(&lb_calld->refs); + if (grpc_lb_glb_trace.enabled()) { + const gpr_atm count = gpr_atm_acq_load(&lb_calld->refs.count); + gpr_log(GPR_DEBUG, "[%s %p] lb_calld %p UNREF %lu->%lu (%s)", + grpc_lb_glb_trace.name(), lb_calld->glb_policy, lb_calld, + (unsigned long)(count + 1), (unsigned long)count, reason); + } + if (done) { + GPR_ASSERT(lb_calld->lb_call != nullptr); + grpc_call_unref(lb_calld->lb_call); + grpc_metadata_array_destroy(&lb_calld->lb_initial_metadata_recv); + grpc_metadata_array_destroy(&lb_calld->lb_trailing_metadata_recv); + grpc_byte_buffer_destroy(lb_calld->send_message_payload); + grpc_byte_buffer_destroy(lb_calld->recv_message_payload); + grpc_slice_unref_internal(lb_calld->lb_call_status_details); + if (lb_calld->client_stats != nullptr) { + grpc_grpclb_client_stats_unref(lb_calld->client_stats); + } + GRPC_LB_POLICY_UNREF(&lb_calld->glb_policy->base, "lb_calld"); + gpr_free(lb_calld); + } +} + +static void lb_call_data_shutdown(glb_lb_policy* glb_policy) { + GPR_ASSERT(glb_policy->lb_calld != nullptr); + GPR_ASSERT(glb_policy->lb_calld->lb_call != nullptr); + // lb_on_server_status_received will complete the cancellation and clean up. + grpc_call_cancel(glb_policy->lb_calld->lb_call, nullptr); + if (glb_policy->lb_calld->client_load_report_timer_callback_pending) { + grpc_timer_cancel(&glb_policy->lb_calld->client_load_report_timer); + } + glb_policy->lb_calld = nullptr; +} /* add lb_token of selected subchannel (address) to the call's initial * metadata */ @@ -334,11 +389,12 @@ static void pending_pick_set_metadata_and_context(pending_pick* pp) { abort(); } // Pass on client stats via context. Passes ownership of the reference. - GPR_ASSERT(pp->client_stats != nullptr); - pp->pick->subchannel_call_context[GRPC_GRPCLB_CLIENT_STATS].value = - pp->client_stats; - pp->pick->subchannel_call_context[GRPC_GRPCLB_CLIENT_STATS].destroy = - destroy_client_stats; + if (pp->client_stats != nullptr) { + pp->pick->subchannel_call_context[GRPC_GRPCLB_CLIENT_STATS].value = + pp->client_stats; + pp->pick->subchannel_call_context[GRPC_GRPCLB_CLIENT_STATS].destroy = + destroy_client_stats; + } } else { if (pp->client_stats != nullptr) { grpc_grpclb_client_stats_unref(pp->client_stats); @@ -605,9 +661,11 @@ static bool pick_from_internal_rr_locked(glb_lb_policy* glb_policy, // the client_load_reporting filter, because we do not create a // subchannel call (and therefore no client_load_reporting filter) // for dropped calls. - GPR_ASSERT(glb_policy->client_stats != nullptr); - grpc_grpclb_client_stats_add_call_dropped_locked( - server->load_balance_token, glb_policy->client_stats); + if (glb_policy->lb_calld != nullptr && + glb_policy->lb_calld->client_stats != nullptr) { + grpc_grpclb_client_stats_add_call_dropped_locked( + server->load_balance_token, glb_policy->lb_calld->client_stats); + } if (force_async) { GRPC_CLOSURE_SCHED(pp->original_on_complete, GRPC_ERROR_NONE); gpr_free(pp); @@ -618,7 +676,11 @@ static bool pick_from_internal_rr_locked(glb_lb_policy* glb_policy, } } // Set client_stats and user_data. - pp->client_stats = grpc_grpclb_client_stats_ref(glb_policy->client_stats); + if (glb_policy->lb_calld != nullptr && + glb_policy->lb_calld->client_stats != nullptr) { + pp->client_stats = + grpc_grpclb_client_stats_ref(glb_policy->lb_calld->client_stats); + } GPR_ASSERT(pp->pick->user_data == nullptr); pp->pick->user_data = (void**)&pp->lb_token; // Pick via the RR policy. @@ -872,9 +934,6 @@ static void glb_destroy(grpc_lb_policy* pol) { GPR_ASSERT(glb_policy->pending_pings == nullptr); gpr_free((void*)glb_policy->server_name); grpc_channel_args_destroy(glb_policy->args); - if (glb_policy->client_stats != nullptr) { - grpc_grpclb_client_stats_unref(glb_policy->client_stats); - } grpc_connectivity_state_destroy(&glb_policy->state_tracker); if (glb_policy->serverlist != nullptr) { grpc_grpclb_destroy_serverlist(glb_policy->serverlist); @@ -892,13 +951,8 @@ static void glb_shutdown_locked(grpc_lb_policy* pol, glb_lb_policy* glb_policy = (glb_lb_policy*)pol; grpc_error* error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Channel shutdown"); glb_policy->shutting_down = true; - /* glb_policy->lb_call and this local lb_call must be consistent at this point - * because glb_policy->lb_call is only assigned in lb_call_init_locked as part - * of query_for_backends_locked, which can only be invoked while - * glb_policy->shutting_down is false. */ - if (glb_policy->lb_call != nullptr) { - grpc_call_cancel(glb_policy->lb_call, nullptr); - /* lb_on_server_status_received will pick up the cancel and clean up */ + if (glb_policy->lb_calld != nullptr) { + lb_call_data_shutdown(glb_policy); } if (glb_policy->retry_timer_callback_pending) { grpc_timer_cancel(&glb_policy->lb_call_retry_timer); @@ -1048,7 +1102,6 @@ static void start_picking_locked(glb_lb_policy* glb_policy) { grpc_timer_init(&glb_policy->lb_fallback_timer, deadline, &glb_policy->lb_on_fallback); } - glb_policy->started_picking = true; glb_policy->lb_call_backoff->Reset(); query_for_backends_locked(glb_policy); @@ -1089,7 +1142,6 @@ static int glb_pick_locked(grpc_lb_policy* pol, gpr_log(GPR_INFO, "[grpclb %p] about to PICK from RR %p", glb_policy, glb_policy->rr_policy); } - GPR_ASSERT(glb_policy->client_stats != nullptr); pick_done = pick_from_internal_rr_locked(glb_policy, false /* force_async */, pp); } @@ -1139,8 +1191,8 @@ static void glb_notify_on_state_change_locked(grpc_lb_policy* pol, static void lb_call_on_retry_timer_locked(void* arg, grpc_error* error) { glb_lb_policy* glb_policy = (glb_lb_policy*)arg; glb_policy->retry_timer_callback_pending = false; - if (!glb_policy->shutting_down && glb_policy->lb_call == nullptr && - error == GRPC_ERROR_NONE) { + if (!glb_policy->shutting_down && error == GRPC_ERROR_NONE && + glb_policy->lb_calld == nullptr) { if (grpc_lb_glb_trace.enabled()) { gpr_log(GPR_INFO, "[grpclb %p] Restarting call to LB server", glb_policy); } @@ -1149,84 +1201,55 @@ static void lb_call_on_retry_timer_locked(void* arg, grpc_error* error) { GRPC_LB_POLICY_UNREF(&glb_policy->base, "grpclb_retry_timer"); } -static void maybe_restart_lb_call(glb_lb_policy* glb_policy) { - if (glb_policy->started_picking && glb_policy->updating_lb_call) { - if (glb_policy->retry_timer_callback_pending) { - grpc_timer_cancel(&glb_policy->lb_call_retry_timer); - } - if (!glb_policy->shutting_down) start_picking_locked(glb_policy); - glb_policy->updating_lb_call = false; - } else if (!glb_policy->shutting_down) { - /* if we aren't shutting down, restart the LB client call after some time */ - grpc_millis next_try = glb_policy->lb_call_backoff->NextAttemptTime(); - if (grpc_lb_glb_trace.enabled()) { - gpr_log(GPR_DEBUG, "[grpclb %p] Connection to LB server lost...", +static void start_lb_call_retry_timer_locked(glb_lb_policy* glb_policy) { + grpc_millis next_try = glb_policy->lb_call_backoff->NextAttemptTime(); + if (grpc_lb_glb_trace.enabled()) { + gpr_log(GPR_DEBUG, "[grpclb %p] Connection to LB server lost...", + glb_policy); + grpc_millis timeout = next_try - grpc_core::ExecCtx::Get()->Now(); + if (timeout > 0) { + gpr_log(GPR_DEBUG, + "[grpclb %p] ... retry_timer_active in %" PRIuPTR "ms.", + glb_policy, timeout); + } else { + gpr_log(GPR_DEBUG, "[grpclb %p] ... retry_timer_active immediately.", glb_policy); - grpc_millis timeout = next_try - grpc_core::ExecCtx::Get()->Now(); - if (timeout > 0) { - gpr_log(GPR_DEBUG, - "[grpclb %p] ... retry LB call after %" PRIuPTR "ms.", - glb_policy, timeout); - } else { - gpr_log(GPR_DEBUG, "[grpclb %p] ... retry LB call immediately.", - glb_policy); - } } - GRPC_LB_POLICY_REF(&glb_policy->base, "grpclb_retry_timer"); - GRPC_CLOSURE_INIT(&glb_policy->lb_on_call_retry, - lb_call_on_retry_timer_locked, glb_policy, - grpc_combiner_scheduler(glb_policy->base.combiner)); - glb_policy->retry_timer_callback_pending = true; - grpc_timer_init(&glb_policy->lb_call_retry_timer, next_try, - &glb_policy->lb_on_call_retry); } - GRPC_LB_POLICY_UNREF(&glb_policy->base, - "lb_on_server_status_received_locked"); + GRPC_LB_POLICY_REF(&glb_policy->base, "grpclb_retry_timer"); + GRPC_CLOSURE_INIT(&glb_policy->lb_on_call_retry, + lb_call_on_retry_timer_locked, glb_policy, + grpc_combiner_scheduler(glb_policy->base.combiner)); + glb_policy->retry_timer_callback_pending = true; + grpc_timer_init(&glb_policy->lb_call_retry_timer, next_try, + &glb_policy->lb_on_call_retry); } -static void send_client_load_report_locked(void* arg, grpc_error* error); +static void maybe_send_client_load_report_locked(void* arg, grpc_error* error); -static void schedule_next_client_load_report(glb_lb_policy* glb_policy) { +static void schedule_next_client_load_report(glb_lb_call_data* lb_calld) { const grpc_millis next_client_load_report_time = - grpc_core::ExecCtx::Get()->Now() + - glb_policy->client_stats_report_interval; - GRPC_CLOSURE_INIT(&glb_policy->client_load_report_closure, - send_client_load_report_locked, glb_policy, - grpc_combiner_scheduler(glb_policy->base.combiner)); - grpc_timer_init(&glb_policy->client_load_report_timer, + grpc_core::ExecCtx::Get()->Now() + lb_calld->client_stats_report_interval; + GRPC_CLOSURE_INIT( + &lb_calld->client_load_report_closure, + maybe_send_client_load_report_locked, lb_calld, + grpc_combiner_scheduler(lb_calld->glb_policy->base.combiner)); + grpc_timer_init(&lb_calld->client_load_report_timer, next_client_load_report_time, - &glb_policy->client_load_report_closure); + &lb_calld->client_load_report_closure); + lb_calld->client_load_report_timer_callback_pending = true; } static void client_load_report_done_locked(void* arg, grpc_error* error) { - glb_lb_policy* glb_policy = (glb_lb_policy*)arg; - grpc_byte_buffer_destroy(glb_policy->client_load_report_payload); - glb_policy->client_load_report_payload = nullptr; - if (error != GRPC_ERROR_NONE || glb_policy->lb_call == nullptr) { - glb_policy->client_load_report_timer_callback_pending = false; - GRPC_LB_POLICY_UNREF(&glb_policy->base, "client_load_report"); - if (glb_policy->lb_call == nullptr) { - maybe_restart_lb_call(glb_policy); - } + glb_lb_call_data* lb_calld = (glb_lb_call_data*)arg; + glb_lb_policy* glb_policy = lb_calld->glb_policy; + grpc_byte_buffer_destroy(lb_calld->send_message_payload); + lb_calld->send_message_payload = nullptr; + if (error != GRPC_ERROR_NONE || lb_calld != glb_policy->lb_calld) { + glb_lb_call_data_unref(lb_calld, "client_load_report"); return; } - schedule_next_client_load_report(glb_policy); -} - -static void do_send_client_load_report_locked(glb_lb_policy* glb_policy) { - grpc_op op; - memset(&op, 0, sizeof(op)); - op.op = GRPC_OP_SEND_MESSAGE; - op.data.send_message.send_message = glb_policy->client_load_report_payload; - GRPC_CLOSURE_INIT(&glb_policy->client_load_report_closure, - client_load_report_done_locked, glb_policy, - grpc_combiner_scheduler(glb_policy->base.combiner)); - grpc_call_error call_error = grpc_call_start_batch_and_execute( - glb_policy->lb_call, &op, 1, &glb_policy->client_load_report_closure); - if (call_error != GRPC_CALL_OK) { - gpr_log(GPR_ERROR, "[grpclb %p] call_error=%d", glb_policy, call_error); - GPR_ASSERT(GRPC_CALL_OK == call_error); - } + schedule_next_client_load_report(lb_calld); } static bool load_report_counters_are_zero(grpc_grpclb_request* request) { @@ -1241,341 +1264,377 @@ static bool load_report_counters_are_zero(grpc_grpclb_request* request) { (drop_entries == nullptr || drop_entries->num_entries == 0); } -static void send_client_load_report_locked(void* arg, grpc_error* error) { - glb_lb_policy* glb_policy = (glb_lb_policy*)arg; - if (error == GRPC_ERROR_CANCELLED || glb_policy->lb_call == nullptr) { - glb_policy->client_load_report_timer_callback_pending = false; - GRPC_LB_POLICY_UNREF(&glb_policy->base, "client_load_report"); - if (glb_policy->lb_call == nullptr) { - maybe_restart_lb_call(glb_policy); - } - return; - } +static void send_client_load_report_locked(glb_lb_call_data* lb_calld) { + glb_lb_policy* glb_policy = lb_calld->glb_policy; // Construct message payload. - GPR_ASSERT(glb_policy->client_load_report_payload == nullptr); + GPR_ASSERT(lb_calld->send_message_payload == nullptr); grpc_grpclb_request* request = - grpc_grpclb_load_report_request_create_locked(glb_policy->client_stats); + grpc_grpclb_load_report_request_create_locked(lb_calld->client_stats); // Skip client load report if the counters were all zero in the last // report and they are still zero in this one. if (load_report_counters_are_zero(request)) { - if (glb_policy->last_client_load_report_counters_were_zero) { + if (lb_calld->last_client_load_report_counters_were_zero) { grpc_grpclb_request_destroy(request); - schedule_next_client_load_report(glb_policy); + schedule_next_client_load_report(lb_calld); return; } - glb_policy->last_client_load_report_counters_were_zero = true; + lb_calld->last_client_load_report_counters_were_zero = true; } else { - glb_policy->last_client_load_report_counters_were_zero = false; + lb_calld->last_client_load_report_counters_were_zero = false; } grpc_slice request_payload_slice = grpc_grpclb_request_encode(request); - glb_policy->client_load_report_payload = + lb_calld->send_message_payload = grpc_raw_byte_buffer_create(&request_payload_slice, 1); grpc_slice_unref_internal(request_payload_slice); grpc_grpclb_request_destroy(request); + // Send the report. + grpc_op op; + memset(&op, 0, sizeof(op)); + op.op = GRPC_OP_SEND_MESSAGE; + op.data.send_message.send_message = lb_calld->send_message_payload; + GRPC_CLOSURE_INIT(&lb_calld->client_load_report_closure, + client_load_report_done_locked, lb_calld, + grpc_combiner_scheduler(glb_policy->base.combiner)); + grpc_call_error call_error = grpc_call_start_batch_and_execute( + lb_calld->lb_call, &op, 1, &lb_calld->client_load_report_closure); + if (call_error != GRPC_CALL_OK) { + gpr_log(GPR_ERROR, "[grpclb %p] call_error=%d", glb_policy, call_error); + GPR_ASSERT(GRPC_CALL_OK == call_error); + } +} + +static void maybe_send_client_load_report_locked(void* arg, grpc_error* error) { + glb_lb_call_data* lb_calld = (glb_lb_call_data*)arg; + glb_lb_policy* glb_policy = lb_calld->glb_policy; + lb_calld->client_load_report_timer_callback_pending = false; + if (error != GRPC_ERROR_NONE || lb_calld != glb_policy->lb_calld) { + glb_lb_call_data_unref(lb_calld, "client_load_report"); + return; + } // If we've already sent the initial request, then we can go ahead and send // the load report. Otherwise, we need to wait until the initial request has - // been sent to send this (see lb_on_sent_initial_request_locked() below). - if (glb_policy->initial_request_sent) { - do_send_client_load_report_locked(glb_policy); + // been sent to send this (see lb_on_sent_initial_request_locked()). + if (lb_calld->send_message_payload == nullptr) { + send_client_load_report_locked(lb_calld); + } else { + lb_calld->client_load_report_is_due = true; } } static void lb_on_sent_initial_request_locked(void* arg, grpc_error* error); static void lb_on_server_status_received_locked(void* arg, grpc_error* error); static void lb_on_response_received_locked(void* arg, grpc_error* error); -static void lb_call_init_locked(glb_lb_policy* glb_policy) { +static glb_lb_call_data* lb_call_data_create_locked(glb_lb_policy* glb_policy) { + GPR_ASSERT(!glb_policy->shutting_down); + // Init the LB call. Note that the LB call will progress every time there's + // activity in glb_policy->base.interested_parties, which is comprised of the + // polling entities from client_channel. GPR_ASSERT(glb_policy->server_name != nullptr); GPR_ASSERT(glb_policy->server_name[0] != '\0'); - GPR_ASSERT(glb_policy->lb_call == nullptr); - GPR_ASSERT(!glb_policy->shutting_down); - - /* Note the following LB call progresses every time there's activity in \a - * glb_policy->base.interested_parties, which is comprised of the polling - * entities from \a client_channel. */ grpc_slice host = grpc_slice_from_copied_string(glb_policy->server_name); grpc_millis deadline = glb_policy->lb_call_timeout_ms == 0 ? GRPC_MILLIS_INF_FUTURE : grpc_core::ExecCtx::Get()->Now() + glb_policy->lb_call_timeout_ms; - glb_policy->lb_call = grpc_channel_create_pollset_set_call( + glb_lb_call_data* lb_calld = (glb_lb_call_data*)gpr_zalloc(sizeof(*lb_calld)); + lb_calld->lb_call = grpc_channel_create_pollset_set_call( glb_policy->lb_channel, nullptr, GRPC_PROPAGATE_DEFAULTS, glb_policy->base.interested_parties, GRPC_MDSTR_SLASH_GRPC_DOT_LB_DOT_V1_DOT_LOADBALANCER_SLASH_BALANCELOAD, &host, deadline, nullptr); grpc_slice_unref_internal(host); - - if (glb_policy->client_stats != nullptr) { - grpc_grpclb_client_stats_unref(glb_policy->client_stats); - } - glb_policy->client_stats = grpc_grpclb_client_stats_create(); - - grpc_metadata_array_init(&glb_policy->lb_initial_metadata_recv); - grpc_metadata_array_init(&glb_policy->lb_trailing_metadata_recv); - + // Init the LB call request payload. grpc_grpclb_request* request = grpc_grpclb_request_create(glb_policy->server_name); grpc_slice request_payload_slice = grpc_grpclb_request_encode(request); - glb_policy->lb_request_payload = + lb_calld->send_message_payload = grpc_raw_byte_buffer_create(&request_payload_slice, 1); grpc_slice_unref_internal(request_payload_slice); grpc_grpclb_request_destroy(request); - - GRPC_CLOSURE_INIT(&glb_policy->lb_on_sent_initial_request, - lb_on_sent_initial_request_locked, glb_policy, + // Init other data associated with the LB call. + lb_calld->glb_policy = glb_policy; + gpr_ref_init(&lb_calld->refs, 1); + grpc_metadata_array_init(&lb_calld->lb_initial_metadata_recv); + grpc_metadata_array_init(&lb_calld->lb_trailing_metadata_recv); + GRPC_CLOSURE_INIT(&lb_calld->lb_on_sent_initial_request, + lb_on_sent_initial_request_locked, lb_calld, grpc_combiner_scheduler(glb_policy->base.combiner)); - GRPC_CLOSURE_INIT(&glb_policy->lb_on_server_status_received, - lb_on_server_status_received_locked, glb_policy, + GRPC_CLOSURE_INIT(&lb_calld->lb_on_response_received, + lb_on_response_received_locked, lb_calld, grpc_combiner_scheduler(glb_policy->base.combiner)); - GRPC_CLOSURE_INIT(&glb_policy->lb_on_response_received, - lb_on_response_received_locked, glb_policy, + GRPC_CLOSURE_INIT(&lb_calld->lb_on_server_status_received, + lb_on_server_status_received_locked, lb_calld, grpc_combiner_scheduler(glb_policy->base.combiner)); - - grpc_core::BackOff::Options backoff_options; - backoff_options - .set_initial_backoff(GRPC_GRPCLB_INITIAL_CONNECT_BACKOFF_SECONDS * 1000) - .set_multiplier(GRPC_GRPCLB_RECONNECT_BACKOFF_MULTIPLIER) - .set_jitter(GRPC_GRPCLB_RECONNECT_JITTER) - .set_max_backoff(GRPC_GRPCLB_RECONNECT_MAX_BACKOFF_SECONDS * 1000); - - glb_policy->lb_call_backoff.Init(backoff_options); - - glb_policy->initial_request_sent = false; - glb_policy->seen_initial_response = false; - glb_policy->last_client_load_report_counters_were_zero = false; -} - -static void lb_call_destroy_locked(glb_lb_policy* glb_policy) { - GPR_ASSERT(glb_policy->lb_call != nullptr); - grpc_call_unref(glb_policy->lb_call); - glb_policy->lb_call = nullptr; - - grpc_metadata_array_destroy(&glb_policy->lb_initial_metadata_recv); - grpc_metadata_array_destroy(&glb_policy->lb_trailing_metadata_recv); - - grpc_byte_buffer_destroy(glb_policy->lb_request_payload); - grpc_slice_unref_internal(glb_policy->lb_call_status_details); - - if (glb_policy->client_load_report_timer_callback_pending) { - grpc_timer_cancel(&glb_policy->client_load_report_timer); - } + // Hold a ref to the glb_policy. + GRPC_LB_POLICY_REF(&glb_policy->base, "lb_calld"); + return lb_calld; } /* * Auxiliary functions and LB client callbacks. */ + static void query_for_backends_locked(glb_lb_policy* glb_policy) { GPR_ASSERT(glb_policy->lb_channel != nullptr); if (glb_policy->shutting_down) return; - - lb_call_init_locked(glb_policy); - + // Init the LB call data. + GPR_ASSERT(glb_policy->lb_calld == nullptr); + glb_policy->lb_calld = lb_call_data_create_locked(glb_policy); if (grpc_lb_glb_trace.enabled()) { gpr_log(GPR_INFO, - "[grpclb %p] Query for backends (lb_channel: %p, lb_call: %p)", - glb_policy, glb_policy->lb_channel, glb_policy->lb_call); + "[grpclb %p] Query for backends (lb_channel: %p, lb_calld: %p, " + "lb_call: %p)", + glb_policy, glb_policy->lb_channel, glb_policy->lb_calld, + glb_policy->lb_calld->lb_call); } - GPR_ASSERT(glb_policy->lb_call != nullptr); - + GPR_ASSERT(glb_policy->lb_calld->lb_call != nullptr); + // Create the ops. grpc_call_error call_error; grpc_op ops[3]; memset(ops, 0, sizeof(ops)); - + // Op: send initial metadata. grpc_op* op = ops; op->op = GRPC_OP_SEND_INITIAL_METADATA; op->data.send_initial_metadata.count = 0; op->flags = 0; op->reserved = nullptr; op++; + // Op: send request message. + GPR_ASSERT(glb_policy->lb_calld->send_message_payload != nullptr); + op->op = GRPC_OP_SEND_MESSAGE; + op->data.send_message.send_message = + glb_policy->lb_calld->send_message_payload; + op->flags = 0; + op->reserved = nullptr; + op++; + glb_lb_call_data_ref(glb_policy->lb_calld, + "lb_on_sent_initial_request_locked"); + call_error = grpc_call_start_batch_and_execute( + glb_policy->lb_calld->lb_call, ops, (size_t)(op - ops), + &glb_policy->lb_calld->lb_on_sent_initial_request); + GPR_ASSERT(GRPC_CALL_OK == call_error); + // Op: recv initial metadata. + op = ops; op->op = GRPC_OP_RECV_INITIAL_METADATA; op->data.recv_initial_metadata.recv_initial_metadata = - &glb_policy->lb_initial_metadata_recv; + &glb_policy->lb_calld->lb_initial_metadata_recv; op->flags = 0; op->reserved = nullptr; op++; - GPR_ASSERT(glb_policy->lb_request_payload != nullptr); - op->op = GRPC_OP_SEND_MESSAGE; - op->data.send_message.send_message = glb_policy->lb_request_payload; + // Op: recv response. + op->op = GRPC_OP_RECV_MESSAGE; + op->data.recv_message.recv_message = + &glb_policy->lb_calld->recv_message_payload; op->flags = 0; op->reserved = nullptr; op++; - /* take a ref to be released in lb_on_sent_initial_request_locked() */ - GRPC_LB_POLICY_REF(&glb_policy->base, "lb_on_sent_initial_request_locked"); + glb_lb_call_data_ref(glb_policy->lb_calld, "lb_on_response_received_locked"); call_error = grpc_call_start_batch_and_execute( - glb_policy->lb_call, ops, (size_t)(op - ops), - &glb_policy->lb_on_sent_initial_request); + glb_policy->lb_calld->lb_call, ops, (size_t)(op - ops), + &glb_policy->lb_calld->lb_on_response_received); GPR_ASSERT(GRPC_CALL_OK == call_error); - + // Op: recv server status. op = ops; op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; op->data.recv_status_on_client.trailing_metadata = - &glb_policy->lb_trailing_metadata_recv; - op->data.recv_status_on_client.status = &glb_policy->lb_call_status; + &glb_policy->lb_calld->lb_trailing_metadata_recv; + op->data.recv_status_on_client.status = &glb_policy->lb_calld->lb_call_status; op->data.recv_status_on_client.status_details = - &glb_policy->lb_call_status_details; + &glb_policy->lb_calld->lb_call_status_details; op->flags = 0; op->reserved = nullptr; op++; - /* take a ref to be released in lb_on_server_status_received_locked() */ - GRPC_LB_POLICY_REF(&glb_policy->base, "lb_on_server_status_received_locked"); + // This callback signals the end of the LB call, so it relies on the initial + // ref instead of a new ref. When it's invoked, it's the initial ref that is + // unreffed. call_error = grpc_call_start_batch_and_execute( - glb_policy->lb_call, ops, (size_t)(op - ops), - &glb_policy->lb_on_server_status_received); - GPR_ASSERT(GRPC_CALL_OK == call_error); - - op = ops; - op->op = GRPC_OP_RECV_MESSAGE; - op->data.recv_message.recv_message = &glb_policy->lb_response_payload; - op->flags = 0; - op->reserved = nullptr; - op++; - /* take a ref to be unref'd/reused in lb_on_response_received_locked() */ - GRPC_LB_POLICY_REF(&glb_policy->base, "lb_on_response_received_locked"); - call_error = grpc_call_start_batch_and_execute( - glb_policy->lb_call, ops, (size_t)(op - ops), - &glb_policy->lb_on_response_received); + glb_policy->lb_calld->lb_call, ops, (size_t)(op - ops), + &glb_policy->lb_calld->lb_on_server_status_received); GPR_ASSERT(GRPC_CALL_OK == call_error); } static void lb_on_sent_initial_request_locked(void* arg, grpc_error* error) { - glb_lb_policy* glb_policy = (glb_lb_policy*)arg; - glb_policy->initial_request_sent = true; + glb_lb_call_data* lb_calld = (glb_lb_call_data*)arg; + grpc_byte_buffer_destroy(lb_calld->send_message_payload); + lb_calld->send_message_payload = nullptr; // If we attempted to send a client load report before the initial request was - // sent, send the load report now. - if (glb_policy->client_load_report_payload != nullptr) { - do_send_client_load_report_locked(glb_policy); + // sent (and this lb_calld is still in use), send the load report now. + if (lb_calld->client_load_report_is_due && + lb_calld == lb_calld->glb_policy->lb_calld) { + send_client_load_report_locked(lb_calld); + lb_calld->client_load_report_is_due = false; } - GRPC_LB_POLICY_UNREF(&glb_policy->base, "lb_on_sent_initial_request_locked"); + glb_lb_call_data_unref(lb_calld, "lb_on_sent_initial_request_locked"); } static void lb_on_response_received_locked(void* arg, grpc_error* error) { - glb_lb_policy* glb_policy = (glb_lb_policy*)arg; + glb_lb_call_data* lb_calld = (glb_lb_call_data*)arg; + glb_lb_policy* glb_policy = lb_calld->glb_policy; + // Empty payload means the LB call was cancelled. + if (lb_calld != glb_policy->lb_calld || + lb_calld->recv_message_payload == nullptr) { + glb_lb_call_data_unref(lb_calld, "lb_on_response_received_locked"); + return; + } grpc_op ops[2]; memset(ops, 0, sizeof(ops)); grpc_op* op = ops; - if (glb_policy->lb_response_payload != nullptr) { - glb_policy->lb_call_backoff->Reset(); - /* Received data from the LB server. Look inside - * glb_policy->lb_response_payload, for a serverlist. */ - grpc_byte_buffer_reader bbr; - grpc_byte_buffer_reader_init(&bbr, glb_policy->lb_response_payload); - grpc_slice response_slice = grpc_byte_buffer_reader_readall(&bbr); - grpc_byte_buffer_reader_destroy(&bbr); - grpc_byte_buffer_destroy(glb_policy->lb_response_payload); - - grpc_grpclb_initial_response* response = nullptr; - if (!glb_policy->seen_initial_response && - (response = grpc_grpclb_initial_response_parse(response_slice)) != - nullptr) { - if (response->has_client_stats_report_interval) { - glb_policy->client_stats_report_interval = GPR_MAX( - GPR_MS_PER_SEC, grpc_grpclb_duration_to_millis( - &response->client_stats_report_interval)); - if (grpc_lb_glb_trace.enabled()) { - gpr_log(GPR_INFO, - "[grpclb %p] Received initial LB response message; " - "client load reporting interval = %" PRIdPTR " milliseconds", - glb_policy, glb_policy->client_stats_report_interval); - } - /* take a ref to be unref'd in send_client_load_report_locked() */ - glb_policy->client_load_report_timer_callback_pending = true; - GRPC_LB_POLICY_REF(&glb_policy->base, "client_load_report"); - schedule_next_client_load_report(glb_policy); - } else if (grpc_lb_glb_trace.enabled()) { + glb_policy->lb_call_backoff->Reset(); + grpc_byte_buffer_reader bbr; + grpc_byte_buffer_reader_init(&bbr, lb_calld->recv_message_payload); + grpc_slice response_slice = grpc_byte_buffer_reader_readall(&bbr); + grpc_byte_buffer_reader_destroy(&bbr); + grpc_byte_buffer_destroy(lb_calld->recv_message_payload); + lb_calld->recv_message_payload = nullptr; + grpc_grpclb_initial_response* initial_response; + grpc_grpclb_serverlist* serverlist; + if (!lb_calld->seen_initial_response && + (initial_response = grpc_grpclb_initial_response_parse(response_slice)) != + nullptr) { + // Have NOT seen initial response, look for initial response. + if (initial_response->has_client_stats_report_interval) { + lb_calld->client_stats_report_interval = GPR_MAX( + GPR_MS_PER_SEC, grpc_grpclb_duration_to_millis( + &initial_response->client_stats_report_interval)); + if (grpc_lb_glb_trace.enabled()) { gpr_log(GPR_INFO, - "[grpclb %p] Received initial LB response message; client load " - "reporting NOT enabled", - glb_policy); + "[grpclb %p] Received initial LB response message; " + "client load reporting interval = %" PRIdPTR " milliseconds", + glb_policy, lb_calld->client_stats_report_interval); } - grpc_grpclb_initial_response_destroy(response); - glb_policy->seen_initial_response = true; - } else { - grpc_grpclb_serverlist* serverlist = - grpc_grpclb_response_parse_serverlist(response_slice); - if (serverlist != nullptr) { - GPR_ASSERT(glb_policy->lb_call != nullptr); + } else if (grpc_lb_glb_trace.enabled()) { + gpr_log(GPR_INFO, + "[grpclb %p] Received initial LB response message; client load " + "reporting NOT enabled", + glb_policy); + } + grpc_grpclb_initial_response_destroy(initial_response); + lb_calld->seen_initial_response = true; + } else if ((serverlist = grpc_grpclb_response_parse_serverlist( + response_slice)) != nullptr) { + // Have seen initial response, look for serverlist. + GPR_ASSERT(lb_calld->lb_call != nullptr); + if (grpc_lb_glb_trace.enabled()) { + gpr_log(GPR_INFO, + "[grpclb %p] Serverlist with %" PRIuPTR " servers received", + glb_policy, serverlist->num_servers); + for (size_t i = 0; i < serverlist->num_servers; ++i) { + grpc_resolved_address addr; + parse_server(serverlist->servers[i], &addr); + char* ipport; + grpc_sockaddr_to_string(&ipport, &addr, false); + gpr_log(GPR_INFO, "[grpclb %p] Serverlist[%" PRIuPTR "]: %s", + glb_policy, i, ipport); + gpr_free(ipport); + } + } + /* update serverlist */ + if (serverlist->num_servers > 0) { + // Start sending client load report only after we start using the + // serverlist returned from the current LB call. + if (lb_calld->client_stats_report_interval > 0 && + lb_calld->client_stats == nullptr) { + lb_calld->client_stats = grpc_grpclb_client_stats_create(); + glb_lb_call_data_ref(lb_calld, "client_load_report"); + schedule_next_client_load_report(lb_calld); + } + if (grpc_grpclb_serverlist_equals(glb_policy->serverlist, serverlist)) { if (grpc_lb_glb_trace.enabled()) { gpr_log(GPR_INFO, - "[grpclb %p] Serverlist with %" PRIuPTR " servers received", - glb_policy, serverlist->num_servers); - for (size_t i = 0; i < serverlist->num_servers; ++i) { - grpc_resolved_address addr; - parse_server(serverlist->servers[i], &addr); - char* ipport; - grpc_sockaddr_to_string(&ipport, &addr, false); - gpr_log(GPR_INFO, "[grpclb %p] Serverlist[%" PRIuPTR "]: %s", - glb_policy, i, ipport); - gpr_free(ipport); - } + "[grpclb %p] Incoming server list identical to current, " + "ignoring.", + glb_policy); } - /* update serverlist */ - if (serverlist->num_servers > 0) { - if (grpc_grpclb_serverlist_equals(glb_policy->serverlist, - serverlist)) { - if (grpc_lb_glb_trace.enabled()) { - gpr_log(GPR_INFO, - "[grpclb %p] Incoming server list identical to current, " - "ignoring.", - glb_policy); - } - grpc_grpclb_destroy_serverlist(serverlist); - } else { /* new serverlist */ - if (glb_policy->serverlist != nullptr) { - /* dispose of the old serverlist */ - grpc_grpclb_destroy_serverlist(glb_policy->serverlist); - } else { - /* or dispose of the fallback */ - grpc_lb_addresses_destroy(glb_policy->fallback_backend_addresses); - glb_policy->fallback_backend_addresses = nullptr; - if (glb_policy->fallback_timer_callback_pending) { - grpc_timer_cancel(&glb_policy->lb_fallback_timer); - } - } - /* and update the copy in the glb_lb_policy instance. This - * serverlist instance will be destroyed either upon the next - * update or in glb_destroy() */ - glb_policy->serverlist = serverlist; - glb_policy->serverlist_index = 0; - rr_handover_locked(glb_policy); - } + grpc_grpclb_destroy_serverlist(serverlist); + } else { /* new serverlist */ + if (glb_policy->serverlist != nullptr) { + /* dispose of the old serverlist */ + grpc_grpclb_destroy_serverlist(glb_policy->serverlist); } else { - if (grpc_lb_glb_trace.enabled()) { - gpr_log(GPR_INFO, - "[grpclb %p] Received empty server list, ignoring.", - glb_policy); + /* or dispose of the fallback */ + grpc_lb_addresses_destroy(glb_policy->fallback_backend_addresses); + glb_policy->fallback_backend_addresses = nullptr; + if (glb_policy->fallback_timer_callback_pending) { + grpc_timer_cancel(&glb_policy->lb_fallback_timer); + glb_policy->fallback_timer_callback_pending = false; } - grpc_grpclb_destroy_serverlist(serverlist); } - } else { /* serverlist == nullptr */ - gpr_log(GPR_ERROR, - "[grpclb %p] Invalid LB response received: '%s'. Ignoring.", - glb_policy, - grpc_dump_slice(response_slice, GPR_DUMP_ASCII | GPR_DUMP_HEX)); + /* and update the copy in the glb_lb_policy instance. This + * serverlist instance will be destroyed either upon the next + * update or in glb_destroy() */ + glb_policy->serverlist = serverlist; + glb_policy->serverlist_index = 0; + rr_handover_locked(glb_policy); } + } else { + if (grpc_lb_glb_trace.enabled()) { + gpr_log(GPR_INFO, "[grpclb %p] Received empty server list, ignoring.", + glb_policy); + } + grpc_grpclb_destroy_serverlist(serverlist); + } + } else { + // No valid initial response or serverlist found. + gpr_log(GPR_ERROR, + "[grpclb %p] Invalid LB response received: '%s'. Ignoring.", + glb_policy, + grpc_dump_slice(response_slice, GPR_DUMP_ASCII | GPR_DUMP_HEX)); + } + grpc_slice_unref_internal(response_slice); + if (!glb_policy->shutting_down) { + // Keep listening for serverlist updates. + op->op = GRPC_OP_RECV_MESSAGE; + op->data.recv_message.recv_message = &lb_calld->recv_message_payload; + op->flags = 0; + op->reserved = nullptr; + op++; + // Reuse the "lb_on_response_received_locked" ref taken in + // query_for_backends_locked(). + const grpc_call_error call_error = grpc_call_start_batch_and_execute( + lb_calld->lb_call, ops, (size_t)(op - ops), + &lb_calld->lb_on_response_received); + GPR_ASSERT(GRPC_CALL_OK == call_error); + } else { + glb_lb_call_data_unref(lb_calld, + "lb_on_response_received_locked+glb_shutdown"); + } +} + +static void lb_on_server_status_received_locked(void* arg, grpc_error* error) { + glb_lb_call_data* lb_calld = (glb_lb_call_data*)arg; + glb_lb_policy* glb_policy = lb_calld->glb_policy; + GPR_ASSERT(lb_calld->lb_call != nullptr); + if (grpc_lb_glb_trace.enabled()) { + char* status_details = + grpc_slice_to_c_string(lb_calld->lb_call_status_details); + gpr_log(GPR_INFO, + "[grpclb %p] Status from LB server received. Status = %d, details " + "= '%s', (lb_calld: %p, lb_call: %p), error '%s'", + lb_calld->glb_policy, lb_calld->lb_call_status, status_details, + lb_calld, lb_calld->lb_call, grpc_error_string(error)); + gpr_free(status_details); + } + // If this lb_calld is still in use, this call ended because of a failure so + // we want to retry connecting. Otherwise, we have deliberately ended this + // call and no further action is required. + if (lb_calld == glb_policy->lb_calld) { + glb_policy->lb_calld = nullptr; + if (lb_calld->client_load_report_timer_callback_pending) { + grpc_timer_cancel(&lb_calld->client_load_report_timer); } - grpc_slice_unref_internal(response_slice); - if (!glb_policy->shutting_down) { - /* keep listening for serverlist updates */ - op->op = GRPC_OP_RECV_MESSAGE; - op->data.recv_message.recv_message = &glb_policy->lb_response_payload; - op->flags = 0; - op->reserved = nullptr; - op++; - /* reuse the "lb_on_response_received_locked" ref taken in - * query_for_backends_locked() */ - const grpc_call_error call_error = grpc_call_start_batch_and_execute( - glb_policy->lb_call, ops, (size_t)(op - ops), - &glb_policy->lb_on_response_received); /* loop */ - GPR_ASSERT(GRPC_CALL_OK == call_error); + GPR_ASSERT(!glb_policy->shutting_down); + if (lb_calld->seen_initial_response) { + // If we lose connection to the LB server, reset the backoff and restart + // the LB call immediately. + glb_policy->lb_call_backoff->Reset(); + query_for_backends_locked(glb_policy); } else { - GRPC_LB_POLICY_UNREF(&glb_policy->base, - "lb_on_response_received_locked_shutdown"); + // If this LB call fails establishing any connection to the LB server, + // retry later. + start_lb_call_retry_timer_locked(glb_policy); } - } else { /* empty payload: call cancelled. */ - /* dispose of the "lb_on_response_received_locked" ref taken in - * query_for_backends_locked() and reused in every reception loop */ - GRPC_LB_POLICY_UNREF(&glb_policy->base, - "lb_on_response_received_locked_empty_payload"); } + glb_lb_call_data_unref(lb_calld, "lb_call_ended"); } static void lb_on_fallback_timer_locked(void* arg, grpc_error* error) { @@ -1597,29 +1656,6 @@ static void lb_on_fallback_timer_locked(void* arg, grpc_error* error) { GRPC_LB_POLICY_UNREF(&glb_policy->base, "grpclb_fallback_timer"); } -static void lb_on_server_status_received_locked(void* arg, grpc_error* error) { - glb_lb_policy* glb_policy = (glb_lb_policy*)arg; - GPR_ASSERT(glb_policy->lb_call != nullptr); - if (grpc_lb_glb_trace.enabled()) { - char* status_details = - grpc_slice_to_c_string(glb_policy->lb_call_status_details); - gpr_log(GPR_INFO, - "[grpclb %p] Status from LB server received. Status = %d, Details " - "= '%s', (call: %p), error '%s'", - glb_policy, glb_policy->lb_call_status, status_details, - glb_policy->lb_call, grpc_error_string(error)); - gpr_free(status_details); - } - /* We need to perform cleanups no matter what. */ - lb_call_destroy_locked(glb_policy); - // If the load report timer is still pending, we wait for it to be - // called before restarting the call. Otherwise, we restart the call - // here. - if (!glb_policy->client_load_report_timer_callback_pending) { - maybe_restart_lb_call(glb_policy); - } -} - static void fallback_update_locked(glb_lb_policy* glb_policy, const grpc_lb_addresses* addresses) { GPR_ASSERT(glb_policy->fallback_backend_addresses != nullptr); @@ -1701,7 +1737,7 @@ static void glb_lb_channel_on_connectivity_changed_cb(void* arg, switch (glb_policy->lb_channel_connectivity) { case GRPC_CHANNEL_CONNECTING: case GRPC_CHANNEL_TRANSIENT_FAILURE: { - /* resub. */ + // Keep watching the LB channel. grpc_channel_element* client_channel_elem = grpc_channel_stack_last_element( grpc_channel_get_channel_stack(glb_policy->lb_channel)); @@ -1714,29 +1750,26 @@ static void glb_lb_channel_on_connectivity_changed_cb(void* arg, &glb_policy->lb_channel_on_connectivity_changed, nullptr); break; } + // The LB channel may be IDLE because it's shut down before the update. + // Restart the LB call to kick the LB channel into gear. case GRPC_CHANNEL_IDLE: - // lb channel inactive (probably shutdown prior to update). Restart lb - // call to kick the lb channel into gear. - /* fallthrough */ case GRPC_CHANNEL_READY: - if (glb_policy->lb_call != nullptr) { - glb_policy->updating_lb_call = true; - grpc_call_cancel(glb_policy->lb_call, nullptr); - // lb_on_server_status_received() will pick up the cancel and reinit - // lb_call. - } else if (glb_policy->started_picking) { + if (glb_policy->lb_calld != nullptr) { + lb_call_data_shutdown(glb_policy); + } + if (glb_policy->started_picking) { if (glb_policy->retry_timer_callback_pending) { grpc_timer_cancel(&glb_policy->lb_call_retry_timer); } - start_picking_locked(glb_policy); + glb_policy->lb_call_backoff->Reset(); + query_for_backends_locked(glb_policy); } - /* fallthrough */ + // Fall through. case GRPC_CHANNEL_SHUTDOWN: done: glb_policy->watching_lb_channel = false; GRPC_LB_POLICY_UNREF(&glb_policy->base, "watch_lb_channel_connectivity_cb_shutdown"); - break; } } @@ -1851,6 +1884,14 @@ static grpc_lb_policy* glb_create(grpc_lb_policy_factory* factory, grpc_lb_policy_init(&glb_policy->base, &glb_lb_policy_vtable, args->combiner); grpc_connectivity_state_init(&glb_policy->state_tracker, GRPC_CHANNEL_IDLE, "grpclb"); + // Init LB call backoff option. + grpc_core::BackOff::Options backoff_options; + backoff_options + .set_initial_backoff(GRPC_GRPCLB_INITIAL_CONNECT_BACKOFF_SECONDS * 1000) + .set_multiplier(GRPC_GRPCLB_RECONNECT_BACKOFF_MULTIPLIER) + .set_jitter(GRPC_GRPCLB_RECONNECT_JITTER) + .set_max_backoff(GRPC_GRPCLB_RECONNECT_MAX_BACKOFF_SECONDS * 1000); + glb_policy->lb_call_backoff.Init(backoff_options); return &glb_policy->base; } diff --git a/src/core/ext/filters/http/message_compress/message_compress_filter.cc b/src/core/ext/filters/http/message_compress/message_compress_filter.cc index d0b9750497..0218ec6e40 100644 --- a/src/core/ext/filters/http/message_compress/message_compress_filter.cc +++ b/src/core/ext/filters/http/message_compress/message_compress_filter.cc @@ -27,6 +27,7 @@ #include "src/core/ext/filters/http/message_compress/message_compress_filter.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/compression/algorithm_metadata.h" +#include "src/core/lib/compression/compression_internal.h" #include "src/core/lib/compression/message_compress.h" #include "src/core/lib/gpr/string.h" #include "src/core/lib/profiling/timers.h" @@ -53,7 +54,7 @@ struct call_data { grpc_linked_mdelem accept_stream_encoding_storage; /** Compression algorithm we'll try to use. It may be given by incoming * metadata, or by the channel's default compression settings. */ - grpc_compression_algorithm compression_algorithm; + grpc_message_compression_algorithm message_compression_algorithm; initial_metadata_state send_initial_metadata_state; grpc_error* cancel_error; grpc_closure start_send_message_batch_in_call_combiner; @@ -68,15 +69,10 @@ struct call_data { struct channel_data { /** The default, channel-level, compression algorithm */ grpc_compression_algorithm default_compression_algorithm; - /** Bitset of enabled algorithms */ + /** Bitset of enabled compression algorithms */ uint32_t enabled_algorithms_bitset; /** Supported compression algorithms */ - uint32_t supported_compression_algorithms; - - /** The default, channel-level, stream compression algorithm */ - grpc_stream_compression_algorithm default_stream_compression_algorithm; - /** Bitset of enabled stream compression algorithms */ - uint32_t enabled_stream_compression_algorithms_bitset; + uint32_t supported_message_compression_algorithms; /** Supported stream compression algorithms */ uint32_t supported_stream_compression_algorithms; }; @@ -91,7 +87,7 @@ static bool skip_compression(grpc_call_element* elem, uint32_t flags, return true; } if (has_compression_algorithm) { - if (calld->compression_algorithm == GRPC_COMPRESS_NONE) { + if (calld->message_compression_algorithm == GRPC_MESSAGE_COMPRESS_NONE) { return true; } return false; /* we have an actual call-specific algorithm */ @@ -110,70 +106,53 @@ static grpc_error* process_send_initial_metadata( call_data* calld = (call_data*)elem->call_data; channel_data* channeld = (channel_data*)elem->channel_data; *has_compression_algorithm = false; + grpc_compression_algorithm compression_algorithm; grpc_stream_compression_algorithm stream_compression_algorithm = GRPC_STREAM_COMPRESS_NONE; - if (initial_metadata->idx.named.grpc_internal_stream_encoding_request != - nullptr) { + if (initial_metadata->idx.named.grpc_internal_encoding_request != nullptr) { grpc_mdelem md = - initial_metadata->idx.named.grpc_internal_stream_encoding_request->md; - if (!grpc_stream_compression_algorithm_parse( - GRPC_MDVALUE(md), &stream_compression_algorithm)) { + initial_metadata->idx.named.grpc_internal_encoding_request->md; + if (!grpc_compression_algorithm_parse(GRPC_MDVALUE(md), + &compression_algorithm)) { char* val = grpc_slice_to_c_string(GRPC_MDVALUE(md)); gpr_log(GPR_ERROR, - "Invalid stream compression algorithm: '%s' (unknown). Ignoring.", - val); + "Invalid compression algorithm: '%s' (unknown). Ignoring.", val); gpr_free(val); + calld->message_compression_algorithm = GRPC_MESSAGE_COMPRESS_NONE; stream_compression_algorithm = GRPC_STREAM_COMPRESS_NONE; } - if (!GPR_BITGET(channeld->enabled_stream_compression_algorithms_bitset, - stream_compression_algorithm)) { - char* val = grpc_slice_to_c_string(GRPC_MDVALUE(md)); - gpr_log( - GPR_ERROR, - "Invalid stream compression algorithm: '%s' (previously disabled). " - "Ignoring.", - val); - gpr_free(val); - stream_compression_algorithm = GRPC_STREAM_COMPRESS_NONE; - } - *has_compression_algorithm = true; - grpc_metadata_batch_remove( - initial_metadata, - initial_metadata->idx.named.grpc_internal_stream_encoding_request); - /* Disable message-wise compression */ - calld->compression_algorithm = GRPC_COMPRESS_NONE; - if (initial_metadata->idx.named.grpc_internal_encoding_request != nullptr) { - grpc_metadata_batch_remove( - initial_metadata, - initial_metadata->idx.named.grpc_internal_encoding_request); - } - } else if (initial_metadata->idx.named.grpc_internal_encoding_request != - nullptr) { - grpc_mdelem md = - initial_metadata->idx.named.grpc_internal_encoding_request->md; - if (!grpc_compression_algorithm_parse(GRPC_MDVALUE(md), - &calld->compression_algorithm)) { + if (!GPR_BITGET(channeld->enabled_algorithms_bitset, + compression_algorithm)) { char* val = grpc_slice_to_c_string(GRPC_MDVALUE(md)); gpr_log(GPR_ERROR, - "Invalid compression algorithm: '%s' (unknown). Ignoring.", val); + "Invalid compression algorithm: '%s' (previously disabled). " + "Ignoring.", + val); gpr_free(val); - calld->compression_algorithm = GRPC_COMPRESS_NONE; + calld->message_compression_algorithm = GRPC_MESSAGE_COMPRESS_NONE; + stream_compression_algorithm = GRPC_STREAM_COMPRESS_NONE; } *has_compression_algorithm = true; grpc_metadata_batch_remove( initial_metadata, initial_metadata->idx.named.grpc_internal_encoding_request); + calld->message_compression_algorithm = + grpc_compression_algorithm_to_message_compression_algorithm( + compression_algorithm); + stream_compression_algorithm = + grpc_compression_algorithm_to_stream_compression_algorithm( + compression_algorithm); } else { /* If no algorithm was found in the metadata and we aren't * exceptionally skipping compression, fall back to the channel * default */ - if (channeld->default_stream_compression_algorithm != - GRPC_STREAM_COMPRESS_NONE) { + if (channeld->default_compression_algorithm != GRPC_COMPRESS_NONE) { + calld->message_compression_algorithm = + grpc_compression_algorithm_to_message_compression_algorithm( + channeld->default_compression_algorithm); stream_compression_algorithm = - channeld->default_stream_compression_algorithm; - calld->compression_algorithm = GRPC_COMPRESS_NONE; - } else { - calld->compression_algorithm = channeld->default_compression_algorithm; + grpc_compression_algorithm_to_stream_compression_algorithm( + channeld->default_compression_algorithm); } *has_compression_algorithm = true; } @@ -184,10 +163,12 @@ static grpc_error* process_send_initial_metadata( error = grpc_metadata_batch_add_tail( initial_metadata, &calld->stream_compression_algorithm_storage, grpc_stream_compression_encoding_mdelem(stream_compression_algorithm)); - } else if (calld->compression_algorithm != GRPC_COMPRESS_NONE) { + } else if (calld->message_compression_algorithm != + GRPC_MESSAGE_COMPRESS_NONE) { error = grpc_metadata_batch_add_tail( initial_metadata, &calld->compression_algorithm_storage, - grpc_compression_encoding_mdelem(calld->compression_algorithm)); + grpc_message_compression_encoding_mdelem( + calld->message_compression_algorithm)); } if (error != GRPC_ERROR_NONE) return error; @@ -196,11 +177,12 @@ static grpc_error* process_send_initial_metadata( error = grpc_metadata_batch_add_tail( initial_metadata, &calld->accept_encoding_storage, GRPC_MDELEM_ACCEPT_ENCODING_FOR_ALGORITHMS( - channeld->supported_compression_algorithms)); + channeld->supported_message_compression_algorithms)); if (error != GRPC_ERROR_NONE) return error; - /* Do not overwrite accept-encoding header if it already presents. */ + /* Do not overwrite accept-encoding header if it already presents (e.g. added + * by some proxy). */ if (!initial_metadata->idx.named.accept_encoding) { error = grpc_metadata_batch_add_tail( initial_metadata, &calld->accept_stream_encoding_storage, @@ -237,16 +219,16 @@ static void finish_send_message(grpc_call_element* elem) { grpc_slice_buffer_init(&tmp); uint32_t send_flags = calld->send_message_batch->payload->send_message.send_message->flags; - bool did_compress = - grpc_msg_compress(calld->compression_algorithm, &calld->slices, &tmp); + bool did_compress = grpc_msg_compress(calld->message_compression_algorithm, + &calld->slices, &tmp); if (did_compress) { if (grpc_compression_trace.enabled()) { const char* algo_name; const size_t before_size = calld->slices.length; const size_t after_size = tmp.length; const float savings_ratio = 1.0f - (float)after_size / (float)before_size; - GPR_ASSERT(grpc_compression_algorithm_name(calld->compression_algorithm, - &algo_name)); + GPR_ASSERT(grpc_message_compression_algorithm_name( + calld->message_compression_algorithm, &algo_name)); gpr_log(GPR_DEBUG, "Compressed[%s] %" PRIuPTR " bytes vs. %" PRIuPTR " bytes (%.2f%% savings)", @@ -257,8 +239,8 @@ static void finish_send_message(grpc_call_element* elem) { } else { if (grpc_compression_trace.enabled()) { const char* algo_name; - GPR_ASSERT(grpc_compression_algorithm_name(calld->compression_algorithm, - &algo_name)); + GPR_ASSERT(grpc_message_compression_algorithm_name( + calld->message_compression_algorithm, &algo_name)); gpr_log(GPR_DEBUG, "Algorithm '%s' enabled but decided not to compress. Input size: " "%" PRIuPTR, @@ -381,6 +363,7 @@ static void compress_start_transport_stream_op_batch( GRPC_ERROR_REF(calld->cancel_error), "failing send_message op"); } else { grpc_byte_stream_shutdown( + calld->send_message_batch->payload->send_message.send_message, GRPC_ERROR_REF(calld->cancel_error)); } @@ -470,12 +453,11 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem, grpc_channel_element_args* args) { channel_data* channeld = (channel_data*)elem->channel_data; - /* Configuration for message compression */ channeld->enabled_algorithms_bitset = grpc_channel_args_compression_algorithm_get_states(args->channel_args); - channeld->default_compression_algorithm = grpc_channel_args_get_compression_algorithm(args->channel_args); + /* Make sure the default isn't disabled. */ if (!GPR_BITGET(channeld->enabled_algorithms_bitset, channeld->default_compression_algorithm)) { @@ -485,31 +467,18 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem, channeld->default_compression_algorithm = GRPC_COMPRESS_NONE; } - channeld->supported_compression_algorithms = + uint32_t supported_compression_algorithms = (((1u << GRPC_COMPRESS_ALGORITHMS_COUNT) - 1) & channeld->enabled_algorithms_bitset) | 1u; - /* Configuration for stream compression */ - channeld->enabled_stream_compression_algorithms_bitset = - grpc_channel_args_stream_compression_algorithm_get_states( - args->channel_args); - - channeld->default_stream_compression_algorithm = - grpc_channel_args_get_stream_compression_algorithm(args->channel_args); - - if (!GPR_BITGET(channeld->enabled_stream_compression_algorithms_bitset, - channeld->default_stream_compression_algorithm)) { - gpr_log(GPR_DEBUG, - "stream compression algorithm %d not enabled: switching to none", - channeld->default_stream_compression_algorithm); - channeld->default_stream_compression_algorithm = GRPC_STREAM_COMPRESS_NONE; - } + channeld->supported_message_compression_algorithms = + grpc_compression_bitset_to_message_bitset( + supported_compression_algorithms); channeld->supported_stream_compression_algorithms = - (((1u << GRPC_STREAM_COMPRESS_ALGORITHMS_COUNT) - 1) & - channeld->enabled_stream_compression_algorithms_bitset) | - 1u; + grpc_compression_bitset_to_stream_bitset( + supported_compression_algorithms); GPR_ASSERT(!args->is_last); return GRPC_ERROR_NONE; diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc index e067b696a1..530ab17bc7 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc @@ -1886,7 +1886,7 @@ void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_chttp2_transport* t, grpc_chttp2_maybe_complete_recv_message(t, s); if (s->recv_trailing_metadata_finished != nullptr && s->read_closed && s->write_closed) { - if (s->seen_error) { + if (s->seen_error || !t->is_client) { grpc_slice_buffer_reset_and_unref_internal(&s->frame_storage); if (!s->pending_byte_stream) { grpc_slice_buffer_reset_and_unref_internal( diff --git a/src/core/lib/channel/channel_args.cc b/src/core/lib/channel/channel_args.cc index 634286d403..101a6fffbc 100644 --- a/src/core/lib/channel/channel_args.cc +++ b/src/core/lib/channel/channel_args.cc @@ -222,21 +222,6 @@ grpc_compression_algorithm grpc_channel_args_get_compression_algorithm( return GRPC_COMPRESS_NONE; } -grpc_stream_compression_algorithm -grpc_channel_args_get_stream_compression_algorithm(const grpc_channel_args* a) { - size_t i; - if (a == nullptr) return GRPC_STREAM_COMPRESS_NONE; - for (i = 0; i < a->num_args; ++i) { - if (a->args[i].type == GRPC_ARG_INTEGER && - !strcmp(GRPC_STREAM_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM, - a->args[i].key)) { - return (grpc_stream_compression_algorithm)a->args[i].value.integer; - break; - } - } - return GRPC_STREAM_COMPRESS_NONE; -} - grpc_channel_args* grpc_channel_args_set_compression_algorithm( grpc_channel_args* a, grpc_compression_algorithm algorithm) { GPR_ASSERT(algorithm < GRPC_COMPRESS_ALGORITHMS_COUNT); @@ -247,16 +232,6 @@ grpc_channel_args* grpc_channel_args_set_compression_algorithm( return grpc_channel_args_copy_and_add(a, &tmp, 1); } -grpc_channel_args* grpc_channel_args_set_stream_compression_algorithm( - grpc_channel_args* a, grpc_stream_compression_algorithm algorithm) { - GPR_ASSERT(algorithm < GRPC_STREAM_COMPRESS_ALGORITHMS_COUNT); - grpc_arg tmp; - tmp.type = GRPC_ARG_INTEGER; - tmp.key = (char*)GRPC_STREAM_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM; - tmp.value.integer = algorithm; - return grpc_channel_args_copy_and_add(a, &tmp, 1); -} - /** Returns 1 if the argument for compression algorithm's enabled states bitset * was found in \a a, returning the arg's value in \a states. Otherwise, returns * 0. */ @@ -277,26 +252,6 @@ static int find_compression_algorithm_states_bitset(const grpc_channel_args* a, return 0; /* GPR_FALSE */ } -/** Returns 1 if the argument for compression algorithm's enabled states bitset - * was found in \a a, returning the arg's value in \a states. Otherwise, returns - * 0. */ -static int find_stream_compression_algorithm_states_bitset( - const grpc_channel_args* a, int** states_arg) { - if (a != nullptr) { - size_t i; - for (i = 0; i < a->num_args; ++i) { - if (a->args[i].type == GRPC_ARG_INTEGER && - !strcmp(GRPC_STREAM_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET, - a->args[i].key)) { - *states_arg = &a->args[i].value.integer; - **states_arg |= 0x1; /* forcefully enable support for no compression */ - return 1; - } - } - } - return 0; /* GPR_FALSE */ -} - grpc_channel_args* grpc_channel_args_compression_algorithm_set_state( grpc_channel_args** a, grpc_compression_algorithm algorithm, int state) { int* states_arg = nullptr; @@ -337,48 +292,6 @@ grpc_channel_args* grpc_channel_args_compression_algorithm_set_state( return result; } -grpc_channel_args* grpc_channel_args_stream_compression_algorithm_set_state( - grpc_channel_args** a, grpc_stream_compression_algorithm algorithm, - int state) { - int* states_arg = nullptr; - grpc_channel_args* result = *a; - const int states_arg_found = - find_stream_compression_algorithm_states_bitset(*a, &states_arg); - - if (grpc_channel_args_get_stream_compression_algorithm(*a) == algorithm && - state == 0) { - const char* algo_name = nullptr; - GPR_ASSERT(grpc_stream_compression_algorithm_name(algorithm, &algo_name) != - 0); - gpr_log(GPR_ERROR, - "Tried to disable default stream compression algorithm '%s'. The " - "operation has been ignored.", - algo_name); - } else if (states_arg_found) { - if (state != 0) { - GPR_BITSET((unsigned*)states_arg, algorithm); - } else if (algorithm != GRPC_STREAM_COMPRESS_NONE) { - GPR_BITCLEAR((unsigned*)states_arg, algorithm); - } - } else { - /* create a new arg */ - grpc_arg tmp; - tmp.type = GRPC_ARG_INTEGER; - tmp.key = (char*)GRPC_STREAM_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET; - /* all enabled by default */ - tmp.value.integer = (1u << GRPC_STREAM_COMPRESS_ALGORITHMS_COUNT) - 1; - if (state != 0) { - GPR_BITSET((unsigned*)&tmp.value.integer, algorithm); - } else if (algorithm != GRPC_STREAM_COMPRESS_NONE) { - GPR_BITCLEAR((unsigned*)&tmp.value.integer, algorithm); - } - result = grpc_channel_args_copy_and_add(*a, &tmp, 1); - grpc_channel_args_destroy(*a); - *a = result; - } - return result; -} - uint32_t grpc_channel_args_compression_algorithm_get_states( const grpc_channel_args* a) { int* states_arg; @@ -389,17 +302,6 @@ uint32_t grpc_channel_args_compression_algorithm_get_states( } } -uint32_t grpc_channel_args_stream_compression_algorithm_get_states( - const grpc_channel_args* a) { - int* states_arg; - if (find_stream_compression_algorithm_states_bitset(a, &states_arg)) { - return (uint32_t)*states_arg; - } else { - return (1u << GRPC_STREAM_COMPRESS_ALGORITHMS_COUNT) - - 1; /* All algs. enabled */ - } -} - grpc_channel_args* grpc_channel_args_set_socket_mutator( grpc_channel_args* a, grpc_socket_mutator* mutator) { grpc_arg tmp = grpc_socket_mutator_to_arg(mutator); diff --git a/src/core/lib/channel/channel_args.h b/src/core/lib/channel/channel_args.h index 9c7d06f34e..73e9122e75 100644 --- a/src/core/lib/channel/channel_args.h +++ b/src/core/lib/channel/channel_args.h @@ -59,24 +59,12 @@ void grpc_channel_args_destroy(grpc_channel_args* a); grpc_compression_algorithm grpc_channel_args_get_compression_algorithm( const grpc_channel_args* a); -/** Returns the stream compression algorithm set in \a a. */ -grpc_stream_compression_algorithm -grpc_channel_args_get_stream_compression_algorithm(const grpc_channel_args* a); - /** Returns a channel arg instance with compression enabled. If \a a is * non-NULL, its args are copied. N.B. GRPC_COMPRESS_NONE disables compression * for the channel. */ grpc_channel_args* grpc_channel_args_set_compression_algorithm( grpc_channel_args* a, grpc_compression_algorithm algorithm); -/** Returns a channel arg instance with stream compression enabled. If \a a is - * non-NULL, its args are copied. N.B. GRPC_STREAM_COMPRESS_NONE disables - * stream compression for the channel. If a value other than - * GRPC_STREAM_COMPRESS_NONE is set, it takes precedence over message-wise - * compression algorithms. */ -grpc_channel_args* grpc_channel_args_set_stream_compression_algorithm( - grpc_channel_args* a, grpc_stream_compression_algorithm algorithm); - /** Sets the support for the given compression algorithm. By default, all * compression algorithms are enabled. It's an error to disable an algorithm set * by grpc_channel_args_set_compression_algorithm. @@ -87,17 +75,6 @@ grpc_channel_args* grpc_channel_args_set_stream_compression_algorithm( grpc_channel_args* grpc_channel_args_compression_algorithm_set_state( grpc_channel_args** a, grpc_compression_algorithm algorithm, int enabled); -/** Sets the support for the given stream compression algorithm. By default, all - * stream compression algorithms are enabled. It's an error to disable an - * algorithm set by grpc_channel_args_set_stream_compression_algorithm. - * - * Returns an instance with the updated algorithm states. The \a a pointer is - * modified to point to the returned instance (which may be different from the - * input value of \a a). */ -grpc_channel_args* grpc_channel_args_stream_compression_algorithm_set_state( - grpc_channel_args** a, grpc_stream_compression_algorithm algorithm, - int enabled); - /** Returns the bitset representing the support state (true for enabled, false * for disabled) for compression algorithms. * @@ -106,14 +83,6 @@ grpc_channel_args* grpc_channel_args_stream_compression_algorithm_set_state( uint32_t grpc_channel_args_compression_algorithm_get_states( const grpc_channel_args* a); -/** Returns the bitset representing the support state (true for enabled, false - * for disabled) for stream compression algorithms. - * - * The i-th bit of the returned bitset corresponds to the i-th entry in the - * grpc_stream_compression_algorithm enum. */ -uint32_t grpc_channel_args_stream_compression_algorithm_get_states( - const grpc_channel_args* a); - int grpc_channel_args_compare(const grpc_channel_args* a, const grpc_channel_args* b); diff --git a/src/core/lib/compression/algorithm_metadata.h b/src/core/lib/compression/algorithm_metadata.h index 08feafc1bb..7db771ea74 100644 --- a/src/core/lib/compression/algorithm_metadata.h +++ b/src/core/lib/compression/algorithm_metadata.h @@ -20,20 +20,27 @@ #define GRPC_CORE_LIB_COMPRESSION_ALGORITHM_METADATA_H #include <grpc/compression.h> +#include "src/core/lib/compression/compression_internal.h" #include "src/core/lib/transport/metadata.h" /** Return compression algorithm based metadata value */ grpc_slice grpc_compression_algorithm_slice( grpc_compression_algorithm algorithm); -/** Return stream compression algorithm based metadata value */ -grpc_slice grpc_stream_compression_algorithm_slice( - grpc_stream_compression_algorithm algorithm); +/** Find compression algorithm based on passed in mdstr - returns + * GRPC_COMPRESS_ALGORITHM_COUNT on failure */ +grpc_compression_algorithm grpc_compression_algorithm_from_slice( + grpc_slice str); -/** Return compression algorithm based metadata element (grpc-encoding: xxx) */ +/** Return compression algorithm based metadata element */ grpc_mdelem grpc_compression_encoding_mdelem( grpc_compression_algorithm algorithm); +/** Return message compression algorithm based metadata element (grpc-encoding: + * xxx) */ +grpc_mdelem grpc_message_compression_encoding_mdelem( + grpc_message_compression_algorithm algorithm); + /** Return stream compression algorithm based metadata element * (content-encoding: xxx) */ grpc_mdelem grpc_stream_compression_encoding_mdelem( @@ -41,8 +48,8 @@ grpc_mdelem grpc_stream_compression_encoding_mdelem( /** Find compression algorithm based on passed in mdstr - returns * GRPC_COMPRESS_ALGORITHM_COUNT on failure */ -grpc_compression_algorithm grpc_compression_algorithm_from_slice( - grpc_slice str); +grpc_message_compression_algorithm +grpc_message_compression_algorithm_from_slice(grpc_slice str); /** Find stream compression algorithm based on passed in mdstr - returns * GRPC_STREAM_COMPRESS_ALGORITHM_COUNT on failure */ diff --git a/src/core/lib/compression/compression.cc b/src/core/lib/compression/compression.cc index a0d5bdcc78..99e6014b23 100644 --- a/src/core/lib/compression/compression.cc +++ b/src/core/lib/compression/compression.cc @@ -23,40 +23,40 @@ #include <grpc/support/useful.h> #include "src/core/lib/compression/algorithm_metadata.h" +#include "src/core/lib/compression/compression_internal.h" #include "src/core/lib/surface/api_trace.h" #include "src/core/lib/transport/static_metadata.h" +int grpc_compression_algorithm_is_message( + grpc_compression_algorithm algorithm) { + return (algorithm >= GRPC_COMPRESS_MESSAGE_DEFLATE && + algorithm <= GRPC_COMPRESS_MESSAGE_GZIP) + ? 1 + : 0; +} + +int grpc_compression_algorithm_is_stream(grpc_compression_algorithm algorithm) { + return (algorithm == GRPC_COMPRESS_STREAM_GZIP) ? 1 : 0; +} + int grpc_compression_algorithm_parse(grpc_slice name, grpc_compression_algorithm* algorithm) { - /* we use strncmp not only because it's safer (even though in this case it - * doesn't matter, given that we are comparing against string literals, but - * because this way we needn't have "name" nil-terminated (useful for slice - * data, for example) */ if (grpc_slice_eq(name, GRPC_MDSTR_IDENTITY)) { *algorithm = GRPC_COMPRESS_NONE; return 1; - } else if (grpc_slice_eq(name, GRPC_MDSTR_GZIP)) { - *algorithm = GRPC_COMPRESS_GZIP; - return 1; - } else if (grpc_slice_eq(name, GRPC_MDSTR_DEFLATE)) { - *algorithm = GRPC_COMPRESS_DEFLATE; + } else if (grpc_slice_eq(name, GRPC_MDSTR_MESSAGE_SLASH_DEFLATE)) { + *algorithm = GRPC_COMPRESS_MESSAGE_DEFLATE; return 1; - } else { - return 0; - } -} - -int grpc_stream_compression_algorithm_parse( - grpc_slice name, grpc_stream_compression_algorithm* algorithm) { - if (grpc_slice_eq(name, GRPC_MDSTR_IDENTITY)) { - *algorithm = GRPC_STREAM_COMPRESS_NONE; + } else if (grpc_slice_eq(name, GRPC_MDSTR_MESSAGE_SLASH_GZIP)) { + *algorithm = GRPC_COMPRESS_MESSAGE_GZIP; return 1; - } else if (grpc_slice_eq(name, GRPC_MDSTR_GZIP)) { - *algorithm = GRPC_STREAM_COMPRESS_GZIP; + } else if (grpc_slice_eq(name, GRPC_MDSTR_STREAM_SLASH_GZIP)) { + *algorithm = GRPC_COMPRESS_STREAM_GZIP; return 1; } else { return 0; } + return 0; } int grpc_compression_algorithm_name(grpc_compression_algorithm algorithm, @@ -67,113 +67,49 @@ int grpc_compression_algorithm_name(grpc_compression_algorithm algorithm, case GRPC_COMPRESS_NONE: *name = "identity"; return 1; - case GRPC_COMPRESS_DEFLATE: - *name = "deflate"; - return 1; - case GRPC_COMPRESS_GZIP: - *name = "gzip"; + case GRPC_COMPRESS_MESSAGE_DEFLATE: + *name = "message/deflate"; return 1; - case GRPC_COMPRESS_ALGORITHMS_COUNT: - return 0; - } - return 0; -} - -int grpc_stream_compression_algorithm_name( - grpc_stream_compression_algorithm algorithm, const char** name) { - GRPC_API_TRACE( - "grpc_stream_compression_algorithm_parse(algorithm=%d, name=%p)", 2, - ((int)algorithm, name)); - switch (algorithm) { - case GRPC_STREAM_COMPRESS_NONE: - *name = "identity"; + case GRPC_COMPRESS_MESSAGE_GZIP: + *name = "message/gzip"; return 1; - case GRPC_STREAM_COMPRESS_GZIP: - *name = "gzip"; + case GRPC_COMPRESS_STREAM_GZIP: + *name = "stream/gzip"; return 1; - case GRPC_STREAM_COMPRESS_ALGORITHMS_COUNT: + case GRPC_COMPRESS_ALGORITHMS_COUNT: return 0; } return 0; } -grpc_compression_algorithm grpc_compression_algorithm_from_slice( - grpc_slice str) { - if (grpc_slice_eq(str, GRPC_MDSTR_IDENTITY)) return GRPC_COMPRESS_NONE; - if (grpc_slice_eq(str, GRPC_MDSTR_DEFLATE)) return GRPC_COMPRESS_DEFLATE; - if (grpc_slice_eq(str, GRPC_MDSTR_GZIP)) return GRPC_COMPRESS_GZIP; - return GRPC_COMPRESS_ALGORITHMS_COUNT; -} - -grpc_stream_compression_algorithm grpc_stream_compression_algorithm_from_slice( - grpc_slice str) { - if (grpc_slice_eq(str, GRPC_MDSTR_IDENTITY)) return GRPC_STREAM_COMPRESS_NONE; - if (grpc_slice_eq(str, GRPC_MDSTR_GZIP)) return GRPC_STREAM_COMPRESS_GZIP; - return GRPC_STREAM_COMPRESS_ALGORITHMS_COUNT; -} - -grpc_slice grpc_compression_algorithm_slice( - grpc_compression_algorithm algorithm) { - switch (algorithm) { - case GRPC_COMPRESS_NONE: - return GRPC_MDSTR_IDENTITY; - case GRPC_COMPRESS_DEFLATE: - return GRPC_MDSTR_DEFLATE; - case GRPC_COMPRESS_GZIP: - return GRPC_MDSTR_GZIP; - case GRPC_COMPRESS_ALGORITHMS_COUNT: - return grpc_empty_slice(); - } - return grpc_empty_slice(); -} - -grpc_slice grpc_stream_compression_algorithm_slice( - grpc_stream_compression_algorithm algorithm) { - switch (algorithm) { - case GRPC_STREAM_COMPRESS_NONE: - return GRPC_MDSTR_IDENTITY; - case GRPC_STREAM_COMPRESS_GZIP: - return GRPC_MDSTR_GZIP; - case GRPC_STREAM_COMPRESS_ALGORITHMS_COUNT: - return grpc_empty_slice(); - } - return grpc_empty_slice(); -} - -grpc_mdelem grpc_compression_encoding_mdelem( - grpc_compression_algorithm algorithm) { - switch (algorithm) { - case GRPC_COMPRESS_NONE: - return GRPC_MDELEM_GRPC_ENCODING_IDENTITY; - case GRPC_COMPRESS_DEFLATE: - return GRPC_MDELEM_GRPC_ENCODING_DEFLATE; - case GRPC_COMPRESS_GZIP: - return GRPC_MDELEM_GRPC_ENCODING_GZIP; - default: - break; - } - return GRPC_MDNULL; -} - -grpc_mdelem grpc_stream_compression_encoding_mdelem( - grpc_stream_compression_algorithm algorithm) { - switch (algorithm) { - case GRPC_STREAM_COMPRESS_NONE: - return GRPC_MDELEM_CONTENT_ENCODING_IDENTITY; - case GRPC_STREAM_COMPRESS_GZIP: - return GRPC_MDELEM_CONTENT_ENCODING_GZIP; - default: - break; +grpc_compression_algorithm grpc_compression_algorithm_for_level( + grpc_compression_level level, uint32_t accepted_encodings) { + grpc_compression_algorithm algo; + if (level == GRPC_COMPRESS_LEVEL_NONE) { + return GRPC_COMPRESS_NONE; + } else if (level <= GRPC_COMPRESS_LEVEL_HIGH) { + // TODO(mxyan): Design algorithm to select from all algorithms, including + // stream compression algorithm + if (!grpc_compression_algorithm_from_message_stream_compression_algorithm( + &algo, + grpc_message_compression_algorithm_for_level( + level, + grpc_compression_bitset_to_message_bitset(accepted_encodings)), + static_cast<grpc_stream_compression_algorithm>(0))) { + gpr_log(GPR_ERROR, "Parse compression level error"); + return GRPC_COMPRESS_NONE; + } + return algo; + } else { + gpr_log(GPR_ERROR, "Unknown compression level: %d", level); + return GRPC_COMPRESS_NONE; } - return GRPC_MDNULL; } void grpc_compression_options_init(grpc_compression_options* opts) { memset(opts, 0, sizeof(*opts)); /* all enabled by default */ opts->enabled_algorithms_bitset = (1u << GRPC_COMPRESS_ALGORITHMS_COUNT) - 1; - opts->enabled_stream_compression_algorithms_bitset = - (1u << GRPC_STREAM_COMPRESS_ALGORITHMS_COUNT) - 1; } void grpc_compression_options_enable_algorithm( @@ -192,92 +128,48 @@ int grpc_compression_options_is_algorithm_enabled( return GPR_BITGET(opts->enabled_algorithms_bitset, algorithm); } -int grpc_compression_options_is_stream_compression_algorithm_enabled( - const grpc_compression_options* opts, - grpc_stream_compression_algorithm algorithm) { - return GPR_BITGET(opts->enabled_stream_compression_algorithms_bitset, - algorithm); -} - -/* TODO(dgq): Add the ability to specify parameters to the individual - * compression algorithms */ -grpc_compression_algorithm grpc_compression_algorithm_for_level( - grpc_compression_level level, uint32_t accepted_encodings) { - GRPC_API_TRACE("grpc_compression_algorithm_for_level(level=%d)", 1, - ((int)level)); - if (level > GRPC_COMPRESS_LEVEL_HIGH) { - gpr_log(GPR_ERROR, "Unknown compression level %d.", (int)level); - abort(); - } - - const size_t num_supported = - GPR_BITCOUNT(accepted_encodings) - 1; /* discard NONE */ - if (level == GRPC_COMPRESS_LEVEL_NONE || num_supported == 0) { - return GRPC_COMPRESS_NONE; - } - - GPR_ASSERT(level > 0); - - /* Establish a "ranking" or compression algorithms in increasing order of - * compression. - * This is simplistic and we will probably want to introduce other dimensions - * in the future (cpu/memory cost, etc). */ - const grpc_compression_algorithm algos_ranking[] = {GRPC_COMPRESS_GZIP, - GRPC_COMPRESS_DEFLATE}; - - /* intersect algos_ranking with the supported ones keeping the ranked order */ - grpc_compression_algorithm - sorted_supported_algos[GRPC_COMPRESS_ALGORITHMS_COUNT]; - size_t algos_supported_idx = 0; - for (size_t i = 0; i < GPR_ARRAY_SIZE(algos_ranking); i++) { - const grpc_compression_algorithm alg = algos_ranking[i]; - for (size_t j = 0; j < num_supported; j++) { - if (GPR_BITGET(accepted_encodings, alg) == 1) { - /* if \a alg in supported */ - sorted_supported_algos[algos_supported_idx++] = alg; - break; - } - } - if (algos_supported_idx == num_supported) break; +grpc_slice grpc_compression_algorithm_slice( + grpc_compression_algorithm algorithm) { + switch (algorithm) { + case GRPC_COMPRESS_NONE: + return GRPC_MDSTR_IDENTITY; + case GRPC_COMPRESS_MESSAGE_DEFLATE: + return GRPC_MDSTR_MESSAGE_SLASH_DEFLATE; + case GRPC_COMPRESS_MESSAGE_GZIP: + return GRPC_MDSTR_MESSAGE_SLASH_GZIP; + case GRPC_COMPRESS_STREAM_GZIP: + return GRPC_MDSTR_STREAM_SLASH_GZIP; + case GRPC_COMPRESS_ALGORITHMS_COUNT: + return grpc_empty_slice(); } - - switch (level) { - case GRPC_COMPRESS_LEVEL_NONE: - abort(); /* should have been handled already */ - case GRPC_COMPRESS_LEVEL_LOW: - return sorted_supported_algos[0]; - case GRPC_COMPRESS_LEVEL_MED: - return sorted_supported_algos[num_supported / 2]; - case GRPC_COMPRESS_LEVEL_HIGH: - return sorted_supported_algos[num_supported - 1]; - default: - abort(); - }; + return grpc_empty_slice(); } -GRPCAPI grpc_stream_compression_algorithm -grpc_stream_compression_algorithm_for_level( - grpc_stream_compression_level level, uint32_t accepted_stream_encodings) { - GRPC_API_TRACE("grpc_stream_compression_algorithm_for_level(level=%d)", 1, - ((int)level)); - if (level > GRPC_STREAM_COMPRESS_LEVEL_HIGH) { - gpr_log(GPR_ERROR, "Unknown compression level %d.", (int)level); - abort(); - } +grpc_compression_algorithm grpc_compression_algorithm_from_slice( + grpc_slice str) { + if (grpc_slice_eq(str, GRPC_MDSTR_IDENTITY)) return GRPC_COMPRESS_NONE; + if (grpc_slice_eq(str, GRPC_MDSTR_MESSAGE_SLASH_DEFLATE)) + return GRPC_COMPRESS_MESSAGE_DEFLATE; + if (grpc_slice_eq(str, GRPC_MDSTR_MESSAGE_SLASH_GZIP)) + return GRPC_COMPRESS_MESSAGE_GZIP; + if (grpc_slice_eq(str, GRPC_MDSTR_STREAM_SLASH_GZIP)) + return GRPC_COMPRESS_STREAM_GZIP; + return GRPC_COMPRESS_ALGORITHMS_COUNT; +} - switch (level) { - case GRPC_STREAM_COMPRESS_LEVEL_NONE: - return GRPC_STREAM_COMPRESS_NONE; - case GRPC_STREAM_COMPRESS_LEVEL_LOW: - case GRPC_STREAM_COMPRESS_LEVEL_MED: - case GRPC_STREAM_COMPRESS_LEVEL_HIGH: - if (GPR_BITGET(accepted_stream_encodings, GRPC_STREAM_COMPRESS_GZIP) == - 1) { - return GRPC_STREAM_COMPRESS_GZIP; - } else { - return GRPC_STREAM_COMPRESS_NONE; - } +grpc_mdelem grpc_compression_encoding_mdelem( + grpc_compression_algorithm algorithm) { + switch (algorithm) { + case GRPC_COMPRESS_NONE: + return GRPC_MDELEM_GRPC_ENCODING_IDENTITY; + case GRPC_COMPRESS_MESSAGE_DEFLATE: + return GRPC_MDELEM_GRPC_ENCODING_DEFLATE; + case GRPC_COMPRESS_MESSAGE_GZIP: + return GRPC_MDELEM_GRPC_ENCODING_GZIP; + case GRPC_COMPRESS_STREAM_GZIP: + return GRPC_MDELEM_GRPC_ENCODING_GZIP; default: - abort(); + break; } + return GRPC_MDNULL; } diff --git a/src/core/lib/compression/compression_internal.cc b/src/core/lib/compression/compression_internal.cc new file mode 100644 index 0000000000..263cdf06eb --- /dev/null +++ b/src/core/lib/compression/compression_internal.cc @@ -0,0 +1,273 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include <stdlib.h> +#include <string.h> + +#include <grpc/compression.h> +#include <grpc/support/useful.h> + +#include "src/core/lib/compression/algorithm_metadata.h" +#include "src/core/lib/compression/compression_internal.h" +#include "src/core/lib/surface/api_trace.h" +#include "src/core/lib/transport/static_metadata.h" + +/* Interfaces related to MD */ + +grpc_message_compression_algorithm +grpc_message_compression_algorithm_from_slice(grpc_slice str) { + if (grpc_slice_eq(str, GRPC_MDSTR_IDENTITY)) + return GRPC_MESSAGE_COMPRESS_NONE; + if (grpc_slice_eq(str, GRPC_MDSTR_DEFLATE)) + return GRPC_MESSAGE_COMPRESS_DEFLATE; + if (grpc_slice_eq(str, GRPC_MDSTR_GZIP)) return GRPC_MESSAGE_COMPRESS_GZIP; + return GRPC_MESSAGE_COMPRESS_ALGORITHMS_COUNT; +} + +grpc_stream_compression_algorithm grpc_stream_compression_algorithm_from_slice( + grpc_slice str) { + if (grpc_slice_eq(str, GRPC_MDSTR_IDENTITY)) return GRPC_STREAM_COMPRESS_NONE; + if (grpc_slice_eq(str, GRPC_MDSTR_GZIP)) return GRPC_STREAM_COMPRESS_GZIP; + return GRPC_STREAM_COMPRESS_ALGORITHMS_COUNT; +} + +grpc_mdelem grpc_message_compression_encoding_mdelem( + grpc_message_compression_algorithm algorithm) { + switch (algorithm) { + case GRPC_MESSAGE_COMPRESS_NONE: + return GRPC_MDELEM_GRPC_ENCODING_IDENTITY; + case GRPC_MESSAGE_COMPRESS_DEFLATE: + return GRPC_MDELEM_GRPC_ENCODING_DEFLATE; + case GRPC_MESSAGE_COMPRESS_GZIP: + return GRPC_MDELEM_GRPC_ENCODING_GZIP; + default: + break; + } + return GRPC_MDNULL; +} + +grpc_mdelem grpc_stream_compression_encoding_mdelem( + grpc_stream_compression_algorithm algorithm) { + switch (algorithm) { + case GRPC_STREAM_COMPRESS_NONE: + return GRPC_MDELEM_CONTENT_ENCODING_IDENTITY; + case GRPC_STREAM_COMPRESS_GZIP: + return GRPC_MDELEM_CONTENT_ENCODING_GZIP; + default: + break; + } + return GRPC_MDNULL; +} + +/* Interfaces performing transformation between compression algorithms and + * levels. */ +grpc_message_compression_algorithm +grpc_compression_algorithm_to_message_compression_algorithm( + grpc_compression_algorithm algo) { + switch (algo) { + case GRPC_COMPRESS_MESSAGE_DEFLATE: + return GRPC_MESSAGE_COMPRESS_DEFLATE; + case GRPC_COMPRESS_MESSAGE_GZIP: + return GRPC_MESSAGE_COMPRESS_GZIP; + default: + return GRPC_MESSAGE_COMPRESS_NONE; + } +} + +grpc_stream_compression_algorithm +grpc_compression_algorithm_to_stream_compression_algorithm( + grpc_compression_algorithm algo) { + switch (algo) { + case GRPC_COMPRESS_STREAM_GZIP: + return GRPC_STREAM_COMPRESS_GZIP; + default: + return GRPC_STREAM_COMPRESS_NONE; + } +} + +uint32_t grpc_compression_bitset_to_message_bitset(uint32_t bitset) { + return bitset & ((1u << GRPC_MESSAGE_COMPRESS_ALGORITHMS_COUNT) - 1); +} + +uint32_t grpc_compression_bitset_to_stream_bitset(uint32_t bitset) { + uint32_t identity = (bitset & 1u); + uint32_t other_bits = + (bitset >> (GRPC_MESSAGE_COMPRESS_ALGORITHMS_COUNT - 1)) & + ((1u << GRPC_STREAM_COMPRESS_ALGORITHMS_COUNT) - 2); + return identity | other_bits; +} + +uint32_t grpc_compression_bitset_from_message_stream_compression_bitset( + uint32_t message_bitset, uint32_t stream_bitset) { + uint32_t offset_stream_bitset = + (stream_bitset & 1u) | + ((stream_bitset & (~1u)) << (GRPC_MESSAGE_COMPRESS_ALGORITHMS_COUNT - 1)); + return message_bitset | offset_stream_bitset; +} + +int grpc_compression_algorithm_from_message_stream_compression_algorithm( + grpc_compression_algorithm* algorithm, + grpc_message_compression_algorithm message_algorithm, + grpc_stream_compression_algorithm stream_algorithm) { + if (message_algorithm != GRPC_MESSAGE_COMPRESS_NONE && + stream_algorithm != GRPC_STREAM_COMPRESS_NONE) { + *algorithm = GRPC_COMPRESS_NONE; + return 0; + } + if (message_algorithm == GRPC_MESSAGE_COMPRESS_NONE) { + switch (stream_algorithm) { + case GRPC_STREAM_COMPRESS_NONE: + *algorithm = GRPC_COMPRESS_NONE; + return 1; + case GRPC_STREAM_COMPRESS_GZIP: + *algorithm = GRPC_COMPRESS_STREAM_GZIP; + return 1; + default: + *algorithm = GRPC_COMPRESS_NONE; + return 0; + } + } else { + switch (message_algorithm) { + case GRPC_MESSAGE_COMPRESS_NONE: + *algorithm = GRPC_COMPRESS_NONE; + return 1; + case GRPC_MESSAGE_COMPRESS_DEFLATE: + *algorithm = GRPC_COMPRESS_MESSAGE_DEFLATE; + return 1; + case GRPC_MESSAGE_COMPRESS_GZIP: + *algorithm = GRPC_COMPRESS_MESSAGE_GZIP; + return 1; + default: + *algorithm = GRPC_COMPRESS_NONE; + return 0; + } + } + return 0; +} + +/* Interfaces for message compression. */ + +int grpc_message_compression_algorithm_name( + grpc_message_compression_algorithm algorithm, const char** name) { + GRPC_API_TRACE( + "grpc_message_compression_algorithm_parse(algorithm=%d, name=%p)", 2, + ((int)algorithm, name)); + switch (algorithm) { + case GRPC_MESSAGE_COMPRESS_NONE: + *name = "identity"; + return 1; + case GRPC_MESSAGE_COMPRESS_DEFLATE: + *name = "deflate"; + return 1; + case GRPC_MESSAGE_COMPRESS_GZIP: + *name = "gzip"; + return 1; + case GRPC_MESSAGE_COMPRESS_ALGORITHMS_COUNT: + return 0; + } + return 0; +} + +/* TODO(dgq): Add the ability to specify parameters to the individual + * compression algorithms */ +grpc_message_compression_algorithm grpc_message_compression_algorithm_for_level( + grpc_compression_level level, uint32_t accepted_encodings) { + GRPC_API_TRACE("grpc_message_compression_algorithm_for_level(level=%d)", 1, + ((int)level)); + if (level > GRPC_COMPRESS_LEVEL_HIGH) { + gpr_log(GPR_ERROR, "Unknown message compression level %d.", (int)level); + abort(); + } + + const size_t num_supported = + GPR_BITCOUNT(accepted_encodings) - 1; /* discard NONE */ + if (level == GRPC_COMPRESS_LEVEL_NONE || num_supported == 0) { + return GRPC_MESSAGE_COMPRESS_NONE; + } + + GPR_ASSERT(level > 0); + + /* Establish a "ranking" or compression algorithms in increasing order of + * compression. + * This is simplistic and we will probably want to introduce other dimensions + * in the future (cpu/memory cost, etc). */ + const grpc_message_compression_algorithm algos_ranking[] = { + GRPC_MESSAGE_COMPRESS_GZIP, GRPC_MESSAGE_COMPRESS_DEFLATE}; + + /* intersect algos_ranking with the supported ones keeping the ranked order */ + grpc_message_compression_algorithm + sorted_supported_algos[GRPC_MESSAGE_COMPRESS_ALGORITHMS_COUNT]; + size_t algos_supported_idx = 0; + for (size_t i = 0; i < GPR_ARRAY_SIZE(algos_ranking); i++) { + const grpc_message_compression_algorithm alg = algos_ranking[i]; + for (size_t j = 0; j < num_supported; j++) { + if (GPR_BITGET(accepted_encodings, alg) == 1) { + /* if \a alg in supported */ + sorted_supported_algos[algos_supported_idx++] = alg; + break; + } + } + if (algos_supported_idx == num_supported) break; + } + + switch (level) { + case GRPC_COMPRESS_LEVEL_NONE: + abort(); /* should have been handled already */ + case GRPC_COMPRESS_LEVEL_LOW: + return sorted_supported_algos[0]; + case GRPC_COMPRESS_LEVEL_MED: + return sorted_supported_algos[num_supported / 2]; + case GRPC_COMPRESS_LEVEL_HIGH: + return sorted_supported_algos[num_supported - 1]; + default: + abort(); + }; +} + +int grpc_message_compression_algorithm_parse( + grpc_slice value, grpc_message_compression_algorithm* algorithm) { + if (grpc_slice_eq(value, GRPC_MDSTR_IDENTITY)) { + *algorithm = GRPC_MESSAGE_COMPRESS_NONE; + return 1; + } else if (grpc_slice_eq(value, GRPC_MDSTR_DEFLATE)) { + *algorithm = GRPC_MESSAGE_COMPRESS_DEFLATE; + return 1; + } else if (grpc_slice_eq(value, GRPC_MDSTR_GZIP)) { + *algorithm = GRPC_MESSAGE_COMPRESS_GZIP; + return 1; + } else { + return 0; + } + return 0; +} + +/* Interfaces for stream compression. */ + +int grpc_stream_compression_algorithm_parse( + grpc_slice value, grpc_stream_compression_algorithm* algorithm) { + if (grpc_slice_eq(value, GRPC_MDSTR_IDENTITY)) { + *algorithm = GRPC_STREAM_COMPRESS_NONE; + return 1; + } else if (grpc_slice_eq(value, GRPC_MDSTR_GZIP)) { + *algorithm = GRPC_STREAM_COMPRESS_GZIP; + return 1; + } else { + return 0; + } + return 0; +} diff --git a/src/core/lib/compression/compression_internal.h b/src/core/lib/compression/compression_internal.h new file mode 100644 index 0000000000..72f01dd1b7 --- /dev/null +++ b/src/core/lib/compression/compression_internal.h @@ -0,0 +1,86 @@ +/* + * + * Copyright 2017 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_LIB_COMPRESSION_COMPRESSION_INTERNAL_H +#define GRPC_CORE_LIB_COMPRESSION_COMPRESSION_INTERNAL_H + +#include <grpc/impl/codegen/compression_types.h> + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + GRPC_MESSAGE_COMPRESS_NONE = 0, + GRPC_MESSAGE_COMPRESS_DEFLATE, + GRPC_MESSAGE_COMPRESS_GZIP, + /* TODO(ctiller): snappy */ + GRPC_MESSAGE_COMPRESS_ALGORITHMS_COUNT +} grpc_message_compression_algorithm; + +/** Stream compresssion algorithms supported by gRPC */ +typedef enum { + GRPC_STREAM_COMPRESS_NONE = 0, + GRPC_STREAM_COMPRESS_GZIP, + GRPC_STREAM_COMPRESS_ALGORITHMS_COUNT +} grpc_stream_compression_algorithm; + +/* Interfaces performing transformation between compression algorithms and + * levels. */ + +grpc_message_compression_algorithm +grpc_compression_algorithm_to_message_compression_algorithm( + grpc_compression_algorithm algo); + +grpc_stream_compression_algorithm +grpc_compression_algorithm_to_stream_compression_algorithm( + grpc_compression_algorithm algo); + +uint32_t grpc_compression_bitset_to_message_bitset(uint32_t bitset); + +uint32_t grpc_compression_bitset_to_stream_bitset(uint32_t bitset); + +uint32_t grpc_compression_bitset_from_message_stream_compression_bitset( + uint32_t message_bitset, uint32_t stream_bitset); + +int grpc_compression_algorithm_from_message_stream_compression_algorithm( + grpc_compression_algorithm* algorithm, + grpc_message_compression_algorithm message_algorithm, + grpc_stream_compression_algorithm stream_algorithm); + +/* Interfaces for message compression. */ + +int grpc_message_compression_algorithm_name( + grpc_message_compression_algorithm algorithm, const char** name); + +grpc_message_compression_algorithm grpc_message_compression_algorithm_for_level( + grpc_compression_level level, uint32_t accepted_encodings); + +int grpc_message_compression_algorithm_parse( + grpc_slice value, grpc_message_compression_algorithm* algorithm); + +/* Interfaces for stream compression. */ + +int grpc_stream_compression_algorithm_parse( + grpc_slice value, grpc_stream_compression_algorithm* algorithm); + +#ifdef __cplusplus +} +#endif + +#endif /* GRPC_CORE_LIB_COMPRESSION_COMPRESSION_INTERNAL_H */ diff --git a/src/core/lib/compression/compression_ruby.cc b/src/core/lib/compression/compression_ruby.cc new file mode 100644 index 0000000000..293062f5ed --- /dev/null +++ b/src/core/lib/compression/compression_ruby.cc @@ -0,0 +1,66 @@ +/* + * + * Copyright 2017 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include <grpc/compression_ruby.h> +#include <grpc/support/useful.h> + +#include "src/core/lib/surface/api_trace.h" +#include "src/core/lib/transport/static_metadata.h" + +int grpc_compression_algorithm_parse_ruby( + grpc_slice name, grpc_compression_algorithm* algorithm) { + if (grpc_slice_eq(name, GRPC_MDSTR_IDENTITY)) { + *algorithm = GRPC_COMPRESS_NONE; + return 1; + } else if (grpc_slice_eq(name, GRPC_MDSTR_DEFLATE)) { + *algorithm = GRPC_COMPRESS_MESSAGE_DEFLATE; + return 1; + } else if (grpc_slice_eq(name, GRPC_MDSTR_GZIP)) { + *algorithm = GRPC_COMPRESS_MESSAGE_GZIP; + return 1; + } else if (grpc_slice_eq(name, GRPC_MDSTR_STREAM_SLASH_GZIP)) { + *algorithm = GRPC_COMPRESS_STREAM_GZIP; + return 1; + } else { + return 0; + } + return 0; +} + +int grpc_compression_algorithm_name_ruby(grpc_compression_algorithm algorithm, + const char** name) { + GRPC_API_TRACE("grpc_compression_algorithm_parse(algorithm=%d, name=%p)", 2, + ((int)algorithm, name)); + switch (algorithm) { + case GRPC_COMPRESS_NONE: + *name = "identity"; + return 1; + case GRPC_COMPRESS_MESSAGE_DEFLATE: + *name = "deflate"; + return 1; + case GRPC_COMPRESS_MESSAGE_GZIP: + *name = "gzip"; + return 1; + case GRPC_COMPRESS_STREAM_GZIP: + *name = "stream/gzip"; + return 1; + case GRPC_COMPRESS_ALGORITHMS_COUNT: + return 0; + } + return 0; +} diff --git a/src/core/lib/compression/message_compress.cc b/src/core/lib/compression/message_compress.cc index aa43a53f2b..1e9b0f10ee 100644 --- a/src/core/lib/compression/message_compress.cc +++ b/src/core/lib/compression/message_compress.cc @@ -141,25 +141,25 @@ static int copy(grpc_slice_buffer* input, grpc_slice_buffer* output) { return 1; } -static int compress_inner(grpc_compression_algorithm algorithm, +static int compress_inner(grpc_message_compression_algorithm algorithm, grpc_slice_buffer* input, grpc_slice_buffer* output) { switch (algorithm) { - case GRPC_COMPRESS_NONE: + case GRPC_MESSAGE_COMPRESS_NONE: /* the fallback path always needs to be send uncompressed: we simply rely on that here */ return 0; - case GRPC_COMPRESS_DEFLATE: + case GRPC_MESSAGE_COMPRESS_DEFLATE: return zlib_compress(input, output, 0); - case GRPC_COMPRESS_GZIP: + case GRPC_MESSAGE_COMPRESS_GZIP: return zlib_compress(input, output, 1); - case GRPC_COMPRESS_ALGORITHMS_COUNT: + case GRPC_MESSAGE_COMPRESS_ALGORITHMS_COUNT: break; } gpr_log(GPR_ERROR, "invalid compression algorithm %d", algorithm); return 0; } -int grpc_msg_compress(grpc_compression_algorithm algorithm, +int grpc_msg_compress(grpc_message_compression_algorithm algorithm, grpc_slice_buffer* input, grpc_slice_buffer* output) { if (!compress_inner(algorithm, input, output)) { copy(input, output); @@ -168,16 +168,16 @@ int grpc_msg_compress(grpc_compression_algorithm algorithm, return 1; } -int grpc_msg_decompress(grpc_compression_algorithm algorithm, +int grpc_msg_decompress(grpc_message_compression_algorithm algorithm, grpc_slice_buffer* input, grpc_slice_buffer* output) { switch (algorithm) { - case GRPC_COMPRESS_NONE: + case GRPC_MESSAGE_COMPRESS_NONE: return copy(input, output); - case GRPC_COMPRESS_DEFLATE: + case GRPC_MESSAGE_COMPRESS_DEFLATE: return zlib_decompress(input, output, 0); - case GRPC_COMPRESS_GZIP: + case GRPC_MESSAGE_COMPRESS_GZIP: return zlib_decompress(input, output, 1); - case GRPC_COMPRESS_ALGORITHMS_COUNT: + case GRPC_MESSAGE_COMPRESS_ALGORITHMS_COUNT: break; } gpr_log(GPR_ERROR, "invalid compression algorithm %d", algorithm); diff --git a/src/core/lib/compression/message_compress.h b/src/core/lib/compression/message_compress.h index c963fccc73..ed9e5bfa39 100644 --- a/src/core/lib/compression/message_compress.h +++ b/src/core/lib/compression/message_compress.h @@ -19,19 +19,20 @@ #ifndef GRPC_CORE_LIB_COMPRESSION_MESSAGE_COMPRESS_H #define GRPC_CORE_LIB_COMPRESSION_MESSAGE_COMPRESS_H -#include <grpc/compression.h> #include <grpc/slice_buffer.h> +#include "src/core/lib/compression/compression_internal.h" + /* compress 'input' to 'output' using 'algorithm'. On success, appends compressed slices to output and returns 1. On failure, appends uncompressed slices to output and returns 0. */ -int grpc_msg_compress(grpc_compression_algorithm algorithm, +int grpc_msg_compress(grpc_message_compression_algorithm algorithm, grpc_slice_buffer* input, grpc_slice_buffer* output); /* decompress 'input' to 'output' using 'algorithm'. On success, appends slices to output and returns 1. On failure, output is unchanged, and returns 0. */ -int grpc_msg_decompress(grpc_compression_algorithm algorithm, +int grpc_msg_decompress(grpc_message_compression_algorithm algorithm, grpc_slice_buffer* input, grpc_slice_buffer* output); #endif /* GRPC_CORE_LIB_COMPRESSION_MESSAGE_COMPRESS_H */ diff --git a/src/core/lib/gprpp/inlined_vector.h b/src/core/lib/gprpp/inlined_vector.h index b78f85b893..2ced3d74b8 100644 --- a/src/core/lib/gprpp/inlined_vector.h +++ b/src/core/lib/gprpp/inlined_vector.h @@ -40,24 +40,13 @@ namespace grpc_core { // ANY METHOD ADDED HERE MUST COMPLY WITH THE INTERFACE IN THE absl // IMPLEMENTATION! // -// TODO(ctiller, nnoble, roth): Replace this with absl::InlinedVector -// once we integrate absl into the gRPC build system in a usable way. +// TODO(nnoble, roth): Replace this with absl::InlinedVector once we +// integrate absl into the gRPC build system in a usable way. template <typename T, size_t N> class InlinedVector { public: - InlinedVector() {} - ~InlinedVector() { - for (size_t i = 0; i < size_ && i < N; ++i) { - T& value = *reinterpret_cast<T*>(inline_ + i); - value.~T(); - } - if (size_ > N) { // Avoid subtracting two signed values. - for (size_t i = 0; i < size_ - N; ++i) { - dynamic_[i].~T(); - } - } - gpr_free(dynamic_); - } + InlinedVector() { init_data(); } + ~InlinedVector() { destroy_elements(); } // For now, we do not support copying. InlinedVector(const InlinedVector&) = delete; @@ -72,6 +61,15 @@ class InlinedVector { } } + const T& operator[](size_t offset) const { + assert(offset < size_); + if (offset < N) { + return *reinterpret_cast<const T*>(inline_ + offset); + } else { + return dynamic_[offset - N]; + } + } + template <typename... Args> void emplace_back(Args&&... args) { if (size_ < N) { @@ -100,11 +98,35 @@ class InlinedVector { size_t size() const { return size_; } + void clear() { + destroy_elements(); + init_data(); + } + private: + void init_data() { + dynamic_ = nullptr; + size_ = 0; + dynamic_capacity_ = 0; + } + + void destroy_elements() { + for (size_t i = 0; i < size_ && i < N; ++i) { + T& value = *reinterpret_cast<T*>(inline_ + i); + value.~T(); + } + if (size_ > N) { // Avoid subtracting two signed values. + for (size_t i = 0; i < size_ - N; ++i) { + dynamic_[i].~T(); + } + } + gpr_free(dynamic_); + } + typename std::aligned_storage<sizeof(T)>::type inline_[N]; - T* dynamic_ = nullptr; - size_t size_ = 0; - size_t dynamic_capacity_ = 0; + T* dynamic_; + size_t size_; + size_t dynamic_capacity_; }; } // namespace grpc_core diff --git a/src/core/lib/iomgr/ev_epoll1_linux.cc b/src/core/lib/iomgr/ev_epoll1_linux.cc index 42d7cdd348..ad274b839c 100644 --- a/src/core/lib/iomgr/ev_epoll1_linux.cc +++ b/src/core/lib/iomgr/ev_epoll1_linux.cc @@ -680,7 +680,7 @@ static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, pollset->begin_refs++; if (grpc_polling_trace.enabled()) { - gpr_log(GPR_ERROR, "PS:%p BEGIN_STARTS:%p", pollset, worker); + gpr_log(GPR_DEBUG, "PS:%p BEGIN_STARTS:%p", pollset, worker); } if (pollset->seen_inactive) { @@ -699,7 +699,7 @@ static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, gpr_mu_lock(&neighborhood->mu); gpr_mu_lock(&pollset->mu); if (grpc_polling_trace.enabled()) { - gpr_log(GPR_ERROR, "PS:%p BEGIN_REORG:%p kick_state=%s is_reassigning=%d", + gpr_log(GPR_DEBUG, "PS:%p BEGIN_REORG:%p kick_state=%s is_reassigning=%d", pollset, worker, kick_state_string(worker->state), is_reassigning); } @@ -751,7 +751,7 @@ static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, gpr_cv_init(&worker->cv); while (worker->state == UNKICKED && !pollset->shutting_down) { if (grpc_polling_trace.enabled()) { - gpr_log(GPR_ERROR, "PS:%p BEGIN_WAIT:%p kick_state=%s shutdown=%d", + gpr_log(GPR_DEBUG, "PS:%p BEGIN_WAIT:%p kick_state=%s shutdown=%d", pollset, worker, kick_state_string(worker->state), pollset->shutting_down); } @@ -768,7 +768,7 @@ static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, } if (grpc_polling_trace.enabled()) { - gpr_log(GPR_ERROR, + gpr_log(GPR_DEBUG, "PS:%p BEGIN_DONE:%p kick_state=%s shutdown=%d " "kicked_without_poller: %d", pollset, worker, kick_state_string(worker->state), @@ -1019,7 +1019,7 @@ static grpc_error* pollset_kick(grpc_pollset* pollset, } tmp = gpr_strvec_flatten(&log, nullptr); gpr_strvec_destroy(&log); - gpr_log(GPR_ERROR, "%s", tmp); + gpr_log(GPR_DEBUG, "%s", tmp); gpr_free(tmp); } @@ -1030,7 +1030,7 @@ static grpc_error* pollset_kick(grpc_pollset* pollset, GRPC_STATS_INC_POLLSET_KICKED_WITHOUT_POLLER(); pollset->kicked_without_poller = true; if (grpc_polling_trace.enabled()) { - gpr_log(GPR_ERROR, " .. kicked_without_poller"); + gpr_log(GPR_DEBUG, " .. kicked_without_poller"); } goto done; } @@ -1038,14 +1038,14 @@ static grpc_error* pollset_kick(grpc_pollset* pollset, if (root_worker->state == KICKED) { GRPC_STATS_INC_POLLSET_KICKED_AGAIN(); if (grpc_polling_trace.enabled()) { - gpr_log(GPR_ERROR, " .. already kicked %p", root_worker); + gpr_log(GPR_DEBUG, " .. already kicked %p", root_worker); } SET_KICK_STATE(root_worker, KICKED); goto done; } else if (next_worker->state == KICKED) { GRPC_STATS_INC_POLLSET_KICKED_AGAIN(); if (grpc_polling_trace.enabled()) { - gpr_log(GPR_ERROR, " .. already kicked %p", next_worker); + gpr_log(GPR_DEBUG, " .. already kicked %p", next_worker); } SET_KICK_STATE(next_worker, KICKED); goto done; @@ -1056,7 +1056,7 @@ static grpc_error* pollset_kick(grpc_pollset* pollset, &g_active_poller)) { GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(); if (grpc_polling_trace.enabled()) { - gpr_log(GPR_ERROR, " .. kicked %p", root_worker); + gpr_log(GPR_DEBUG, " .. kicked %p", root_worker); } SET_KICK_STATE(root_worker, KICKED); ret_err = grpc_wakeup_fd_wakeup(&global_wakeup_fd); @@ -1064,7 +1064,7 @@ static grpc_error* pollset_kick(grpc_pollset* pollset, } else if (next_worker->state == UNKICKED) { GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(); if (grpc_polling_trace.enabled()) { - gpr_log(GPR_ERROR, " .. kicked %p", next_worker); + gpr_log(GPR_DEBUG, " .. kicked %p", next_worker); } GPR_ASSERT(next_worker->initialized_cv); SET_KICK_STATE(next_worker, KICKED); @@ -1074,7 +1074,7 @@ static grpc_error* pollset_kick(grpc_pollset* pollset, if (root_worker->state != DESIGNATED_POLLER) { if (grpc_polling_trace.enabled()) { gpr_log( - GPR_ERROR, + GPR_DEBUG, " .. kicked root non-poller %p (initialized_cv=%d) (poller=%p)", root_worker, root_worker->initialized_cv, next_worker); } @@ -1087,7 +1087,7 @@ static grpc_error* pollset_kick(grpc_pollset* pollset, } else { GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(); if (grpc_polling_trace.enabled()) { - gpr_log(GPR_ERROR, " .. non-root poller %p (root=%p)", next_worker, + gpr_log(GPR_DEBUG, " .. non-root poller %p (root=%p)", next_worker, root_worker); } SET_KICK_STATE(next_worker, KICKED); @@ -1103,7 +1103,7 @@ static grpc_error* pollset_kick(grpc_pollset* pollset, } else { GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(); if (grpc_polling_trace.enabled()) { - gpr_log(GPR_ERROR, " .. kicked while waking up"); + gpr_log(GPR_DEBUG, " .. kicked while waking up"); } goto done; } @@ -1113,14 +1113,14 @@ static grpc_error* pollset_kick(grpc_pollset* pollset, if (specific_worker->state == KICKED) { if (grpc_polling_trace.enabled()) { - gpr_log(GPR_ERROR, " .. specific worker already kicked"); + gpr_log(GPR_DEBUG, " .. specific worker already kicked"); } goto done; } else if (gpr_tls_get(&g_current_thread_worker) == (intptr_t)specific_worker) { GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(); if (grpc_polling_trace.enabled()) { - gpr_log(GPR_ERROR, " .. mark %p kicked", specific_worker); + gpr_log(GPR_DEBUG, " .. mark %p kicked", specific_worker); } SET_KICK_STATE(specific_worker, KICKED); goto done; @@ -1128,7 +1128,7 @@ static grpc_error* pollset_kick(grpc_pollset* pollset, (grpc_pollset_worker*)gpr_atm_no_barrier_load(&g_active_poller)) { GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(); if (grpc_polling_trace.enabled()) { - gpr_log(GPR_ERROR, " .. kick active poller"); + gpr_log(GPR_DEBUG, " .. kick active poller"); } SET_KICK_STATE(specific_worker, KICKED); ret_err = grpc_wakeup_fd_wakeup(&global_wakeup_fd); @@ -1136,7 +1136,7 @@ static grpc_error* pollset_kick(grpc_pollset* pollset, } else if (specific_worker->initialized_cv) { GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(); if (grpc_polling_trace.enabled()) { - gpr_log(GPR_ERROR, " .. kick waiting worker"); + gpr_log(GPR_DEBUG, " .. kick waiting worker"); } SET_KICK_STATE(specific_worker, KICKED); gpr_cv_signal(&specific_worker->cv); @@ -1144,7 +1144,7 @@ static grpc_error* pollset_kick(grpc_pollset* pollset, } else { GRPC_STATS_INC_POLLSET_KICKED_AGAIN(); if (grpc_polling_trace.enabled()) { - gpr_log(GPR_ERROR, " .. kick non-waiting worker"); + gpr_log(GPR_DEBUG, " .. kick non-waiting worker"); } SET_KICK_STATE(specific_worker, KICKED); goto done; diff --git a/src/core/lib/slice/slice_string_helpers.cc b/src/core/lib/slice/slice_string_helpers.cc index be0db09252..4441a26d8e 100644 --- a/src/core/lib/slice/slice_string_helpers.cc +++ b/src/core/lib/slice/slice_string_helpers.cc @@ -56,24 +56,59 @@ static int slice_find_separator_offset(const grpc_slice str, const char* sep, return 0; } -void grpc_slice_split(grpc_slice str, const char* sep, grpc_slice_buffer* dst) { +static void skip_leading_trailing_spaces(const uint8_t* str_buffer, + size_t* begin, size_t* end) { + while (*begin < *end && str_buffer[*begin] == ' ') { + (*begin)++; + } + while (*begin < *end && str_buffer[*end - 1] == ' ') { + (*end)--; + } +} + +static void grpc_slice_split_inner(grpc_slice str, const char* sep, + grpc_slice_buffer* dst, bool no_space) { const size_t sep_len = strlen(sep); size_t begin, end; + const uint8_t* str_buffer = GRPC_SLICE_START_PTR(str); + size_t sep_pos; GPR_ASSERT(sep_len > 0); if (slice_find_separator_offset(str, sep, 0, &begin, &end) != 0) { do { + sep_pos = end; + if (no_space) { + skip_leading_trailing_spaces(str_buffer, &begin, &end); + } grpc_slice_buffer_add_indexed(dst, grpc_slice_sub(str, begin, end)); - } while (slice_find_separator_offset(str, sep, end + sep_len, &begin, + } while (slice_find_separator_offset(str, sep, sep_pos + sep_len, &begin, &end) != 0); - grpc_slice_buffer_add_indexed( - dst, grpc_slice_sub(str, end + sep_len, GRPC_SLICE_LENGTH(str))); + begin = sep_pos + sep_len; + end = GRPC_SLICE_LENGTH(str); + if (no_space) { + skip_leading_trailing_spaces(str_buffer, &begin, &end); + } + grpc_slice_buffer_add_indexed(dst, grpc_slice_sub(str, begin, end)); } else { /* no sep found, add whole input */ - grpc_slice_buffer_add_indexed(dst, grpc_slice_ref_internal(str)); + begin = 0; + end = GRPC_SLICE_LENGTH(str); + if (no_space) { + skip_leading_trailing_spaces(str_buffer, &begin, &end); + } + grpc_slice_buffer_add_indexed(dst, grpc_slice_sub(str, begin, end)); } } +void grpc_slice_split(grpc_slice str, const char* sep, grpc_slice_buffer* dst) { + grpc_slice_split_inner(str, sep, dst, false); +} + +void grpc_slice_split_without_space(grpc_slice str, const char* sep, + grpc_slice_buffer* dst) { + grpc_slice_split_inner(str, sep, dst, true); +} + bool grpc_parse_slice_to_uint32(grpc_slice str, uint32_t* result) { return gpr_parse_bytes_to_uint32((const char*)GRPC_SLICE_START_PTR(str), GRPC_SLICE_LENGTH(str), result) != 0; diff --git a/src/core/lib/slice/slice_string_helpers.h b/src/core/lib/slice/slice_string_helpers.h index 109084be1f..429f9ff4b5 100644 --- a/src/core/lib/slice/slice_string_helpers.h +++ b/src/core/lib/slice/slice_string_helpers.h @@ -35,6 +35,12 @@ char* grpc_dump_slice(grpc_slice slice, uint32_t flags); * should be a properly initialized instance. */ void grpc_slice_split(grpc_slice str, const char* sep, grpc_slice_buffer* dst); +/** Split \a str by the separator \a sep and remove the leading and trailing + * spaces of each resulting token. Results are stored in \a dst, which should be + * a properly initialized instance. */ +void grpc_slice_split_without_space(grpc_slice str, const char* sep, + grpc_slice_buffer* dst); + bool grpc_parse_slice_to_uint32(grpc_slice str, uint32_t* result); #endif /* GRPC_CORE_LIB_SLICE_SLICE_STRING_HELPERS_H */ diff --git a/src/core/lib/surface/byte_buffer_reader.cc b/src/core/lib/surface/byte_buffer_reader.cc index 81a48e95fc..f7ea5161c7 100644 --- a/src/core/lib/surface/byte_buffer_reader.cc +++ b/src/core/lib/surface/byte_buffer_reader.cc @@ -49,9 +49,12 @@ int grpc_byte_buffer_reader_init(grpc_byte_buffer_reader* reader, case GRPC_BB_RAW: grpc_slice_buffer_init(&decompressed_slices_buffer); if (is_compressed(reader->buffer_in)) { - if (grpc_msg_decompress(reader->buffer_in->data.raw.compression, - &reader->buffer_in->data.raw.slice_buffer, - &decompressed_slices_buffer) == 0) { + if (grpc_msg_decompress( + + grpc_compression_algorithm_to_message_compression_algorithm( + reader->buffer_in->data.raw.compression), + &reader->buffer_in->data.raw.slice_buffer, + &decompressed_slices_buffer) == 0) { gpr_log(GPR_ERROR, "Unexpected error decompressing data for algorithm with enum " "value '%d'.", diff --git a/src/core/lib/surface/call.cc b/src/core/lib/surface/call.cc index 8a579cabe7..ce63fa4d67 100644 --- a/src/core/lib/surface/call.cc +++ b/src/core/lib/surface/call.cc @@ -201,7 +201,7 @@ struct grpc_call { grpc_call_final_info final_info; /* Compression algorithm for *incoming* data */ - grpc_compression_algorithm incoming_compression_algorithm; + grpc_message_compression_algorithm incoming_message_compression_algorithm; /* Stream compression algorithm for *incoming* data */ grpc_stream_compression_algorithm incoming_stream_compression_algorithm; /* Supported encodings (compression algorithms), a bitset */ @@ -340,7 +340,7 @@ grpc_error* grpc_call_create(const grpc_call_create_args* args, call->cq = args->cq; call->start_time = gpr_now(GPR_CLOCK_MONOTONIC); /* Always support no compression */ - GPR_BITSET(&call->encodings_accepted_by_peer, GRPC_COMPRESS_NONE); + GPR_BITSET(&call->encodings_accepted_by_peer, GRPC_MESSAGE_COMPRESS_NONE); call->is_client = args->server_transport_data == nullptr; if (call->is_client) { GRPC_STATS_INC_CLIENT_CALLS_CREATED(); @@ -449,9 +449,9 @@ grpc_error* grpc_call_create(const grpc_call_create_args* args, cancel_with_error(call, STATUS_FROM_API_OVERRIDE, GRPC_ERROR_CANCELLED); } if (args->cq != nullptr) { - GPR_ASSERT( - args->pollset_set_alternative == nullptr && - "Only one of 'cq' and 'pollset_set_alternative' should be non-NULL."); + GPR_ASSERT(args->pollset_set_alternative == nullptr && + "Only one of 'cq' and 'pollset_set_alternative' should be " + "non-nullptr."); GRPC_CQ_INTERNAL_REF(args->cq, "bind"); call->pollent = grpc_polling_entity_create_from_pollset(grpc_cq_pollset(args->cq)); @@ -801,10 +801,10 @@ static void set_status_from_error(grpc_call* call, status_source source, * COMPRESSION */ -static void set_incoming_compression_algorithm( - grpc_call* call, grpc_compression_algorithm algo) { - GPR_ASSERT(algo < GRPC_COMPRESS_ALGORITHMS_COUNT); - call->incoming_compression_algorithm = algo; +static void set_incoming_message_compression_algorithm( + grpc_call* call, grpc_message_compression_algorithm algo) { + GPR_ASSERT(algo < GRPC_MESSAGE_COMPRESS_ALGORITHMS_COUNT); + call->incoming_message_compression_algorithm = algo; } static void set_incoming_stream_compression_algorithm( @@ -815,8 +815,10 @@ static void set_incoming_stream_compression_algorithm( grpc_compression_algorithm grpc_call_test_only_get_compression_algorithm( grpc_call* call) { - grpc_compression_algorithm algorithm; - algorithm = call->incoming_compression_algorithm; + grpc_compression_algorithm algorithm = GRPC_COMPRESS_NONE; + grpc_compression_algorithm_from_message_stream_compression_algorithm( + &algorithm, call->incoming_message_compression_algorithm, + call->incoming_stream_compression_algorithm); return algorithm; } @@ -826,13 +828,6 @@ static grpc_compression_algorithm compression_algorithm_for_level_locked( call->encodings_accepted_by_peer); } -static grpc_stream_compression_algorithm -stream_compression_algorithm_for_level_locked( - grpc_call* call, grpc_stream_compression_level level) { - return grpc_stream_compression_algorithm_for_level( - level, call->stream_encodings_accepted_by_peer); -} - uint32_t grpc_call_test_only_get_message_flags(grpc_call* call) { uint32_t flags; flags = call->test_only_last_message_flags; @@ -841,9 +836,11 @@ uint32_t grpc_call_test_only_get_message_flags(grpc_call* call) { static void destroy_encodings_accepted_by_peer(void* p) { return; } -static void set_encodings_accepted_by_peer(grpc_call* call, grpc_mdelem mdel) { +static void set_encodings_accepted_by_peer(grpc_call* call, grpc_mdelem mdel, + uint32_t* encodings_accepted_by_peer, + bool stream_encoding) { size_t i; - grpc_compression_algorithm algorithm; + uint32_t algorithm; grpc_slice_buffer accept_encoding_parts; grpc_slice accept_encoding_slice; void* accepted_user_data; @@ -851,69 +848,33 @@ static void set_encodings_accepted_by_peer(grpc_call* call, grpc_mdelem mdel) { accepted_user_data = grpc_mdelem_get_user_data(mdel, destroy_encodings_accepted_by_peer); if (accepted_user_data != nullptr) { - call->encodings_accepted_by_peer = + *encodings_accepted_by_peer = (uint32_t)(((uintptr_t)accepted_user_data) - 1); return; } + *encodings_accepted_by_peer = 0; + accept_encoding_slice = GRPC_MDVALUE(mdel); grpc_slice_buffer_init(&accept_encoding_parts); - grpc_slice_split(accept_encoding_slice, ",", &accept_encoding_parts); + grpc_slice_split_without_space(accept_encoding_slice, ",", + &accept_encoding_parts); - /* No need to zero call->encodings_accepted_by_peer: grpc_call_create already - * zeroes the whole grpc_call */ - /* Always support no compression */ - GPR_BITSET(&call->encodings_accepted_by_peer, GRPC_COMPRESS_NONE); + GPR_BITSET(encodings_accepted_by_peer, GRPC_COMPRESS_NONE); for (i = 0; i < accept_encoding_parts.count; i++) { + int r; grpc_slice accept_encoding_entry_slice = accept_encoding_parts.slices[i]; - if (grpc_compression_algorithm_parse(accept_encoding_entry_slice, - &algorithm)) { - GPR_BITSET(&call->encodings_accepted_by_peer, algorithm); + if (!stream_encoding) { + r = grpc_message_compression_algorithm_parse( + accept_encoding_entry_slice, + (grpc_message_compression_algorithm*)&algorithm); } else { - char* accept_encoding_entry_str = - grpc_slice_to_c_string(accept_encoding_entry_slice); - gpr_log(GPR_ERROR, - "Invalid entry in accept encoding metadata: '%s'. Ignoring.", - accept_encoding_entry_str); - gpr_free(accept_encoding_entry_str); + r = grpc_stream_compression_algorithm_parse( + accept_encoding_entry_slice, + (grpc_stream_compression_algorithm*)&algorithm); } - } - - grpc_slice_buffer_destroy_internal(&accept_encoding_parts); - - grpc_mdelem_set_user_data( - mdel, destroy_encodings_accepted_by_peer, - (void*)(((uintptr_t)call->encodings_accepted_by_peer) + 1)); -} - -static void set_stream_encodings_accepted_by_peer(grpc_call* call, - grpc_mdelem mdel) { - size_t i; - grpc_stream_compression_algorithm algorithm; - grpc_slice_buffer accept_encoding_parts; - grpc_slice accept_encoding_slice; - void* accepted_user_data; - - accepted_user_data = - grpc_mdelem_get_user_data(mdel, destroy_encodings_accepted_by_peer); - if (accepted_user_data != nullptr) { - call->stream_encodings_accepted_by_peer = - (uint32_t)(((uintptr_t)accepted_user_data) - 1); - return; - } - - accept_encoding_slice = GRPC_MDVALUE(mdel); - grpc_slice_buffer_init(&accept_encoding_parts); - grpc_slice_split(accept_encoding_slice, ",", &accept_encoding_parts); - - /* Always support no compression */ - GPR_BITSET(&call->stream_encodings_accepted_by_peer, - GRPC_STREAM_COMPRESS_NONE); - for (i = 0; i < accept_encoding_parts.count; i++) { - grpc_slice accept_encoding_entry_slice = accept_encoding_parts.slices[i]; - if (grpc_stream_compression_algorithm_parse(accept_encoding_entry_slice, - &algorithm)) { - GPR_BITSET(&call->stream_encodings_accepted_by_peer, algorithm); + if (r) { + GPR_BITSET(encodings_accepted_by_peer, algorithm); } else { char* accept_encoding_entry_str = grpc_slice_to_c_string(accept_encoding_entry_slice); @@ -928,7 +889,7 @@ static void set_stream_encodings_accepted_by_peer(grpc_call* call, grpc_mdelem_set_user_data( mdel, destroy_encodings_accepted_by_peer, - (void*)(((uintptr_t)call->stream_encodings_accepted_by_peer) + 1)); + (void*)(((uintptr_t)(*encodings_accepted_by_peer)) + 1)); } uint32_t grpc_call_test_only_get_encodings_accepted_by_peer(grpc_call* call) { @@ -937,13 +898,6 @@ uint32_t grpc_call_test_only_get_encodings_accepted_by_peer(grpc_call* call) { return encodings_accepted_by_peer; } -uint32_t grpc_call_test_only_get_stream_encodings_accepted_by_peer( - grpc_call* call) { - uint32_t stream_encodings_accepted_by_peer; - stream_encodings_accepted_by_peer = call->stream_encodings_accepted_by_peer; - return stream_encodings_accepted_by_peer; -} - grpc_stream_compression_algorithm grpc_call_test_only_get_incoming_stream_encodings(grpc_call* call) { return call->incoming_stream_compression_algorithm; @@ -1047,17 +1001,18 @@ static uint32_t decode_status(grpc_mdelem md) { return status; } -static grpc_compression_algorithm decode_compression(grpc_mdelem md) { - grpc_compression_algorithm algorithm = - grpc_compression_algorithm_from_slice(GRPC_MDVALUE(md)); - if (algorithm == GRPC_COMPRESS_ALGORITHMS_COUNT) { +static grpc_message_compression_algorithm decode_message_compression( + grpc_mdelem md) { + grpc_message_compression_algorithm algorithm = + grpc_message_compression_algorithm_from_slice(GRPC_MDVALUE(md)); + if (algorithm == GRPC_MESSAGE_COMPRESS_ALGORITHMS_COUNT) { char* md_c_str = grpc_slice_to_c_string(GRPC_MDVALUE(md)); gpr_log(GPR_ERROR, - "Invalid incoming compression algorithm: '%s'. Interpreting " - "incoming data as uncompressed.", + "Invalid incoming message compression algorithm: '%s'. " + "Interpreting incoming data as uncompressed.", md_c_str); gpr_free(md_c_str); - return GRPC_COMPRESS_NONE; + return GRPC_MESSAGE_COMPRESS_NONE; } return algorithm; } @@ -1102,37 +1057,39 @@ static void publish_app_metadata(grpc_call* call, grpc_metadata_batch* b, static void recv_initial_filter(grpc_call* call, grpc_metadata_batch* b) { if (b->idx.named.content_encoding != nullptr) { - if (b->idx.named.grpc_encoding != nullptr) { - gpr_log(GPR_ERROR, - "Received both content-encoding and grpc-encoding header. " - "Ignoring grpc-encoding."); - grpc_metadata_batch_remove(b, b->idx.named.grpc_encoding); - } GPR_TIMER_BEGIN("incoming_stream_compression_algorithm", 0); set_incoming_stream_compression_algorithm( call, decode_stream_compression(b->idx.named.content_encoding->md)); GPR_TIMER_END("incoming_stream_compression_algorithm", 0); grpc_metadata_batch_remove(b, b->idx.named.content_encoding); - } else if (b->idx.named.grpc_encoding != nullptr) { - GPR_TIMER_BEGIN("incoming_compression_algorithm", 0); - set_incoming_compression_algorithm( - call, decode_compression(b->idx.named.grpc_encoding->md)); - GPR_TIMER_END("incoming_compression_algorithm", 0); + } + if (b->idx.named.grpc_encoding != nullptr) { + GPR_TIMER_BEGIN("incoming_message_compression_algorithm", 0); + set_incoming_message_compression_algorithm( + call, decode_message_compression(b->idx.named.grpc_encoding->md)); + GPR_TIMER_END("incoming_message_compression_algorithm", 0); grpc_metadata_batch_remove(b, b->idx.named.grpc_encoding); } + uint32_t message_encodings_accepted_by_peer = 1u; + uint32_t stream_encodings_accepted_by_peer = 1u; if (b->idx.named.grpc_accept_encoding != nullptr) { GPR_TIMER_BEGIN("encodings_accepted_by_peer", 0); - set_encodings_accepted_by_peer(call, b->idx.named.grpc_accept_encoding->md); + set_encodings_accepted_by_peer(call, b->idx.named.grpc_accept_encoding->md, + &message_encodings_accepted_by_peer, false); grpc_metadata_batch_remove(b, b->idx.named.grpc_accept_encoding); GPR_TIMER_END("encodings_accepted_by_peer", 0); } if (b->idx.named.accept_encoding != nullptr) { GPR_TIMER_BEGIN("stream_encodings_accepted_by_peer", 0); - set_stream_encodings_accepted_by_peer(call, - b->idx.named.accept_encoding->md); + set_encodings_accepted_by_peer(call, b->idx.named.accept_encoding->md, + &stream_encodings_accepted_by_peer, true); grpc_metadata_batch_remove(b, b->idx.named.accept_encoding); GPR_TIMER_END("stream_encodings_accepted_by_peer", 0); } + call->encodings_accepted_by_peer = + grpc_compression_bitset_from_message_stream_compression_bitset( + message_encodings_accepted_by_peer, + stream_encodings_accepted_by_peer); publish_app_metadata(call, b, false); } @@ -1270,6 +1227,7 @@ static void post_batch_completion(batch_control* bctl) { if (bctl->op.send_initial_metadata) { grpc_metadata_batch_destroy( + &call->metadata_batch[0 /* is_receiving */][0 /* is_trailing */]); } if (bctl->op.send_message) { @@ -1277,6 +1235,7 @@ static void post_batch_completion(batch_control* bctl) { } if (bctl->op.send_trailing_metadata) { grpc_metadata_batch_destroy( + &call->metadata_batch[0 /* is_receiving */][1 /* is_trailing */]); } if (bctl->op.recv_trailing_metadata) { @@ -1425,9 +1384,15 @@ static void process_data_after_md(batch_control* bctl) { } else { call->test_only_last_message_flags = call->receiving_stream->flags; if ((call->receiving_stream->flags & GRPC_WRITE_INTERNAL_COMPRESS) && - (call->incoming_compression_algorithm > GRPC_COMPRESS_NONE)) { - *call->receiving_buffer = grpc_raw_compressed_byte_buffer_create( - nullptr, 0, call->incoming_compression_algorithm); + (call->incoming_message_compression_algorithm > + GRPC_MESSAGE_COMPRESS_NONE)) { + grpc_compression_algorithm algo; + GPR_ASSERT( + grpc_compression_algorithm_from_message_stream_compression_algorithm( + &algo, call->incoming_message_compression_algorithm, + (grpc_stream_compression_algorithm)0)); + *call->receiving_buffer = + grpc_raw_compressed_byte_buffer_create(nullptr, 0, algo); } else { *call->receiving_buffer = grpc_raw_byte_buffer_create(nullptr, 0); } @@ -1469,88 +1434,66 @@ static void receiving_stream_ready_in_call_combiner(void* bctlp, } static void validate_filtered_metadata(batch_control* bctl) { + grpc_compression_algorithm compression_algorithm; grpc_call* call = bctl->call; - /* validate compression algorithms */ if (call->incoming_stream_compression_algorithm != - GRPC_STREAM_COMPRESS_NONE) { - const grpc_stream_compression_algorithm algo = - call->incoming_stream_compression_algorithm; + GRPC_STREAM_COMPRESS_NONE && + call->incoming_message_compression_algorithm != + GRPC_MESSAGE_COMPRESS_NONE) { char* error_msg = nullptr; - const grpc_compression_options compression_options = - grpc_channel_compression_options(call->channel); - if (algo >= GRPC_STREAM_COMPRESS_ALGORITHMS_COUNT) { - gpr_asprintf(&error_msg, - "Invalid stream compression algorithm value '%d'.", algo); - gpr_log(GPR_ERROR, "%s", error_msg); - cancel_with_status(call, STATUS_FROM_SURFACE, GRPC_STATUS_UNIMPLEMENTED, - error_msg); - } else if (grpc_compression_options_is_stream_compression_algorithm_enabled( - &compression_options, algo) == 0) { - /* check if algorithm is supported by current channel config */ - const char* algo_name = nullptr; - grpc_stream_compression_algorithm_name(algo, &algo_name); - gpr_asprintf(&error_msg, "Stream compression algorithm '%s' is disabled.", - algo_name); - gpr_log(GPR_ERROR, "%s", error_msg); - cancel_with_status(call, STATUS_FROM_SURFACE, GRPC_STATUS_UNIMPLEMENTED, - error_msg); - } + gpr_asprintf(&error_msg, + "Incoming stream has both stream compression (%d) and message " + "compression (%d).", + call->incoming_stream_compression_algorithm, + call->incoming_message_compression_algorithm); + gpr_log(GPR_ERROR, "%s", error_msg); + cancel_with_status(call, STATUS_FROM_SURFACE, GRPC_STATUS_INTERNAL, + error_msg); gpr_free(error_msg); - - GPR_ASSERT(call->stream_encodings_accepted_by_peer != 0); - if (!GPR_BITGET(call->stream_encodings_accepted_by_peer, - call->incoming_stream_compression_algorithm)) { - if (grpc_compression_trace.enabled()) { - const char* algo_name = nullptr; - grpc_stream_compression_algorithm_name( - call->incoming_stream_compression_algorithm, &algo_name); - gpr_log( - GPR_ERROR, - "Stream compression algorithm (content-encoding = '%s') not " - "present in the bitset of accepted encodings (accept-encodings: " - "'0x%x')", - algo_name, call->stream_encodings_accepted_by_peer); - } - } - } else if (call->incoming_compression_algorithm != GRPC_COMPRESS_NONE) { - const grpc_compression_algorithm algo = - call->incoming_compression_algorithm; + } else if ( + grpc_compression_algorithm_from_message_stream_compression_algorithm( + &compression_algorithm, call->incoming_message_compression_algorithm, + call->incoming_stream_compression_algorithm) == 0) { + char* error_msg = nullptr; + gpr_asprintf(&error_msg, + "Error in incoming message compression (%d) or stream " + "compression (%d).", + call->incoming_stream_compression_algorithm, + call->incoming_message_compression_algorithm); + cancel_with_status(call, STATUS_FROM_SURFACE, GRPC_STATUS_INTERNAL, + error_msg); + gpr_free(error_msg); + } else { char* error_msg = nullptr; const grpc_compression_options compression_options = grpc_channel_compression_options(call->channel); - /* check if algorithm is known */ - if (algo >= GRPC_COMPRESS_ALGORITHMS_COUNT) { + if (compression_algorithm >= GRPC_COMPRESS_ALGORITHMS_COUNT) { gpr_asprintf(&error_msg, "Invalid compression algorithm value '%d'.", - algo); + compression_algorithm); gpr_log(GPR_ERROR, "%s", error_msg); cancel_with_status(call, STATUS_FROM_SURFACE, GRPC_STATUS_UNIMPLEMENTED, error_msg); } else if (grpc_compression_options_is_algorithm_enabled( - &compression_options, algo) == 0) { + &compression_options, compression_algorithm) == 0) { /* check if algorithm is supported by current channel config */ const char* algo_name = nullptr; - grpc_compression_algorithm_name(algo, &algo_name); + grpc_compression_algorithm_name(compression_algorithm, &algo_name); gpr_asprintf(&error_msg, "Compression algorithm '%s' is disabled.", algo_name); gpr_log(GPR_ERROR, "%s", error_msg); cancel_with_status(call, STATUS_FROM_SURFACE, GRPC_STATUS_UNIMPLEMENTED, error_msg); - } else { - call->incoming_compression_algorithm = algo; } gpr_free(error_msg); GPR_ASSERT(call->encodings_accepted_by_peer != 0); - if (!GPR_BITGET(call->encodings_accepted_by_peer, - call->incoming_compression_algorithm)) { + if (!GPR_BITGET(call->encodings_accepted_by_peer, compression_algorithm)) { if (grpc_compression_trace.enabled()) { const char* algo_name = nullptr; - grpc_compression_algorithm_name(call->incoming_compression_algorithm, - &algo_name); + grpc_compression_algorithm_name(compression_algorithm, &algo_name); gpr_log(GPR_ERROR, - "Compression algorithm (grpc-encoding = '%s') not present in " - "the bitset of accepted encodings (grpc-accept-encodings: " - "'0x%x')", + "Compression algorithm ('%s') not present in the bitset of " + "accepted encodings ('0x%x')", algo_name, call->encodings_accepted_by_peer); } } @@ -1693,56 +1636,28 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops, size_t additional_metadata_count = 0; grpc_compression_level effective_compression_level = GRPC_COMPRESS_LEVEL_NONE; - grpc_stream_compression_level effective_stream_compression_level = - GRPC_STREAM_COMPRESS_LEVEL_NONE; bool level_set = false; - bool stream_compression = false; - if (op->data.send_initial_metadata.maybe_stream_compression_level - .is_set) { - effective_stream_compression_level = - op->data.send_initial_metadata.maybe_stream_compression_level - .level; - level_set = true; - stream_compression = true; - } else if (op->data.send_initial_metadata.maybe_compression_level - .is_set) { + if (op->data.send_initial_metadata.maybe_compression_level.is_set) { effective_compression_level = op->data.send_initial_metadata.maybe_compression_level.level; level_set = true; } else { const grpc_compression_options copts = grpc_channel_compression_options(call->channel); - if (copts.default_stream_compression_level.is_set) { - level_set = true; - effective_stream_compression_level = - copts.default_stream_compression_level.level; - stream_compression = true; - } else if (copts.default_level.is_set) { + if (copts.default_level.is_set) { level_set = true; effective_compression_level = copts.default_level.level; } } if (level_set && !call->is_client) { - if (stream_compression) { - const grpc_stream_compression_algorithm calgo = - stream_compression_algorithm_for_level_locked( - call, effective_stream_compression_level); - call->compression_md.key = - GRPC_MDSTR_GRPC_INTERNAL_STREAM_ENCODING_REQUEST; - call->compression_md.value = - grpc_stream_compression_algorithm_slice(calgo); - } else { - const grpc_compression_algorithm calgo = - compression_algorithm_for_level_locked( - call, effective_compression_level); - /* the following will be picked up by the compress filter and used - * as the call's compression algorithm. */ - call->compression_md.key = - GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST; - call->compression_md.value = - grpc_compression_algorithm_slice(calgo); - additional_metadata_count++; - } + const grpc_compression_algorithm calgo = + compression_algorithm_for_level_locked( + call, effective_compression_level); + /* the following will be picked up by the compress filter and used + * as the call's compression algorithm. */ + call->compression_md.key = GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST; + call->compression_md.value = grpc_compression_algorithm_slice(calgo); + additional_metadata_count++; } if (op->data.send_initial_metadata.count + additional_metadata_count > diff --git a/src/core/lib/surface/call_test_only.h b/src/core/lib/surface/call_test_only.h index 90444f85b6..9eb32f03fb 100644 --- a/src/core/lib/surface/call_test_only.h +++ b/src/core/lib/surface/call_test_only.h @@ -21,7 +21,7 @@ #include <grpc/grpc.h> -/** Return the compression algorithm from \a call. +/** Return the message compression algorithm from \a call. * * \warning This function should \b only be used in test code. */ grpc_compression_algorithm grpc_call_test_only_get_compression_algorithm( @@ -38,16 +38,4 @@ uint32_t grpc_call_test_only_get_message_flags(grpc_call* call); * To be indexed by grpc_compression_algorithm enum values. */ uint32_t grpc_call_test_only_get_encodings_accepted_by_peer(grpc_call* call); -/** Returns a bitset for the stream encodings (stream compression algorithms) - * supported by \a call's peer. - * - * To be indexed by grpc_stream_compression_algorithm enum values. */ -uint32_t grpc_call_test_only_get_stream_encodings_accepted_by_peer( - grpc_call* call); - -/** Returns the incoming stream compression algorithm (content-encoding header) - * received by a call. */ -grpc_stream_compression_algorithm -grpc_call_test_only_get_incoming_stream_encodings(grpc_call* call); - #endif /* GRPC_CORE_LIB_SURFACE_CALL_TEST_ONLY_H */ diff --git a/src/core/lib/surface/channel.cc b/src/core/lib/surface/channel.cc index 62db82a1d9..679666bc5f 100644 --- a/src/core/lib/surface/channel.cc +++ b/src/core/lib/surface/channel.cc @@ -142,50 +142,23 @@ grpc_channel* grpc_channel_create_with_builder( GRPC_COMPRESSION_CHANNEL_DEFAULT_LEVEL)) { channel->compression_options.default_level.is_set = true; channel->compression_options.default_level.level = - (grpc_compression_level)grpc_channel_arg_get_integer( + static_cast<grpc_compression_level>(grpc_channel_arg_get_integer( &args->args[i], {GRPC_COMPRESS_LEVEL_NONE, GRPC_COMPRESS_LEVEL_NONE, - GRPC_COMPRESS_LEVEL_COUNT - 1}); - } else if (0 == strcmp(args->args[i].key, - GRPC_STREAM_COMPRESSION_CHANNEL_DEFAULT_LEVEL)) { - channel->compression_options.default_stream_compression_level.is_set = - true; - channel->compression_options.default_stream_compression_level.level = - (grpc_stream_compression_level)grpc_channel_arg_get_integer( - &args->args[i], - {GRPC_STREAM_COMPRESS_LEVEL_NONE, GRPC_STREAM_COMPRESS_LEVEL_NONE, - GRPC_STREAM_COMPRESS_LEVEL_COUNT - 1}); + GRPC_COMPRESS_LEVEL_COUNT - 1})); } else if (0 == strcmp(args->args[i].key, GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM)) { channel->compression_options.default_algorithm.is_set = true; channel->compression_options.default_algorithm.algorithm = - (grpc_compression_algorithm)grpc_channel_arg_get_integer( + static_cast<grpc_compression_algorithm>(grpc_channel_arg_get_integer( &args->args[i], {GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE, - GRPC_COMPRESS_ALGORITHMS_COUNT - 1}); - } else if (0 == strcmp(args->args[i].key, - GRPC_STREAM_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM)) { - channel->compression_options.default_stream_compression_algorithm.is_set = - true; - channel->compression_options.default_stream_compression_algorithm - .algorithm = - (grpc_stream_compression_algorithm)grpc_channel_arg_get_integer( - &args->args[i], - {GRPC_STREAM_COMPRESS_NONE, GRPC_STREAM_COMPRESS_NONE, - GRPC_STREAM_COMPRESS_ALGORITHMS_COUNT - 1}); + GRPC_COMPRESS_ALGORITHMS_COUNT - 1})); } else if (0 == strcmp(args->args[i].key, GRPC_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET)) { channel->compression_options.enabled_algorithms_bitset = (uint32_t)args->args[i].value.integer | 0x1; /* always support no compression */ - } else if (0 == - strcmp( - args->args[i].key, - GRPC_STREAM_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET)) { - channel->compression_options - .enabled_stream_compression_algorithms_bitset = - (uint32_t)args->args[i].value.integer | - 0x1; /* always support no compression */ } } diff --git a/src/core/lib/transport/static_metadata.cc b/src/core/lib/transport/static_metadata.cc index 2213b30f56..82ba7ac51a 100644 --- a/src/core/lib/transport/static_metadata.cc +++ b/src/core/lib/transport/static_metadata.cc @@ -57,51 +57,53 @@ static uint8_t g_bytes[] = { 112, 111, 110, 115, 101, 95, 109, 101, 115, 115, 97, 103, 101, 95, 98, 121, 116, 101, 115, 47, 103, 114, 112, 99, 46, 108, 98, 46, 118, 49, 46, 76, 111, 97, 100, 66, 97, 108, 97, 110, 99, 101, 114, 47, 66, - 97, 108, 97, 110, 99, 101, 76, 111, 97, 100, 48, 49, 50, 105, 100, - 101, 110, 116, 105, 116, 121, 103, 122, 105, 112, 100, 101, 102, 108, 97, - 116, 101, 116, 114, 97, 105, 108, 101, 114, 115, 97, 112, 112, 108, 105, - 99, 97, 116, 105, 111, 110, 47, 103, 114, 112, 99, 80, 79, 83, 84, - 50, 48, 48, 52, 48, 52, 104, 116, 116, 112, 104, 116, 116, 112, 115, - 103, 114, 112, 99, 71, 69, 84, 80, 85, 84, 47, 47, 105, 110, 100, - 101, 120, 46, 104, 116, 109, 108, 50, 48, 52, 50, 48, 54, 51, 48, - 52, 52, 48, 48, 53, 48, 48, 97, 99, 99, 101, 112, 116, 45, 99, - 104, 97, 114, 115, 101, 116, 103, 122, 105, 112, 44, 32, 100, 101, 102, - 108, 97, 116, 101, 97, 99, 99, 101, 112, 116, 45, 108, 97, 110, 103, - 117, 97, 103, 101, 97, 99, 99, 101, 112, 116, 45, 114, 97, 110, 103, - 101, 115, 97, 99, 99, 101, 112, 116, 97, 99, 99, 101, 115, 115, 45, - 99, 111, 110, 116, 114, 111, 108, 45, 97, 108, 108, 111, 119, 45, 111, - 114, 105, 103, 105, 110, 97, 103, 101, 97, 108, 108, 111, 119, 97, 117, - 116, 104, 111, 114, 105, 122, 97, 116, 105, 111, 110, 99, 97, 99, 104, - 101, 45, 99, 111, 110, 116, 114, 111, 108, 99, 111, 110, 116, 101, 110, - 116, 45, 100, 105, 115, 112, 111, 115, 105, 116, 105, 111, 110, 99, 111, - 110, 116, 101, 110, 116, 45, 108, 97, 110, 103, 117, 97, 103, 101, 99, - 111, 110, 116, 101, 110, 116, 45, 108, 101, 110, 103, 116, 104, 99, 111, - 110, 116, 101, 110, 116, 45, 108, 111, 99, 97, 116, 105, 111, 110, 99, - 111, 110, 116, 101, 110, 116, 45, 114, 97, 110, 103, 101, 99, 111, 111, - 107, 105, 101, 100, 97, 116, 101, 101, 116, 97, 103, 101, 120, 112, 101, - 99, 116, 101, 120, 112, 105, 114, 101, 115, 102, 114, 111, 109, 105, 102, - 45, 109, 97, 116, 99, 104, 105, 102, 45, 109, 111, 100, 105, 102, 105, - 101, 100, 45, 115, 105, 110, 99, 101, 105, 102, 45, 110, 111, 110, 101, - 45, 109, 97, 116, 99, 104, 105, 102, 45, 114, 97, 110, 103, 101, 105, - 102, 45, 117, 110, 109, 111, 100, 105, 102, 105, 101, 100, 45, 115, 105, - 110, 99, 101, 108, 97, 115, 116, 45, 109, 111, 100, 105, 102, 105, 101, - 100, 108, 98, 45, 99, 111, 115, 116, 45, 98, 105, 110, 108, 105, 110, - 107, 108, 111, 99, 97, 116, 105, 111, 110, 109, 97, 120, 45, 102, 111, - 114, 119, 97, 114, 100, 115, 112, 114, 111, 120, 121, 45, 97, 117, 116, - 104, 101, 110, 116, 105, 99, 97, 116, 101, 112, 114, 111, 120, 121, 45, - 97, 117, 116, 104, 111, 114, 105, 122, 97, 116, 105, 111, 110, 114, 97, - 110, 103, 101, 114, 101, 102, 101, 114, 101, 114, 114, 101, 102, 114, 101, - 115, 104, 114, 101, 116, 114, 121, 45, 97, 102, 116, 101, 114, 115, 101, - 114, 118, 101, 114, 115, 101, 116, 45, 99, 111, 111, 107, 105, 101, 115, - 116, 114, 105, 99, 116, 45, 116, 114, 97, 110, 115, 112, 111, 114, 116, - 45, 115, 101, 99, 117, 114, 105, 116, 121, 116, 114, 97, 110, 115, 102, - 101, 114, 45, 101, 110, 99, 111, 100, 105, 110, 103, 118, 97, 114, 121, - 118, 105, 97, 119, 119, 119, 45, 97, 117, 116, 104, 101, 110, 116, 105, - 99, 97, 116, 101, 105, 100, 101, 110, 116, 105, 116, 121, 44, 100, 101, - 102, 108, 97, 116, 101, 105, 100, 101, 110, 116, 105, 116, 121, 44, 103, - 122, 105, 112, 100, 101, 102, 108, 97, 116, 101, 44, 103, 122, 105, 112, - 105, 100, 101, 110, 116, 105, 116, 121, 44, 100, 101, 102, 108, 97, 116, - 101, 44, 103, 122, 105, 112}; + 97, 108, 97, 110, 99, 101, 76, 111, 97, 100, 109, 101, 115, 115, 97, + 103, 101, 47, 100, 101, 102, 108, 97, 116, 101, 109, 101, 115, 115, 97, + 103, 101, 47, 103, 122, 105, 112, 115, 116, 114, 101, 97, 109, 47, 103, + 122, 105, 112, 48, 49, 50, 105, 100, 101, 110, 116, 105, 116, 121, 103, + 122, 105, 112, 100, 101, 102, 108, 97, 116, 101, 116, 114, 97, 105, 108, + 101, 114, 115, 97, 112, 112, 108, 105, 99, 97, 116, 105, 111, 110, 47, + 103, 114, 112, 99, 80, 79, 83, 84, 50, 48, 48, 52, 48, 52, 104, + 116, 116, 112, 104, 116, 116, 112, 115, 103, 114, 112, 99, 71, 69, 84, + 80, 85, 84, 47, 47, 105, 110, 100, 101, 120, 46, 104, 116, 109, 108, + 50, 48, 52, 50, 48, 54, 51, 48, 52, 52, 48, 48, 53, 48, 48, + 97, 99, 99, 101, 112, 116, 45, 99, 104, 97, 114, 115, 101, 116, 103, + 122, 105, 112, 44, 32, 100, 101, 102, 108, 97, 116, 101, 97, 99, 99, + 101, 112, 116, 45, 108, 97, 110, 103, 117, 97, 103, 101, 97, 99, 99, + 101, 112, 116, 45, 114, 97, 110, 103, 101, 115, 97, 99, 99, 101, 112, + 116, 97, 99, 99, 101, 115, 115, 45, 99, 111, 110, 116, 114, 111, 108, + 45, 97, 108, 108, 111, 119, 45, 111, 114, 105, 103, 105, 110, 97, 103, + 101, 97, 108, 108, 111, 119, 97, 117, 116, 104, 111, 114, 105, 122, 97, + 116, 105, 111, 110, 99, 97, 99, 104, 101, 45, 99, 111, 110, 116, 114, + 111, 108, 99, 111, 110, 116, 101, 110, 116, 45, 100, 105, 115, 112, 111, + 115, 105, 116, 105, 111, 110, 99, 111, 110, 116, 101, 110, 116, 45, 108, + 97, 110, 103, 117, 97, 103, 101, 99, 111, 110, 116, 101, 110, 116, 45, + 108, 101, 110, 103, 116, 104, 99, 111, 110, 116, 101, 110, 116, 45, 108, + 111, 99, 97, 116, 105, 111, 110, 99, 111, 110, 116, 101, 110, 116, 45, + 114, 97, 110, 103, 101, 99, 111, 111, 107, 105, 101, 100, 97, 116, 101, + 101, 116, 97, 103, 101, 120, 112, 101, 99, 116, 101, 120, 112, 105, 114, + 101, 115, 102, 114, 111, 109, 105, 102, 45, 109, 97, 116, 99, 104, 105, + 102, 45, 109, 111, 100, 105, 102, 105, 101, 100, 45, 115, 105, 110, 99, + 101, 105, 102, 45, 110, 111, 110, 101, 45, 109, 97, 116, 99, 104, 105, + 102, 45, 114, 97, 110, 103, 101, 105, 102, 45, 117, 110, 109, 111, 100, + 105, 102, 105, 101, 100, 45, 115, 105, 110, 99, 101, 108, 97, 115, 116, + 45, 109, 111, 100, 105, 102, 105, 101, 100, 108, 98, 45, 99, 111, 115, + 116, 45, 98, 105, 110, 108, 105, 110, 107, 108, 111, 99, 97, 116, 105, + 111, 110, 109, 97, 120, 45, 102, 111, 114, 119, 97, 114, 100, 115, 112, + 114, 111, 120, 121, 45, 97, 117, 116, 104, 101, 110, 116, 105, 99, 97, + 116, 101, 112, 114, 111, 120, 121, 45, 97, 117, 116, 104, 111, 114, 105, + 122, 97, 116, 105, 111, 110, 114, 97, 110, 103, 101, 114, 101, 102, 101, + 114, 101, 114, 114, 101, 102, 114, 101, 115, 104, 114, 101, 116, 114, 121, + 45, 97, 102, 116, 101, 114, 115, 101, 114, 118, 101, 114, 115, 101, 116, + 45, 99, 111, 111, 107, 105, 101, 115, 116, 114, 105, 99, 116, 45, 116, + 114, 97, 110, 115, 112, 111, 114, 116, 45, 115, 101, 99, 117, 114, 105, + 116, 121, 116, 114, 97, 110, 115, 102, 101, 114, 45, 101, 110, 99, 111, + 100, 105, 110, 103, 118, 97, 114, 121, 118, 105, 97, 119, 119, 119, 45, + 97, 117, 116, 104, 101, 110, 116, 105, 99, 97, 116, 101, 105, 100, 101, + 110, 116, 105, 116, 121, 44, 100, 101, 102, 108, 97, 116, 101, 105, 100, + 101, 110, 116, 105, 116, 121, 44, 103, 122, 105, 112, 100, 101, 102, 108, + 97, 116, 101, 44, 103, 122, 105, 112, 105, 100, 101, 110, 116, 105, 116, + 121, 44, 100, 101, 102, 108, 97, 116, 101, 44, 103, 122, 105, 112}; static void static_ref(void* unused) {} static void static_unref(void* unused) {} @@ -213,6 +215,9 @@ grpc_slice_refcount grpc_static_metadata_refcounts[GRPC_STATIC_MDSTR_COUNT] = { {&grpc_static_metadata_vtable, &static_sub_refcnt}, {&grpc_static_metadata_vtable, &static_sub_refcnt}, {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, }; const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT] = { @@ -245,77 +250,80 @@ const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT] = { {&grpc_static_metadata_refcounts[26], {{g_bytes + 333, 30}}}, {&grpc_static_metadata_refcounts[27], {{g_bytes + 363, 31}}}, {&grpc_static_metadata_refcounts[28], {{g_bytes + 394, 36}}}, - {&grpc_static_metadata_refcounts[29], {{g_bytes + 430, 1}}}, - {&grpc_static_metadata_refcounts[30], {{g_bytes + 431, 1}}}, - {&grpc_static_metadata_refcounts[31], {{g_bytes + 432, 1}}}, - {&grpc_static_metadata_refcounts[32], {{g_bytes + 433, 8}}}, - {&grpc_static_metadata_refcounts[33], {{g_bytes + 441, 4}}}, - {&grpc_static_metadata_refcounts[34], {{g_bytes + 445, 7}}}, - {&grpc_static_metadata_refcounts[35], {{g_bytes + 452, 8}}}, - {&grpc_static_metadata_refcounts[36], {{g_bytes + 460, 16}}}, - {&grpc_static_metadata_refcounts[37], {{g_bytes + 476, 4}}}, - {&grpc_static_metadata_refcounts[38], {{g_bytes + 480, 3}}}, - {&grpc_static_metadata_refcounts[39], {{g_bytes + 483, 3}}}, - {&grpc_static_metadata_refcounts[40], {{g_bytes + 486, 4}}}, - {&grpc_static_metadata_refcounts[41], {{g_bytes + 490, 5}}}, - {&grpc_static_metadata_refcounts[42], {{g_bytes + 495, 4}}}, - {&grpc_static_metadata_refcounts[43], {{g_bytes + 499, 3}}}, - {&grpc_static_metadata_refcounts[44], {{g_bytes + 502, 3}}}, - {&grpc_static_metadata_refcounts[45], {{g_bytes + 505, 1}}}, - {&grpc_static_metadata_refcounts[46], {{g_bytes + 506, 11}}}, - {&grpc_static_metadata_refcounts[47], {{g_bytes + 517, 3}}}, - {&grpc_static_metadata_refcounts[48], {{g_bytes + 520, 3}}}, - {&grpc_static_metadata_refcounts[49], {{g_bytes + 523, 3}}}, - {&grpc_static_metadata_refcounts[50], {{g_bytes + 526, 3}}}, - {&grpc_static_metadata_refcounts[51], {{g_bytes + 529, 3}}}, - {&grpc_static_metadata_refcounts[52], {{g_bytes + 532, 14}}}, - {&grpc_static_metadata_refcounts[53], {{g_bytes + 546, 13}}}, - {&grpc_static_metadata_refcounts[54], {{g_bytes + 559, 15}}}, - {&grpc_static_metadata_refcounts[55], {{g_bytes + 574, 13}}}, - {&grpc_static_metadata_refcounts[56], {{g_bytes + 587, 6}}}, - {&grpc_static_metadata_refcounts[57], {{g_bytes + 593, 27}}}, - {&grpc_static_metadata_refcounts[58], {{g_bytes + 620, 3}}}, - {&grpc_static_metadata_refcounts[59], {{g_bytes + 623, 5}}}, - {&grpc_static_metadata_refcounts[60], {{g_bytes + 628, 13}}}, - {&grpc_static_metadata_refcounts[61], {{g_bytes + 641, 13}}}, - {&grpc_static_metadata_refcounts[62], {{g_bytes + 654, 19}}}, - {&grpc_static_metadata_refcounts[63], {{g_bytes + 673, 16}}}, - {&grpc_static_metadata_refcounts[64], {{g_bytes + 689, 14}}}, - {&grpc_static_metadata_refcounts[65], {{g_bytes + 703, 16}}}, - {&grpc_static_metadata_refcounts[66], {{g_bytes + 719, 13}}}, - {&grpc_static_metadata_refcounts[67], {{g_bytes + 732, 6}}}, - {&grpc_static_metadata_refcounts[68], {{g_bytes + 738, 4}}}, - {&grpc_static_metadata_refcounts[69], {{g_bytes + 742, 4}}}, - {&grpc_static_metadata_refcounts[70], {{g_bytes + 746, 6}}}, - {&grpc_static_metadata_refcounts[71], {{g_bytes + 752, 7}}}, - {&grpc_static_metadata_refcounts[72], {{g_bytes + 759, 4}}}, - {&grpc_static_metadata_refcounts[73], {{g_bytes + 763, 8}}}, - {&grpc_static_metadata_refcounts[74], {{g_bytes + 771, 17}}}, - {&grpc_static_metadata_refcounts[75], {{g_bytes + 788, 13}}}, + {&grpc_static_metadata_refcounts[29], {{g_bytes + 430, 15}}}, + {&grpc_static_metadata_refcounts[30], {{g_bytes + 445, 12}}}, + {&grpc_static_metadata_refcounts[31], {{g_bytes + 457, 11}}}, + {&grpc_static_metadata_refcounts[32], {{g_bytes + 468, 1}}}, + {&grpc_static_metadata_refcounts[33], {{g_bytes + 469, 1}}}, + {&grpc_static_metadata_refcounts[34], {{g_bytes + 470, 1}}}, + {&grpc_static_metadata_refcounts[35], {{g_bytes + 471, 8}}}, + {&grpc_static_metadata_refcounts[36], {{g_bytes + 479, 4}}}, + {&grpc_static_metadata_refcounts[37], {{g_bytes + 483, 7}}}, + {&grpc_static_metadata_refcounts[38], {{g_bytes + 490, 8}}}, + {&grpc_static_metadata_refcounts[39], {{g_bytes + 498, 16}}}, + {&grpc_static_metadata_refcounts[40], {{g_bytes + 514, 4}}}, + {&grpc_static_metadata_refcounts[41], {{g_bytes + 518, 3}}}, + {&grpc_static_metadata_refcounts[42], {{g_bytes + 521, 3}}}, + {&grpc_static_metadata_refcounts[43], {{g_bytes + 524, 4}}}, + {&grpc_static_metadata_refcounts[44], {{g_bytes + 528, 5}}}, + {&grpc_static_metadata_refcounts[45], {{g_bytes + 533, 4}}}, + {&grpc_static_metadata_refcounts[46], {{g_bytes + 537, 3}}}, + {&grpc_static_metadata_refcounts[47], {{g_bytes + 540, 3}}}, + {&grpc_static_metadata_refcounts[48], {{g_bytes + 543, 1}}}, + {&grpc_static_metadata_refcounts[49], {{g_bytes + 544, 11}}}, + {&grpc_static_metadata_refcounts[50], {{g_bytes + 555, 3}}}, + {&grpc_static_metadata_refcounts[51], {{g_bytes + 558, 3}}}, + {&grpc_static_metadata_refcounts[52], {{g_bytes + 561, 3}}}, + {&grpc_static_metadata_refcounts[53], {{g_bytes + 564, 3}}}, + {&grpc_static_metadata_refcounts[54], {{g_bytes + 567, 3}}}, + {&grpc_static_metadata_refcounts[55], {{g_bytes + 570, 14}}}, + {&grpc_static_metadata_refcounts[56], {{g_bytes + 584, 13}}}, + {&grpc_static_metadata_refcounts[57], {{g_bytes + 597, 15}}}, + {&grpc_static_metadata_refcounts[58], {{g_bytes + 612, 13}}}, + {&grpc_static_metadata_refcounts[59], {{g_bytes + 625, 6}}}, + {&grpc_static_metadata_refcounts[60], {{g_bytes + 631, 27}}}, + {&grpc_static_metadata_refcounts[61], {{g_bytes + 658, 3}}}, + {&grpc_static_metadata_refcounts[62], {{g_bytes + 661, 5}}}, + {&grpc_static_metadata_refcounts[63], {{g_bytes + 666, 13}}}, + {&grpc_static_metadata_refcounts[64], {{g_bytes + 679, 13}}}, + {&grpc_static_metadata_refcounts[65], {{g_bytes + 692, 19}}}, + {&grpc_static_metadata_refcounts[66], {{g_bytes + 711, 16}}}, + {&grpc_static_metadata_refcounts[67], {{g_bytes + 727, 14}}}, + {&grpc_static_metadata_refcounts[68], {{g_bytes + 741, 16}}}, + {&grpc_static_metadata_refcounts[69], {{g_bytes + 757, 13}}}, + {&grpc_static_metadata_refcounts[70], {{g_bytes + 770, 6}}}, + {&grpc_static_metadata_refcounts[71], {{g_bytes + 776, 4}}}, + {&grpc_static_metadata_refcounts[72], {{g_bytes + 780, 4}}}, + {&grpc_static_metadata_refcounts[73], {{g_bytes + 784, 6}}}, + {&grpc_static_metadata_refcounts[74], {{g_bytes + 790, 7}}}, + {&grpc_static_metadata_refcounts[75], {{g_bytes + 797, 4}}}, {&grpc_static_metadata_refcounts[76], {{g_bytes + 801, 8}}}, - {&grpc_static_metadata_refcounts[77], {{g_bytes + 809, 19}}}, - {&grpc_static_metadata_refcounts[78], {{g_bytes + 828, 13}}}, - {&grpc_static_metadata_refcounts[79], {{g_bytes + 841, 11}}}, - {&grpc_static_metadata_refcounts[80], {{g_bytes + 852, 4}}}, - {&grpc_static_metadata_refcounts[81], {{g_bytes + 856, 8}}}, - {&grpc_static_metadata_refcounts[82], {{g_bytes + 864, 12}}}, - {&grpc_static_metadata_refcounts[83], {{g_bytes + 876, 18}}}, - {&grpc_static_metadata_refcounts[84], {{g_bytes + 894, 19}}}, - {&grpc_static_metadata_refcounts[85], {{g_bytes + 913, 5}}}, - {&grpc_static_metadata_refcounts[86], {{g_bytes + 918, 7}}}, - {&grpc_static_metadata_refcounts[87], {{g_bytes + 925, 7}}}, - {&grpc_static_metadata_refcounts[88], {{g_bytes + 932, 11}}}, - {&grpc_static_metadata_refcounts[89], {{g_bytes + 943, 6}}}, - {&grpc_static_metadata_refcounts[90], {{g_bytes + 949, 10}}}, - {&grpc_static_metadata_refcounts[91], {{g_bytes + 959, 25}}}, - {&grpc_static_metadata_refcounts[92], {{g_bytes + 984, 17}}}, - {&grpc_static_metadata_refcounts[93], {{g_bytes + 1001, 4}}}, - {&grpc_static_metadata_refcounts[94], {{g_bytes + 1005, 3}}}, - {&grpc_static_metadata_refcounts[95], {{g_bytes + 1008, 16}}}, - {&grpc_static_metadata_refcounts[96], {{g_bytes + 1024, 16}}}, - {&grpc_static_metadata_refcounts[97], {{g_bytes + 1040, 13}}}, - {&grpc_static_metadata_refcounts[98], {{g_bytes + 1053, 12}}}, - {&grpc_static_metadata_refcounts[99], {{g_bytes + 1065, 21}}}, + {&grpc_static_metadata_refcounts[77], {{g_bytes + 809, 17}}}, + {&grpc_static_metadata_refcounts[78], {{g_bytes + 826, 13}}}, + {&grpc_static_metadata_refcounts[79], {{g_bytes + 839, 8}}}, + {&grpc_static_metadata_refcounts[80], {{g_bytes + 847, 19}}}, + {&grpc_static_metadata_refcounts[81], {{g_bytes + 866, 13}}}, + {&grpc_static_metadata_refcounts[82], {{g_bytes + 879, 11}}}, + {&grpc_static_metadata_refcounts[83], {{g_bytes + 890, 4}}}, + {&grpc_static_metadata_refcounts[84], {{g_bytes + 894, 8}}}, + {&grpc_static_metadata_refcounts[85], {{g_bytes + 902, 12}}}, + {&grpc_static_metadata_refcounts[86], {{g_bytes + 914, 18}}}, + {&grpc_static_metadata_refcounts[87], {{g_bytes + 932, 19}}}, + {&grpc_static_metadata_refcounts[88], {{g_bytes + 951, 5}}}, + {&grpc_static_metadata_refcounts[89], {{g_bytes + 956, 7}}}, + {&grpc_static_metadata_refcounts[90], {{g_bytes + 963, 7}}}, + {&grpc_static_metadata_refcounts[91], {{g_bytes + 970, 11}}}, + {&grpc_static_metadata_refcounts[92], {{g_bytes + 981, 6}}}, + {&grpc_static_metadata_refcounts[93], {{g_bytes + 987, 10}}}, + {&grpc_static_metadata_refcounts[94], {{g_bytes + 997, 25}}}, + {&grpc_static_metadata_refcounts[95], {{g_bytes + 1022, 17}}}, + {&grpc_static_metadata_refcounts[96], {{g_bytes + 1039, 4}}}, + {&grpc_static_metadata_refcounts[97], {{g_bytes + 1043, 3}}}, + {&grpc_static_metadata_refcounts[98], {{g_bytes + 1046, 16}}}, + {&grpc_static_metadata_refcounts[99], {{g_bytes + 1062, 16}}}, + {&grpc_static_metadata_refcounts[100], {{g_bytes + 1078, 13}}}, + {&grpc_static_metadata_refcounts[101], {{g_bytes + 1091, 12}}}, + {&grpc_static_metadata_refcounts[102], {{g_bytes + 1103, 21}}}, }; uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT] = { @@ -325,16 +333,16 @@ uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 4, 6, 6, 8, 8, 2, 4, 4}; static const int8_t elems_r[] = { - 11, 9, -3, 0, 10, 27, -74, 28, 0, 14, -7, 0, 0, 0, 18, 8, -2, - 0, 0, 13, 12, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, -50, 0, -33, -55, -56, -57, -58, -57, 0, 40, 39, 38, 37, 36, 35, 34, - 33, 32, 31, 30, 29, 28, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 22, - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 12, 11, 0}; + 11, 9, -3, 0, 10, 25, -77, 26, 0, 11, -7, 0, 0, 0, 21, 14, 1, + 0, 0, 33, 12, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, -56, 0, -36, -61, -60, -39, -63, -64, 0, 36, 35, 34, 33, + 34, 33, 32, 31, 31, 30, 29, 28, 27, 26, 26, 25, 25, 24, 23, 22, 21, + 20, 19, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 12, 11, 0}; static uint32_t elems_phash(uint32_t i) { - i -= 45; - uint32_t x = i % 98; - uint32_t y = i / 98; + i -= 48; + uint32_t x = i % 101; + uint32_t y = i / 101; uint32_t h = x; if (y < GPR_ARRAY_SIZE(elems_r)) { uint32_t delta = (uint32_t)elems_r[y]; @@ -344,31 +352,31 @@ static uint32_t elems_phash(uint32_t i) { } static const uint16_t elem_keys[] = { - 1032, 1033, 1034, 247, 248, 249, 250, 251, 1623, 143, 144, 45, - 46, 440, 441, 442, 1523, 1632, 1633, 932, 933, 934, 729, 730, - 1423, 1532, 1533, 535, 731, 1923, 2023, 2123, 5223, 5523, 5623, 5723, - 5823, 1436, 1653, 5923, 6023, 6123, 6223, 6323, 6423, 6523, 6623, 6723, - 6823, 6923, 7023, 7123, 7223, 5423, 7323, 7423, 7523, 7623, 7723, 7823, - 7923, 8023, 8123, 8223, 1096, 1097, 1098, 1099, 8323, 8423, 8523, 8623, - 8723, 8823, 8923, 9023, 9123, 9223, 9323, 323, 9423, 9523, 1697, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 137, 238, 239, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0}; + 1065, 1066, 1067, 256, 257, 258, 259, 260, 1671, 149, 150, 48, + 49, 455, 456, 457, 962, 963, 964, 1568, 1683, 1684, 753, 754, + 1465, 553, 755, 2083, 2186, 5688, 5997, 1580, 1581, 6100, 6306, 6409, + 6512, 6615, 6718, 6821, 1481, 1704, 6924, 7027, 7130, 7233, 1980, 7336, + 7439, 7542, 7645, 7748, 7851, 5894, 7954, 8057, 6203, 8160, 8263, 8366, + 8469, 8572, 8675, 8778, 1129, 1130, 1131, 1132, 8881, 8984, 9087, 9190, + 9293, 9396, 9499, 9602, 9705, 9808, 9911, 332, 10014, 10117, 0, 0, + 0, 1748, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 143, 247, + 248, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0}; static const uint8_t elem_idxs[] = { 76, 79, 77, 19, 20, 21, 22, 23, 25, 15, 16, 17, 18, 11, - 12, 13, 38, 83, 84, 3, 4, 5, 0, 1, 43, 36, 37, 6, - 2, 72, 50, 57, 24, 28, 29, 30, 31, 7, 26, 32, 33, 34, - 35, 39, 40, 41, 42, 44, 45, 46, 47, 48, 49, 27, 51, 52, - 53, 54, 55, 56, 58, 59, 60, 61, 78, 80, 81, 82, 62, 63, - 64, 65, 66, 67, 68, 69, 70, 71, 73, 14, 74, 75, 85, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 8, 9, 10}; + 12, 13, 3, 4, 5, 38, 83, 84, 0, 1, 43, 6, 2, 50, + 57, 24, 28, 36, 37, 29, 31, 32, 33, 34, 35, 39, 7, 26, + 40, 41, 42, 44, 72, 45, 46, 47, 48, 49, 51, 27, 52, 53, + 30, 54, 55, 56, 58, 59, 60, 61, 78, 80, 81, 82, 62, 63, + 64, 65, 66, 67, 68, 69, 70, 71, 73, 14, 74, 75, 255, 255, + 255, 85, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 8, 9, 10}; grpc_mdelem grpc_static_mdelem_for_static_strings(int a, int b) { if (a == -1 || b == -1) return GRPC_MDNULL; - uint32_t k = (uint32_t)(a * 100 + b); + uint32_t k = (uint32_t)(a * 103 + b); uint32_t h = elems_phash(k); return h < GPR_ARRAY_SIZE(elem_keys) && elem_keys[h] == k && elem_idxs[h] != 255 @@ -379,177 +387,177 @@ grpc_mdelem grpc_static_mdelem_for_static_strings(int a, int b) { grpc_mdelem_data grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT] = { {{&grpc_static_metadata_refcounts[7], {{g_bytes + 50, 11}}}, - {&grpc_static_metadata_refcounts[29], {{g_bytes + 430, 1}}}}, + {&grpc_static_metadata_refcounts[32], {{g_bytes + 468, 1}}}}, {{&grpc_static_metadata_refcounts[7], {{g_bytes + 50, 11}}}, - {&grpc_static_metadata_refcounts[30], {{g_bytes + 431, 1}}}}, + {&grpc_static_metadata_refcounts[33], {{g_bytes + 469, 1}}}}, {{&grpc_static_metadata_refcounts[7], {{g_bytes + 50, 11}}}, - {&grpc_static_metadata_refcounts[31], {{g_bytes + 432, 1}}}}, + {&grpc_static_metadata_refcounts[34], {{g_bytes + 470, 1}}}}, {{&grpc_static_metadata_refcounts[9], {{g_bytes + 77, 13}}}, - {&grpc_static_metadata_refcounts[32], {{g_bytes + 433, 8}}}}, + {&grpc_static_metadata_refcounts[35], {{g_bytes + 471, 8}}}}, {{&grpc_static_metadata_refcounts[9], {{g_bytes + 77, 13}}}, - {&grpc_static_metadata_refcounts[33], {{g_bytes + 441, 4}}}}, + {&grpc_static_metadata_refcounts[36], {{g_bytes + 479, 4}}}}, {{&grpc_static_metadata_refcounts[9], {{g_bytes + 77, 13}}}, - {&grpc_static_metadata_refcounts[34], {{g_bytes + 445, 7}}}}, + {&grpc_static_metadata_refcounts[37], {{g_bytes + 483, 7}}}}, {{&grpc_static_metadata_refcounts[5], {{g_bytes + 36, 2}}}, - {&grpc_static_metadata_refcounts[35], {{g_bytes + 452, 8}}}}, + {&grpc_static_metadata_refcounts[38], {{g_bytes + 490, 8}}}}, {{&grpc_static_metadata_refcounts[14], {{g_bytes + 158, 12}}}, - {&grpc_static_metadata_refcounts[36], {{g_bytes + 460, 16}}}}, + {&grpc_static_metadata_refcounts[39], {{g_bytes + 498, 16}}}}, {{&grpc_static_metadata_refcounts[1], {{g_bytes + 5, 7}}}, - {&grpc_static_metadata_refcounts[37], {{g_bytes + 476, 4}}}}, + {&grpc_static_metadata_refcounts[40], {{g_bytes + 514, 4}}}}, {{&grpc_static_metadata_refcounts[2], {{g_bytes + 12, 7}}}, - {&grpc_static_metadata_refcounts[38], {{g_bytes + 480, 3}}}}, + {&grpc_static_metadata_refcounts[41], {{g_bytes + 518, 3}}}}, {{&grpc_static_metadata_refcounts[2], {{g_bytes + 12, 7}}}, - {&grpc_static_metadata_refcounts[39], {{g_bytes + 483, 3}}}}, + {&grpc_static_metadata_refcounts[42], {{g_bytes + 521, 3}}}}, {{&grpc_static_metadata_refcounts[4], {{g_bytes + 29, 7}}}, - {&grpc_static_metadata_refcounts[40], {{g_bytes + 486, 4}}}}, + {&grpc_static_metadata_refcounts[43], {{g_bytes + 524, 4}}}}, {{&grpc_static_metadata_refcounts[4], {{g_bytes + 29, 7}}}, - {&grpc_static_metadata_refcounts[41], {{g_bytes + 490, 5}}}}, + {&grpc_static_metadata_refcounts[44], {{g_bytes + 528, 5}}}}, {{&grpc_static_metadata_refcounts[4], {{g_bytes + 29, 7}}}, - {&grpc_static_metadata_refcounts[42], {{g_bytes + 495, 4}}}}, + {&grpc_static_metadata_refcounts[45], {{g_bytes + 533, 4}}}}, {{&grpc_static_metadata_refcounts[3], {{g_bytes + 19, 10}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, {{&grpc_static_metadata_refcounts[1], {{g_bytes + 5, 7}}}, - {&grpc_static_metadata_refcounts[43], {{g_bytes + 499, 3}}}}, + {&grpc_static_metadata_refcounts[46], {{g_bytes + 537, 3}}}}, {{&grpc_static_metadata_refcounts[1], {{g_bytes + 5, 7}}}, - {&grpc_static_metadata_refcounts[44], {{g_bytes + 502, 3}}}}, + {&grpc_static_metadata_refcounts[47], {{g_bytes + 540, 3}}}}, {{&grpc_static_metadata_refcounts[0], {{g_bytes + 0, 5}}}, - {&grpc_static_metadata_refcounts[45], {{g_bytes + 505, 1}}}}, + {&grpc_static_metadata_refcounts[48], {{g_bytes + 543, 1}}}}, {{&grpc_static_metadata_refcounts[0], {{g_bytes + 0, 5}}}, - {&grpc_static_metadata_refcounts[46], {{g_bytes + 506, 11}}}}, + {&grpc_static_metadata_refcounts[49], {{g_bytes + 544, 11}}}}, {{&grpc_static_metadata_refcounts[2], {{g_bytes + 12, 7}}}, - {&grpc_static_metadata_refcounts[47], {{g_bytes + 517, 3}}}}, + {&grpc_static_metadata_refcounts[50], {{g_bytes + 555, 3}}}}, {{&grpc_static_metadata_refcounts[2], {{g_bytes + 12, 7}}}, - {&grpc_static_metadata_refcounts[48], {{g_bytes + 520, 3}}}}, + {&grpc_static_metadata_refcounts[51], {{g_bytes + 558, 3}}}}, {{&grpc_static_metadata_refcounts[2], {{g_bytes + 12, 7}}}, - {&grpc_static_metadata_refcounts[49], {{g_bytes + 523, 3}}}}, + {&grpc_static_metadata_refcounts[52], {{g_bytes + 561, 3}}}}, {{&grpc_static_metadata_refcounts[2], {{g_bytes + 12, 7}}}, - {&grpc_static_metadata_refcounts[50], {{g_bytes + 526, 3}}}}, + {&grpc_static_metadata_refcounts[53], {{g_bytes + 564, 3}}}}, {{&grpc_static_metadata_refcounts[2], {{g_bytes + 12, 7}}}, - {&grpc_static_metadata_refcounts[51], {{g_bytes + 529, 3}}}}, - {{&grpc_static_metadata_refcounts[52], {{g_bytes + 532, 14}}}, + {&grpc_static_metadata_refcounts[54], {{g_bytes + 567, 3}}}}, + {{&grpc_static_metadata_refcounts[55], {{g_bytes + 570, 14}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, {{&grpc_static_metadata_refcounts[16], {{g_bytes + 186, 15}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, {{&grpc_static_metadata_refcounts[16], {{g_bytes + 186, 15}}}, - {&grpc_static_metadata_refcounts[53], {{g_bytes + 546, 13}}}}, - {{&grpc_static_metadata_refcounts[54], {{g_bytes + 559, 15}}}, + {&grpc_static_metadata_refcounts[56], {{g_bytes + 584, 13}}}}, + {{&grpc_static_metadata_refcounts[57], {{g_bytes + 597, 15}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[55], {{g_bytes + 574, 13}}}, + {{&grpc_static_metadata_refcounts[58], {{g_bytes + 612, 13}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[56], {{g_bytes + 587, 6}}}, + {{&grpc_static_metadata_refcounts[59], {{g_bytes + 625, 6}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[57], {{g_bytes + 593, 27}}}, + {{&grpc_static_metadata_refcounts[60], {{g_bytes + 631, 27}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[58], {{g_bytes + 620, 3}}}, + {{&grpc_static_metadata_refcounts[61], {{g_bytes + 658, 3}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[59], {{g_bytes + 623, 5}}}, + {{&grpc_static_metadata_refcounts[62], {{g_bytes + 661, 5}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[60], {{g_bytes + 628, 13}}}, + {{&grpc_static_metadata_refcounts[63], {{g_bytes + 666, 13}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[61], {{g_bytes + 641, 13}}}, + {{&grpc_static_metadata_refcounts[64], {{g_bytes + 679, 13}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[62], {{g_bytes + 654, 19}}}, + {{&grpc_static_metadata_refcounts[65], {{g_bytes + 692, 19}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, {{&grpc_static_metadata_refcounts[15], {{g_bytes + 170, 16}}}, - {&grpc_static_metadata_refcounts[32], {{g_bytes + 433, 8}}}}, + {&grpc_static_metadata_refcounts[35], {{g_bytes + 471, 8}}}}, {{&grpc_static_metadata_refcounts[15], {{g_bytes + 170, 16}}}, - {&grpc_static_metadata_refcounts[33], {{g_bytes + 441, 4}}}}, + {&grpc_static_metadata_refcounts[36], {{g_bytes + 479, 4}}}}, {{&grpc_static_metadata_refcounts[15], {{g_bytes + 170, 16}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[63], {{g_bytes + 673, 16}}}, + {{&grpc_static_metadata_refcounts[66], {{g_bytes + 711, 16}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[64], {{g_bytes + 689, 14}}}, + {{&grpc_static_metadata_refcounts[67], {{g_bytes + 727, 14}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[65], {{g_bytes + 703, 16}}}, + {{&grpc_static_metadata_refcounts[68], {{g_bytes + 741, 16}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[66], {{g_bytes + 719, 13}}}, + {{&grpc_static_metadata_refcounts[69], {{g_bytes + 757, 13}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, {{&grpc_static_metadata_refcounts[14], {{g_bytes + 158, 12}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[67], {{g_bytes + 732, 6}}}, + {{&grpc_static_metadata_refcounts[70], {{g_bytes + 770, 6}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[68], {{g_bytes + 738, 4}}}, + {{&grpc_static_metadata_refcounts[71], {{g_bytes + 776, 4}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[69], {{g_bytes + 742, 4}}}, + {{&grpc_static_metadata_refcounts[72], {{g_bytes + 780, 4}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[70], {{g_bytes + 746, 6}}}, + {{&grpc_static_metadata_refcounts[73], {{g_bytes + 784, 6}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[71], {{g_bytes + 752, 7}}}, + {{&grpc_static_metadata_refcounts[74], {{g_bytes + 790, 7}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[72], {{g_bytes + 759, 4}}}, + {{&grpc_static_metadata_refcounts[75], {{g_bytes + 797, 4}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, {{&grpc_static_metadata_refcounts[20], {{g_bytes + 278, 4}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[73], {{g_bytes + 763, 8}}}, + {{&grpc_static_metadata_refcounts[76], {{g_bytes + 801, 8}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[74], {{g_bytes + 771, 17}}}, + {{&grpc_static_metadata_refcounts[77], {{g_bytes + 809, 17}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[75], {{g_bytes + 788, 13}}}, + {{&grpc_static_metadata_refcounts[78], {{g_bytes + 826, 13}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[76], {{g_bytes + 801, 8}}}, + {{&grpc_static_metadata_refcounts[79], {{g_bytes + 839, 8}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[77], {{g_bytes + 809, 19}}}, + {{&grpc_static_metadata_refcounts[80], {{g_bytes + 847, 19}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[78], {{g_bytes + 828, 13}}}, + {{&grpc_static_metadata_refcounts[81], {{g_bytes + 866, 13}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, {{&grpc_static_metadata_refcounts[21], {{g_bytes + 282, 8}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[79], {{g_bytes + 841, 11}}}, + {{&grpc_static_metadata_refcounts[82], {{g_bytes + 879, 11}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[80], {{g_bytes + 852, 4}}}, + {{&grpc_static_metadata_refcounts[83], {{g_bytes + 890, 4}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[81], {{g_bytes + 856, 8}}}, + {{&grpc_static_metadata_refcounts[84], {{g_bytes + 894, 8}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[82], {{g_bytes + 864, 12}}}, + {{&grpc_static_metadata_refcounts[85], {{g_bytes + 902, 12}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[83], {{g_bytes + 876, 18}}}, + {{&grpc_static_metadata_refcounts[86], {{g_bytes + 914, 18}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[84], {{g_bytes + 894, 19}}}, + {{&grpc_static_metadata_refcounts[87], {{g_bytes + 932, 19}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[85], {{g_bytes + 913, 5}}}, + {{&grpc_static_metadata_refcounts[88], {{g_bytes + 951, 5}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[86], {{g_bytes + 918, 7}}}, + {{&grpc_static_metadata_refcounts[89], {{g_bytes + 956, 7}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[87], {{g_bytes + 925, 7}}}, + {{&grpc_static_metadata_refcounts[90], {{g_bytes + 963, 7}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[88], {{g_bytes + 932, 11}}}, + {{&grpc_static_metadata_refcounts[91], {{g_bytes + 970, 11}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[89], {{g_bytes + 943, 6}}}, + {{&grpc_static_metadata_refcounts[92], {{g_bytes + 981, 6}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[90], {{g_bytes + 949, 10}}}, + {{&grpc_static_metadata_refcounts[93], {{g_bytes + 987, 10}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[91], {{g_bytes + 959, 25}}}, + {{&grpc_static_metadata_refcounts[94], {{g_bytes + 997, 25}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[92], {{g_bytes + 984, 17}}}, + {{&grpc_static_metadata_refcounts[95], {{g_bytes + 1022, 17}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, {{&grpc_static_metadata_refcounts[19], {{g_bytes + 268, 10}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[93], {{g_bytes + 1001, 4}}}, + {{&grpc_static_metadata_refcounts[96], {{g_bytes + 1039, 4}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[94], {{g_bytes + 1005, 3}}}, + {{&grpc_static_metadata_refcounts[97], {{g_bytes + 1043, 3}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, - {{&grpc_static_metadata_refcounts[95], {{g_bytes + 1008, 16}}}, + {{&grpc_static_metadata_refcounts[98], {{g_bytes + 1046, 16}}}, {&grpc_static_metadata_refcounts[23], {{g_bytes + 302, 0}}}}, {{&grpc_static_metadata_refcounts[10], {{g_bytes + 90, 20}}}, - {&grpc_static_metadata_refcounts[32], {{g_bytes + 433, 8}}}}, + {&grpc_static_metadata_refcounts[35], {{g_bytes + 471, 8}}}}, {{&grpc_static_metadata_refcounts[10], {{g_bytes + 90, 20}}}, - {&grpc_static_metadata_refcounts[34], {{g_bytes + 445, 7}}}}, + {&grpc_static_metadata_refcounts[37], {{g_bytes + 483, 7}}}}, {{&grpc_static_metadata_refcounts[10], {{g_bytes + 90, 20}}}, - {&grpc_static_metadata_refcounts[96], {{g_bytes + 1024, 16}}}}, + {&grpc_static_metadata_refcounts[99], {{g_bytes + 1062, 16}}}}, {{&grpc_static_metadata_refcounts[10], {{g_bytes + 90, 20}}}, - {&grpc_static_metadata_refcounts[33], {{g_bytes + 441, 4}}}}, + {&grpc_static_metadata_refcounts[36], {{g_bytes + 479, 4}}}}, {{&grpc_static_metadata_refcounts[10], {{g_bytes + 90, 20}}}, - {&grpc_static_metadata_refcounts[97], {{g_bytes + 1040, 13}}}}, + {&grpc_static_metadata_refcounts[100], {{g_bytes + 1078, 13}}}}, {{&grpc_static_metadata_refcounts[10], {{g_bytes + 90, 20}}}, - {&grpc_static_metadata_refcounts[98], {{g_bytes + 1053, 12}}}}, + {&grpc_static_metadata_refcounts[101], {{g_bytes + 1091, 12}}}}, {{&grpc_static_metadata_refcounts[10], {{g_bytes + 90, 20}}}, - {&grpc_static_metadata_refcounts[99], {{g_bytes + 1065, 21}}}}, + {&grpc_static_metadata_refcounts[102], {{g_bytes + 1103, 21}}}}, {{&grpc_static_metadata_refcounts[16], {{g_bytes + 186, 15}}}, - {&grpc_static_metadata_refcounts[32], {{g_bytes + 433, 8}}}}, + {&grpc_static_metadata_refcounts[35], {{g_bytes + 471, 8}}}}, {{&grpc_static_metadata_refcounts[16], {{g_bytes + 186, 15}}}, - {&grpc_static_metadata_refcounts[33], {{g_bytes + 441, 4}}}}, + {&grpc_static_metadata_refcounts[36], {{g_bytes + 479, 4}}}}, {{&grpc_static_metadata_refcounts[16], {{g_bytes + 186, 15}}}, - {&grpc_static_metadata_refcounts[97], {{g_bytes + 1040, 13}}}}, + {&grpc_static_metadata_refcounts[100], {{g_bytes + 1078, 13}}}}, }; bool grpc_static_callout_is_default[GRPC_BATCH_CALLOUTS_COUNT] = { true, // :path diff --git a/src/core/lib/transport/static_metadata.h b/src/core/lib/transport/static_metadata.h index ce3a11b009..21dc7a3d3f 100644 --- a/src/core/lib/transport/static_metadata.h +++ b/src/core/lib/transport/static_metadata.h @@ -29,7 +29,7 @@ #include "src/core/lib/transport/metadata.h" -#define GRPC_STATIC_MDSTR_COUNT 100 +#define GRPC_STATIC_MDSTR_COUNT 103 extern const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT]; /* ":path" */ #define GRPC_MDSTR_PATH (grpc_static_slice_table[0]) @@ -93,149 +93,155 @@ extern const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT]; /* "/grpc.lb.v1.LoadBalancer/BalanceLoad" */ #define GRPC_MDSTR_SLASH_GRPC_DOT_LB_DOT_V1_DOT_LOADBALANCER_SLASH_BALANCELOAD \ (grpc_static_slice_table[28]) +/* "message/deflate" */ +#define GRPC_MDSTR_MESSAGE_SLASH_DEFLATE (grpc_static_slice_table[29]) +/* "message/gzip" */ +#define GRPC_MDSTR_MESSAGE_SLASH_GZIP (grpc_static_slice_table[30]) +/* "stream/gzip" */ +#define GRPC_MDSTR_STREAM_SLASH_GZIP (grpc_static_slice_table[31]) /* "0" */ -#define GRPC_MDSTR_0 (grpc_static_slice_table[29]) +#define GRPC_MDSTR_0 (grpc_static_slice_table[32]) /* "1" */ -#define GRPC_MDSTR_1 (grpc_static_slice_table[30]) +#define GRPC_MDSTR_1 (grpc_static_slice_table[33]) /* "2" */ -#define GRPC_MDSTR_2 (grpc_static_slice_table[31]) +#define GRPC_MDSTR_2 (grpc_static_slice_table[34]) /* "identity" */ -#define GRPC_MDSTR_IDENTITY (grpc_static_slice_table[32]) +#define GRPC_MDSTR_IDENTITY (grpc_static_slice_table[35]) /* "gzip" */ -#define GRPC_MDSTR_GZIP (grpc_static_slice_table[33]) +#define GRPC_MDSTR_GZIP (grpc_static_slice_table[36]) /* "deflate" */ -#define GRPC_MDSTR_DEFLATE (grpc_static_slice_table[34]) +#define GRPC_MDSTR_DEFLATE (grpc_static_slice_table[37]) /* "trailers" */ -#define GRPC_MDSTR_TRAILERS (grpc_static_slice_table[35]) +#define GRPC_MDSTR_TRAILERS (grpc_static_slice_table[38]) /* "application/grpc" */ -#define GRPC_MDSTR_APPLICATION_SLASH_GRPC (grpc_static_slice_table[36]) +#define GRPC_MDSTR_APPLICATION_SLASH_GRPC (grpc_static_slice_table[39]) /* "POST" */ -#define GRPC_MDSTR_POST (grpc_static_slice_table[37]) +#define GRPC_MDSTR_POST (grpc_static_slice_table[40]) /* "200" */ -#define GRPC_MDSTR_200 (grpc_static_slice_table[38]) +#define GRPC_MDSTR_200 (grpc_static_slice_table[41]) /* "404" */ -#define GRPC_MDSTR_404 (grpc_static_slice_table[39]) +#define GRPC_MDSTR_404 (grpc_static_slice_table[42]) /* "http" */ -#define GRPC_MDSTR_HTTP (grpc_static_slice_table[40]) +#define GRPC_MDSTR_HTTP (grpc_static_slice_table[43]) /* "https" */ -#define GRPC_MDSTR_HTTPS (grpc_static_slice_table[41]) +#define GRPC_MDSTR_HTTPS (grpc_static_slice_table[44]) /* "grpc" */ -#define GRPC_MDSTR_GRPC (grpc_static_slice_table[42]) +#define GRPC_MDSTR_GRPC (grpc_static_slice_table[45]) /* "GET" */ -#define GRPC_MDSTR_GET (grpc_static_slice_table[43]) +#define GRPC_MDSTR_GET (grpc_static_slice_table[46]) /* "PUT" */ -#define GRPC_MDSTR_PUT (grpc_static_slice_table[44]) +#define GRPC_MDSTR_PUT (grpc_static_slice_table[47]) /* "/" */ -#define GRPC_MDSTR_SLASH (grpc_static_slice_table[45]) +#define GRPC_MDSTR_SLASH (grpc_static_slice_table[48]) /* "/index.html" */ -#define GRPC_MDSTR_SLASH_INDEX_DOT_HTML (grpc_static_slice_table[46]) +#define GRPC_MDSTR_SLASH_INDEX_DOT_HTML (grpc_static_slice_table[49]) /* "204" */ -#define GRPC_MDSTR_204 (grpc_static_slice_table[47]) +#define GRPC_MDSTR_204 (grpc_static_slice_table[50]) /* "206" */ -#define GRPC_MDSTR_206 (grpc_static_slice_table[48]) +#define GRPC_MDSTR_206 (grpc_static_slice_table[51]) /* "304" */ -#define GRPC_MDSTR_304 (grpc_static_slice_table[49]) +#define GRPC_MDSTR_304 (grpc_static_slice_table[52]) /* "400" */ -#define GRPC_MDSTR_400 (grpc_static_slice_table[50]) +#define GRPC_MDSTR_400 (grpc_static_slice_table[53]) /* "500" */ -#define GRPC_MDSTR_500 (grpc_static_slice_table[51]) +#define GRPC_MDSTR_500 (grpc_static_slice_table[54]) /* "accept-charset" */ -#define GRPC_MDSTR_ACCEPT_CHARSET (grpc_static_slice_table[52]) +#define GRPC_MDSTR_ACCEPT_CHARSET (grpc_static_slice_table[55]) /* "gzip, deflate" */ -#define GRPC_MDSTR_GZIP_COMMA_DEFLATE (grpc_static_slice_table[53]) +#define GRPC_MDSTR_GZIP_COMMA_DEFLATE (grpc_static_slice_table[56]) /* "accept-language" */ -#define GRPC_MDSTR_ACCEPT_LANGUAGE (grpc_static_slice_table[54]) +#define GRPC_MDSTR_ACCEPT_LANGUAGE (grpc_static_slice_table[57]) /* "accept-ranges" */ -#define GRPC_MDSTR_ACCEPT_RANGES (grpc_static_slice_table[55]) +#define GRPC_MDSTR_ACCEPT_RANGES (grpc_static_slice_table[58]) /* "accept" */ -#define GRPC_MDSTR_ACCEPT (grpc_static_slice_table[56]) +#define GRPC_MDSTR_ACCEPT (grpc_static_slice_table[59]) /* "access-control-allow-origin" */ -#define GRPC_MDSTR_ACCESS_CONTROL_ALLOW_ORIGIN (grpc_static_slice_table[57]) +#define GRPC_MDSTR_ACCESS_CONTROL_ALLOW_ORIGIN (grpc_static_slice_table[60]) /* "age" */ -#define GRPC_MDSTR_AGE (grpc_static_slice_table[58]) +#define GRPC_MDSTR_AGE (grpc_static_slice_table[61]) /* "allow" */ -#define GRPC_MDSTR_ALLOW (grpc_static_slice_table[59]) +#define GRPC_MDSTR_ALLOW (grpc_static_slice_table[62]) /* "authorization" */ -#define GRPC_MDSTR_AUTHORIZATION (grpc_static_slice_table[60]) +#define GRPC_MDSTR_AUTHORIZATION (grpc_static_slice_table[63]) /* "cache-control" */ -#define GRPC_MDSTR_CACHE_CONTROL (grpc_static_slice_table[61]) +#define GRPC_MDSTR_CACHE_CONTROL (grpc_static_slice_table[64]) /* "content-disposition" */ -#define GRPC_MDSTR_CONTENT_DISPOSITION (grpc_static_slice_table[62]) +#define GRPC_MDSTR_CONTENT_DISPOSITION (grpc_static_slice_table[65]) /* "content-language" */ -#define GRPC_MDSTR_CONTENT_LANGUAGE (grpc_static_slice_table[63]) +#define GRPC_MDSTR_CONTENT_LANGUAGE (grpc_static_slice_table[66]) /* "content-length" */ -#define GRPC_MDSTR_CONTENT_LENGTH (grpc_static_slice_table[64]) +#define GRPC_MDSTR_CONTENT_LENGTH (grpc_static_slice_table[67]) /* "content-location" */ -#define GRPC_MDSTR_CONTENT_LOCATION (grpc_static_slice_table[65]) +#define GRPC_MDSTR_CONTENT_LOCATION (grpc_static_slice_table[68]) /* "content-range" */ -#define GRPC_MDSTR_CONTENT_RANGE (grpc_static_slice_table[66]) +#define GRPC_MDSTR_CONTENT_RANGE (grpc_static_slice_table[69]) /* "cookie" */ -#define GRPC_MDSTR_COOKIE (grpc_static_slice_table[67]) +#define GRPC_MDSTR_COOKIE (grpc_static_slice_table[70]) /* "date" */ -#define GRPC_MDSTR_DATE (grpc_static_slice_table[68]) +#define GRPC_MDSTR_DATE (grpc_static_slice_table[71]) /* "etag" */ -#define GRPC_MDSTR_ETAG (grpc_static_slice_table[69]) +#define GRPC_MDSTR_ETAG (grpc_static_slice_table[72]) /* "expect" */ -#define GRPC_MDSTR_EXPECT (grpc_static_slice_table[70]) +#define GRPC_MDSTR_EXPECT (grpc_static_slice_table[73]) /* "expires" */ -#define GRPC_MDSTR_EXPIRES (grpc_static_slice_table[71]) +#define GRPC_MDSTR_EXPIRES (grpc_static_slice_table[74]) /* "from" */ -#define GRPC_MDSTR_FROM (grpc_static_slice_table[72]) +#define GRPC_MDSTR_FROM (grpc_static_slice_table[75]) /* "if-match" */ -#define GRPC_MDSTR_IF_MATCH (grpc_static_slice_table[73]) +#define GRPC_MDSTR_IF_MATCH (grpc_static_slice_table[76]) /* "if-modified-since" */ -#define GRPC_MDSTR_IF_MODIFIED_SINCE (grpc_static_slice_table[74]) +#define GRPC_MDSTR_IF_MODIFIED_SINCE (grpc_static_slice_table[77]) /* "if-none-match" */ -#define GRPC_MDSTR_IF_NONE_MATCH (grpc_static_slice_table[75]) +#define GRPC_MDSTR_IF_NONE_MATCH (grpc_static_slice_table[78]) /* "if-range" */ -#define GRPC_MDSTR_IF_RANGE (grpc_static_slice_table[76]) +#define GRPC_MDSTR_IF_RANGE (grpc_static_slice_table[79]) /* "if-unmodified-since" */ -#define GRPC_MDSTR_IF_UNMODIFIED_SINCE (grpc_static_slice_table[77]) +#define GRPC_MDSTR_IF_UNMODIFIED_SINCE (grpc_static_slice_table[80]) /* "last-modified" */ -#define GRPC_MDSTR_LAST_MODIFIED (grpc_static_slice_table[78]) +#define GRPC_MDSTR_LAST_MODIFIED (grpc_static_slice_table[81]) /* "lb-cost-bin" */ -#define GRPC_MDSTR_LB_COST_BIN (grpc_static_slice_table[79]) +#define GRPC_MDSTR_LB_COST_BIN (grpc_static_slice_table[82]) /* "link" */ -#define GRPC_MDSTR_LINK (grpc_static_slice_table[80]) +#define GRPC_MDSTR_LINK (grpc_static_slice_table[83]) /* "location" */ -#define GRPC_MDSTR_LOCATION (grpc_static_slice_table[81]) +#define GRPC_MDSTR_LOCATION (grpc_static_slice_table[84]) /* "max-forwards" */ -#define GRPC_MDSTR_MAX_FORWARDS (grpc_static_slice_table[82]) +#define GRPC_MDSTR_MAX_FORWARDS (grpc_static_slice_table[85]) /* "proxy-authenticate" */ -#define GRPC_MDSTR_PROXY_AUTHENTICATE (grpc_static_slice_table[83]) +#define GRPC_MDSTR_PROXY_AUTHENTICATE (grpc_static_slice_table[86]) /* "proxy-authorization" */ -#define GRPC_MDSTR_PROXY_AUTHORIZATION (grpc_static_slice_table[84]) +#define GRPC_MDSTR_PROXY_AUTHORIZATION (grpc_static_slice_table[87]) /* "range" */ -#define GRPC_MDSTR_RANGE (grpc_static_slice_table[85]) +#define GRPC_MDSTR_RANGE (grpc_static_slice_table[88]) /* "referer" */ -#define GRPC_MDSTR_REFERER (grpc_static_slice_table[86]) +#define GRPC_MDSTR_REFERER (grpc_static_slice_table[89]) /* "refresh" */ -#define GRPC_MDSTR_REFRESH (grpc_static_slice_table[87]) +#define GRPC_MDSTR_REFRESH (grpc_static_slice_table[90]) /* "retry-after" */ -#define GRPC_MDSTR_RETRY_AFTER (grpc_static_slice_table[88]) +#define GRPC_MDSTR_RETRY_AFTER (grpc_static_slice_table[91]) /* "server" */ -#define GRPC_MDSTR_SERVER (grpc_static_slice_table[89]) +#define GRPC_MDSTR_SERVER (grpc_static_slice_table[92]) /* "set-cookie" */ -#define GRPC_MDSTR_SET_COOKIE (grpc_static_slice_table[90]) +#define GRPC_MDSTR_SET_COOKIE (grpc_static_slice_table[93]) /* "strict-transport-security" */ -#define GRPC_MDSTR_STRICT_TRANSPORT_SECURITY (grpc_static_slice_table[91]) +#define GRPC_MDSTR_STRICT_TRANSPORT_SECURITY (grpc_static_slice_table[94]) /* "transfer-encoding" */ -#define GRPC_MDSTR_TRANSFER_ENCODING (grpc_static_slice_table[92]) +#define GRPC_MDSTR_TRANSFER_ENCODING (grpc_static_slice_table[95]) /* "vary" */ -#define GRPC_MDSTR_VARY (grpc_static_slice_table[93]) +#define GRPC_MDSTR_VARY (grpc_static_slice_table[96]) /* "via" */ -#define GRPC_MDSTR_VIA (grpc_static_slice_table[94]) +#define GRPC_MDSTR_VIA (grpc_static_slice_table[97]) /* "www-authenticate" */ -#define GRPC_MDSTR_WWW_AUTHENTICATE (grpc_static_slice_table[95]) +#define GRPC_MDSTR_WWW_AUTHENTICATE (grpc_static_slice_table[98]) /* "identity,deflate" */ -#define GRPC_MDSTR_IDENTITY_COMMA_DEFLATE (grpc_static_slice_table[96]) +#define GRPC_MDSTR_IDENTITY_COMMA_DEFLATE (grpc_static_slice_table[99]) /* "identity,gzip" */ -#define GRPC_MDSTR_IDENTITY_COMMA_GZIP (grpc_static_slice_table[97]) +#define GRPC_MDSTR_IDENTITY_COMMA_GZIP (grpc_static_slice_table[100]) /* "deflate,gzip" */ -#define GRPC_MDSTR_DEFLATE_COMMA_GZIP (grpc_static_slice_table[98]) +#define GRPC_MDSTR_DEFLATE_COMMA_GZIP (grpc_static_slice_table[101]) /* "identity,deflate,gzip" */ #define GRPC_MDSTR_IDENTITY_COMMA_DEFLATE_COMMA_GZIP \ - (grpc_static_slice_table[99]) + (grpc_static_slice_table[102]) extern const grpc_slice_refcount_vtable grpc_static_metadata_vtable; extern grpc_slice_refcount diff --git a/src/core/tsi/ssl_transport_security.cc b/src/core/tsi/ssl_transport_security.cc index 229f7efd37..b396a621bd 100644 --- a/src/core/tsi/ssl_transport_security.cc +++ b/src/core/tsi/ssl_transport_security.cc @@ -96,8 +96,7 @@ struct tsi_ssl_server_handshaker_factory { typedef struct { tsi_handshaker base; SSL* ssl; - BIO* into_ssl; - BIO* from_ssl; + BIO* network_io; tsi_result result; tsi_ssl_handshaker_factory* factory_ref; } tsi_ssl_handshaker; @@ -105,8 +104,7 @@ typedef struct { typedef struct { tsi_frame_protector base; SSL* ssl; - BIO* into_ssl; - BIO* from_ssl; + BIO* network_io; unsigned char* buffer; size_t buffer_size; size_t buffer_offset; @@ -730,11 +728,11 @@ static tsi_result ssl_protector_protect(tsi_frame_protector* self, tsi_result result = TSI_OK; /* First see if we have some pending data in the SSL BIO. */ - int pending_in_ssl = (int)BIO_pending(impl->from_ssl); + int pending_in_ssl = (int)BIO_pending(impl->network_io); if (pending_in_ssl > 0) { *unprotected_bytes_size = 0; GPR_ASSERT(*protected_output_frames_size <= INT_MAX); - read_from_ssl = BIO_read(impl->from_ssl, protected_output_frames, + read_from_ssl = BIO_read(impl->network_io, protected_output_frames, (int)*protected_output_frames_size); if (read_from_ssl < 0) { gpr_log(GPR_ERROR, @@ -762,7 +760,7 @@ static tsi_result ssl_protector_protect(tsi_frame_protector* self, if (result != TSI_OK) return result; GPR_ASSERT(*protected_output_frames_size <= INT_MAX); - read_from_ssl = BIO_read(impl->from_ssl, protected_output_frames, + read_from_ssl = BIO_read(impl->network_io, protected_output_frames, (int)*protected_output_frames_size); if (read_from_ssl < 0) { gpr_log(GPR_ERROR, "Could not read from BIO after SSL_write."); @@ -788,20 +786,20 @@ static tsi_result ssl_protector_protect_flush( impl->buffer_offset = 0; } - pending = (int)BIO_pending(impl->from_ssl); + pending = (int)BIO_pending(impl->network_io); GPR_ASSERT(pending >= 0); *still_pending_size = (size_t)pending; if (*still_pending_size == 0) return TSI_OK; GPR_ASSERT(*protected_output_frames_size <= INT_MAX); - read_from_ssl = BIO_read(impl->from_ssl, protected_output_frames, + read_from_ssl = BIO_read(impl->network_io, protected_output_frames, (int)*protected_output_frames_size); if (read_from_ssl <= 0) { gpr_log(GPR_ERROR, "Could not read from BIO after SSL_write."); return TSI_INTERNAL_ERROR; } *protected_output_frames_size = (size_t)read_from_ssl; - pending = (int)BIO_pending(impl->from_ssl); + pending = (int)BIO_pending(impl->network_io); GPR_ASSERT(pending >= 0); *still_pending_size = (size_t)pending; return TSI_OK; @@ -831,7 +829,7 @@ static tsi_result ssl_protector_unprotect( /* Then, try to write some data to ssl. */ GPR_ASSERT(*protected_frames_bytes_size <= INT_MAX); - written_into_ssl = BIO_write(impl->into_ssl, protected_frames_bytes, + written_into_ssl = BIO_write(impl->network_io, protected_frames_bytes, (int)*protected_frames_bytes_size); if (written_into_ssl < 0) { gpr_log(GPR_ERROR, "Sending protected frame to ssl failed with %d", @@ -853,6 +851,7 @@ static void ssl_protector_destroy(tsi_frame_protector* self) { tsi_ssl_frame_protector* impl = (tsi_ssl_frame_protector*)self; if (impl->buffer != nullptr) gpr_free(impl->buffer); if (impl->ssl != nullptr) SSL_free(impl->ssl); + if (impl->network_io != nullptr) BIO_free(impl->network_io); gpr_free(self); } @@ -916,10 +915,10 @@ static tsi_result ssl_handshaker_get_bytes_to_send_to_peer(tsi_handshaker* self, return TSI_INVALID_ARGUMENT; } GPR_ASSERT(*bytes_size <= INT_MAX); - bytes_read_from_ssl = BIO_read(impl->from_ssl, bytes, (int)*bytes_size); + bytes_read_from_ssl = BIO_read(impl->network_io, bytes, (int)*bytes_size); if (bytes_read_from_ssl < 0) { *bytes_size = 0; - if (!BIO_should_retry(impl->from_ssl)) { + if (!BIO_should_retry(impl->network_io)) { impl->result = TSI_INTERNAL_ERROR; return impl->result; } else { @@ -927,7 +926,7 @@ static tsi_result ssl_handshaker_get_bytes_to_send_to_peer(tsi_handshaker* self, } } *bytes_size = (size_t)bytes_read_from_ssl; - return BIO_pending(impl->from_ssl) == 0 ? TSI_OK : TSI_INCOMPLETE_DATA; + return BIO_pending(impl->network_io) == 0 ? TSI_OK : TSI_INCOMPLETE_DATA; } static tsi_result ssl_handshaker_get_result(tsi_handshaker* self) { @@ -948,7 +947,7 @@ static tsi_result ssl_handshaker_process_bytes_from_peer( } GPR_ASSERT(*bytes_size <= INT_MAX); bytes_written_into_ssl_size = - BIO_write(impl->into_ssl, bytes, (int)*bytes_size); + BIO_write(impl->network_io, bytes, (int)*bytes_size); if (bytes_written_into_ssl_size < 0) { gpr_log(GPR_ERROR, "Could not write to memory BIO."); impl->result = TSI_INTERNAL_ERROR; @@ -965,7 +964,7 @@ static tsi_result ssl_handshaker_process_bytes_from_peer( ssl_result = SSL_get_error(impl->ssl, ssl_result); switch (ssl_result) { case SSL_ERROR_WANT_READ: - if (BIO_pending(impl->from_ssl) == 0) { + if (BIO_pending(impl->network_io) == 0) { /* We need more data. */ return TSI_INCOMPLETE_DATA; } else { @@ -1058,12 +1057,13 @@ static tsi_result ssl_handshaker_create_frame_protector( return TSI_INTERNAL_ERROR; } - /* Transfer ownership of ssl to the frame protector. It is OK as the caller - * cannot call anything else but destroy on the handshaker after this call. */ + /* Transfer ownership of ssl and network_io to the frame protector. It is OK + * as the caller cannot call anything else but destroy on the handshaker + * after this call. */ protector_impl->ssl = impl->ssl; impl->ssl = nullptr; - protector_impl->into_ssl = impl->into_ssl; - protector_impl->from_ssl = impl->from_ssl; + protector_impl->network_io = impl->network_io; + impl->network_io = nullptr; protector_impl->base.vtable = &frame_protector_vtable; *protector = &protector_impl->base; @@ -1072,7 +1072,8 @@ static tsi_result ssl_handshaker_create_frame_protector( static void ssl_handshaker_destroy(tsi_handshaker* self) { tsi_ssl_handshaker* impl = (tsi_ssl_handshaker*)self; - SSL_free(impl->ssl); /* The BIO objects are owned by ssl */ + SSL_free(impl->ssl); + BIO_free(impl->network_io); tsi_ssl_handshaker_factory_unref(impl->factory_ref); gpr_free(impl); } @@ -1094,8 +1095,8 @@ static tsi_result create_tsi_ssl_handshaker(SSL_CTX* ctx, int is_client, tsi_ssl_handshaker_factory* factory, tsi_handshaker** handshaker) { SSL* ssl = SSL_new(ctx); - BIO* into_ssl = nullptr; - BIO* from_ssl = nullptr; + BIO* network_io = nullptr; + BIO* ssl_io = nullptr; tsi_ssl_handshaker* impl = nullptr; *handshaker = nullptr; if (ctx == nullptr) { @@ -1107,16 +1108,12 @@ static tsi_result create_tsi_ssl_handshaker(SSL_CTX* ctx, int is_client, } SSL_set_info_callback(ssl, ssl_info_callback); - into_ssl = BIO_new(BIO_s_mem()); - from_ssl = BIO_new(BIO_s_mem()); - if (into_ssl == nullptr || from_ssl == nullptr) { - gpr_log(GPR_ERROR, "BIO_new failed."); + if (!BIO_new_bio_pair(&network_io, 0, &ssl_io, 0)) { + gpr_log(GPR_ERROR, "BIO_new_bio_pair failed."); SSL_free(ssl); - if (into_ssl != nullptr) BIO_free(into_ssl); - if (from_ssl != nullptr) BIO_free(into_ssl); return TSI_OUT_OF_RESOURCES; } - SSL_set_bio(ssl, into_ssl, from_ssl); + SSL_set_bio(ssl, ssl_io, ssl_io); if (is_client) { int ssl_result; SSL_set_connect_state(ssl); @@ -1125,6 +1122,7 @@ static tsi_result create_tsi_ssl_handshaker(SSL_CTX* ctx, int is_client, gpr_log(GPR_ERROR, "Invalid server name indication %s.", server_name_indication); SSL_free(ssl); + BIO_free(network_io); return TSI_INTERNAL_ERROR; } } @@ -1135,6 +1133,7 @@ static tsi_result create_tsi_ssl_handshaker(SSL_CTX* ctx, int is_client, "Unexpected error received from first SSL_do_handshake call: %s", ssl_error_string(ssl_result)); SSL_free(ssl); + BIO_free(network_io); return TSI_INTERNAL_ERROR; } } else { @@ -1143,8 +1142,7 @@ static tsi_result create_tsi_ssl_handshaker(SSL_CTX* ctx, int is_client, impl = (tsi_ssl_handshaker*)gpr_zalloc(sizeof(*impl)); impl->ssl = ssl; - impl->into_ssl = into_ssl; - impl->from_ssl = from_ssl; + impl->network_io = network_io; impl->result = TSI_HANDSHAKE_IN_PROGRESS; impl->base.vtable = &handshaker_vtable; impl->factory_ref = tsi_ssl_handshaker_factory_ref(factory); diff --git a/src/csharp/Grpc.IntegrationTesting/InteropClient.cs b/src/csharp/Grpc.IntegrationTesting/InteropClient.cs index e83a8a7274..10c31c455e 100644 --- a/src/csharp/Grpc.IntegrationTesting/InteropClient.cs +++ b/src/csharp/Grpc.IntegrationTesting/InteropClient.cs @@ -685,7 +685,7 @@ namespace Grpc.IntegrationTesting private static Metadata CreateClientCompressionMetadata(bool compressed) { - var algorithmName = compressed ? "gzip" : "identity"; + var algorithmName = compressed ? "message/gzip" : "identity"; return new Metadata { { new Metadata.Entry(Metadata.CompressionRequestAlgorithmMetadataKey, algorithmName) } diff --git a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m index 805e54b890..d44e39f551 100644 --- a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m +++ b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m @@ -46,10 +46,10 @@ hostConfig.compressAlgorithm = GRPC_COMPRESS_NONE; break; case GRPCCompressDeflate: - hostConfig.compressAlgorithm = GRPC_COMPRESS_DEFLATE; + hostConfig.compressAlgorithm = GRPC_COMPRESS_MESSAGE_DEFLATE; break; case GRPCCompressGzip: - hostConfig.compressAlgorithm = GRPC_COMPRESS_GZIP; + hostConfig.compressAlgorithm = GRPC_COMPRESS_MESSAGE_GZIP; break; default: NSLog(@"Invalid compression algorithm"); diff --git a/src/objective-c/GRPCClient/private/GRPCWrappedCall.m b/src/objective-c/GRPCClient/private/GRPCWrappedCall.m index d26d13475d..9a0fa5954a 100644 --- a/src/objective-c/GRPCClient/private/GRPCWrappedCall.m +++ b/src/objective-c/GRPCClient/private/GRPCWrappedCall.m @@ -68,8 +68,6 @@ _op.data.send_initial_metadata.metadata = metadata.grpc_metadataArray; _op.data.send_initial_metadata.maybe_compression_level.is_set = false; _op.data.send_initial_metadata.maybe_compression_level.level = 0; - _op.data.send_initial_metadata.maybe_stream_compression_level.is_set = false; - _op.data.send_initial_metadata.maybe_stream_compression_level.level = 0; _op.flags = flags; _handler = handler; } diff --git a/src/php/ext/grpc/call.c b/src/php/ext/grpc/call.c index c4997f720d..ff55c3cbfa 100644 --- a/src/php/ext/grpc/call.c +++ b/src/php/ext/grpc/call.c @@ -99,6 +99,7 @@ zval *grpc_parse_metadata_array(grpc_metadata_array 1 TSRMLS_CC); efree(str_key); efree(str_val); + PHP_GRPC_FREE_STD_ZVAL(array); return NULL; } php_grpc_add_next_index_stringl(data, str_val, @@ -127,10 +128,12 @@ bool create_metadata_array(zval *array, grpc_metadata_array *metadata) { HashTable *inner_array_hash; zval *value; zval *inner_array; + grpc_metadata_array_init(metadata); + metadata->count = 0; + metadata->metadata = NULL; if (Z_TYPE_P(array) != IS_ARRAY) { return false; } - grpc_metadata_array_init(metadata); array_hash = Z_ARRVAL_P(array); char *key; @@ -174,6 +177,18 @@ bool create_metadata_array(zval *array, grpc_metadata_array *metadata) { return true; } +void grpc_php_metadata_array_destroy_including_entries( + grpc_metadata_array* array) { + size_t i; + if (array->metadata) { + for (i = 0; i < array->count; i++) { + grpc_slice_unref(array->metadata[i].key); + grpc_slice_unref(array->metadata[i].value); + } + } + grpc_metadata_array_destroy(array); +} + /* Wraps a grpc_call struct in a PHP object. Owned indicates whether the struct should be destroyed at the end of the object's lifecycle */ zval *grpc_php_wrap_call(grpc_call *wrapped, bool owned TSRMLS_DC) { @@ -502,8 +517,8 @@ PHP_METHOD(Call, startBatch) { } cleanup: - grpc_metadata_array_destroy(&metadata); - grpc_metadata_array_destroy(&trailing_metadata); + grpc_php_metadata_array_destroy_including_entries(&metadata); + grpc_php_metadata_array_destroy_including_entries(&trailing_metadata); grpc_metadata_array_destroy(&recv_metadata); grpc_metadata_array_destroy(&recv_trailing_metadata); grpc_slice_unref(recv_status_details); @@ -526,7 +541,9 @@ cleanup: */ PHP_METHOD(Call, getPeer) { wrapped_grpc_call *call = Z_WRAPPED_GRPC_CALL_P(getThis()); - PHP_GRPC_RETURN_STRING(grpc_call_get_peer(call->wrapped), 1); + char *peer = grpc_call_get_peer(call->wrapped); + PHP_GRPC_RETVAL_STRING(peer, 1); + gpr_free(peer); } /** diff --git a/src/php/ext/grpc/call.h b/src/php/ext/grpc/call.h index 5bde5d5390..104ac301c1 100644 --- a/src/php/ext/grpc/call.h +++ b/src/php/ext/grpc/call.h @@ -69,5 +69,6 @@ void grpc_init_call(TSRMLS_D); /* Populates a grpc_metadata_array with the data in a PHP array object. Returns true on success and false on failure */ bool create_metadata_array(zval *array, grpc_metadata_array *metadata); - +void grpc_php_metadata_array_destroy_including_entries( + grpc_metadata_array* array); #endif /* NET_GRPC_PHP_GRPC_CHANNEL_H_ */ diff --git a/src/php/ext/grpc/call_credentials.c b/src/php/ext/grpc/call_credentials.c index a395d53614..41c488a79c 100644 --- a/src/php/ext/grpc/call_credentials.c +++ b/src/php/ext/grpc/call_credentials.c @@ -120,6 +120,8 @@ PHP_METHOD(CallCredentials, createFromPlugin) { fci->params, fci->param_count) == FAILURE) { zend_throw_exception(spl_ce_InvalidArgumentException, "createFromPlugin expects 1 callback", 1 TSRMLS_CC); + free(fci); + free(fci_cache); return; } @@ -183,15 +185,17 @@ int plugin_get_metadata( *status = GRPC_STATUS_OK; *error_details = NULL; + bool should_return = false; grpc_metadata_array metadata; if (retval == NULL || Z_TYPE_P(retval) != IS_ARRAY) { *status = GRPC_STATUS_INVALID_ARGUMENT; - return true; // Synchronous return. + should_return = true; // Synchronous return. } if (!create_metadata_array(retval, &metadata)) { *status = GRPC_STATUS_INVALID_ARGUMENT; - return true; // Synchronous return. + should_return = true; // Synchronous return. + grpc_php_metadata_array_destroy_including_entries(&metadata); } if (retval != NULL) { @@ -204,6 +208,9 @@ int plugin_get_metadata( PHP_GRPC_FREE_STD_ZVAL(retval); #endif } + if (should_return) { + return true; + } if (metadata.count > GRPC_METADATA_CREDENTIALS_PLUGIN_SYNC_MAX) { *status = GRPC_STATUS_INTERNAL; diff --git a/src/php/ext/grpc/channel.c b/src/php/ext/grpc/channel.c index db59869c7f..4054723b43 100644 --- a/src/php/ext/grpc/channel.c +++ b/src/php/ext/grpc/channel.c @@ -41,6 +41,7 @@ #include <grpc/grpc.h> #include <grpc/grpc_security.h> +#include <grpc/support/alloc.h> #include "completion_queue.h" #include "channel_credentials.h" @@ -56,22 +57,63 @@ int le_plink; /* Frees and destroys an instance of wrapped_grpc_channel */ PHP_GRPC_FREE_WRAPPED_FUNC_START(wrapped_grpc_channel) + bool is_last_wrapper = false; + // In_persistent_list is used when the user don't close the channel. + // In this case, le in the list won't be freed. + bool in_persistent_list = true; if (p->wrapper != NULL) { gpr_mu_lock(&p->wrapper->mu); if (p->wrapper->wrapped != NULL) { - php_grpc_zend_resource *rsrc; - php_grpc_int key_len = strlen(p->wrapper->key); - // only destroy the channel here if not found in the persistent list - gpr_mu_lock(&global_persistent_list_mu); - if (!(PHP_GRPC_PERSISTENT_LIST_FIND(&EG(persistent_list), p->wrapper->key, - key_len, rsrc))) { - grpc_channel_destroy(p->wrapper->wrapped); - free(p->wrapper->target); - free(p->wrapper->args_hashstr); + if (p->wrapper->is_valid) { + php_grpc_zend_resource *rsrc; + php_grpc_int key_len = strlen(p->wrapper->key); + // only destroy the channel here if not found in the persistent list + gpr_mu_lock(&global_persistent_list_mu); + if (!(PHP_GRPC_PERSISTENT_LIST_FIND(&EG(persistent_list), p->wrapper->key, + key_len, rsrc))) { + in_persistent_list = false; + grpc_channel_destroy(p->wrapper->wrapped); + free(p->wrapper->target); + free(p->wrapper->args_hashstr); + if(p->wrapper->creds_hashstr != NULL){ + free(p->wrapper->creds_hashstr); + p->wrapper->creds_hashstr = NULL; + } + } + gpr_mu_unlock(&global_persistent_list_mu); } - gpr_mu_unlock(&global_persistent_list_mu); + } + p->wrapper->ref_count -= 1; + if (p->wrapper->ref_count == 0) { + is_last_wrapper = true; } gpr_mu_unlock(&p->wrapper->mu); + if (is_last_wrapper) { + if (in_persistent_list) { + // If ref_count==0 and the key still in the list, it means the user + // don't call channel->close().persistent list should free the + // allocation in such case, as well as related wrapped channel. + if (p->wrapper->wrapped != NULL) { + gpr_mu_lock(&p->wrapper->mu); + grpc_channel_destroy(p->wrapper->wrapped); + free(p->wrapper->target); + free(p->wrapper->args_hashstr); + if(p->wrapper->creds_hashstr != NULL){ + free(p->wrapper->creds_hashstr); + p->wrapper->creds_hashstr = NULL; + } + p->wrapper->wrapped = NULL; + php_grpc_delete_persistent_list_entry(p->wrapper->key, + strlen(p->wrapper->key) + TSRMLS_CC); + gpr_mu_unlock(&p->wrapper->mu); + } + } + gpr_mu_destroy(&p->wrapper->mu); + free(p->wrapper->key); + free(p->wrapper); + } + p->wrapper = NULL; } PHP_GRPC_FREE_WRAPPED_FUNC_END() @@ -276,9 +318,16 @@ PHP_METHOD(Channel, __construct) { channel->wrapper->key = key; channel->wrapper->target = strdup(target); channel->wrapper->args_hashstr = strdup(sha1str); + channel->wrapper->creds_hashstr = NULL; + channel->wrapper->ref_count = 1; + channel->wrapper->is_valid = true; if (creds != NULL && creds->hashstr != NULL) { - channel->wrapper->creds_hashstr = creds->hashstr; + php_grpc_int creds_hashstr_len = strlen(creds->hashstr); + char *channel_creds_hashstr = malloc(creds_hashstr_len + 1); + strcpy(channel_creds_hashstr, creds->hashstr); + channel->wrapper->creds_hashstr = channel_creds_hashstr; } + gpr_mu_init(&channel->wrapper->mu); smart_str_free(&buf); @@ -303,7 +352,17 @@ PHP_METHOD(Channel, __construct) { channel, target, args, creds, key, key_len TSRMLS_CC); } else { efree(args.args); + if (channel->wrapper->creds_hashstr != NULL){ + free(channel->wrapper->creds_hashstr); + channel->wrapper->creds_hashstr = NULL; + } + free(channel->wrapper->creds_hashstr); + free(channel->wrapper->key); + free(channel->wrapper->target); + free(channel->wrapper->args_hashstr); + free(channel->wrapper); channel->wrapper = le->channel; + channel->wrapper->ref_count += 1; } } } @@ -323,7 +382,8 @@ PHP_METHOD(Channel, getTarget) { } char *target = grpc_channel_get_target(channel->wrapper->wrapped); gpr_mu_unlock(&channel->wrapper->mu); - PHP_GRPC_RETURN_STRING(target, 1); + PHP_GRPC_RETVAL_STRING(target, 1); + gpr_free(target); } /** @@ -411,18 +471,46 @@ PHP_METHOD(Channel, watchConnectivityState) { */ PHP_METHOD(Channel, close) { wrapped_grpc_channel *channel = Z_WRAPPED_GRPC_CHANNEL_P(getThis()); - gpr_mu_lock(&channel->wrapper->mu); - if (channel->wrapper->wrapped != NULL) { - grpc_channel_destroy(channel->wrapper->wrapped); - free(channel->wrapper->target); - free(channel->wrapper->args_hashstr); - channel->wrapper->wrapped = NULL; - - php_grpc_delete_persistent_list_entry(channel->wrapper->key, - strlen(channel->wrapper->key) - TSRMLS_CC); + bool is_last_wrapper = false; + if (channel->wrapper != NULL) { + // Channel_wrapper hasn't call close before. + gpr_mu_lock(&channel->wrapper->mu); + if (channel->wrapper->wrapped != NULL) { + if (channel->wrapper->is_valid) { + // Wrapped channel hasn't been destoryed by other wrapper. + grpc_channel_destroy(channel->wrapper->wrapped); + free(channel->wrapper->target); + free(channel->wrapper->args_hashstr); + if(channel->wrapper->creds_hashstr != NULL){ + free(channel->wrapper->creds_hashstr); + channel->wrapper->creds_hashstr = NULL; + } + channel->wrapper->wrapped = NULL; + channel->wrapper->is_valid = false; + + php_grpc_delete_persistent_list_entry(channel->wrapper->key, + strlen(channel->wrapper->key) + TSRMLS_CC); + } + } + channel->wrapper->ref_count -= 1; + if(channel->wrapper->ref_count == 0){ + // Mark that the wrapper can be freed because mu should be + // destroyed outside the lock. + is_last_wrapper = true; + } + gpr_mu_unlock(&channel->wrapper->mu); } - gpr_mu_unlock(&channel->wrapper->mu); + gpr_mu_lock(&global_persistent_list_mu); + if (is_last_wrapper) { + gpr_mu_destroy(&channel->wrapper->mu); + free(channel->wrapper->key); + free(channel->wrapper); + } + // Set channel->wrapper to NULL to avoid call close twice for the same + // channel. + channel->wrapper = NULL; + gpr_mu_unlock(&global_persistent_list_mu); } // Delete an entry from the persistent list @@ -437,6 +525,7 @@ void php_grpc_delete_persistent_list_entry(char *key, php_grpc_int key_len le = (channel_persistent_le_t *)rsrc->ptr; le->channel = NULL; php_grpc_zend_hash_del(&EG(persistent_list), key, key_len+1); + free(le); } gpr_mu_unlock(&global_persistent_list_mu); } diff --git a/src/php/ext/grpc/channel.h b/src/php/ext/grpc/channel.h index 69adc4782c..86bfdea51a 100755 --- a/src/php/ext/grpc/channel.h +++ b/src/php/ext/grpc/channel.h @@ -40,6 +40,11 @@ typedef struct _grpc_channel_wrapper { char *args_hashstr; char *creds_hashstr; gpr_mu mu; + // is_valid is used to check the wrapped channel has been freed + // before to avoid double free. + bool is_valid; + // ref_count is used to let the last wrapper free related channel and key. + size_t ref_count; } grpc_channel_wrapper; /* Wrapper struct for grpc_channel that can be associated with a PHP object */ diff --git a/src/php/ext/grpc/channel_credentials.c b/src/php/ext/grpc/channel_credentials.c index d120d6e90f..624d7cc75c 100644 --- a/src/php/ext/grpc/channel_credentials.c +++ b/src/php/ext/grpc/channel_credentials.c @@ -57,8 +57,13 @@ static grpc_ssl_roots_override_result get_ssl_roots_override( /* Frees and destroys an instance of wrapped_grpc_channel_credentials */ PHP_GRPC_FREE_WRAPPED_FUNC_START(wrapped_grpc_channel_credentials) + if (p->hashstr != NULL) { + free(p->hashstr); + p->hashstr = NULL; + } if (p->wrapped != NULL) { grpc_channel_credentials_release(p->wrapped); + p->wrapped = NULL; } PHP_GRPC_FREE_WRAPPED_FUNC_END() @@ -152,7 +157,7 @@ PHP_METHOD(ChannelCredentials, createSsl) { } php_grpc_int hashkey_len = root_certs_length + cert_chain_length; - char *hashkey = emalloc(hashkey_len); + char *hashkey = emalloc(hashkey_len + 1); if (root_certs_length > 0) { strcpy(hashkey, pem_root_certs); } @@ -199,8 +204,13 @@ PHP_METHOD(ChannelCredentials, createComposite) { grpc_channel_credentials *creds = grpc_composite_channel_credentials_create(cred1->wrapped, cred2->wrapped, NULL); + // wrapped_grpc_channel_credentials object should keeps it's own + // allocation. Otherwise it conflicts free hashstr with call.c. + php_grpc_int cred1_len = strlen(cred1->hashstr); + char *cred1_hashstr = malloc(cred1_len+1); + strcpy(cred1_hashstr, cred1->hashstr); zval *creds_object = - grpc_php_wrap_channel_credentials(creds, cred1->hashstr, true + grpc_php_wrap_channel_credentials(creds, cred1_hashstr, true TSRMLS_CC); RETURN_DESTROY_ZVAL(creds_object); } diff --git a/src/php/ext/grpc/php7_wrapper.h b/src/php/ext/grpc/php7_wrapper.h index 96091f9dad..2f4a53611c 100644 --- a/src/php/ext/grpc/php7_wrapper.h +++ b/src/php/ext/grpc/php7_wrapper.h @@ -33,6 +33,7 @@ #define php_grpc_add_next_index_stringl(data, str, len, b) \ add_next_index_stringl(data, str, len, b) +#define PHP_GRPC_RETVAL_STRING(val, dup) RETVAL_STRING(val, dup) #define PHP_GRPC_RETURN_STRING(val, dup) RETURN_STRING(val, dup) #define PHP_GRPC_MAKE_STD_ZVAL(pzv) MAKE_STD_ZVAL(pzv) #define PHP_GRPC_FREE_STD_ZVAL(pzv) @@ -145,6 +146,7 @@ static inline int php_grpc_zend_hash_find(HashTable *ht, char *key, int len, #define php_grpc_add_next_index_stringl(data, str, len, b) \ add_next_index_stringl(data, str, len) +#define PHP_GRPC_RETVAL_STRING(val, dup) RETVAL_STRING(val) #define PHP_GRPC_RETURN_STRING(val, dup) RETURN_STRING(val) #define PHP_GRPC_MAKE_STD_ZVAL(pzv) \ pzv = (zval *)emalloc(sizeof(zval)); diff --git a/src/php/ext/grpc/php_grpc.c b/src/php/ext/grpc/php_grpc.c index 0f2c5b8114..5971babc00 100644 --- a/src/php/ext/grpc/php_grpc.c +++ b/src/php/ext/grpc/php_grpc.c @@ -253,7 +253,8 @@ PHP_MSHUTDOWN_FUNCTION(grpc) { */ PHP_MINFO_FUNCTION(grpc) { php_info_print_table_start(); - php_info_print_table_header(2, "grpc support", "enabled"); + php_info_print_table_row(2, "grpc support", "enabled"); + php_info_print_table_row(2, "grpc module version", PHP_GRPC_VERSION); php_info_print_table_end(); /* Remove comments if you have entries in php.ini diff --git a/src/proto/grpc/testing/control.proto b/src/proto/grpc/testing/control.proto index 2ff2e4e8a2..57592662c4 100644 --- a/src/proto/grpc/testing/control.proto +++ b/src/proto/grpc/testing/control.proto @@ -108,6 +108,9 @@ message ClientConfig { // Number of messages on a stream before it gets finished/restarted int32 messages_per_stream = 18; + + // Use coalescing API when possible. + bool use_coalesce_api = 19; } message ClientStatus { ClientStats stats = 1; } diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi index 6ee833697d..30253fc20c 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi @@ -276,15 +276,10 @@ cdef extern from "grpc/grpc.h": uint8_t is_set grpc_compression_level level - ctypedef struct grpc_op_send_initial_metadata_maybe_stream_compression_level: - uint8_t is_set - grpc_stream_compression_level level - ctypedef struct grpc_op_data_send_initial_metadata: size_t count grpc_metadata *metadata grpc_op_send_initial_metadata_maybe_compression_level maybe_compression_level - grpc_op_send_initial_metadata_maybe_stream_compression_level maybe_stream_compression_level ctypedef struct grpc_op_data_send_status_from_server: size_t trailing_metadata_count @@ -562,8 +557,9 @@ cdef extern from "grpc/compression.h": ctypedef enum grpc_compression_algorithm: GRPC_COMPRESS_NONE - GRPC_COMPRESS_DEFLATE - GRPC_COMPRESS_GZIP + GRPC_COMPRESS_MESSAGE_DEFLATE + GRPC_COMPRESS_MESSAGE_GZIP + GRPC_COMPRESS_STREAM_GZIP GRPC_COMPRESS_ALGORITHMS_COUNT ctypedef enum grpc_compression_level: diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/operation.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/operation.pyx.pxi index 3c91abf722..239d0f3f95 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/operation.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/operation.pyx.pxi @@ -40,7 +40,6 @@ cdef class SendInitialMetadataOperation(Operation): self.c_op.data.send_initial_metadata.metadata = self._c_initial_metadata self.c_op.data.send_initial_metadata.count = self._c_initial_metadata_count self.c_op.data.send_initial_metadata.maybe_compression_level.is_set = 0 - self.c_op.data.send_initial_metadata.maybe_stream_compression_level.is_set = 0 cdef void un_c(self): _release_c_metadata( diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi index b2343b53d6..f9d4171283 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi @@ -112,8 +112,8 @@ class OperationType: class CompressionAlgorithm: none = GRPC_COMPRESS_NONE - deflate = GRPC_COMPRESS_DEFLATE - gzip = GRPC_COMPRESS_GZIP + deflate = GRPC_COMPRESS_MESSAGE_DEFLATE + gzip = GRPC_COMPRESS_MESSAGE_GZIP class CompressionLevel: diff --git a/src/python/grpcio/grpc/_interceptor.py b/src/python/grpcio/grpc/_interceptor.py index 56a280624f..d029472c68 100644 --- a/src/python/grpcio/grpc/_interceptor.py +++ b/src/python/grpcio/grpc/_interceptor.py @@ -51,6 +51,30 @@ class _ClientCallDetails( pass +def _unwrap_client_call_details(call_details, default_details): + try: + method = call_details.method + except AttributeError: + method = default_details.method + + try: + timeout = call_details.timeout + except AttributeError: + timeout = default_details.timeout + + try: + metadata = call_details.metadata + except AttributeError: + metadata = default_details.metadata + + try: + credentials = call_details.credentials + except AttributeError: + credentials = default_details.credentials + + return method, timeout, metadata, credentials + + class _LocalFailure(grpc.RpcError, grpc.Future, grpc.Call): def __init__(self, exception, traceback): @@ -126,15 +150,18 @@ class _UnaryUnaryMultiCallable(grpc.UnaryUnaryMultiCallable): def future(self, request, timeout=None, metadata=None, credentials=None): - def continuation(client_call_details, request): - return self._thunk(client_call_details.method).future( - request, - timeout=client_call_details.timeout, - metadata=client_call_details.metadata, - credentials=client_call_details.credentials) - client_call_details = _ClientCallDetails(self._method, timeout, metadata, credentials) + + def continuation(new_details, request): + new_method, new_timeout, new_metadata, new_credentials = ( + _unwrap_client_call_details(new_details, client_call_details)) + return self._thunk(new_method).future( + request, + timeout=new_timeout, + metadata=new_metadata, + credentials=new_credentials) + try: return self._interceptor.intercept_unary_unary( continuation, client_call_details, request) @@ -150,16 +177,18 @@ class _UnaryStreamMultiCallable(grpc.UnaryStreamMultiCallable): self._interceptor = interceptor def __call__(self, request, timeout=None, metadata=None, credentials=None): + client_call_details = _ClientCallDetails(self._method, timeout, + metadata, credentials) - def continuation(client_call_details, request): - return self._thunk(client_call_details.method)( + def continuation(new_details, request): + new_method, new_timeout, new_metadata, new_credentials = ( + _unwrap_client_call_details(new_details, client_call_details)) + return self._thunk(new_method)( request, - timeout=client_call_details.timeout, - metadata=client_call_details.metadata, - credentials=client_call_details.credentials) + timeout=new_timeout, + metadata=new_metadata, + credentials=new_credentials) - client_call_details = _ClientCallDetails(self._method, timeout, - metadata, credentials) try: return self._interceptor.intercept_unary_stream( continuation, client_call_details, request) @@ -203,17 +232,18 @@ class _StreamUnaryMultiCallable(grpc.StreamUnaryMultiCallable): timeout=None, metadata=None, credentials=None): - - def continuation(client_call_details, request_iterator): - return self._thunk(client_call_details.method).future( - request_iterator, - timeout=client_call_details.timeout, - metadata=client_call_details.metadata, - credentials=client_call_details.credentials) - client_call_details = _ClientCallDetails(self._method, timeout, metadata, credentials) + def continuation(new_details, request_iterator): + new_method, new_timeout, new_metadata, new_credentials = ( + _unwrap_client_call_details(new_details, client_call_details)) + return self._thunk(new_method).future( + request_iterator, + timeout=new_timeout, + metadata=new_metadata, + credentials=new_credentials) + try: return self._interceptor.intercept_stream_unary( continuation, client_call_details, request_iterator) @@ -233,17 +263,18 @@ class _StreamStreamMultiCallable(grpc.StreamStreamMultiCallable): timeout=None, metadata=None, credentials=None): - - def continuation(client_call_details, request_iterator): - return self._thunk(client_call_details.method)( - request_iterator, - timeout=client_call_details.timeout, - metadata=client_call_details.metadata, - credentials=client_call_details.credentials) - client_call_details = _ClientCallDetails(self._method, timeout, metadata, credentials) + def continuation(new_details, request_iterator): + new_method, new_timeout, new_metadata, new_credentials = ( + _unwrap_client_call_details(new_details, client_call_details)) + return self._thunk(new_method)( + request_iterator, + timeout=new_timeout, + metadata=new_metadata, + credentials=new_credentials) + try: return self._interceptor.intercept_stream_stream( continuation, client_call_details, request_iterator) diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 9debb22249..86122f909c 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -69,6 +69,8 @@ CORE_SOURCE_FILES = [ 'src/core/lib/channel/handshaker_factory.cc', 'src/core/lib/channel/handshaker_registry.cc', 'src/core/lib/compression/compression.cc', + 'src/core/lib/compression/compression_internal.cc', + 'src/core/lib/compression/compression_ruby.cc', 'src/core/lib/compression/message_compress.cc', 'src/core/lib/compression/stream_compression.cc', 'src/core/lib/compression/stream_compression_gzip.cc', diff --git a/src/ruby/ext/grpc/rb_compression_options.c b/src/ruby/ext/grpc/rb_compression_options.c index e24f20d2f9..a7e37099af 100644 --- a/src/ruby/ext/grpc/rb_compression_options.c +++ b/src/ruby/ext/grpc/rb_compression_options.c @@ -23,6 +23,7 @@ #include "rb_grpc_imports.generated.h" #include <grpc/compression.h> +#include <grpc/compression_ruby.h> #include <grpc/grpc.h> #include <grpc/impl/codegen/compression_types.h> #include <grpc/impl/codegen/grpc_types.h> @@ -174,7 +175,7 @@ void grpc_rb_compression_options_algorithm_name_to_value_internal( /* Raise an error if the name isn't recognized as a compression algorithm by * the algorithm parse function * in GRPC core. */ - if (!grpc_compression_algorithm_parse(name_slice, algorithm_value)) { + if (!grpc_compression_algorithm_parse_ruby(name_slice, algorithm_value)) { tmp_str = grpc_slice_to_c_string(name_slice); rb_raise(rb_eNameError, "Invalid compression algorithm name: %s", tmp_str); } @@ -286,7 +287,7 @@ VALUE grpc_rb_compression_options_algorithm_value_to_name_internal( grpc_compression_algorithm internal_value) { char* algorithm_name = NULL; - if (!grpc_compression_algorithm_name(internal_value, &algorithm_name)) { + if (!grpc_compression_algorithm_name_ruby(internal_value, &algorithm_name)) { rb_raise(rb_eArgError, "Failed to convert algorithm value to name"); } diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.c b/src/ruby/ext/grpc/rb_grpc_imports.generated.c index 56f1d4c93f..5473c52bb5 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.c +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.c @@ -22,16 +22,17 @@ #include "rb_grpc_imports.generated.h" +grpc_compression_algorithm_is_message_type grpc_compression_algorithm_is_message_import; +grpc_compression_algorithm_is_stream_type grpc_compression_algorithm_is_stream_import; grpc_compression_algorithm_parse_type grpc_compression_algorithm_parse_import; grpc_compression_algorithm_name_type grpc_compression_algorithm_name_import; -grpc_stream_compression_algorithm_name_type grpc_stream_compression_algorithm_name_import; grpc_compression_algorithm_for_level_type grpc_compression_algorithm_for_level_import; -grpc_stream_compression_algorithm_for_level_type grpc_stream_compression_algorithm_for_level_import; grpc_compression_options_init_type grpc_compression_options_init_import; grpc_compression_options_enable_algorithm_type grpc_compression_options_enable_algorithm_import; grpc_compression_options_disable_algorithm_type grpc_compression_options_disable_algorithm_import; grpc_compression_options_is_algorithm_enabled_type grpc_compression_options_is_algorithm_enabled_import; -grpc_compression_options_is_stream_compression_algorithm_enabled_type grpc_compression_options_is_stream_compression_algorithm_enabled_import; +grpc_compression_algorithm_parse_ruby_type grpc_compression_algorithm_parse_ruby_import; +grpc_compression_algorithm_name_ruby_type grpc_compression_algorithm_name_ruby_import; grpc_metadata_array_init_type grpc_metadata_array_init_import; grpc_metadata_array_destroy_type grpc_metadata_array_destroy_import; grpc_call_details_init_type grpc_call_details_init_import; @@ -294,16 +295,17 @@ gpr_sleep_until_type gpr_sleep_until_import; gpr_timespec_to_micros_type gpr_timespec_to_micros_import; void grpc_rb_load_imports(HMODULE library) { + grpc_compression_algorithm_is_message_import = (grpc_compression_algorithm_is_message_type) GetProcAddress(library, "grpc_compression_algorithm_is_message"); + grpc_compression_algorithm_is_stream_import = (grpc_compression_algorithm_is_stream_type) GetProcAddress(library, "grpc_compression_algorithm_is_stream"); grpc_compression_algorithm_parse_import = (grpc_compression_algorithm_parse_type) GetProcAddress(library, "grpc_compression_algorithm_parse"); grpc_compression_algorithm_name_import = (grpc_compression_algorithm_name_type) GetProcAddress(library, "grpc_compression_algorithm_name"); - grpc_stream_compression_algorithm_name_import = (grpc_stream_compression_algorithm_name_type) GetProcAddress(library, "grpc_stream_compression_algorithm_name"); grpc_compression_algorithm_for_level_import = (grpc_compression_algorithm_for_level_type) GetProcAddress(library, "grpc_compression_algorithm_for_level"); - grpc_stream_compression_algorithm_for_level_import = (grpc_stream_compression_algorithm_for_level_type) GetProcAddress(library, "grpc_stream_compression_algorithm_for_level"); grpc_compression_options_init_import = (grpc_compression_options_init_type) GetProcAddress(library, "grpc_compression_options_init"); grpc_compression_options_enable_algorithm_import = (grpc_compression_options_enable_algorithm_type) GetProcAddress(library, "grpc_compression_options_enable_algorithm"); grpc_compression_options_disable_algorithm_import = (grpc_compression_options_disable_algorithm_type) GetProcAddress(library, "grpc_compression_options_disable_algorithm"); grpc_compression_options_is_algorithm_enabled_import = (grpc_compression_options_is_algorithm_enabled_type) GetProcAddress(library, "grpc_compression_options_is_algorithm_enabled"); - grpc_compression_options_is_stream_compression_algorithm_enabled_import = (grpc_compression_options_is_stream_compression_algorithm_enabled_type) GetProcAddress(library, "grpc_compression_options_is_stream_compression_algorithm_enabled"); + grpc_compression_algorithm_parse_ruby_import = (grpc_compression_algorithm_parse_ruby_type) GetProcAddress(library, "grpc_compression_algorithm_parse_ruby"); + grpc_compression_algorithm_name_ruby_import = (grpc_compression_algorithm_name_ruby_type) GetProcAddress(library, "grpc_compression_algorithm_name_ruby"); grpc_metadata_array_init_import = (grpc_metadata_array_init_type) GetProcAddress(library, "grpc_metadata_array_init"); grpc_metadata_array_destroy_import = (grpc_metadata_array_destroy_type) GetProcAddress(library, "grpc_metadata_array_destroy"); grpc_call_details_init_import = (grpc_call_details_init_type) GetProcAddress(library, "grpc_call_details_init"); diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.h b/src/ruby/ext/grpc/rb_grpc_imports.generated.h index 1f2bd3e321..d701d2f571 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.h +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.h @@ -26,6 +26,7 @@ #include <windows.h> #include <grpc/compression.h> +#include <grpc/compression_ruby.h> #include <grpc/grpc.h> #include <grpc/grpc_posix.h> #include <grpc/grpc_security.h> @@ -45,21 +46,21 @@ #include <grpc/support/thd.h> #include <grpc/support/time.h> +typedef int(*grpc_compression_algorithm_is_message_type)(grpc_compression_algorithm algorithm); +extern grpc_compression_algorithm_is_message_type grpc_compression_algorithm_is_message_import; +#define grpc_compression_algorithm_is_message grpc_compression_algorithm_is_message_import +typedef int(*grpc_compression_algorithm_is_stream_type)(grpc_compression_algorithm algorithm); +extern grpc_compression_algorithm_is_stream_type grpc_compression_algorithm_is_stream_import; +#define grpc_compression_algorithm_is_stream grpc_compression_algorithm_is_stream_import typedef int(*grpc_compression_algorithm_parse_type)(grpc_slice value, grpc_compression_algorithm* algorithm); extern grpc_compression_algorithm_parse_type grpc_compression_algorithm_parse_import; #define grpc_compression_algorithm_parse grpc_compression_algorithm_parse_import typedef int(*grpc_compression_algorithm_name_type)(grpc_compression_algorithm algorithm, const char** name); extern grpc_compression_algorithm_name_type grpc_compression_algorithm_name_import; #define grpc_compression_algorithm_name grpc_compression_algorithm_name_import -typedef int(*grpc_stream_compression_algorithm_name_type)(grpc_stream_compression_algorithm algorithm, const char** name); -extern grpc_stream_compression_algorithm_name_type grpc_stream_compression_algorithm_name_import; -#define grpc_stream_compression_algorithm_name grpc_stream_compression_algorithm_name_import typedef grpc_compression_algorithm(*grpc_compression_algorithm_for_level_type)(grpc_compression_level level, uint32_t accepted_encodings); extern grpc_compression_algorithm_for_level_type grpc_compression_algorithm_for_level_import; #define grpc_compression_algorithm_for_level grpc_compression_algorithm_for_level_import -typedef grpc_stream_compression_algorithm(*grpc_stream_compression_algorithm_for_level_type)(grpc_stream_compression_level level, uint32_t accepted_stream_encodings); -extern grpc_stream_compression_algorithm_for_level_type grpc_stream_compression_algorithm_for_level_import; -#define grpc_stream_compression_algorithm_for_level grpc_stream_compression_algorithm_for_level_import typedef void(*grpc_compression_options_init_type)(grpc_compression_options* opts); extern grpc_compression_options_init_type grpc_compression_options_init_import; #define grpc_compression_options_init grpc_compression_options_init_import @@ -72,9 +73,12 @@ extern grpc_compression_options_disable_algorithm_type grpc_compression_options_ typedef int(*grpc_compression_options_is_algorithm_enabled_type)(const grpc_compression_options* opts, grpc_compression_algorithm algorithm); extern grpc_compression_options_is_algorithm_enabled_type grpc_compression_options_is_algorithm_enabled_import; #define grpc_compression_options_is_algorithm_enabled grpc_compression_options_is_algorithm_enabled_import -typedef int(*grpc_compression_options_is_stream_compression_algorithm_enabled_type)(const grpc_compression_options* opts, grpc_stream_compression_algorithm algorithm); -extern grpc_compression_options_is_stream_compression_algorithm_enabled_type grpc_compression_options_is_stream_compression_algorithm_enabled_import; -#define grpc_compression_options_is_stream_compression_algorithm_enabled grpc_compression_options_is_stream_compression_algorithm_enabled_import +typedef int(*grpc_compression_algorithm_parse_ruby_type)(grpc_slice value, grpc_compression_algorithm* algorithm); +extern grpc_compression_algorithm_parse_ruby_type grpc_compression_algorithm_parse_ruby_import; +#define grpc_compression_algorithm_parse_ruby grpc_compression_algorithm_parse_ruby_import +typedef int(*grpc_compression_algorithm_name_ruby_type)(grpc_compression_algorithm algorithm, const char** name); +extern grpc_compression_algorithm_name_ruby_type grpc_compression_algorithm_name_ruby_import; +#define grpc_compression_algorithm_name_ruby grpc_compression_algorithm_name_ruby_import typedef void(*grpc_metadata_array_init_type)(grpc_metadata_array* array); extern grpc_metadata_array_init_type grpc_metadata_array_init_import; #define grpc_metadata_array_init grpc_metadata_array_init_import |