diff options
author | Mark D. Roth <roth@google.com> | 2016-09-13 11:10:51 -0700 |
---|---|---|
committer | Mark D. Roth <roth@google.com> | 2016-09-13 11:10:51 -0700 |
commit | 1beb35b24b277598b9101f122de4cf8400973e96 (patch) | |
tree | 4b7be1b7ae067a4e6182fd48b197f560e0ec9720 /src/core/ext | |
parent | 38525a9a082df5c8a61efe046cde9cb14ae4170c (diff) | |
parent | 46131d849efa3fabace12e1dcd2c17d9f1fee35e (diff) |
Merge branch 'grpclb_resolver_changes' into grpclb_resolver_changes2
Diffstat (limited to 'src/core/ext')
-rw-r--r-- | src/core/ext/client_config/resolver_result.c | 102 | ||||
-rw-r--r-- | src/core/ext/client_config/resolver_result.h | 106 | ||||
-rw-r--r-- | src/core/ext/transport/chttp2/transport/chttp2_transport.c | 13 | ||||
-rw-r--r-- | src/core/ext/transport/chttp2/transport/frame.h | 2 | ||||
-rw-r--r-- | src/core/ext/transport/chttp2/transport/hpack_encoder.c | 10 | ||||
-rw-r--r-- | src/core/ext/transport/chttp2/transport/hpack_encoder.h | 1 | ||||
-rw-r--r-- | src/core/ext/transport/chttp2/transport/internal.h | 2 | ||||
-rw-r--r-- | src/core/ext/transport/chttp2/transport/writing.c | 12 |
8 files changed, 134 insertions, 114 deletions
diff --git a/src/core/ext/client_config/resolver_result.c b/src/core/ext/client_config/resolver_result.c index b0602d583d..ac263b9a46 100644 --- a/src/core/ext/client_config/resolver_result.c +++ b/src/core/ext/client_config/resolver_result.c @@ -1,35 +1,33 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ +// +// Copyright 2015, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// #include "src/core/ext/client_config/resolver_result.h" @@ -38,8 +36,8 @@ #include <grpc/support/alloc.h> #include <grpc/support/string_util.h> -grpc_addresses *grpc_addresses_create(size_t num_addresses) { - grpc_addresses *addresses = gpr_malloc(sizeof(grpc_addresses)); +grpc_addresses* grpc_addresses_create(size_t num_addresses) { + grpc_addresses* addresses = gpr_malloc(sizeof(grpc_addresses)); addresses->num_addresses = num_addresses; const size_t addresses_size = sizeof(grpc_address) * num_addresses; addresses->addresses = gpr_malloc(addresses_size); @@ -47,37 +45,37 @@ grpc_addresses *grpc_addresses_create(size_t num_addresses) { return addresses; } -grpc_addresses *grpc_addresses_copy(grpc_addresses* addresses) { - grpc_addresses *new = grpc_addresses_create(addresses->num_addresses); +grpc_addresses* grpc_addresses_copy(grpc_addresses* addresses) { + grpc_addresses* new = grpc_addresses_create(addresses->num_addresses); memcpy(new->addresses, addresses->addresses, sizeof(grpc_address) * addresses->num_addresses); return new; } -void grpc_addresses_set_address(grpc_addresses *addresses, size_t index, - void *address, size_t address_len, +void grpc_addresses_set_address(grpc_addresses* addresses, size_t index, + void* address, size_t address_len, bool is_balancer) { GPR_ASSERT(index < addresses->num_addresses); - grpc_address *target = &addresses->addresses[index]; + grpc_address* target = &addresses->addresses[index]; memcpy(target->address.addr, address, address_len); target->address.len = address_len; target->is_balancer = is_balancer; } -void grpc_addresses_destroy(grpc_addresses *addresses) { +void grpc_addresses_destroy(grpc_addresses* addresses) { gpr_free(addresses->addresses); gpr_free(addresses); } struct grpc_resolver_result { gpr_refcount refs; - grpc_addresses *addresses; - char *lb_policy_name; + grpc_addresses* addresses; + char* lb_policy_name; }; -grpc_resolver_result *grpc_resolver_result_create(grpc_addresses *addresses, - const char *lb_policy_name) { - grpc_resolver_result *result = gpr_malloc(sizeof(*result)); +grpc_resolver_result* grpc_resolver_result_create(grpc_addresses* addresses, + const char* lb_policy_name) { + grpc_resolver_result* result = gpr_malloc(sizeof(*result)); memset(result, 0, sizeof(*result)); gpr_ref_init(&result->refs, 1); result->addresses = addresses; @@ -85,12 +83,12 @@ grpc_resolver_result *grpc_resolver_result_create(grpc_addresses *addresses, return result; } -void grpc_resolver_result_ref(grpc_resolver_result *result) { +void grpc_resolver_result_ref(grpc_resolver_result* result) { gpr_ref(&result->refs); } -void grpc_resolver_result_unref(grpc_exec_ctx *exec_ctx, - grpc_resolver_result *result) { +void grpc_resolver_result_unref(grpc_exec_ctx* exec_ctx, + grpc_resolver_result* result) { if (gpr_unref(&result->refs)) { grpc_addresses_destroy(result->addresses); gpr_free(result->lb_policy_name); @@ -98,12 +96,12 @@ void grpc_resolver_result_unref(grpc_exec_ctx *exec_ctx, } } -grpc_addresses *grpc_resolver_result_get_addresses( - grpc_resolver_result *result) { +grpc_addresses* grpc_resolver_result_get_addresses( + grpc_resolver_result* result) { return result->addresses; } -const char *grpc_resolver_result_get_lb_policy_name( - grpc_resolver_result *result) { +const char* grpc_resolver_result_get_lb_policy_name( + grpc_resolver_result* result) { return result->lb_policy_name; } diff --git a/src/core/ext/client_config/resolver_result.h b/src/core/ext/client_config/resolver_result.h index b1a3457565..fa60c8cc6d 100644 --- a/src/core/ext/client_config/resolver_result.h +++ b/src/core/ext/client_config/resolver_result.h @@ -1,35 +1,33 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ +// +// Copyright 2015, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// #ifndef GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_RESULT_H #define GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_RESULT_H @@ -39,7 +37,7 @@ #include "src/core/ext/client_config/lb_policy.h" #include "src/core/lib/iomgr/resolve_address.h" -/** Used to represent addresses returned by the resolver. */ +/// Used to represent addresses returned by the resolver. typedef struct grpc_address { grpc_resolved_address address; bool is_balancer; @@ -47,37 +45,37 @@ typedef struct grpc_address { typedef struct grpc_addresses { size_t num_addresses; - grpc_address *addresses; + grpc_address* addresses; } grpc_addresses; -/** Returns a grpc_addresses struct with enough space for - \a num_addresses addresses. */ -grpc_addresses *grpc_addresses_create(size_t num_addresses); +/// Returns a grpc_addresses struct with enough space for +/// \a num_addresses addresses. +grpc_addresses* grpc_addresses_create(size_t num_addresses); -grpc_addresses *grpc_addresses_copy(grpc_addresses* addresses); +grpc_addresses* grpc_addresses_copy(grpc_addresses* addresses); -void grpc_addresses_set_address(grpc_addresses *addresses, size_t index, - void *address, size_t address_len, +void grpc_addresses_set_address(grpc_addresses* addresses, size_t index, + void* address, size_t address_len, bool is_balancer); -void grpc_addresses_destroy(grpc_addresses *addresses); +void grpc_addresses_destroy(grpc_addresses* addresses); -/** Results reported from a grpc_resolver. */ +/// Results reported from a grpc_resolver. typedef struct grpc_resolver_result grpc_resolver_result; -/** Takes ownership of \a addresses. */ -grpc_resolver_result *grpc_resolver_result_create(grpc_addresses *addresses, - const char *lb_policy_name); -void grpc_resolver_result_ref(grpc_resolver_result *result); -void grpc_resolver_result_unref(grpc_exec_ctx *exec_ctx, - grpc_resolver_result *result); +/// Takes ownership of \a addresses. +grpc_resolver_result* grpc_resolver_result_create(grpc_addresses* addresses, + const char* lb_policy_name); +void grpc_resolver_result_ref(grpc_resolver_result* result); +void grpc_resolver_result_unref(grpc_exec_ctx* exec_ctx, + grpc_resolver_result* result); -/** Caller does NOT take ownership of result. */ -grpc_addresses *grpc_resolver_result_get_addresses( - grpc_resolver_result *result); +/// Caller does NOT take ownership of result. +grpc_addresses* grpc_resolver_result_get_addresses( + grpc_resolver_result* result); -/** Caller does NOT take ownership of result. */ -const char *grpc_resolver_result_get_lb_policy_name( - grpc_resolver_result *result); +/// Caller does NOT take ownership of result. +const char* grpc_resolver_result_get_lb_policy_name( + grpc_resolver_result* result); #endif /* GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_RESULT_H */ diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.c b/src/core/ext/transport/chttp2/transport/chttp2_transport.c index 0e8dfb7d96..00999e3b94 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.c +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.c @@ -408,6 +408,19 @@ static void init_transport(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, push_setting(exec_ctx, t, GRPC_CHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE, (uint32_t)channel_args->args[i].value.integer); } + } else if (0 == strcmp(channel_args->args[i].key, + GRPC_ARG_HTTP2_MAX_FRAME_SIZE)) { + if (channel_args->args[i].type != GRPC_ARG_INTEGER) { + gpr_log(GPR_ERROR, "%s: must be an integer", + GRPC_ARG_HTTP2_MAX_FRAME_SIZE); + } else if (channel_args->args[i].value.integer < 16384 || + channel_args->args[i].value.integer > 16777215) { + gpr_log(GPR_ERROR, "%s: must be between 16384 and 16777215", + GRPC_ARG_HTTP2_MAX_FRAME_SIZE); + } else { + push_setting(exec_ctx, t, GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE, + (uint32_t)channel_args->args[i].value.integer); + } } } } diff --git a/src/core/ext/transport/chttp2/transport/frame.h b/src/core/ext/transport/chttp2/transport/frame.h index 7776609367..507aae4100 100644 --- a/src/core/ext/transport/chttp2/transport/frame.h +++ b/src/core/ext/transport/chttp2/transport/frame.h @@ -52,8 +52,6 @@ typedef struct grpc_chttp2_transport_parsing grpc_chttp2_transport_parsing; #define GRPC_CHTTP2_FRAME_GOAWAY 7 #define GRPC_CHTTP2_FRAME_WINDOW_UPDATE 8 -#define GRPC_CHTTP2_MAX_PAYLOAD_LENGTH ((1 << 14) - 1) - #define GRPC_CHTTP2_DATA_FLAG_END_STREAM 1 #define GRPC_CHTTP2_FLAG_ACK 1 #define GRPC_CHTTP2_DATA_FLAG_END_HEADERS 4 diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder.c b/src/core/ext/transport/chttp2/transport/hpack_encoder.c index 2cb8205d94..581471ba02 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.c +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.c @@ -78,6 +78,8 @@ typedef struct { uint32_t stream_id; gpr_slice_buffer *output; grpc_transport_one_way_stats *stats; + /* maximum size of a frame */ + size_t max_frame_size; } framer_state; /* fills p (which is expected to be 9 bytes long) with a data frame header */ @@ -123,7 +125,7 @@ static void begin_frame(framer_state *st) { needed */ static void ensure_space(framer_state *st, size_t need_bytes) { if (st->output->length - st->output_length_at_start_of_frame + need_bytes <= - GRPC_CHTTP2_MAX_PAYLOAD_LENGTH) { + st->max_frame_size) { return; } finish_frame(st, 0, 0); @@ -149,8 +151,8 @@ static void add_header_data(framer_state *st, gpr_slice slice) { size_t len = GPR_SLICE_LENGTH(slice); size_t remaining; if (len == 0) return; - remaining = GRPC_CHTTP2_MAX_PAYLOAD_LENGTH + - st->output_length_at_start_of_frame - st->output->length; + remaining = st->max_frame_size + st->output_length_at_start_of_frame - + st->output->length; if (len <= remaining) { st->stats->header_bytes += len; gpr_slice_buffer_add(st->output, slice); @@ -542,6 +544,7 @@ void grpc_chttp2_hpack_compressor_set_max_table_size( void grpc_chttp2_encode_header(grpc_chttp2_hpack_compressor *c, uint32_t stream_id, grpc_metadata_batch *metadata, int is_eof, + size_t max_frame_size, grpc_transport_one_way_stats *stats, gpr_slice_buffer *outbuf) { framer_state st; @@ -555,6 +558,7 @@ void grpc_chttp2_encode_header(grpc_chttp2_hpack_compressor *c, st.output = outbuf; st.is_first_frame = 1; st.stats = stats; + st.max_frame_size = max_frame_size; /* Encode a metadata batch; store the returned values, representing a metadata element that needs to be unreffed back into the metadata diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder.h b/src/core/ext/transport/chttp2/transport/hpack_encoder.h index 0f7b0b063a..4c3a931549 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.h +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.h @@ -91,6 +91,7 @@ void grpc_chttp2_hpack_compressor_set_max_usable_size( void grpc_chttp2_encode_header(grpc_chttp2_hpack_compressor *c, uint32_t id, grpc_metadata_batch *metadata, int is_eof, + size_t max_frame_size, grpc_transport_one_way_stats *stats, gpr_slice_buffer *outbuf); diff --git a/src/core/ext/transport/chttp2/transport/internal.h b/src/core/ext/transport/chttp2/transport/internal.h index e1dcf5262a..d67c014e54 100644 --- a/src/core/ext/transport/chttp2/transport/internal.h +++ b/src/core/ext/transport/chttp2/transport/internal.h @@ -223,6 +223,8 @@ typedef struct { uint8_t is_client; /** callback for when writing is done */ grpc_closure done_cb; + /** maximum frame size */ + uint32_t max_frame_size; } grpc_chttp2_transport_writing; struct grpc_chttp2_transport_parsing { diff --git a/src/core/ext/transport/chttp2/transport/writing.c b/src/core/ext/transport/chttp2/transport/writing.c index 8f7a1f55c6..311b26e354 100644 --- a/src/core/ext/transport/chttp2/transport/writing.c +++ b/src/core/ext/transport/chttp2/transport/writing.c @@ -51,6 +51,10 @@ int grpc_chttp2_unlocking_check_writes( GPR_TIMER_BEGIN("grpc_chttp2_unlocking_check_writes", 0); + transport_writing->max_frame_size = + transport_global->settings[GRPC_ACKED_SETTINGS] + [GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE]; + /* simple writes are queued to qbuf, and flushed here */ gpr_slice_buffer_swap(&transport_global->qbuf, &transport_writing->outbuf); GPR_ASSERT(transport_global->qbuf.count == 0); @@ -206,14 +210,15 @@ static void finalize_outbuf(grpc_exec_ctx *exec_ctx, while ( grpc_chttp2_list_pop_writing_stream(transport_writing, &stream_writing)) { uint32_t max_outgoing = - (uint32_t)GPR_MIN(GRPC_CHTTP2_MAX_PAYLOAD_LENGTH, + (uint32_t)GPR_MIN(transport_writing->max_frame_size, GPR_MIN(stream_writing->outgoing_window, transport_writing->outgoing_window)); /* send initial metadata if it's available */ if (stream_writing->send_initial_metadata != NULL) { grpc_chttp2_encode_header( &transport_writing->hpack_compressor, stream_writing->id, - stream_writing->send_initial_metadata, 0, &stream_writing->stats, + stream_writing->send_initial_metadata, 0, + transport_writing->max_frame_size, &stream_writing->stats, &transport_writing->outbuf); stream_writing->send_initial_metadata = NULL; stream_writing->sent_initial_metadata = 1; @@ -303,7 +308,8 @@ static void finalize_outbuf(grpc_exec_ctx *exec_ctx, } else { grpc_chttp2_encode_header( &transport_writing->hpack_compressor, stream_writing->id, - stream_writing->send_trailing_metadata, 1, &stream_writing->stats, + stream_writing->send_trailing_metadata, 1, + transport_writing->max_frame_size, &stream_writing->stats, &transport_writing->outbuf); } if (!transport_writing->is_client && !stream_writing->read_closed) { |