Eliminate grpc_metadata_batch_{init,destroy,move} (#27349)

* Eliminate grpc_metadata_batch_{init,destroy,move}

* fixes

* fixes

* fixes

* fixes

* portability fixes

* fixes

* fix

* fix

* fix

* be explicit about being explicit
pull/27412/head^2
Craig Tiller 3 years ago committed by GitHub
parent 3ba0bddbbc
commit 9872da79a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      src/core/ext/filters/client_channel/client_channel.cc
  2. 19
      src/core/ext/filters/client_channel/health/health_check_client.cc
  3. 4
      src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc
  4. 51
      src/core/ext/filters/client_channel/retry_filter.cc
  5. 4
      src/core/ext/filters/client_channel/subchannel.cc
  6. 2
      src/core/ext/filters/deadline/deadline_filter.cc
  7. 2
      src/core/ext/filters/fault_injection/fault_injection_filter.cc
  8. 34
      src/core/ext/filters/http/client/http_client_filter.cc
  9. 2
      src/core/ext/filters/http/client_authority_filter.cc
  10. 10
      src/core/ext/filters/http/message_compress/message_compress_filter.cc
  11. 2
      src/core/ext/filters/http/message_compress/message_decompress_filter.cc
  12. 62
      src/core/ext/filters/http/server/http_server_filter.cc
  13. 4
      src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc
  14. 6
      src/core/ext/transport/binder/transport/binder_transport.cc
  15. 34
      src/core/ext/transport/chttp2/transport/chttp2_transport.cc
  16. 3
      src/core/ext/transport/chttp2/transport/frame_rst_stream.cc
  17. 8
      src/core/ext/transport/chttp2/transport/hpack_parser.cc
  18. 6
      src/core/ext/transport/chttp2/transport/incoming_metadata.cc
  19. 9
      src/core/ext/transport/chttp2/transport/incoming_metadata.h
  20. 3
      src/core/ext/transport/chttp2/transport/internal.h
  21. 17
      src/core/ext/transport/chttp2/transport/parsing.cc
  22. 17
      src/core/ext/transport/chttp2/transport/writing.cc
  23. 10
      src/core/ext/transport/cronet/transport/cronet_transport.cc
  24. 34
      src/core/ext/transport/inproc/inproc_transport.cc
  25. 14
      src/core/lib/security/authorization/evaluate_args.cc
  26. 8
      src/core/lib/security/transport/client_auth_filter.cc
  27. 2
      src/core/lib/security/transport/server_auth_filter.cc
  28. 67
      src/core/lib/surface/call.cc
  29. 15
      src/core/lib/surface/server.cc
  30. 17
      src/core/lib/transport/metadata_batch.cc
  31. 45
      src/core/lib/transport/metadata_batch.h
  32. 6
      src/core/lib/transport/transport_op_string.cc
  33. 14
      src/cpp/ext/filters/census/client_filter.cc
  34. 12
      src/cpp/ext/filters/census/server_filter.cc
  35. 7
      test/core/end2end/tests/filter_status_code.cc
  36. 18
      test/core/transport/binder/binder_transport_test.cc
  37. 39
      test/core/transport/chttp2/hpack_encoder_test.cc
  38. 48
      test/core/transport/metadata_test.cc
  39. 7
      test/core/util/evaluate_args_test_util.h
  40. 4
      test/cpp/microbenchmarks/bm_call_create.cc
  41. 12
      test/cpp/microbenchmarks/bm_chttp2_hpack.cc
  42. 27
      test/cpp/microbenchmarks/bm_chttp2_transport.cc

@ -2497,7 +2497,7 @@ class ClientChannel::LoadBalancedCall::Metadata
std::vector<std::pair<std::string, std::string>> TestOnlyCopyToVector()
override {
std::vector<std::pair<std::string, std::string>> result;
(*batch_)->ForEach([&](grpc_mdelem md) {
batch_->ForEach([&](grpc_mdelem md) {
auto key = std::string(StringViewFromSlice(GRPC_MDKEY(md)));
if (key != ":path") {
result.push_back(
@ -2532,8 +2532,7 @@ class ClientChannel::LoadBalancedCall::LbCallState
const LoadBalancingPolicy::BackendMetricData* GetBackendMetricData()
override {
if (lb_call_->backend_metric_data_ == nullptr) {
grpc_linked_mdelem* md = (*lb_call_->recv_trailing_metadata_)
->legacy_index()
grpc_linked_mdelem* md = lb_call_->recv_trailing_metadata_->legacy_index()
->named.x_endpoint_load_metrics_bin;
if (md != nullptr) {
lb_call_->backend_metric_data_ =
@ -2914,8 +2913,7 @@ void ClientChannel::LoadBalancedCall::RecvTrailingMetadataReady(
StringViewFromSlice(message));
} else {
// Get status from headers.
const auto& fields =
(*self->recv_trailing_metadata_)->legacy_index()->named;
const auto& fields = self->recv_trailing_metadata_->legacy_index()->named;
GPR_ASSERT(fields.grpc_status != nullptr);
grpc_status_code code =
grpc_get_status_code_from_metadata(fields.grpc_status->md);

@ -315,7 +315,6 @@ void HealthCheckClient::CallState::StartCall() {
batch_.on_complete = GRPC_CLOSURE_INIT(&on_complete_, OnComplete, this,
grpc_schedule_on_exec_ctx);
// Add send_initial_metadata op.
grpc_metadata_batch_init(&send_initial_metadata_);
error = grpc_metadata_batch_add_head(
&send_initial_metadata_, &path_metadata_storage_,
grpc_mdelem_from_slices(
@ -333,12 +332,10 @@ void HealthCheckClient::CallState::StartCall() {
payload_.send_message.send_message.reset(send_message_.get());
batch_.send_message = true;
// Add send_trailing_metadata op.
grpc_metadata_batch_init(&send_trailing_metadata_);
payload_.send_trailing_metadata.send_trailing_metadata =
&send_trailing_metadata_;
batch_.send_trailing_metadata = true;
// Add recv_initial_metadata op.
grpc_metadata_batch_init(&recv_initial_metadata_);
payload_.recv_initial_metadata.recv_initial_metadata =
&recv_initial_metadata_;
payload_.recv_initial_metadata.recv_flags = nullptr;
@ -363,7 +360,6 @@ void HealthCheckClient::CallState::StartCall() {
// Initialize recv_trailing_metadata batch.
recv_trailing_metadata_batch_.payload = &payload_;
// Add recv_trailing_metadata op.
grpc_metadata_batch_init(&recv_trailing_metadata_);
payload_.recv_trailing_metadata.recv_trailing_metadata =
&recv_trailing_metadata_;
payload_.recv_trailing_metadata.collect_stats = &collect_stats_;
@ -441,8 +437,8 @@ void HealthCheckClient::CallState::OnComplete(void* arg,
HealthCheckClient::CallState* self =
static_cast<HealthCheckClient::CallState*>(arg);
GRPC_CALL_COMBINER_STOP(&self->call_combiner_, "on_complete");
grpc_metadata_batch_destroy(&self->send_initial_metadata_);
grpc_metadata_batch_destroy(&self->send_trailing_metadata_);
self->send_initial_metadata_.Clear();
self->send_trailing_metadata_.Clear();
self->call_->Unref(DEBUG_LOCATION, "on_complete");
}
@ -451,7 +447,7 @@ void HealthCheckClient::CallState::RecvInitialMetadataReady(
HealthCheckClient::CallState* self =
static_cast<HealthCheckClient::CallState*>(arg);
GRPC_CALL_COMBINER_STOP(&self->call_combiner_, "recv_initial_metadata_ready");
grpc_metadata_batch_destroy(&self->recv_initial_metadata_);
self->recv_initial_metadata_.Clear();
self->call_->Unref(DEBUG_LOCATION, "recv_initial_metadata_ready");
}
@ -558,11 +554,10 @@ void HealthCheckClient::CallState::RecvTrailingMetadataReady(
grpc_error_get_status(error, GRPC_MILLIS_INF_FUTURE, &status,
nullptr /* slice */, nullptr /* http_error */,
nullptr /* error_string */);
} else if ((*self->recv_trailing_metadata_)
.legacy_index()
->named.grpc_status != nullptr) {
} else if (self->recv_trailing_metadata_.legacy_index()->named.grpc_status !=
nullptr) {
status = grpc_get_status_code_from_metadata(
(*self->recv_trailing_metadata_).legacy_index()->named.grpc_status->md);
self->recv_trailing_metadata_.legacy_index()->named.grpc_status->md);
}
if (GRPC_TRACE_FLAG_ENABLED(grpc_health_check_client_trace)) {
gpr_log(GPR_INFO,
@ -571,7 +566,7 @@ void HealthCheckClient::CallState::RecvTrailingMetadataReady(
self->health_check_client_.get(), self, status);
}
// Clean up.
grpc_metadata_batch_destroy(&self->recv_trailing_metadata_);
self->recv_trailing_metadata_.Clear();
// For status UNIMPLEMENTED, give up and assume always healthy.
bool retry = true;
if (status == GRPC_STATUS_UNIMPLEMENTED) {

@ -102,8 +102,8 @@ static void clr_start_transport_stream_op_batch(
if (batch->send_initial_metadata) {
// Grab client stats object from metadata.
auto client_stats_md =
(*batch->payload->send_initial_metadata.send_initial_metadata)
->Remove(grpc_slice_from_static_string(
batch->payload->send_initial_metadata.send_initial_metadata->Remove(
grpc_slice_from_static_string(
grpc_core::kGrpcLbClientStatsMetadataKey));
if (client_stats_md.has_value()) {
grpc_core::GrpcLbClientStats* client_stats =

@ -1308,18 +1308,6 @@ RetryFilter::CallData::CallAttempt::BatchData::~BatchData() {
call_attempt_->calld_->chand_, call_attempt_->calld_,
call_attempt_.get(), this);
}
if (batch_.send_initial_metadata) {
grpc_metadata_batch_destroy(&call_attempt_->send_initial_metadata_);
}
if (batch_.send_trailing_metadata) {
grpc_metadata_batch_destroy(&call_attempt_->send_trailing_metadata_);
}
if (batch_.recv_initial_metadata) {
grpc_metadata_batch_destroy(&call_attempt_->recv_initial_metadata_);
}
if (batch_.recv_trailing_metadata) {
grpc_metadata_batch_destroy(&call_attempt_->recv_trailing_metadata_);
}
GRPC_CALL_STACK_UNREF(call_attempt_->calld_->owning_call_, "Retry BatchData");
call_attempt_.reset(DEBUG_LOCATION, "~BatchData");
}
@ -1363,9 +1351,8 @@ void RetryFilter::CallData::CallAttempt::BatchData::
return;
}
// Return metadata.
grpc_metadata_batch_move(
&call_attempt_->recv_initial_metadata_,
pending->batch->payload->recv_initial_metadata.recv_initial_metadata);
*pending->batch->payload->recv_initial_metadata.recv_initial_metadata =
std::move(call_attempt_->recv_initial_metadata_);
// Propagate trailing_metadata_available.
*pending->batch->payload->recv_initial_metadata.trailing_metadata_available =
call_attempt_->trailing_metadata_available_;
@ -1565,12 +1552,12 @@ void GetCallStatus(grpc_millis deadline, grpc_metadata_batch* md_batch,
*is_lb_drop = true;
}
} else {
GPR_ASSERT((*md_batch)->legacy_index()->named.grpc_status != nullptr);
GPR_ASSERT(md_batch->legacy_index()->named.grpc_status != nullptr);
*status = grpc_get_status_code_from_metadata(
(*md_batch)->legacy_index()->named.grpc_status->md);
if ((*md_batch)->legacy_index()->named.grpc_retry_pushback_ms != nullptr) {
md_batch->legacy_index()->named.grpc_status->md);
if (md_batch->legacy_index()->named.grpc_retry_pushback_ms != nullptr) {
*server_pushback_md =
&(*md_batch)->legacy_index()->named.grpc_retry_pushback_ms->md;
&md_batch->legacy_index()->named.grpc_retry_pushback_ms->md;
}
}
GRPC_ERROR_UNREF(error);
@ -1602,9 +1589,8 @@ void RetryFilter::CallData::CallAttempt::BatchData::
&call_attempt_->collect_stats_,
pending->batch->payload->recv_trailing_metadata.collect_stats);
// Return metadata.
grpc_metadata_batch_move(
&call_attempt_->recv_trailing_metadata_,
pending->batch->payload->recv_trailing_metadata.recv_trailing_metadata);
*pending->batch->payload->recv_trailing_metadata.recv_trailing_metadata =
std::move(call_attempt_->recv_trailing_metadata_);
// Add closure.
closures->Add(pending->batch->payload->recv_trailing_metadata
.recv_trailing_metadata_ready,
@ -1924,13 +1910,12 @@ void RetryFilter::CallData::CallAttempt::BatchData::
call_attempt_->send_initial_metadata_storage_ =
static_cast<grpc_linked_mdelem*>(calld->arena_->Alloc(
sizeof(grpc_linked_mdelem) *
(calld->send_initial_metadata_->non_deadline_count() +
(calld->send_initial_metadata_.non_deadline_count() +
(calld->num_attempts_completed_ > 0))));
grpc_metadata_batch_copy(&calld->send_initial_metadata_,
&call_attempt_->send_initial_metadata_,
call_attempt_->send_initial_metadata_storage_);
if (GPR_UNLIKELY((*call_attempt_->send_initial_metadata_)
.legacy_index()
if (GPR_UNLIKELY(call_attempt_->send_initial_metadata_.legacy_index()
->named.grpc_previous_rpc_attempts != nullptr)) {
grpc_metadata_batch_remove(&call_attempt_->send_initial_metadata_,
GRPC_BATCH_GRPC_PREVIOUS_RPC_ATTEMPTS);
@ -1942,7 +1927,7 @@ void RetryFilter::CallData::CallAttempt::BatchData::
grpc_error_handle error = grpc_metadata_batch_add_tail(
&call_attempt_->send_initial_metadata_,
&call_attempt_->send_initial_metadata_storage_
[calld->send_initial_metadata_->non_deadline_count()],
[calld->send_initial_metadata_.non_deadline_count()],
retry_md, GRPC_BATCH_GRPC_PREVIOUS_RPC_ATTEMPTS);
if (GPR_UNLIKELY(error != GRPC_ERROR_NONE)) {
gpr_log(GPR_ERROR, "error adding retry metadata: %s",
@ -1988,7 +1973,7 @@ void RetryFilter::CallData::CallAttempt::BatchData::
call_attempt_->send_trailing_metadata_storage_ =
static_cast<grpc_linked_mdelem*>(calld->arena_->Alloc(
sizeof(grpc_linked_mdelem) *
calld->send_trailing_metadata_->non_deadline_count()));
calld->send_trailing_metadata_.non_deadline_count()));
grpc_metadata_batch_copy(&calld->send_trailing_metadata_,
&call_attempt_->send_trailing_metadata_,
call_attempt_->send_trailing_metadata_storage_);
@ -2002,7 +1987,7 @@ void RetryFilter::CallData::CallAttempt::BatchData::
AddRetriableRecvInitialMetadataOp() {
call_attempt_->started_recv_initial_metadata_ = true;
batch_.recv_initial_metadata = true;
grpc_metadata_batch_init(&call_attempt_->recv_initial_metadata_);
call_attempt_->recv_initial_metadata_.Clear();
batch_.payload->recv_initial_metadata.recv_initial_metadata =
&call_attempt_->recv_initial_metadata_;
batch_.payload->recv_initial_metadata.trailing_metadata_available =
@ -2029,7 +2014,7 @@ void RetryFilter::CallData::CallAttempt::BatchData::
AddRetriableRecvTrailingMetadataOp() {
call_attempt_->started_recv_trailing_metadata_ = true;
batch_.recv_trailing_metadata = true;
grpc_metadata_batch_init(&call_attempt_->recv_trailing_metadata_);
call_attempt_->recv_trailing_metadata_.Clear();
batch_.payload->recv_trailing_metadata.recv_trailing_metadata =
&call_attempt_->recv_trailing_metadata_;
batch_.payload->recv_trailing_metadata.collect_stats =
@ -2308,7 +2293,7 @@ void RetryFilter::CallData::MaybeCacheSendOpsForBatch(PendingBatch* pending) {
batch->payload->send_initial_metadata.send_initial_metadata;
send_initial_metadata_storage_ = static_cast<grpc_linked_mdelem*>(
arena_->Alloc(sizeof(grpc_linked_mdelem) *
(*send_initial_metadata)->non_deadline_count()));
send_initial_metadata->non_deadline_count()));
grpc_metadata_batch_copy(send_initial_metadata, &send_initial_metadata_,
send_initial_metadata_storage_);
send_initial_metadata_flags_ =
@ -2329,7 +2314,7 @@ void RetryFilter::CallData::MaybeCacheSendOpsForBatch(PendingBatch* pending) {
batch->payload->send_trailing_metadata.send_trailing_metadata;
send_trailing_metadata_storage_ = static_cast<grpc_linked_mdelem*>(
arena_->Alloc(sizeof(grpc_linked_mdelem) *
(*send_trailing_metadata)->non_deadline_count()));
send_trailing_metadata->non_deadline_count()));
grpc_metadata_batch_copy(send_trailing_metadata, &send_trailing_metadata_,
send_trailing_metadata_storage_);
}
@ -2340,7 +2325,7 @@ void RetryFilter::CallData::FreeCachedSendInitialMetadata() {
gpr_log(GPR_INFO, "chand=%p calld=%p: destroying send_initial_metadata",
chand_, this);
}
grpc_metadata_batch_destroy(&send_initial_metadata_);
send_initial_metadata_.Clear();
}
void RetryFilter::CallData::FreeCachedSendMessage(size_t idx) {
@ -2357,7 +2342,7 @@ void RetryFilter::CallData::FreeCachedSendTrailingMetadata() {
gpr_log(GPR_INFO, "chand=%p calld=%p: destroying send_trailing_metadata",
chand_, this);
}
grpc_metadata_batch_destroy(&send_trailing_metadata_);
send_trailing_metadata_.Clear();
}
void RetryFilter::CallData::FreeAllCachedSendOpData() {

@ -255,9 +255,9 @@ void GetCallStatus(grpc_status_code* status, grpc_millis deadline,
if (error != GRPC_ERROR_NONE) {
grpc_error_get_status(error, deadline, status, nullptr, nullptr, nullptr);
} else {
if ((*md_batch)->legacy_index()->named.grpc_status != nullptr) {
if (md_batch->legacy_index()->named.grpc_status != nullptr) {
*status = grpc_get_status_code_from_metadata(
(*md_batch)->legacy_index()->named.grpc_status->md);
md_batch->legacy_index()->named.grpc_status->md);
} else {
*status = GRPC_STATUS_UNKNOWN;
}

@ -295,7 +295,7 @@ static void deadline_client_start_transport_stream_op_batch(
static void recv_initial_metadata_ready(void* arg, grpc_error_handle error) {
grpc_call_element* elem = static_cast<grpc_call_element*>(arg);
server_call_data* calld = static_cast<server_call_data*>(elem->call_data);
start_timer_if_needed(elem, (*calld->recv_initial_metadata)->deadline());
start_timer_if_needed(elem, calld->recv_initial_metadata->deadline());
// Invoke the next callback.
grpc_core::Closure::Run(DEBUG_LOCATION,
calld->next_recv_initial_metadata_ready,

@ -347,7 +347,7 @@ void CallData::DecideWhetherToInjectFaults(
*fi_policy_);
}
};
(*initial_metadata)->ForEach([&](grpc_mdelem md) {
initial_metadata->ForEach([&](grpc_mdelem md) {
absl::string_view key = StringViewFromSlice(GRPC_MDKEY(md));
// Only perform string comparison if:
// 1. Needs to check this header;

@ -112,18 +112,18 @@ struct channel_data {
static grpc_error_handle client_filter_incoming_metadata(
grpc_metadata_batch* b) {
if ((*b)->legacy_index()->named.status != nullptr) {
if (b->legacy_index()->named.status != nullptr) {
/* If both gRPC status and HTTP status are provided in the response, we
* should prefer the gRPC status code, as mentioned in
* https://github.com/grpc/grpc/blob/master/doc/http-grpc-status-mapping.md.
*/
if ((*b)->legacy_index()->named.grpc_status != nullptr ||
grpc_mdelem_static_value_eq((*b)->legacy_index()->named.status->md,
if (b->legacy_index()->named.grpc_status != nullptr ||
grpc_mdelem_static_value_eq(b->legacy_index()->named.status->md,
GRPC_MDELEM_STATUS_200)) {
grpc_metadata_batch_remove(b, GRPC_BATCH_STATUS);
} else {
char* val = grpc_dump_slice(
GRPC_MDVALUE((*b)->legacy_index()->named.status->md), GPR_DUMP_ASCII);
GRPC_MDVALUE(b->legacy_index()->named.status->md), GPR_DUMP_ASCII);
std::string msg =
absl::StrCat("Received http2 header with status: ", val);
grpc_error_handle e = grpc_error_set_str(
@ -141,32 +141,32 @@ static grpc_error_handle client_filter_incoming_metadata(
}
}
if ((*b)->legacy_index()->named.grpc_message != nullptr) {
if (b->legacy_index()->named.grpc_message != nullptr) {
grpc_slice pct_decoded_msg = grpc_core::PermissivePercentDecodeSlice(
GRPC_MDVALUE((*b)->legacy_index()->named.grpc_message->md));
GRPC_MDVALUE(b->legacy_index()->named.grpc_message->md));
if (grpc_slice_is_equivalent(
pct_decoded_msg,
GRPC_MDVALUE((*b)->legacy_index()->named.grpc_message->md))) {
GRPC_MDVALUE(b->legacy_index()->named.grpc_message->md))) {
grpc_slice_unref_internal(pct_decoded_msg);
} else {
grpc_metadata_batch_set_value((*b)->legacy_index()->named.grpc_message,
grpc_metadata_batch_set_value(b->legacy_index()->named.grpc_message,
pct_decoded_msg);
}
}
if ((*b)->legacy_index()->named.content_type != nullptr) {
if (b->legacy_index()->named.content_type != nullptr) {
if (!grpc_mdelem_static_value_eq(
(*b)->legacy_index()->named.content_type->md,
b->legacy_index()->named.content_type->md,
GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC)) {
if (grpc_slice_buf_start_eq(
GRPC_MDVALUE((*b)->legacy_index()->named.content_type->md),
GRPC_MDVALUE(b->legacy_index()->named.content_type->md),
EXPECTED_CONTENT_TYPE, EXPECTED_CONTENT_TYPE_LENGTH) &&
(GRPC_SLICE_START_PTR(GRPC_MDVALUE(
(*b)->legacy_index()
b->legacy_index()
->named.content_type->md))[EXPECTED_CONTENT_TYPE_LENGTH] ==
'+' ||
GRPC_SLICE_START_PTR(GRPC_MDVALUE(
(*b)->legacy_index()
b->legacy_index()
->named.content_type->md))[EXPECTED_CONTENT_TYPE_LENGTH] ==
';')) {
/* Although the C implementation doesn't (currently) generate them,
@ -178,7 +178,7 @@ static grpc_error_handle client_filter_incoming_metadata(
/* TODO(klempner): We're currently allowing this, but we shouldn't
see it without a proxy so log for now. */
char* val = grpc_dump_slice(
GRPC_MDVALUE((*b)->legacy_index()->named.content_type->md),
GRPC_MDVALUE(b->legacy_index()->named.content_type->md),
GPR_DUMP_ASCII);
gpr_log(GPR_INFO, "Unexpected content-type '%s'", val);
gpr_free(val);
@ -319,8 +319,8 @@ static char* slice_buffer_to_string(grpc_slice_buffer* slice_buffer) {
static grpc_error_handle update_path_for_get(
grpc_call_element* elem, grpc_transport_stream_op_batch* batch) {
call_data* calld = static_cast<call_data*>(elem->call_data);
grpc_slice path_slice = GRPC_MDVALUE(
(*batch->payload->send_initial_metadata.send_initial_metadata)
grpc_slice path_slice =
GRPC_MDVALUE(batch->payload->send_initial_metadata.send_initial_metadata
->legacy_index()
->named.path->md);
/* sum up individual component's lengths and allocate enough memory to
@ -355,7 +355,7 @@ static grpc_error_handle update_path_for_get(
grpc_mdelem_from_slices(GRPC_MDSTR_PATH, path_with_query_slice);
grpc_metadata_batch* b =
batch->payload->send_initial_metadata.send_initial_metadata;
return grpc_metadata_batch_substitute(b, (*b)->legacy_index()->named.path,
return grpc_metadata_batch_substitute(b, b->legacy_index()->named.path,
mdelem_path_and_query);
}

@ -56,7 +56,7 @@ void client_authority_start_transport_stream_op_batch(
// Handle send_initial_metadata.
// If the initial metadata doesn't already contain :authority, add it.
if (batch->send_initial_metadata &&
(*batch->payload->send_initial_metadata.send_initial_metadata)
batch->payload->send_initial_metadata.send_initial_metadata
->legacy_index()
->named.authority == nullptr) {
grpc_error_handle error = grpc_metadata_batch_add_head(

@ -191,15 +191,13 @@ bool CallData::SkipMessageCompression() {
// channel's default setting.
grpc_compression_algorithm FindCompressionAlgorithm(
grpc_metadata_batch* initial_metadata, ChannelData* channeld) {
if ((*initial_metadata)
->legacy_index()
->named.grpc_internal_encoding_request == nullptr) {
if (initial_metadata->legacy_index()->named.grpc_internal_encoding_request ==
nullptr) {
return channeld->default_compression_algorithm();
}
grpc_compression_algorithm compression_algorithm;
// Parse the compression algorithm from the initial metadata.
grpc_mdelem md = (*initial_metadata)
->legacy_index()
grpc_mdelem md = initial_metadata->legacy_index()
->named.grpc_internal_encoding_request->md;
GPR_ASSERT(grpc_compression_algorithm_parse(GRPC_MDVALUE(md),
&compression_algorithm));
@ -275,7 +273,7 @@ grpc_error_handle CallData::ProcessSendInitialMetadata(
if (error != GRPC_ERROR_NONE) return error;
// Do not overwrite accept-encoding header if it already presents (e.g., added
// by some proxy).
if (!(*initial_metadata)->legacy_index()->named.accept_encoding) {
if (!initial_metadata->legacy_index()->named.accept_encoding) {
error = grpc_metadata_batch_add_tail(
initial_metadata, &accept_stream_encoding_storage_,
GRPC_MDELEM_ACCEPT_STREAM_ENCODING_FOR_ALGORITHMS(

@ -153,7 +153,7 @@ void CallData::OnRecvInitialMetadataReady(void* arg, grpc_error_handle error) {
CallData* calld = static_cast<CallData*>(arg);
if (error == GRPC_ERROR_NONE) {
grpc_linked_mdelem* grpc_encoding =
(*calld->recv_initial_metadata_)->legacy_index()->named.grpc_encoding;
calld->recv_initial_metadata_->legacy_index()->named.grpc_encoding;
if (grpc_encoding != nullptr) {
calld->algorithm_ = DecodeMessageCompressionAlgorithm(grpc_encoding->md);
}

@ -104,16 +104,16 @@ struct channel_data {
} // namespace
static grpc_error_handle hs_filter_outgoing_metadata(grpc_metadata_batch* b) {
if ((*b)->legacy_index()->named.grpc_message != nullptr) {
if (b->legacy_index()->named.grpc_message != nullptr) {
grpc_slice pct_encoded_msg = grpc_core::PercentEncodeSlice(
GRPC_MDVALUE((*b)->legacy_index()->named.grpc_message->md),
GRPC_MDVALUE(b->legacy_index()->named.grpc_message->md),
grpc_core::PercentEncodingType::Compatible);
if (grpc_slice_is_equivalent(
pct_encoded_msg,
GRPC_MDVALUE((*b)->legacy_index()->named.grpc_message->md))) {
GRPC_MDVALUE(b->legacy_index()->named.grpc_message->md))) {
grpc_slice_unref_internal(pct_encoded_msg);
} else {
grpc_metadata_batch_set_value((*b)->legacy_index()->named.grpc_message,
grpc_metadata_batch_set_value(b->legacy_index()->named.grpc_message,
pct_encoded_msg);
}
}
@ -161,19 +161,19 @@ static grpc_error_handle hs_filter_incoming_metadata(grpc_call_element* elem,
grpc_error_handle error = GRPC_ERROR_NONE;
static const char* error_name = "Failed processing incoming headers";
if ((*b)->legacy_index()->named.method != nullptr) {
if (md_strict_equal((*b)->legacy_index()->named.method->md,
if (b->legacy_index()->named.method != nullptr) {
if (md_strict_equal(b->legacy_index()->named.method->md,
GRPC_MDELEM_METHOD_POST)) {
*calld->recv_initial_metadata_flags &=
~(GRPC_INITIAL_METADATA_CACHEABLE_REQUEST |
GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST);
} else if (md_strict_equal((*b)->legacy_index()->named.method->md,
} else if (md_strict_equal(b->legacy_index()->named.method->md,
GRPC_MDELEM_METHOD_PUT)) {
*calld->recv_initial_metadata_flags &=
~GRPC_INITIAL_METADATA_CACHEABLE_REQUEST;
*calld->recv_initial_metadata_flags |=
GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST;
} else if (md_strict_equal((*b)->legacy_index()->named.method->md,
} else if (md_strict_equal(b->legacy_index()->named.method->md,
GRPC_MDELEM_METHOD_GET)) {
*calld->recv_initial_metadata_flags |=
GRPC_INITIAL_METADATA_CACHEABLE_REQUEST;
@ -183,7 +183,7 @@ static grpc_error_handle hs_filter_incoming_metadata(grpc_call_element* elem,
hs_add_error(error_name, &error,
grpc_attach_md_to_error(
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Bad header"),
(*b)->legacy_index()->named.method->md));
b->legacy_index()->named.method->md));
}
grpc_metadata_batch_remove(b, GRPC_BATCH_METHOD);
} else {
@ -194,13 +194,13 @@ static grpc_error_handle hs_filter_incoming_metadata(grpc_call_element* elem,
GRPC_ERROR_STR_KEY, grpc_slice_from_static_string(":method")));
}
if ((*b)->legacy_index()->named.te != nullptr) {
if (!grpc_mdelem_static_value_eq((*b)->legacy_index()->named.te->md,
if (b->legacy_index()->named.te != nullptr) {
if (!grpc_mdelem_static_value_eq(b->legacy_index()->named.te->md,
GRPC_MDELEM_TE_TRAILERS)) {
hs_add_error(error_name, &error,
grpc_attach_md_to_error(
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Bad header"),
(*b)->legacy_index()->named.te->md));
b->legacy_index()->named.te->md));
}
grpc_metadata_batch_remove(b, GRPC_BATCH_TE);
} else {
@ -210,17 +210,17 @@ static grpc_error_handle hs_filter_incoming_metadata(grpc_call_element* elem,
GRPC_ERROR_STR_KEY, grpc_slice_from_static_string("te")));
}
if ((*b)->legacy_index()->named.scheme != nullptr) {
if (!md_strict_equal((*b)->legacy_index()->named.scheme->md,
if (b->legacy_index()->named.scheme != nullptr) {
if (!md_strict_equal(b->legacy_index()->named.scheme->md,
GRPC_MDELEM_SCHEME_HTTP) &&
!md_strict_equal((*b)->legacy_index()->named.scheme->md,
!md_strict_equal(b->legacy_index()->named.scheme->md,
GRPC_MDELEM_SCHEME_HTTPS) &&
!grpc_mdelem_static_value_eq((*b)->legacy_index()->named.scheme->md,
!grpc_mdelem_static_value_eq(b->legacy_index()->named.scheme->md,
GRPC_MDELEM_SCHEME_GRPC)) {
hs_add_error(error_name, &error,
grpc_attach_md_to_error(
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Bad header"),
(*b)->legacy_index()->named.scheme->md));
b->legacy_index()->named.scheme->md));
}
grpc_metadata_batch_remove(b, GRPC_BATCH_SCHEME);
} else {
@ -231,19 +231,19 @@ static grpc_error_handle hs_filter_incoming_metadata(grpc_call_element* elem,
GRPC_ERROR_STR_KEY, grpc_slice_from_static_string(":scheme")));
}
if ((*b)->legacy_index()->named.content_type != nullptr) {
if (b->legacy_index()->named.content_type != nullptr) {
if (!grpc_mdelem_static_value_eq(
(*b)->legacy_index()->named.content_type->md,
b->legacy_index()->named.content_type->md,
GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC)) {
if (grpc_slice_buf_start_eq(
GRPC_MDVALUE((*b)->legacy_index()->named.content_type->md),
GRPC_MDVALUE(b->legacy_index()->named.content_type->md),
EXPECTED_CONTENT_TYPE, EXPECTED_CONTENT_TYPE_LENGTH) &&
(GRPC_SLICE_START_PTR(GRPC_MDVALUE(
(*b)->legacy_index()
b->legacy_index()
->named.content_type->md))[EXPECTED_CONTENT_TYPE_LENGTH] ==
'+' ||
GRPC_SLICE_START_PTR(GRPC_MDVALUE(
(*b)->legacy_index()
b->legacy_index()
->named.content_type->md))[EXPECTED_CONTENT_TYPE_LENGTH] ==
';')) {
/* Although the C implementation doesn't (currently) generate them,
@ -255,7 +255,7 @@ static grpc_error_handle hs_filter_incoming_metadata(grpc_call_element* elem,
/* TODO(klempner): We're currently allowing this, but we shouldn't
see it without a proxy so log for now. */
char* val = grpc_dump_slice(
GRPC_MDVALUE((*b)->legacy_index()->named.content_type->md),
GRPC_MDVALUE(b->legacy_index()->named.content_type->md),
GPR_DUMP_ASCII);
gpr_log(GPR_INFO, "Unexpected content-type '%s'", val);
gpr_free(val);
@ -264,7 +264,7 @@ static grpc_error_handle hs_filter_incoming_metadata(grpc_call_element* elem,
grpc_metadata_batch_remove(b, GRPC_BATCH_CONTENT_TYPE);
}
if ((*b)->legacy_index()->named.path == nullptr) {
if (b->legacy_index()->named.path == nullptr) {
hs_add_error(
error_name, &error,
grpc_error_set_str(
@ -275,7 +275,7 @@ static grpc_error_handle hs_filter_incoming_metadata(grpc_call_element* elem,
/* We have a cacheable request made with GET verb. The path contains the
* query parameter which is base64 encoded request payload. */
const char k_query_separator = '?';
grpc_slice path_slice = GRPC_MDVALUE((*b)->legacy_index()->named.path->md);
grpc_slice path_slice = GRPC_MDVALUE(b->legacy_index()->named.path->md);
uint8_t* path_ptr = GRPC_SLICE_START_PTR(path_slice);
size_t path_length = GRPC_SLICE_LENGTH(path_slice);
/* offset of the character '?' */
@ -291,7 +291,7 @@ static grpc_error_handle hs_filter_incoming_metadata(grpc_call_element* elem,
grpc_mdelem mdelem_path_without_query = grpc_mdelem_from_slices(
GRPC_MDSTR_PATH, grpc_slice_sub(path_slice, 0, offset));
grpc_metadata_batch_substitute(b, (*b)->legacy_index()->named.path,
grpc_metadata_batch_substitute(b, b->legacy_index()->named.path,
mdelem_path_without_query);
/* decode payload from query and add to the slice buffer to be returned */
@ -312,9 +312,9 @@ static grpc_error_handle hs_filter_incoming_metadata(grpc_call_element* elem,
}
}
if ((*b)->legacy_index()->named.host != nullptr &&
(*b)->legacy_index()->named.authority == nullptr) {
grpc_linked_mdelem* el = (*b)->legacy_index()->named.host;
if (b->legacy_index()->named.host != nullptr &&
b->legacy_index()->named.authority == nullptr) {
grpc_linked_mdelem* el = b->legacy_index()->named.host;
grpc_mdelem md = GRPC_MDELEM_REF(el->md);
grpc_metadata_batch_remove(b, el);
hs_add_error(
@ -327,7 +327,7 @@ static grpc_error_handle hs_filter_incoming_metadata(grpc_call_element* elem,
GRPC_MDELEM_UNREF(md);
}
if ((*b)->legacy_index()->named.authority == nullptr) {
if (b->legacy_index()->named.authority == nullptr) {
hs_add_error(
error_name, &error,
grpc_error_set_str(
@ -337,7 +337,7 @@ static grpc_error_handle hs_filter_incoming_metadata(grpc_call_element* elem,
channel_data* chand = static_cast<channel_data*>(elem->channel_data);
if (!chand->surface_user_agent &&
(*b)->legacy_index()->named.user_agent != nullptr) {
b->legacy_index()->named.user_agent != nullptr) {
grpc_metadata_batch_remove(b, GRPC_BATCH_USER_AGENT);
}

@ -46,8 +46,8 @@ struct call_data {
// Find the user agent metadata element in the batch
static bool get_user_agent_mdelem(const grpc_metadata_batch* batch,
grpc_mdelem* md) {
if ((*batch)->legacy_index()->named.user_agent != nullptr) {
*md = (*batch)->legacy_index()->named.user_agent->md;
if (batch->legacy_index()->named.user_agent != nullptr) {
*md = batch->legacy_index()->named.user_agent->md;
return true;
}
return false;

@ -120,7 +120,7 @@ static void set_pollset_set(grpc_transport*, grpc_stream*, grpc_pollset_set*) {
static void AssignMetadata(grpc_metadata_batch* mb, grpc_core::Arena* arena,
const grpc_binder::Metadata& md) {
grpc_metadata_batch_init(mb);
mb->Clear();
for (auto& p : md) {
grpc_linked_mdelem* glm = static_cast<grpc_linked_mdelem*>(
arena->Alloc(sizeof(grpc_linked_mdelem)));
@ -396,7 +396,7 @@ static void perform_stream_op_locked(void* stream_op,
grpc_binder::Metadata init_md;
auto batch = op->payload->send_initial_metadata.send_initial_metadata;
(*batch)->ForEach([&](grpc_mdelem md) {
batch->ForEach([&](grpc_mdelem md) {
absl::string_view key = grpc_core::StringViewFromSlice(GRPC_MDKEY(md));
absl::string_view value =
grpc_core::StringViewFromSlice(GRPC_MDVALUE(md));
@ -448,7 +448,7 @@ static void perform_stream_op_locked(void* stream_op,
auto batch = op->payload->send_trailing_metadata.send_trailing_metadata;
grpc_binder::Metadata trailing_metadata;
(*batch)->ForEach([&](grpc_mdelem md) {
batch->ForEach([&](grpc_mdelem md) {
// Client will not send trailing metadata.
GPR_ASSERT(!gbt->is_client);

@ -646,8 +646,8 @@ grpc_chttp2_stream::grpc_chttp2_stream(grpc_chttp2_transport* t,
: t(t),
refcount(refcount),
reffer(this),
metadata_buffer{grpc_chttp2_incoming_metadata_buffer(arena),
grpc_chttp2_incoming_metadata_buffer(arena)} {
initial_metadata_buffer(arena),
trailing_metadata_buffer(arena) {
if (server_data) {
id = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(server_data));
*t->accepting_stream = this;
@ -1252,9 +1252,9 @@ void grpc_chttp2_complete_closure_step(grpc_chttp2_transport* t,
}
static bool contains_non_ok_status(grpc_metadata_batch* batch) {
if ((*batch)->legacy_index()->named.grpc_status != nullptr) {
if (batch->legacy_index()->named.grpc_status != nullptr) {
return !grpc_mdelem_static_value_eq(
(*batch)->legacy_index()->named.grpc_status->md,
batch->legacy_index()->named.grpc_status->md,
GRPC_MDELEM_GRPC_STATUS_0);
}
return false;
@ -1350,7 +1350,7 @@ static void complete_fetch_locked(void* gs, grpc_error_handle error) {
static void log_metadata(const grpc_metadata_batch* md_batch, uint32_t id,
bool is_client, bool is_initial) {
(*md_batch)->ForEach([=](grpc_mdelem md) {
md_batch->ForEach([=](grpc_mdelem md) {
char* key = grpc_slice_to_c_string(GRPC_MDKEY(md));
char* value = grpc_slice_to_c_string(GRPC_MDVALUE(md));
gpr_log(GPR_INFO, "HTTP:%d:%s:%s: %s: %s", id, is_initial ? "HDR" : "TRL",
@ -1411,12 +1411,11 @@ static void perform_stream_op_locked(void* stream_op,
on_complete->next_data.scratch |= CLOSURE_BARRIER_MAY_COVER_WRITE;
// Identify stream compression
if ((*op_payload->send_initial_metadata.send_initial_metadata)
->legacy_index()
if (op_payload->send_initial_metadata.send_initial_metadata->legacy_index()
->named.content_encoding == nullptr ||
grpc_stream_compression_method_parse(
GRPC_MDVALUE(
(*op_payload->send_initial_metadata.send_initial_metadata)
op_payload->send_initial_metadata.send_initial_metadata
->legacy_index()
->named.content_encoding->md),
true, &s->stream_compression_method) == 0) {
@ -1432,8 +1431,7 @@ static void perform_stream_op_locked(void* stream_op,
s->send_initial_metadata =
op_payload->send_initial_metadata.send_initial_metadata;
if (t->is_client) {
s->deadline =
GPR_MIN(s->deadline, (*s->send_initial_metadata)->deadline());
s->deadline = std::min(s->deadline, s->send_initial_metadata->deadline());
}
if (contains_non_ok_status(s->send_initial_metadata)) {
s->seen_error = true;
@ -1627,14 +1625,12 @@ static void perform_stream_op(grpc_transport* gt, grpc_stream* gs,
if (!t->is_client) {
if (op->send_initial_metadata) {
grpc_millis deadline =
(*op->payload->send_initial_metadata.send_initial_metadata)
->deadline();
op->payload->send_initial_metadata.send_initial_metadata->deadline();
GPR_ASSERT(deadline == GRPC_MILLIS_INF_FUTURE);
}
if (op->send_trailing_metadata) {
grpc_millis deadline =
(*op->payload->send_trailing_metadata.send_trailing_metadata)
->deadline();
grpc_millis deadline = op->payload->send_trailing_metadata
.send_trailing_metadata->deadline();
GPR_ASSERT(deadline == GRPC_MILLIS_INF_FUTURE);
}
}
@ -1861,7 +1857,7 @@ void grpc_chttp2_maybe_complete_recv_initial_metadata(
&s->unprocessed_incoming_frames_buffer);
}
}
grpc_chttp2_incoming_metadata_buffer_publish(&s->metadata_buffer[0],
grpc_chttp2_incoming_metadata_buffer_publish(&s->initial_metadata_buffer,
s->recv_initial_metadata);
null_then_sched_closure(&s->recv_initial_metadata_ready);
}
@ -2015,7 +2011,7 @@ void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_chttp2_transport* t,
s->recv_trailing_metadata_finished != nullptr) {
grpc_transport_move_stats(&s->stats, s->collecting_stats);
s->collecting_stats = nullptr;
grpc_chttp2_incoming_metadata_buffer_publish(&s->metadata_buffer[1],
grpc_chttp2_incoming_metadata_buffer_publish(&s->trailing_metadata_buffer,
s->recv_trailing_metadata);
null_then_sched_closure(&s->recv_trailing_metadata_finished);
}
@ -2109,13 +2105,13 @@ void grpc_chttp2_fake_status(grpc_chttp2_transport* t, grpc_chttp2_stream* s,
gpr_ltoa(status, status_string);
GRPC_LOG_IF_ERROR("add_status",
grpc_chttp2_incoming_metadata_buffer_replace_or_add(
&s->metadata_buffer[1], GRPC_MDSTR_GRPC_STATUS,
&s->trailing_metadata_buffer, GRPC_MDSTR_GRPC_STATUS,
grpc_core::UnmanagedMemorySlice(status_string)));
if (!GRPC_SLICE_IS_EMPTY(slice)) {
GRPC_LOG_IF_ERROR(
"add_status_message",
grpc_chttp2_incoming_metadata_buffer_replace_or_add(
&s->metadata_buffer[1], GRPC_MDSTR_GRPC_MESSAGE, slice));
&s->trailing_metadata_buffer, GRPC_MDSTR_GRPC_MESSAGE, slice));
}
s->published_metadata[1] = GRPC_METADATA_SYNTHESIZED_FROM_FAKE;
grpc_chttp2_maybe_complete_recv_trailing_metadata(t, s);

@ -103,7 +103,8 @@ grpc_error_handle grpc_chttp2_rst_stream_parser_parse(void* parser,
((static_cast<uint32_t>(p->reason_bytes[2])) << 8) |
((static_cast<uint32_t>(p->reason_bytes[3])));
grpc_error_handle error = GRPC_ERROR_NONE;
if (reason != GRPC_HTTP2_NO_ERROR || s->metadata_buffer[1].size == 0) {
if (reason != GRPC_HTTP2_NO_ERROR ||
s->trailing_metadata_buffer.size == 0) {
error = grpc_error_set_int(
grpc_error_set_str(
GRPC_ERROR_CREATE_FROM_STATIC_STRING("RST_STREAM"),

@ -1348,10 +1348,10 @@ static void force_client_rst_stream(void* sp, grpc_error_handle /*error*/) {
static void parse_stream_compression_md(grpc_chttp2_transport* /*t*/,
grpc_chttp2_stream* s,
grpc_metadata_batch* initial_metadata) {
if ((*initial_metadata)->legacy_index()->named.content_encoding == nullptr ||
if (initial_metadata->legacy_index()->named.content_encoding == nullptr ||
grpc_stream_compression_method_parse(
GRPC_MDVALUE(
(*initial_metadata)->legacy_index()->named.content_encoding->md),
initial_metadata->legacy_index()->named.content_encoding->md),
false, &s->stream_decompression_method) == 0) {
s->stream_decompression_method =
GRPC_STREAM_COMPRESSION_IDENTITY_DECOMPRESS;
@ -1383,14 +1383,14 @@ grpc_error_handle grpc_chttp2_header_parser_parse(void* hpack_parser,
stream id on a header */
if (s != nullptr) {
if (parser->is_boundary()) {
if (s->header_frames_received == GPR_ARRAY_SIZE(s->metadata_buffer)) {
if (s->header_frames_received == 2) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"Too many trailer frames");
}
/* Process stream compression md element if it exists */
if (s->header_frames_received ==
0) { /* Only acts on initial metadata */
parse_stream_compression_md(t, s, &s->metadata_buffer[0].batch);
parse_stream_compression_md(t, s, &s->initial_metadata_buffer.batch);
}
s->published_metadata[s->header_frames_received] =
GRPC_METADATA_PUBLISHED_FROM_WIRE;

@ -45,7 +45,7 @@ grpc_error_handle grpc_chttp2_incoming_metadata_buffer_add(
grpc_error_handle grpc_chttp2_incoming_metadata_buffer_replace_or_add(
grpc_chttp2_incoming_metadata_buffer* buffer, grpc_slice key,
grpc_slice value) {
if (buffer->batch->ReplaceIfExists(key, value)) return GRPC_ERROR_NONE;
if (buffer->batch.ReplaceIfExists(key, value)) return GRPC_ERROR_NONE;
return grpc_chttp2_incoming_metadata_buffer_add(
buffer, grpc_mdelem_from_slices(grpc_slice_ref_internal(key),
grpc_slice_ref_internal(value)));
@ -53,10 +53,10 @@ grpc_error_handle grpc_chttp2_incoming_metadata_buffer_replace_or_add(
void grpc_chttp2_incoming_metadata_buffer_set_deadline(
grpc_chttp2_incoming_metadata_buffer* buffer, grpc_millis deadline) {
buffer->batch->SetDeadline(deadline);
buffer->batch.SetDeadline(deadline);
}
void grpc_chttp2_incoming_metadata_buffer_publish(
grpc_chttp2_incoming_metadata_buffer* buffer, grpc_metadata_batch* batch) {
grpc_metadata_batch_move(&buffer->batch, batch);
*batch = std::move(buffer->batch);
}

@ -25,13 +25,8 @@
struct grpc_chttp2_incoming_metadata_buffer {
explicit grpc_chttp2_incoming_metadata_buffer(grpc_core::Arena* arena)
: arena(arena) {
grpc_metadata_batch_init(&batch);
batch->ClearDeadline();
}
~grpc_chttp2_incoming_metadata_buffer() {
grpc_metadata_batch_destroy(&batch);
}
: arena(arena) {}
~grpc_chttp2_incoming_metadata_buffer() = default;
static constexpr size_t kPreallocatedMDElem = 10;

@ -589,7 +589,8 @@ struct grpc_chttp2_stream {
grpc_published_metadata_method published_metadata[2] = {};
bool final_metadata_requested = false;
grpc_chttp2_incoming_metadata_buffer metadata_buffer[2];
grpc_chttp2_incoming_metadata_buffer initial_metadata_buffer;
grpc_chttp2_incoming_metadata_buffer trailing_metadata_buffer;
grpc_slice_buffer frame_storage; /* protected by t combiner */

@ -451,7 +451,8 @@ handle_timeout(grpc_chttp2_stream* s, grpc_mdelem md) {
}
if (timeout != GRPC_MILLIS_INF_FUTURE) {
grpc_chttp2_incoming_metadata_buffer_set_deadline(
&s->metadata_buffer[0], grpc_core::ExecCtx::Get()->Now() + timeout);
&s->initial_metadata_buffer,
grpc_core::ExecCtx::Get()->Now() + timeout);
}
GRPC_MDELEM_UNREF(md);
return GRPC_ERROR_NONE;
@ -504,7 +505,8 @@ static grpc_error_handle on_initial_header(void* tp, grpc_mdelem md) {
return handle_timeout(s, md);
}
const size_t new_size = s->metadata_buffer[0].size + GRPC_MDELEM_LENGTH(md);
const size_t new_size =
s->initial_metadata_buffer.size + GRPC_MDELEM_LENGTH(md);
const size_t metadata_size_limit =
t->settings[GRPC_ACKED_SETTINGS]
[GRPC_CHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE];
@ -512,8 +514,8 @@ static grpc_error_handle on_initial_header(void* tp, grpc_mdelem md) {
return handle_metadata_size_limit_exceeded(t, s, md, new_size,
metadata_size_limit);
} else {
grpc_error_handle error =
grpc_chttp2_incoming_metadata_buffer_add(&s->metadata_buffer[0], md);
grpc_error_handle error = grpc_chttp2_incoming_metadata_buffer_add(
&s->initial_metadata_buffer, md);
if (GPR_UNLIKELY(error != GRPC_ERROR_NONE)) {
return handle_metadata_add_failure(t, s, md, error);
}
@ -539,7 +541,8 @@ static grpc_error_handle on_trailing_header(void* tp, grpc_mdelem md) {
gpr_free(value);
}
const size_t new_size = s->metadata_buffer[1].size + GRPC_MDELEM_LENGTH(md);
const size_t new_size =
s->trailing_metadata_buffer.size + GRPC_MDELEM_LENGTH(md);
const size_t metadata_size_limit =
t->settings[GRPC_ACKED_SETTINGS]
[GRPC_CHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE];
@ -561,8 +564,8 @@ static grpc_error_handle on_trailing_header(void* tp, grpc_mdelem md) {
s->seen_error = true;
GRPC_MDELEM_UNREF(md);
} else {
grpc_error_handle error =
grpc_chttp2_incoming_metadata_buffer_add(&s->metadata_buffer[1], md);
grpc_error_handle error = grpc_chttp2_incoming_metadata_buffer_add(
&s->trailing_metadata_buffer, md);
if (error != GRPC_ERROR_NONE) {
grpc_chttp2_cancel_stream(t, s, error);
grpc_chttp2_parsing_become_skip_parser(t);

@ -193,8 +193,8 @@ static uint32_t target_write_size(grpc_chttp2_transport* /*t*/) {
// Returns true if initial_metadata contains only default headers.
static bool is_default_initial_metadata(grpc_metadata_batch* initial_metadata) {
return (*initial_metadata)->default_count() ==
(*initial_metadata)->non_deadline_count();
return initial_metadata->default_count() ==
initial_metadata->non_deadline_count();
}
namespace {
@ -469,7 +469,7 @@ class StreamWriteContext {
[GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE], // max_frame_size
&s_->stats.outgoing // stats
},
**s_->send_initial_metadata, &t_->outbuf);
*s_->send_initial_metadata, &t_->outbuf);
grpc_chttp2_reset_ping_clock(t_);
write_context_->IncInitialMetadataWrites();
}
@ -580,7 +580,7 @@ class StreamWriteContext {
grpc_core::MetadataArray(
extra_headers_for_trailing_metadata_,
num_extra_headers_for_trailing_metadata_),
**s_->send_trailing_metadata),
*s_->send_trailing_metadata),
&t_->outbuf);
}
write_context_->IncTrailingMetadataWrites();
@ -601,17 +601,16 @@ class StreamWriteContext {
gpr_log(GPR_INFO, "not sending initial_metadata (Trailers-Only)"));
// When sending Trailers-Only, we need to move the :status and
// content-type headers to the trailers.
if ((*s_->send_initial_metadata)->legacy_index()->named.status != nullptr) {
if (s_->send_initial_metadata->legacy_index()->named.status != nullptr) {
extra_headers_for_trailing_metadata_
[num_extra_headers_for_trailing_metadata_++] =
&(*s_->send_initial_metadata)->legacy_index()->named.status->md;
&s_->send_initial_metadata->legacy_index()->named.status->md;
}
if ((*s_->send_initial_metadata)->legacy_index()->named.content_type !=
if (s_->send_initial_metadata->legacy_index()->named.content_type !=
nullptr) {
extra_headers_for_trailing_metadata_
[num_extra_headers_for_trailing_metadata_++] =
&(*s_->send_initial_metadata)
->legacy_index()
&s_->send_initial_metadata->legacy_index()
->named.content_type->md;
}
}

@ -705,7 +705,7 @@ static void convert_metadata_to_cronet_headers(
bidirectional_stream_header** pp_headers, size_t* p_num_headers,
const char** method) {
/* Get number of header fields */
size_t num_headers_available = (*metadata)->count();
size_t num_headers_available = metadata->count();
/* Allocate enough memory. It is freed in the on_stream_ready callback
*/
bidirectional_stream_header* headers =
@ -719,7 +719,7 @@ static void convert_metadata_to_cronet_headers(
TODO (makdharma): Eliminate need to traverse the LL second time for perf.
*/
size_t num_headers = 0;
(*metadata)->ForEach([&](grpc_mdelem mdelem) {
metadata->ForEach([&](grpc_mdelem mdelem) {
char* key = grpc_slice_to_c_string(GRPC_MDKEY(mdelem));
char* value;
if (grpc_is_binary_header_internal(GRPC_MDKEY(mdelem))) {
@ -760,12 +760,12 @@ static void convert_metadata_to_cronet_headers(
headers[num_headers].value = value;
num_headers++;
});
if ((*metadata)->deadline() != GRPC_MILLIS_INF_FUTURE) {
if (metadata->deadline() != GRPC_MILLIS_INF_FUTURE) {
char* key = grpc_slice_to_c_string(GRPC_MDSTR_GRPC_TIMEOUT);
char* value =
static_cast<char*>(gpr_malloc(GRPC_HTTP2_TIMEOUT_ENCODE_MIN_BUFSIZE));
grpc_http2_encode_timeout(
(*metadata)->deadline() - grpc_core::ExecCtx::Get()->Now(), value);
metadata->deadline() - grpc_core::ExecCtx::Get()->Now(), value);
headers[num_headers].key = key;
headers[num_headers].value = value;
@ -789,7 +789,7 @@ static void parse_grpc_header(const uint8_t* data, int* length,
static bool header_has_authority(const grpc_metadata_batch* b) {
bool found = false;
(*b)->ForEach([&](grpc_mdelem elem) {
b->ForEach([&](grpc_mdelem elem) {
if (grpc_slice_eq_static_interned(GRPC_MDKEY(elem), GRPC_MDSTR_AUTHORITY)) {
found = true;
}

@ -132,11 +132,6 @@ struct inproc_stream {
ref("inproc_init_stream:init");
ref("inproc_init_stream:list");
grpc_metadata_batch_init(&to_read_initial_md);
grpc_metadata_batch_init(&to_read_trailing_md);
grpc_metadata_batch_init(&write_buffer_initial_md);
grpc_metadata_batch_init(&write_buffer_trailing_md);
stream_list_prev = nullptr;
gpr_mu_lock(&t->mu->mu);
stream_list_next = t->stream_list;
@ -285,7 +280,7 @@ struct inproc_stream {
void log_metadata(const grpc_metadata_batch* md_batch, bool is_client,
bool is_initial) {
(*md_batch)->ForEach([=](grpc_mdelem md) {
md_batch->ForEach([=](grpc_mdelem md) {
char* key = grpc_slice_to_c_string(GRPC_MDKEY(md));
char* value = grpc_slice_to_c_string(GRPC_MDVALUE(md));
gpr_log(GPR_INFO, "INPROC:%s:%s: %s: %s", is_initial ? "HDR" : "TRL",
@ -310,7 +305,7 @@ grpc_error_handle fill_in_metadata(inproc_stream* s,
*markfilled = true;
}
grpc_error_handle error = GRPC_ERROR_NONE;
(*metadata)->ForEach([&](grpc_mdelem md) {
metadata->ForEach([&](grpc_mdelem md) {
if (error != GRPC_ERROR_NONE) return;
grpc_linked_mdelem* nelem =
static_cast<grpc_linked_mdelem*>(s->arena->Alloc(sizeof(*nelem)));
@ -334,8 +329,8 @@ int init_stream(grpc_transport* gt, grpc_stream* gs,
void close_stream_locked(inproc_stream* s) {
if (!s->closed) {
// Release the metadata that we would have written out
grpc_metadata_batch_destroy(&s->write_buffer_initial_md);
grpc_metadata_batch_destroy(&s->write_buffer_trailing_md);
s->write_buffer_initial_md.Clear();
s->write_buffer_trailing_md.Clear();
if (s->listed) {
inproc_stream* p = s->stream_list_prev;
@ -360,8 +355,8 @@ void close_stream_locked(inproc_stream* s) {
void close_other_side_locked(inproc_stream* s, const char* reason) {
if (s->other_side != nullptr) {
// First release the metadata that came from the other side's arena
grpc_metadata_batch_destroy(&s->to_read_initial_md);
grpc_metadata_batch_destroy(&s->to_read_trailing_md);
s->to_read_initial_md.Clear();
s->to_read_trailing_md.Clear();
s->other_side->unref(reason);
s->other_side_closed = true;
@ -412,8 +407,6 @@ void fail_helper_locked(inproc_stream* s, grpc_error_handle error) {
s->trailing_md_sent = true;
grpc_metadata_batch fake_md;
grpc_metadata_batch_init(&fake_md);
inproc_stream* other = s->other_side;
grpc_metadata_batch* dest = (other == nullptr)
? &s->write_buffer_trailing_md
@ -421,7 +414,6 @@ void fail_helper_locked(inproc_stream* s, grpc_error_handle error) {
bool* destfilled = (other == nullptr) ? &s->write_buffer_trailing_md_filled
: &other->to_read_trailing_md_filled;
fill_in_metadata(s, &fake_md, 0, dest, nullptr, destfilled);
grpc_metadata_batch_destroy(&fake_md);
if (other != nullptr) {
if (other->cancel_other_error == GRPC_ERROR_NONE) {
@ -438,7 +430,6 @@ void fail_helper_locked(inproc_stream* s, grpc_error_handle error) {
// If this is a server, provide initial metadata with a path and authority
// since it expects that as well as no error yet
grpc_metadata_batch fake_md;
grpc_metadata_batch_init(&fake_md);
grpc_linked_mdelem* path_md =
static_cast<grpc_linked_mdelem*>(s->arena->Alloc(sizeof(*path_md)));
path_md->md = grpc_mdelem_from_slices(g_fake_path_key, g_fake_path_value);
@ -456,7 +447,6 @@ void fail_helper_locked(inproc_stream* s, grpc_error_handle error) {
.recv_initial_metadata,
s->recv_initial_md_op->payload->recv_initial_metadata.recv_flags,
nullptr);
grpc_metadata_batch_destroy(&fake_md);
err = GRPC_ERROR_NONE;
} else {
err = GRPC_ERROR_REF(error);
@ -707,9 +697,8 @@ void op_state_machine_locked(inproc_stream* s, grpc_error_handle error) {
.recv_initial_metadata,
s->recv_initial_md_op->payload->recv_initial_metadata.recv_flags,
nullptr);
(*s->recv_initial_md_op->payload->recv_initial_metadata
.recv_initial_metadata)
->SetDeadline(s->deadline);
s->recv_initial_md_op->payload->recv_initial_metadata
.recv_initial_metadata->SetDeadline(s->deadline);
if (s->recv_initial_md_op->payload->recv_initial_metadata
.trailing_metadata_available != nullptr) {
*s->recv_initial_md_op->payload->recv_initial_metadata
@ -911,7 +900,6 @@ bool cancel_stream_locked(inproc_stream* s, grpc_error_handle error) {
s->trailing_md_sent = true;
grpc_metadata_batch cancel_md;
grpc_metadata_batch_init(&cancel_md);
grpc_metadata_batch* dest = (other == nullptr)
? &s->write_buffer_trailing_md
@ -919,7 +907,6 @@ bool cancel_stream_locked(inproc_stream* s, grpc_error_handle error) {
bool* destfilled = (other == nullptr) ? &s->write_buffer_trailing_md_filled
: &other->to_read_trailing_md_filled;
fill_in_metadata(s, &cancel_md, 0, dest, nullptr, destfilled);
grpc_metadata_batch_destroy(&cancel_md);
if (other != nullptr) {
if (other->cancel_other_error == GRPC_ERROR_NONE) {
@ -1032,9 +1019,8 @@ void perform_stream_op(grpc_transport* gt, grpc_stream* gs,
if (s->t->is_client) {
grpc_millis* dl =
(other == nullptr) ? &s->write_buffer_deadline : &other->deadline;
*dl = GPR_MIN(
*dl, (*op->payload->send_initial_metadata.send_initial_metadata)
->deadline());
*dl = std::min(*dl, op->payload->send_initial_metadata
.send_initial_metadata->deadline());
s->initial_md_sent = true;
}
}

@ -81,8 +81,8 @@ EvaluateArgs::PerChannelArgs::PerChannelArgs(grpc_auth_context* auth_context,
absl::string_view EvaluateArgs::GetPath() const {
absl::string_view path;
if (metadata_ != nullptr &&
(*metadata_)->legacy_index()->named.path != nullptr) {
grpc_linked_mdelem* elem = (*metadata_)->legacy_index()->named.path;
metadata_->legacy_index()->named.path != nullptr) {
grpc_linked_mdelem* elem = metadata_->legacy_index()->named.path;
const grpc_slice& val = GRPC_MDVALUE(elem->md);
path = StringViewFromSlice(val);
}
@ -92,8 +92,8 @@ absl::string_view EvaluateArgs::GetPath() const {
absl::string_view EvaluateArgs::GetHost() const {
absl::string_view host;
if (metadata_ != nullptr &&
(*metadata_)->legacy_index()->named.host != nullptr) {
grpc_linked_mdelem* elem = (*metadata_)->legacy_index()->named.host;
metadata_->legacy_index()->named.host != nullptr) {
grpc_linked_mdelem* elem = metadata_->legacy_index()->named.host;
const grpc_slice& val = GRPC_MDVALUE(elem->md);
host = StringViewFromSlice(val);
}
@ -103,8 +103,8 @@ absl::string_view EvaluateArgs::GetHost() const {
absl::string_view EvaluateArgs::GetMethod() const {
absl::string_view method;
if (metadata_ != nullptr &&
(*metadata_)->legacy_index()->named.method != nullptr) {
grpc_linked_mdelem* elem = (*metadata_)->legacy_index()->named.method;
metadata_->legacy_index()->named.method != nullptr) {
grpc_linked_mdelem* elem = metadata_->legacy_index()->named.method;
const grpc_slice& val = GRPC_MDVALUE(elem->md);
method = StringViewFromSlice(val);
}
@ -117,7 +117,7 @@ std::multimap<absl::string_view, absl::string_view> EvaluateArgs::GetHeaders()
if (metadata_ == nullptr) {
return headers;
}
(*metadata_)->ForEach([&](grpc_mdelem md) {
metadata_->ForEach([&](grpc_mdelem md) {
const grpc_slice& key = GRPC_MDKEY(md);
const grpc_slice& val = GRPC_MDVALUE(md);
headers.emplace(StringViewFromSlice(key), StringViewFromSlice(val));

@ -372,13 +372,13 @@ static void client_auth_start_transport_stream_op_batch(
if (batch->send_initial_metadata) {
grpc_metadata_batch* metadata =
batch->payload->send_initial_metadata.send_initial_metadata;
if ((*metadata)->legacy_index()->named.path != nullptr) {
if (metadata->legacy_index()->named.path != nullptr) {
calld->method = grpc_slice_ref_internal(
GRPC_MDVALUE((*metadata)->legacy_index()->named.path->md));
GRPC_MDVALUE(metadata->legacy_index()->named.path->md));
}
if ((*metadata)->legacy_index()->named.authority != nullptr) {
if (metadata->legacy_index()->named.authority != nullptr) {
calld->host = grpc_slice_ref_internal(
GRPC_MDVALUE((*metadata)->legacy_index()->named.authority->md));
GRPC_MDVALUE(metadata->legacy_index()->named.authority->md));
batch->handler_private.extra_arg = elem;
GRPC_CALL_STACK_REF(calld->owning_call, "check_call_host");
GRPC_CLOSURE_INIT(&calld->async_result_closure, on_host_checked, batch,

@ -98,7 +98,7 @@ static grpc_metadata_array metadata_batch_to_md_array(
const grpc_metadata_batch* batch) {
grpc_metadata_array result;
grpc_metadata_array_init(&result);
(*batch)->ForEach([&](grpc_mdelem md) {
batch->ForEach([&](grpc_mdelem md) {
grpc_metadata* usr_md = nullptr;
grpc_slice key = GRPC_MDKEY(md);
grpc_slice value = GRPC_MDVALUE(md);

@ -143,13 +143,7 @@ struct grpc_call {
cq(args.cq),
channel(args.channel),
is_client(args.server_transport_data == nullptr),
stream_op_payload(context) {
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
metadata_batch[i][j]->ClearDeadline();
}
}
}
stream_op_payload(context) {}
~grpc_call() {
for (int i = 0; i < GRPC_CONTEXT_COUNT; ++i) {
@ -545,20 +539,17 @@ static void release_call(void* call, grpc_error_handle /*error*/) {
static void destroy_call(void* call, grpc_error_handle /*error*/) {
GPR_TIMER_SCOPE("destroy_call", 0);
size_t i;
int ii;
grpc_call* c = static_cast<grpc_call*>(call);
for (i = 0; i < 2; i++) {
grpc_metadata_batch_destroy(
&c->metadata_batch[1 /* is_receiving */][i /* is_initial */]);
for (int i = 0; i < 2; i++) {
c->metadata_batch[1 /* is_receiving */][i /* is_initial */].Clear();
}
c->receiving_stream.reset();
parent_call* pc = get_parent_call(c);
if (pc != nullptr) {
pc->~parent_call();
}
for (ii = 0; ii < c->send_extra_metadata_count; ii++) {
GRPC_MDELEM_UNREF(c->send_extra_metadata[ii].md);
for (int i = 0; i < c->send_extra_metadata_count; i++) {
GRPC_MDELEM_UNREF(c->send_extra_metadata[i].md);
}
if (c->cq) {
GRPC_CQ_INTERNAL_UNREF(c->cq, "bind");
@ -1000,20 +991,20 @@ static grpc_stream_compression_algorithm decode_stream_compression(
static void publish_app_metadata(grpc_call* call, grpc_metadata_batch* b,
int is_trailing) {
if ((*b)->non_deadline_count() == 0) return;
if (b->non_deadline_count() == 0) return;
if (!call->is_client && is_trailing) return;
if (is_trailing && call->buffered_metadata[1] == nullptr) return;
GPR_TIMER_SCOPE("publish_app_metadata", 0);
grpc_metadata_array* dest;
grpc_metadata* mdusr;
dest = call->buffered_metadata[is_trailing];
if (dest->count + (*b)->non_deadline_count() > dest->capacity) {
dest->capacity = GPR_MAX(dest->capacity + (*b)->non_deadline_count(),
if (dest->count + b->non_deadline_count() > dest->capacity) {
dest->capacity = std::max(dest->capacity + b->non_deadline_count(),
dest->capacity * 3 / 2);
dest->metadata = static_cast<grpc_metadata*>(
gpr_realloc(dest->metadata, sizeof(grpc_metadata) * dest->capacity));
}
(*b)->ForEach([&](grpc_mdelem md) {
b->ForEach([&](grpc_mdelem md) {
mdusr = &dest->metadata[dest->count++];
/* we pass back borrowed slices that are valid whilst the call is valid */
mdusr->key = GRPC_MDKEY(md);
@ -1022,33 +1013,33 @@ 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)->legacy_index()->named.content_encoding != nullptr) {
if (b->legacy_index()->named.content_encoding != nullptr) {
GPR_TIMER_SCOPE("incoming_stream_compression_algorithm", 0);
set_incoming_stream_compression_algorithm(
call, decode_stream_compression(
(*b)->legacy_index()->named.content_encoding->md));
b->legacy_index()->named.content_encoding->md));
grpc_metadata_batch_remove(b, GRPC_BATCH_CONTENT_ENCODING);
}
if ((*b)->legacy_index()->named.grpc_encoding != nullptr) {
if (b->legacy_index()->named.grpc_encoding != nullptr) {
GPR_TIMER_SCOPE("incoming_message_compression_algorithm", 0);
set_incoming_message_compression_algorithm(
call, decode_message_compression(
(*b)->legacy_index()->named.grpc_encoding->md));
call,
decode_message_compression(b->legacy_index()->named.grpc_encoding->md));
grpc_metadata_batch_remove(b, GRPC_BATCH_GRPC_ENCODING);
}
uint32_t message_encodings_accepted_by_peer = 1u;
uint32_t stream_encodings_accepted_by_peer = 1u;
if ((*b)->legacy_index()->named.grpc_accept_encoding != nullptr) {
if (b->legacy_index()->named.grpc_accept_encoding != nullptr) {
GPR_TIMER_SCOPE("encodings_accepted_by_peer", 0);
set_encodings_accepted_by_peer(
call, (*b)->legacy_index()->named.grpc_accept_encoding->md,
call, b->legacy_index()->named.grpc_accept_encoding->md,
&message_encodings_accepted_by_peer, false);
grpc_metadata_batch_remove(b, GRPC_BATCH_GRPC_ACCEPT_ENCODING);
}
if ((*b)->legacy_index()->named.accept_encoding != nullptr) {
if (b->legacy_index()->named.accept_encoding != nullptr) {
GPR_TIMER_SCOPE("stream_encodings_accepted_by_peer", 0);
set_encodings_accepted_by_peer(
call, (*b)->legacy_index()->named.accept_encoding->md,
set_encodings_accepted_by_peer(call,
b->legacy_index()->named.accept_encoding->md,
&stream_encodings_accepted_by_peer, true);
grpc_metadata_batch_remove(b, GRPC_BATCH_ACCEPT_ENCODING);
}
@ -1064,9 +1055,9 @@ static void recv_trailing_filter(void* args, grpc_metadata_batch* b,
grpc_call* call = static_cast<grpc_call*>(args);
if (batch_error != GRPC_ERROR_NONE) {
set_final_status(call, batch_error);
} else if ((*b)->legacy_index()->named.grpc_status != nullptr) {
} else if (b->legacy_index()->named.grpc_status != nullptr) {
grpc_status_code status_code = grpc_get_status_code_from_metadata(
(*b)->legacy_index()->named.grpc_status->md);
b->legacy_index()->named.grpc_status->md);
grpc_error_handle error = GRPC_ERROR_NONE;
if (status_code != GRPC_STATUS_OK) {
char* peer = grpc_call_get_peer(call);
@ -1076,11 +1067,11 @@ static void recv_trailing_filter(void* args, grpc_metadata_batch* b,
static_cast<intptr_t>(status_code));
gpr_free(peer);
}
if ((*b)->legacy_index()->named.grpc_message != nullptr) {
if (b->legacy_index()->named.grpc_message != nullptr) {
error = grpc_error_set_str(
error, GRPC_ERROR_STR_GRPC_MESSAGE,
grpc_slice_ref_internal(
GRPC_MDVALUE((*b)->legacy_index()->named.grpc_message->md)));
GRPC_MDVALUE(b->legacy_index()->named.grpc_message->md)));
grpc_metadata_batch_remove(b, GRPC_BATCH_GRPC_MESSAGE);
} else if (error != GRPC_ERROR_NONE) {
error = grpc_error_set_str(error, GRPC_ERROR_STR_GRPC_MESSAGE,
@ -1192,8 +1183,7 @@ static void post_batch_completion(batch_control* bctl) {
gpr_atm_acq_load(&bctl->batch_error)));
if (bctl->op.send_initial_metadata) {
grpc_metadata_batch_destroy(
&call->metadata_batch[0 /* is_receiving */][0 /* is_trailing */]);
call->metadata_batch[0 /* is_receiving */][0 /* is_trailing */].Clear();
}
if (bctl->op.send_message) {
if (bctl->op.payload->send_message.stream_write_closed &&
@ -1205,8 +1195,7 @@ static void post_batch_completion(batch_control* bctl) {
call->sending_message = false;
}
if (bctl->op.send_trailing_metadata) {
grpc_metadata_batch_destroy(
&call->metadata_batch[0 /* is_receiving */][1 /* is_trailing */]);
call->metadata_batch[0 /* is_receiving */][1 /* is_trailing */].Clear();
}
if (bctl->op.recv_trailing_metadata) {
/* propagate cancellation to any interested children */
@ -1488,7 +1477,7 @@ static void receiving_initial_metadata_ready(void* bctlp,
GPR_TIMER_SCOPE("validate_filtered_metadata", 0);
validate_filtered_metadata(bctl);
grpc_millis deadline = (*md)->deadline();
grpc_millis deadline = md->deadline();
if (deadline != GRPC_MILLIS_INF_FUTURE && !call->is_client) {
call->send_deadline = deadline;
}
@ -1676,7 +1665,7 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops,
}
/* TODO(ctiller): just make these the same variable? */
if (call->is_client) {
call->metadata_batch[0][0]->SetDeadline(call->send_deadline);
call->metadata_batch[0][0].SetDeadline(call->send_deadline);
}
stream_op_payload->send_initial_metadata.send_initial_metadata =
&call->metadata_batch[0 /* is_receiving */][0 /* is_trailing */];
@ -2032,7 +2021,7 @@ bool grpc_call_is_trailers_only(const grpc_call* call) {
bool result = call->is_trailers_only;
GPR_DEBUG_ASSERT(
!result ||
call->metadata_batch[1 /* is_receiving */][0 /* is_trailing */]->empty());
call->metadata_batch[1 /* is_receiving */][0 /* is_trailing */].empty());
return result;
}

@ -1382,24 +1382,21 @@ void Server::CallData::RecvInitialMetadataReady(void* arg,
grpc_millis op_deadline;
if (error == GRPC_ERROR_NONE) {
GPR_DEBUG_ASSERT(
(*calld->recv_initial_metadata_)->legacy_index()->named.path !=
nullptr);
calld->recv_initial_metadata_->legacy_index()->named.path != nullptr);
GPR_DEBUG_ASSERT(
(*calld->recv_initial_metadata_)->legacy_index()->named.authority !=
calld->recv_initial_metadata_->legacy_index()->named.authority !=
nullptr);
calld->path_.emplace(grpc_slice_ref_internal(GRPC_MDVALUE(
(*calld->recv_initial_metadata_)->legacy_index()->named.path->md)));
calld->host_.emplace(
grpc_slice_ref_internal(GRPC_MDVALUE((*calld->recv_initial_metadata_)
->legacy_index()
->named.authority->md)));
calld->recv_initial_metadata_->legacy_index()->named.path->md)));
calld->host_.emplace(grpc_slice_ref_internal(GRPC_MDVALUE(
calld->recv_initial_metadata_->legacy_index()->named.authority->md)));
grpc_metadata_batch_remove(calld->recv_initial_metadata_, GRPC_BATCH_PATH);
grpc_metadata_batch_remove(calld->recv_initial_metadata_,
GRPC_BATCH_AUTHORITY);
} else {
GRPC_ERROR_REF(error);
}
op_deadline = (*calld->recv_initial_metadata_)->deadline();
op_deadline = calld->recv_initial_metadata_->deadline();
if (op_deadline != GRPC_MILLIS_INF_FUTURE) {
calld->deadline_ = op_deadline;
}

@ -94,6 +94,17 @@ MetadataMap::MetadataMap(MetadataMap&& other) noexcept {
other.deadline_ = GRPC_MILLIS_INF_FUTURE;
}
MetadataMap& MetadataMap::operator=(MetadataMap&& other) noexcept {
Clear();
list_ = other.list_;
idx_ = other.idx_;
deadline_ = other.deadline_;
memset(&other.list_, 0, sizeof(list_));
memset(&other.idx_, 0, sizeof(idx_));
other.deadline_ = GRPC_MILLIS_INF_FUTURE;
return *this;
}
MetadataMap::~MetadataMap() {
AssertValidCallouts();
for (auto* l = list_.head; l; l = l->next) {
@ -373,10 +384,10 @@ void grpc_metadata_batch_set_value(grpc_linked_mdelem* storage,
void grpc_metadata_batch_copy(grpc_metadata_batch* src,
grpc_metadata_batch* dst,
grpc_linked_mdelem* storage) {
grpc_metadata_batch_init(dst);
(*dst)->SetDeadline((*src)->deadline());
dst->Clear();
dst->SetDeadline(src->deadline());
size_t i = 0;
(*src)->ForEach([&](grpc_mdelem md) {
src->ForEach([&](grpc_mdelem md) {
// If the mdelem is not external, take a ref.
// Otherwise, create a new copy, holding its own refs to the
// underlying slices.

@ -196,42 +196,35 @@ class MetadataMap {
} // namespace grpc_core
using grpc_metadata_batch =
grpc_core::ManualConstructor<grpc_core::MetadataMap>;
using grpc_metadata_batch = grpc_core::MetadataMap;
inline void grpc_metadata_batch_init(grpc_metadata_batch* batch) {
batch->Init();
}
inline void grpc_metadata_batch_destroy(grpc_metadata_batch* batch) {
batch->Destroy();
}
inline void grpc_metadata_batch_clear(grpc_metadata_batch* batch) {
(*batch)->Clear();
batch->Clear();
}
inline bool grpc_metadata_batch_is_empty(grpc_metadata_batch* batch) {
return (*batch)->empty();
return batch->empty();
}
/* Returns the transport size of the batch. */
inline size_t grpc_metadata_batch_size(grpc_metadata_batch* batch) {
return (*batch)->TransportSize();
return batch->TransportSize();
}
/** Remove \a storage from the batch, unreffing the mdelem contained */
inline void grpc_metadata_batch_remove(grpc_metadata_batch* batch,
grpc_linked_mdelem* storage) {
(*batch)->Remove(storage);
batch->Remove(storage);
}
inline void grpc_metadata_batch_remove(grpc_metadata_batch* batch,
grpc_metadata_batch_callouts_index idx) {
(*batch)->Remove(idx);
batch->Remove(idx);
}
/** Substitute a new mdelem for an old value */
inline grpc_error_handle grpc_metadata_batch_substitute(
grpc_metadata_batch* batch, grpc_linked_mdelem* storage,
grpc_mdelem new_mdelem) {
return (*batch)->Substitute(storage, new_mdelem);
return batch->Substitute(storage, new_mdelem);
}
void grpc_metadata_batch_set_value(grpc_linked_mdelem* storage,
@ -247,7 +240,7 @@ void grpc_metadata_batch_set_value(grpc_linked_mdelem* storage,
inline absl::optional<absl::string_view> grpc_metadata_batch_get_value(
grpc_metadata_batch* batch, absl::string_view target_key,
std::string* concatenated_value) {
return (*batch)->GetValue(target_key, concatenated_value);
return batch->GetValue(target_key, concatenated_value);
}
/** Add \a storage to the beginning of \a batch. storage->md is
@ -257,13 +250,13 @@ inline absl::optional<absl::string_view> grpc_metadata_batch_get_value(
for the lifetime of the call. */
inline GRPC_MUST_USE_RESULT grpc_error_handle grpc_metadata_batch_link_head(
grpc_metadata_batch* batch, grpc_linked_mdelem* storage) {
return (*batch)->LinkHead(storage);
return batch->LinkHead(storage);
}
inline GRPC_MUST_USE_RESULT grpc_error_handle grpc_metadata_batch_link_head(
grpc_metadata_batch* batch, grpc_linked_mdelem* storage,
grpc_metadata_batch_callouts_index idx) {
return (*batch)->LinkHead(storage, idx);
return batch->LinkHead(storage, idx);
}
/** Add \a storage to the end of \a batch. storage->md is
@ -273,13 +266,13 @@ inline GRPC_MUST_USE_RESULT grpc_error_handle grpc_metadata_batch_link_head(
for the lifetime of the call. */
inline GRPC_MUST_USE_RESULT grpc_error_handle grpc_metadata_batch_link_tail(
grpc_metadata_batch* batch, grpc_linked_mdelem* storage) {
return (*batch)->LinkTail(storage);
return batch->LinkTail(storage);
}
inline GRPC_MUST_USE_RESULT grpc_error_handle grpc_metadata_batch_link_tail(
grpc_metadata_batch* batch, grpc_linked_mdelem* storage,
grpc_metadata_batch_callouts_index idx) {
return (*batch)->LinkTail(storage, idx);
return batch->LinkTail(storage, idx);
}
/** Add \a elem_to_add as the first element in \a batch, using
@ -291,7 +284,7 @@ inline GRPC_MUST_USE_RESULT grpc_error_handle grpc_metadata_batch_link_tail(
inline grpc_error_handle grpc_metadata_batch_add_head(
grpc_metadata_batch* batch, grpc_linked_mdelem* storage,
grpc_mdelem elem_to_add) {
return (*batch)->AddHead(storage, elem_to_add);
return batch->AddHead(storage, elem_to_add);
}
// TODO(arjunroy, roth): Remove redundant methods.
@ -319,7 +312,7 @@ inline grpc_error_handle GRPC_MUST_USE_RESULT grpc_metadata_batch_add_head(
inline GRPC_MUST_USE_RESULT grpc_error_handle grpc_metadata_batch_add_tail(
grpc_metadata_batch* batch, grpc_linked_mdelem* storage,
grpc_mdelem elem_to_add) {
return (*batch)->AddTail(storage, elem_to_add);
return batch->AddTail(storage, elem_to_add);
}
inline grpc_error_handle GRPC_MUST_USE_RESULT grpc_metadata_batch_add_tail(
@ -344,13 +337,12 @@ typedef grpc_filtered_mdelem (*grpc_metadata_batch_filter_func)(
inline GRPC_MUST_USE_RESULT grpc_error_handle grpc_metadata_batch_filter(
grpc_metadata_batch* batch, grpc_metadata_batch_filter_func func,
void* user_data, const char* composite_error_string) {
return (*batch)->Filter(
[=](grpc_mdelem elem) { return func(user_data, elem); },
return batch->Filter([=](grpc_mdelem elem) { return func(user_data, elem); },
composite_error_string);
}
inline void grpc_metadata_batch_assert_ok(grpc_metadata_batch* batch) {
(*batch)->AssertOk();
batch->AssertOk();
}
/// Copies \a src to \a dst. \a storage must point to an array of
@ -366,9 +358,4 @@ void grpc_metadata_batch_copy(grpc_metadata_batch* src,
grpc_metadata_batch* dst,
grpc_linked_mdelem* storage);
inline void grpc_metadata_batch_move(grpc_metadata_batch* src,
grpc_metadata_batch* dst) {
dst->Init(std::move(**src));
}
#endif /* GRPC_CORE_LIB_TRANSPORT_METADATA_BATCH_H */

@ -54,13 +54,13 @@ static void put_metadata(grpc_mdelem md, std::vector<std::string>* out) {
static void put_metadata_list(const grpc_metadata_batch& md,
std::vector<std::string>* out) {
bool first = true;
md->ForEach([&](grpc_mdelem elem) {
md.ForEach([&](grpc_mdelem elem) {
if (!first) out->push_back(", ");
first = false;
put_metadata(elem, out);
});
if (md->deadline() != GRPC_MILLIS_INF_FUTURE) {
out->push_back(absl::StrFormat(" deadline=%" PRId64, md->deadline()));
if (md.deadline() != GRPC_MILLIS_INF_FUTURE) {
out->push_back(absl::StrFormat(" deadline=%" PRId64, md.deadline()));
}
}

@ -123,15 +123,15 @@ void OpenCensusCallTracer::OpenCensusCallAttemptTracer::RecordReceivedMessage(
namespace {
void FilterTrailingMetadata(grpc_metadata_batch* b, uint64_t* elapsed_time) {
if ((*b)->legacy_index()->named.grpc_server_stats_bin != nullptr) {
if (b->legacy_index()->named.grpc_server_stats_bin != nullptr) {
ServerStatsDeserialize(
reinterpret_cast<const char*>(GRPC_SLICE_START_PTR(GRPC_MDVALUE(
(*b)->legacy_index()->named.grpc_server_stats_bin->md))),
GRPC_SLICE_LENGTH(GRPC_MDVALUE(
(*b)->legacy_index()->named.grpc_server_stats_bin->md)),
reinterpret_cast<const char*>(GRPC_SLICE_START_PTR(
GRPC_MDVALUE(b->legacy_index()->named.grpc_server_stats_bin->md))),
GRPC_SLICE_LENGTH(
GRPC_MDVALUE(b->legacy_index()->named.grpc_server_stats_bin->md)),
elapsed_time);
grpc_metadata_batch_remove(
b, (*b)->legacy_index()->named.grpc_server_stats_bin);
grpc_metadata_batch_remove(b,
b->legacy_index()->named.grpc_server_stats_bin);
}
}

@ -45,18 +45,18 @@ struct ServerMetadataElements {
void FilterInitialMetadata(grpc_metadata_batch* b,
ServerMetadataElements* sml) {
if ((*b)->legacy_index()->named.path != nullptr) {
if (b->legacy_index()->named.path != nullptr) {
sml->path = grpc_slice_ref_internal(
GRPC_MDVALUE((*b)->legacy_index()->named.path->md));
GRPC_MDVALUE(b->legacy_index()->named.path->md));
}
if ((*b)->legacy_index()->named.grpc_trace_bin != nullptr) {
if (b->legacy_index()->named.grpc_trace_bin != nullptr) {
sml->tracing_slice = grpc_slice_ref_internal(
GRPC_MDVALUE((*b)->legacy_index()->named.grpc_trace_bin->md));
GRPC_MDVALUE(b->legacy_index()->named.grpc_trace_bin->md));
grpc_metadata_batch_remove(b, GRPC_BATCH_GRPC_TRACE_BIN);
}
if ((*b)->legacy_index()->named.grpc_tags_bin != nullptr) {
if (b->legacy_index()->named.grpc_tags_bin != nullptr) {
sml->census_proto = grpc_slice_ref_internal(
GRPC_MDVALUE((*b)->legacy_index()->named.grpc_tags_bin->md));
GRPC_MDVALUE(b->legacy_index()->named.grpc_tags_bin->md));
grpc_metadata_batch_remove(b, GRPC_BATCH_GRPC_TAGS_BIN);
}
}

@ -263,11 +263,10 @@ static void server_start_transport_stream_op_batch(
if (data->call == g_server_call_stack) {
if (op->send_initial_metadata) {
auto* batch = op->payload->send_initial_metadata.send_initial_metadata;
if ((*batch)->legacy_index()->named.status != nullptr) {
if (batch->legacy_index()->named.status != nullptr) {
/* Replace the HTTP status with 404 */
grpc_metadata_batch_substitute(batch,
(*batch)->legacy_index()->named.status,
GRPC_MDELEM_STATUS_404);
grpc_metadata_batch_substitute(
batch, batch->legacy_index()->named.status, GRPC_MDELEM_STATUS_404);
}
}
}

@ -148,7 +148,7 @@ MATCHER_P(GrpcErrorMessageContains, msg, "") {
void VerifyMetadataEqual(const Metadata& md,
const grpc_metadata_batch& grpc_md) {
size_t i = 0;
grpc_md->ForEach([&](grpc_mdelem mdelm) {
grpc_md.ForEach([&](grpc_mdelem mdelm) {
EXPECT_EQ(grpc_core::StringViewFromSlice(GRPC_MDKEY(mdelm)), md[i].first);
EXPECT_EQ(grpc_core::StringViewFromSlice(GRPC_MDVALUE(mdelm)),
md[i].second);
@ -163,7 +163,6 @@ struct MakeSendInitialMetadata {
const std::string& method_ref,
grpc_transport_stream_op_batch* op)
: storage(initial_metadata.size()) {
grpc_metadata_batch_init(&grpc_initial_metadata);
size_t i = 0;
for (const auto& md : initial_metadata) {
const std::string& key = md.first;
@ -187,9 +186,7 @@ struct MakeSendInitialMetadata {
op->payload->send_initial_metadata.send_initial_metadata =
&grpc_initial_metadata;
}
~MakeSendInitialMetadata() {
grpc_metadata_batch_destroy(&grpc_initial_metadata);
}
~MakeSendInitialMetadata() {}
std::vector<grpc_linked_mdelem> storage;
grpc_linked_mdelem method_ref_storage;
@ -218,7 +215,6 @@ struct MakeSendTrailingMetadata {
explicit MakeSendTrailingMetadata(const Metadata& trailing_metadata,
grpc_transport_stream_op_batch* op) {
EXPECT_TRUE(trailing_metadata.empty());
grpc_metadata_batch_init(&grpc_trailing_metadata);
op->send_trailing_metadata = true;
op->payload->send_trailing_metadata.send_trailing_metadata =
@ -232,7 +228,6 @@ struct MakeRecvInitialMetadata {
explicit MakeRecvInitialMetadata(grpc_transport_stream_op_batch* op,
Expectation* call_before = nullptr)
: ready(&notification) {
grpc_metadata_batch_init(&grpc_initial_metadata);
op->recv_initial_metadata = true;
op->payload->recv_initial_metadata.recv_initial_metadata =
&grpc_initial_metadata;
@ -245,9 +240,7 @@ struct MakeRecvInitialMetadata {
}
}
~MakeRecvInitialMetadata() {
grpc_metadata_batch_destroy(&grpc_initial_metadata);
}
~MakeRecvInitialMetadata() {}
MockGrpcClosure ready;
grpc_metadata_batch grpc_initial_metadata;
@ -277,7 +270,6 @@ struct MakeRecvTrailingMetadata {
explicit MakeRecvTrailingMetadata(grpc_transport_stream_op_batch* op,
Expectation* call_before = nullptr)
: ready(&notification) {
grpc_metadata_batch_init(&grpc_trailing_metadata);
op->recv_trailing_metadata = true;
op->payload->recv_trailing_metadata.recv_trailing_metadata =
&grpc_trailing_metadata;
@ -290,9 +282,7 @@ struct MakeRecvTrailingMetadata {
}
}
~MakeRecvTrailingMetadata() {
grpc_metadata_batch_destroy(&grpc_trailing_metadata);
}
~MakeRecvTrailingMetadata() {}
MockGrpcClosure ready;
grpc_metadata_batch grpc_trailing_metadata;

@ -163,8 +163,6 @@ static void verify(const verify_params params, const char* expected,
static_cast<grpc_linked_mdelem*>(gpr_malloc(sizeof(*e) * nheaders));
grpc_metadata_batch b;
grpc_metadata_batch_init(&b);
va_start(l, nheaders);
for (i = 0; i < nheaders; i++) {
char* key = va_arg(l, char*);
@ -175,7 +173,7 @@ static void verify(const verify_params params, const char* expected,
}
e[i].md = grpc_mdelem_from_slices(
grpc_slice_intern(grpc_slice_from_static_string(key)), value_slice);
GPR_ASSERT(GRPC_ERROR_NONE == b->LinkTail(&e[i]));
GPR_ASSERT(GRPC_ERROR_NONE == b.LinkTail(&e[i]));
}
va_end(l);
@ -197,11 +195,10 @@ static void verify(const verify_params params, const char* expected,
16384, /* max_frame_size */
&stats /* stats */
};
g_compressor->EncodeHeaders(hopt, *b, &output);
g_compressor->EncodeHeaders(hopt, b, &output);
verify_frames(output, params.eof);
merged = grpc_slice_merge(output.slices, output.count);
grpc_slice_buffer_destroy_internal(&output);
grpc_metadata_batch_destroy(&b);
if (!grpc_slice_eq(merged, expect)) {
char* expect_str = grpc_dump_slice(expect, GPR_DUMP_HEX | GPR_DUMP_ASCII);
@ -250,14 +247,12 @@ static void verify_continuation_headers(const char* key, const char* value,
grpc_mdelem elem = grpc_mdelem_from_slices(
grpc_slice_intern(grpc_slice_from_static_string(key)),
grpc_slice_intern(grpc_slice_from_static_string(value)));
grpc_linked_mdelem* e =
static_cast<grpc_linked_mdelem*>(gpr_malloc(sizeof(*e)));
grpc_linked_mdelem e;
e.md = elem;
e.prev = nullptr;
e.next = nullptr;
grpc_metadata_batch b;
grpc_metadata_batch_init(&b);
e[0].md = elem;
e[0].prev = nullptr;
e[0].next = nullptr;
GPR_ASSERT(GRPC_ERROR_NONE == b->LinkTail(&e[0]));
GPR_ASSERT(GRPC_ERROR_NONE == b.LinkTail(&e));
grpc_slice_buffer_init(&output);
grpc_transport_one_way_stats stats;
@ -268,11 +263,9 @@ static void verify_continuation_headers(const char* key, const char* value,
false, /* use_true_binary_metadata */
150, /* max_frame_size */
&stats /* stats */};
g_compressor->EncodeHeaders(hopt, *b, &output);
g_compressor->EncodeHeaders(hopt, b, &output);
verify_frames(output, is_eof);
grpc_slice_buffer_destroy_internal(&output);
grpc_metadata_batch_destroy(&b);
gpr_free(e);
}
static void test_continuation_headers() {
@ -338,14 +331,12 @@ static void verify_table_size_change_match_elem_size(const char* key,
grpc_slice_intern(grpc_slice_from_static_string(value)));
size_t elem_size = grpc_core::MetadataSizeInHPackTable(elem, use_true_binary);
size_t initial_table_size = g_compressor->test_only_table_size();
grpc_linked_mdelem* e =
static_cast<grpc_linked_mdelem*>(gpr_malloc(sizeof(*e)));
grpc_linked_mdelem e;
e.md = elem;
e.prev = nullptr;
e.next = nullptr;
grpc_metadata_batch b;
grpc_metadata_batch_init(&b);
e[0].md = elem;
e[0].prev = nullptr;
e[0].next = nullptr;
GPR_ASSERT(GRPC_ERROR_NONE == b->LinkTail(&e[0]));
GPR_ASSERT(GRPC_ERROR_NONE == b.LinkTail(&e));
grpc_slice_buffer_init(&output);
grpc_transport_one_way_stats stats;
@ -356,14 +347,12 @@ static void verify_table_size_change_match_elem_size(const char* key,
use_true_binary, /* use_true_binary_metadata */
16384, /* max_frame_size */
&stats /* stats */};
g_compressor->EncodeHeaders(hopt, *b, &output);
g_compressor->EncodeHeaders(hopt, b, &output);
verify_frames(output, false);
grpc_slice_buffer_destroy_internal(&output);
grpc_metadata_batch_destroy(&b);
GPR_ASSERT(g_compressor->test_only_table_size() ==
elem_size + initial_table_size);
gpr_free(e);
}
static void test_encode_header_size() {

@ -67,6 +67,7 @@ static void test_create_metadata(bool intern_keys, bool intern_values) {
intern_keys, intern_values);
grpc_init();
{
grpc_core::ExecCtx exec_ctx;
m1 = grpc_mdelem_from_slices(
maybe_intern(grpc_slice_from_static_string("a"), intern_keys),
@ -87,7 +88,7 @@ static void test_create_metadata(bool intern_keys, bool intern_values) {
GRPC_MDELEM_UNREF(m1);
GRPC_MDELEM_UNREF(m2);
GRPC_MDELEM_UNREF(m3);
}
grpc_shutdown();
}
@ -102,6 +103,7 @@ static void test_create_many_ephemeral_metadata(bool intern_keys,
intern_keys, intern_values);
grpc_init();
{
grpc_core::ExecCtx exec_ctx;
/* add, and immediately delete a bunch of different elements */
for (i = 0; i < MANY; i++) {
@ -110,7 +112,7 @@ static void test_create_many_ephemeral_metadata(bool intern_keys,
maybe_intern(grpc_slice_from_static_string("a"), intern_keys),
maybe_intern(grpc_slice_from_copied_string(buffer), intern_values)));
}
}
grpc_shutdown();
}
@ -124,6 +126,7 @@ static void test_create_many_persistant_metadata(void) {
gpr_log(GPR_INFO, "test_create_many_persistant_metadata");
grpc_init();
{
grpc_core::ExecCtx exec_ctx;
/* add phase */
for (i = 0; i < MANY; i++) {
@ -145,7 +148,7 @@ static void test_create_many_persistant_metadata(void) {
for (i = 0; i < MANY; i++) {
GRPC_MDELEM_UNREF(created[i]);
}
}
grpc_shutdown();
gpr_free(created);
@ -158,6 +161,7 @@ static void test_spin_creating_the_same_thing(bool intern_keys,
intern_keys, intern_values);
grpc_init();
{
grpc_core::ExecCtx exec_ctx;
grpc_mdelem a, b, c;
GRPC_MDELEM_UNREF(
@ -176,7 +180,7 @@ static void test_spin_creating_the_same_thing(bool intern_keys,
GPR_ASSERT(a.payload == b.payload);
GPR_ASSERT(a.payload == c.payload);
}
}
grpc_shutdown();
}
@ -185,6 +189,7 @@ static void test_identity_laws(bool intern_keys, bool intern_values) {
intern_keys, intern_values);
grpc_init();
{
grpc_core::ExecCtx exec_ctx;
grpc_mdelem a, b, c;
a = grpc_mdelem_from_slices(
@ -216,7 +221,7 @@ static void test_identity_laws(bool intern_keys, bool intern_values) {
GRPC_MDELEM_UNREF(a);
GRPC_MDELEM_UNREF(b);
GRPC_MDELEM_UNREF(c);
}
grpc_shutdown();
}
@ -231,12 +236,14 @@ static void test_things_stick_around(void) {
gpr_log(GPR_INFO, "test_things_stick_around");
grpc_init();
{
grpc_core::ExecCtx exec_ctx;
for (i = 0; i < nstrs; i++) {
std::string buffer =
absl::StrFormat("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%" PRIuPTR "x", i);
strs[i] = grpc_slice_intern(grpc_slice_from_static_string(buffer.c_str()));
strs[i] =
grpc_slice_intern(grpc_slice_from_static_string(buffer.c_str()));
shuf[i] = i;
}
@ -263,7 +270,7 @@ static void test_things_stick_around(void) {
grpc_slice_unref_internal(test);
}
}
}
grpc_shutdown();
gpr_free(strs);
gpr_free(shuf);
@ -276,6 +283,7 @@ static void test_user_data_works(void) {
gpr_log(GPR_INFO, "test_user_data_works");
grpc_init();
{
grpc_core::ExecCtx exec_ctx;
ud1 = static_cast<int*>(gpr_malloc(sizeof(int)));
*ud1 = 1;
@ -288,7 +296,7 @@ static void test_user_data_works(void) {
grpc_mdelem_set_user_data(md, gpr_free, ud2);
GPR_ASSERT(grpc_mdelem_get_user_data(md, gpr_free) == ud1);
GRPC_MDELEM_UNREF(md);
}
grpc_shutdown();
}
@ -299,6 +307,7 @@ static void test_user_data_works_for_allocated_md(void) {
gpr_log(GPR_INFO, "test_user_data_works");
grpc_init();
{
grpc_core::ExecCtx exec_ctx;
ud1 = static_cast<int*>(gpr_malloc(sizeof(int)));
*ud1 = 1;
@ -310,7 +319,7 @@ static void test_user_data_works_for_allocated_md(void) {
grpc_mdelem_set_user_data(md, gpr_free, ud2);
GPR_ASSERT(grpc_mdelem_get_user_data(md, gpr_free) == ud1);
GRPC_MDELEM_UNREF(md);
}
grpc_shutdown();
}
@ -318,6 +327,7 @@ static void test_copied_static_metadata(bool dup_key, bool dup_value) {
gpr_log(GPR_INFO, "test_static_metadata: dup_key=%d dup_value=%d", dup_key,
dup_value);
grpc_init();
{
grpc_core::ExecCtx exec_ctx;
for (size_t i = 0; i < GRPC_STATIC_MDELEM_COUNT; i++) {
@ -335,29 +345,29 @@ static void test_copied_static_metadata(bool dup_key, bool dup_value) {
GRPC_MDELEM_UNREF(p);
GRPC_MDELEM_UNREF(q);
}
}
grpc_shutdown();
}
static void test_grpc_metadata_batch_get_value_with_absent_key(void) {
grpc_init();
{
grpc_metadata_batch metadata;
grpc_metadata_batch_init(&metadata);
std::string concatenated_value;
absl::optional<absl::string_view> value = grpc_metadata_batch_get_value(
&metadata, "absent_key", &concatenated_value);
GPR_ASSERT(value == absl::nullopt);
grpc_metadata_batch_destroy(&metadata);
}
grpc_shutdown();
}
static void test_grpc_metadata_batch_get_value_returns_one_value(void) {
grpc_init();
{
const char* kKey = "some_key";
const char* kValue = "some_value";
grpc_metadata_batch metadata;
grpc_metadata_batch_init(&metadata);
grpc_linked_mdelem storage;
grpc_metadata_batch metadata;
storage.md = grpc_mdelem_from_slices(
grpc_slice_intern(grpc_slice_from_static_string(kKey)),
grpc_slice_intern(grpc_slice_from_static_string(kValue)));
@ -368,24 +378,24 @@ static void test_grpc_metadata_batch_get_value_returns_one_value(void) {
grpc_metadata_batch_get_value(&metadata, kKey, &concatenated_value);
GPR_ASSERT(value.has_value());
GPR_ASSERT(value.value() == kValue);
grpc_metadata_batch_destroy(&metadata);
}
grpc_shutdown();
}
static void test_grpc_metadata_batch_get_value_returns_multiple_values(void) {
grpc_init();
{
const char* kKey = "some_key";
const char* kValue1 = "value1";
const char* kValue2 = "value2";
grpc_metadata_batch metadata;
grpc_metadata_batch_init(&metadata);
grpc_linked_mdelem storage1;
grpc_linked_mdelem storage2;
grpc_metadata_batch metadata;
storage1.md = grpc_mdelem_from_slices(
grpc_slice_intern(grpc_slice_from_static_string(kKey)),
grpc_slice_intern(grpc_slice_from_static_string(kValue1)));
GPR_ASSERT(grpc_metadata_batch_link_tail(&metadata, &storage1) ==
GRPC_ERROR_NONE);
grpc_linked_mdelem storage2;
storage2.md = grpc_mdelem_from_slices(
grpc_slice_intern(grpc_slice_from_static_string(kKey)),
grpc_slice_intern(grpc_slice_from_static_string(kValue2)));
@ -396,7 +406,7 @@ static void test_grpc_metadata_batch_get_value_returns_multiple_values(void) {
grpc_metadata_batch_get_value(&metadata, kKey, &concatenated_value);
GPR_ASSERT(value.has_value());
GPR_ASSERT(value.value() == absl::StrCat(kValue1, ",", kValue2));
grpc_metadata_batch_destroy(&metadata);
}
grpc_shutdown();
}

@ -28,12 +28,9 @@ namespace grpc_core {
class EvaluateArgsTestUtil {
public:
EvaluateArgsTestUtil() { grpc_metadata_batch_init(&metadata_); }
EvaluateArgsTestUtil() = default;
~EvaluateArgsTestUtil() {
grpc_metadata_batch_destroy(&metadata_);
delete channel_args_;
}
~EvaluateArgsTestUtil() { delete channel_args_; }
void AddPairToMetadata(const char* key, const char* value) {
metadata_storage_.emplace_back();

@ -467,10 +467,10 @@ class SendEmptyMetadata {
class Op {
public:
Op(SendEmptyMetadata* p, grpc_call_stack* /*s*/) {
grpc_metadata_batch_init(&batch_);
batch_.Clear();
p->op_payload_.send_initial_metadata.send_initial_metadata = &batch_;
}
void Finish() { grpc_metadata_batch_destroy(&batch_); }
void Finish() {}
private:
grpc_metadata_batch batch_;

@ -70,8 +70,7 @@ static void BM_HpackEncoderEncodeDeadline(benchmark::State& state) {
grpc_millis saved_now = grpc_core::ExecCtx::Get()->Now();
grpc_metadata_batch b;
grpc_metadata_batch_init(&b);
b->SetDeadline(saved_now + 30 * 1000);
b.SetDeadline(saved_now + 30 * 1000);
grpc_core::HPackCompressor c;
grpc_transport_one_way_stats stats;
@ -87,11 +86,10 @@ static void BM_HpackEncoderEncodeDeadline(benchmark::State& state) {
static_cast<size_t>(1024),
&stats,
},
*b, &outbuf);
b, &outbuf);
grpc_slice_buffer_reset_and_unref_internal(&outbuf);
grpc_core::ExecCtx::Get()->Flush();
}
grpc_metadata_batch_destroy(&b);
grpc_slice_buffer_destroy_internal(&outbuf);
std::ostringstream label;
@ -112,10 +110,9 @@ static void BM_HpackEncoderEncodeHeader(benchmark::State& state) {
grpc_core::ExecCtx exec_ctx;
static bool logged_representative_output = false;
grpc_metadata_batch b;
grpc_metadata_batch_init(&b);
std::vector<grpc_mdelem> elems = Fixture::GetElems();
std::vector<grpc_linked_mdelem> storage(elems.size());
grpc_metadata_batch b;
for (size_t i = 0; i < elems.size(); i++) {
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"addmd", grpc_metadata_batch_add_tail(&b, &storage[i], elems[i])));
@ -136,7 +133,7 @@ static void BM_HpackEncoderEncodeHeader(benchmark::State& state) {
static_cast<size_t>(state.range(1) + kEnsureMaxFrameAtLeast),
&stats,
},
*b, &outbuf);
b, &outbuf);
if (!logged_representative_output && state.iterations() > 3) {
logged_representative_output = true;
for (size_t i = 0; i < outbuf.count; i++) {
@ -148,7 +145,6 @@ static void BM_HpackEncoderEncodeHeader(benchmark::State& state) {
grpc_slice_buffer_reset_and_unref_internal(&outbuf);
grpc_core::ExecCtx::Get()->Flush();
}
grpc_metadata_batch_destroy(&b);
grpc_slice_buffer_destroy_internal(&outbuf);
std::ostringstream label;

@ -323,11 +323,9 @@ static void BM_StreamCreateSendInitialMetadataDestroy(benchmark::State& state) {
op.payload = &op_payload;
};
grpc_metadata_batch b;
grpc_metadata_batch_init(&b);
b->ClearDeadline();
std::vector<grpc_mdelem> elems = Metadata::GetElems();
std::vector<grpc_linked_mdelem> storage(elems.size());
grpc_metadata_batch b;
for (size_t i = 0; i < elems.size(); i++) {
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"addmd", grpc_metadata_batch_add_tail(&b, &storage[i], elems[i])));
@ -359,7 +357,6 @@ static void BM_StreamCreateSendInitialMetadataDestroy(benchmark::State& state) {
grpc_core::ExecCtx::Run(DEBUG_LOCATION, start.get(), GRPC_ERROR_NONE);
f.FlushExecCtx();
gpr_event_wait(&bm_done, gpr_inf_future(GPR_CLOCK_REALTIME));
grpc_metadata_batch_destroy(&b);
track_counters.Finish(state);
}
BENCHMARK_TEMPLATE(BM_StreamCreateSendInitialMetadataDestroy,
@ -427,12 +424,10 @@ static void BM_TransportStreamSend(benchmark::State& state) {
grpc_slice send_slice = grpc_slice_malloc_large(state.range(0));
memset(GRPC_SLICE_START_PTR(send_slice), 0, GRPC_SLICE_LENGTH(send_slice));
grpc_core::ManualConstructor<grpc_core::SliceBufferByteStream> send_stream;
grpc_metadata_batch b;
grpc_metadata_batch_init(&b);
b->ClearDeadline();
std::vector<grpc_mdelem> elems =
RepresentativeClientInitialMetadata::GetElems();
std::vector<grpc_linked_mdelem> storage(elems.size());
grpc_metadata_batch b;
for (size_t i = 0; i < elems.size(); i++) {
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"addmd", grpc_metadata_batch_add_tail(&b, &storage[i], elems[i])));
@ -491,7 +486,6 @@ static void BM_TransportStreamSend(benchmark::State& state) {
MakeOnceClosure([s](grpc_error_handle /*error*/) { delete s; }));
f.FlushExecCtx();
track_counters.Finish(state);
grpc_metadata_batch_destroy(&b);
grpc_slice_unref(send_slice);
}
BENCHMARK(BM_TransportStreamSend)->Range(0, 128 * 1024 * 1024);
@ -569,14 +563,10 @@ static void BM_TransportStreamRecv(benchmark::State& state) {
op.payload = &op_payload;
};
grpc_metadata_batch b;
grpc_metadata_batch_init(&b);
grpc_metadata_batch b_recv;
grpc_metadata_batch_init(&b_recv);
b->ClearDeadline();
std::vector<grpc_mdelem> elems =
RepresentativeClientInitialMetadata::GetElems();
std::vector<grpc_linked_mdelem> storage(elems.size());
grpc_metadata_batch b;
for (size_t i = 0; i < elems.size(); i++) {
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"addmd", grpc_metadata_batch_add_tail(&b, &storage[i], elems[i])));
@ -639,10 +629,11 @@ static void BM_TransportStreamRecv(benchmark::State& state) {
});
reset_op();
auto b_recv = absl::make_unique<grpc_metadata_batch>();
op.send_initial_metadata = true;
op.payload->send_initial_metadata.send_initial_metadata = &b;
op.recv_initial_metadata = true;
op.payload->recv_initial_metadata.recv_initial_metadata = &b_recv;
op.payload->recv_initial_metadata.recv_initial_metadata = b_recv.get();
op.payload->recv_initial_metadata.recv_initial_metadata_ready =
do_nothing.get();
op.on_complete = c.get();
@ -676,10 +667,10 @@ static void BM_TransportStreamRecv(benchmark::State& state) {
f.FlushExecCtx();
gpr_event_wait(stream_cancel_done, gpr_inf_future(GPR_CLOCK_REALTIME));
done_events.emplace_back(stream_cancel_done);
s->DestroyThen(
MakeOnceClosure([s](grpc_error_handle /*error*/) { delete s; }));
grpc_metadata_batch_destroy(&b);
grpc_metadata_batch_destroy(&b_recv);
s->DestroyThen(MakeOnceClosure([s, &b_recv](grpc_error_handle /*error*/) {
b_recv.reset();
delete s;
}));
f.FlushExecCtx();
track_counters.Finish(state);
grpc_slice_unref(incoming_data);

Loading…
Cancel
Save