[Transport] Update Chttp2 context list to include relative offset of traced RPCs within outgoing buffer (#32825)

The PR also creates a separate BUILD target for:
- chttp2 context list
- iomgr buffer_list
- iomgr internal errqueue

This would allow the context list to be included as standalone
dependencies for EventEngine implementations.
pull/32907/head
Vignesh Babu 2 years ago committed by GitHub
parent 702958b3c2
commit c515eba30b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 57
      BUILD
  2. 52
      CMakeLists.txt
  3. 2
      Makefile
  4. 2
      bazel/grpc_build_system.bzl
  5. 41
      build_autogenerated.yaml
  6. 1
      config.m4
  7. 1
      config.w32
  8. 4
      gRPC-C++.podspec
  9. 5
      gRPC-Core.podspec
  10. 3
      grpc.gemspec
  11. 2
      grpc.gyp
  12. 3
      package.xml
  13. 57
      src/core/ext/transport/chttp2/transport/chttp2_transport.cc
  14. 21
      src/core/ext/transport/chttp2/transport/chttp2_transport.h
  15. 71
      src/core/ext/transport/chttp2/transport/context_list.cc
  16. 54
      src/core/ext/transport/chttp2/transport/context_list.h
  17. 70
      src/core/ext/transport/chttp2/transport/context_list_entry.h
  18. 5
      src/core/ext/transport/chttp2/transport/internal.h
  19. 17
      src/core/ext/transport/chttp2/transport/writing.cc
  20. 1
      src/core/lib/iomgr/buffer_list.h
  21. 1
      src/python/grpcio/grpc_core_dependencies.py
  22. 17
      test/core/transport/chttp2/BUILD
  23. 181
      test/core/transport/chttp2/context_list_test.cc
  24. 3
      tools/doxygen/Doxyfile.c++.internal
  25. 3
      tools/doxygen/Doxyfile.core.internal
  26. 24
      tools/run_tests/generated/tests.json

57
BUILD

@ -1233,7 +1233,6 @@ grpc_cc_library(
"//src/core:lib/compression/compression.cc", "//src/core:lib/compression/compression.cc",
"//src/core:lib/compression/compression_internal.cc", "//src/core:lib/compression/compression_internal.cc",
"//src/core:lib/compression/message_compress.cc", "//src/core:lib/compression/message_compress.cc",
"//src/core:lib/iomgr/buffer_list.cc",
"//src/core:lib/iomgr/call_combiner.cc", "//src/core:lib/iomgr/call_combiner.cc",
"//src/core:lib/iomgr/cfstream_handle.cc", "//src/core:lib/iomgr/cfstream_handle.cc",
"//src/core:lib/iomgr/dualstack_socket_posix.cc", "//src/core:lib/iomgr/dualstack_socket_posix.cc",
@ -1252,7 +1251,6 @@ grpc_cc_library(
"//src/core:lib/iomgr/gethostname_fallback.cc", "//src/core:lib/iomgr/gethostname_fallback.cc",
"//src/core:lib/iomgr/gethostname_host_name_max.cc", "//src/core:lib/iomgr/gethostname_host_name_max.cc",
"//src/core:lib/iomgr/gethostname_sysconf.cc", "//src/core:lib/iomgr/gethostname_sysconf.cc",
"//src/core:lib/iomgr/internal_errqueue.cc",
"//src/core:lib/iomgr/iocp_windows.cc", "//src/core:lib/iomgr/iocp_windows.cc",
"//src/core:lib/iomgr/iomgr.cc", "//src/core:lib/iomgr/iomgr.cc",
"//src/core:lib/iomgr/iomgr_posix.cc", "//src/core:lib/iomgr/iomgr_posix.cc",
@ -1344,7 +1342,6 @@ grpc_cc_library(
"//src/core:lib/compression/compression_internal.h", "//src/core:lib/compression/compression_internal.h",
"//src/core:lib/compression/message_compress.h", "//src/core:lib/compression/message_compress.h",
"//src/core:lib/iomgr/block_annotate.h", "//src/core:lib/iomgr/block_annotate.h",
"//src/core:lib/iomgr/buffer_list.h",
"//src/core:lib/iomgr/call_combiner.h", "//src/core:lib/iomgr/call_combiner.h",
"//src/core:lib/iomgr/cfstream_handle.h", "//src/core:lib/iomgr/cfstream_handle.h",
"//src/core:lib/iomgr/dynamic_annotations.h", "//src/core:lib/iomgr/dynamic_annotations.h",
@ -1357,7 +1354,6 @@ grpc_cc_library(
"//src/core:lib/iomgr/ev_poll_posix.h", "//src/core:lib/iomgr/ev_poll_posix.h",
"//src/core:lib/iomgr/ev_posix.h", "//src/core:lib/iomgr/ev_posix.h",
"//src/core:lib/iomgr/gethostname.h", "//src/core:lib/iomgr/gethostname.h",
"//src/core:lib/iomgr/internal_errqueue.h",
"//src/core:lib/iomgr/iocp_windows.h", "//src/core:lib/iomgr/iocp_windows.h",
"//src/core:lib/iomgr/iomgr.h", "//src/core:lib/iomgr/iomgr.h",
"//src/core:lib/iomgr/load_file.h", "//src/core:lib/iomgr/load_file.h",
@ -1462,6 +1458,8 @@ grpc_cc_library(
"gpr", "gpr",
"grpc_public_hdrs", "grpc_public_hdrs",
"grpc_trace", "grpc_trace",
"iomgr_buffer_list",
"iomgr_internal_errqueue",
"iomgr_timer", "iomgr_timer",
"orphanable", "orphanable",
"parse_address", "parse_address",
@ -2607,6 +2605,45 @@ grpc_cc_library(
], ],
) )
grpc_cc_library(
name = "iomgr_internal_errqueue",
srcs = [
"//src/core:lib/iomgr/internal_errqueue.cc",
],
hdrs = [
"//src/core:lib/iomgr/internal_errqueue.h",
],
tags = ["nofixdeps"],
visibility = ["@grpc:iomgr_internal_errqueue"],
deps = [
"gpr",
"//src/core:iomgr_port",
"//src/core:strerror",
],
)
grpc_cc_library(
name = "iomgr_buffer_list",
srcs = [
"//src/core:lib/iomgr/buffer_list.cc",
],
hdrs = [
"//src/core:lib/iomgr/buffer_list.h",
],
external_deps = [
"absl/strings",
"absl/strings:str_format",
],
tags = ["nofixdeps"],
visibility = ["@grpc:iomgr_buffer_list"],
deps = [
"gpr",
"iomgr_internal_errqueue",
"//src/core:error",
"//src/core:iomgr_port",
],
)
grpc_cc_library( grpc_cc_library(
name = "uri_parser", name = "uri_parser",
srcs = [ srcs = [
@ -3708,12 +3745,19 @@ grpc_cc_library(
deps = ["gpr"], deps = ["gpr"],
) )
grpc_cc_library(
name = "chttp2_context_list_entry",
hdrs = [
"//src/core:ext/transport/chttp2/transport/context_list_entry.h",
],
deps = ["gpr"],
)
grpc_cc_library( grpc_cc_library(
name = "grpc_transport_chttp2", name = "grpc_transport_chttp2",
srcs = [ srcs = [
"//src/core:ext/transport/chttp2/transport/bin_decoder.cc", "//src/core:ext/transport/chttp2/transport/bin_decoder.cc",
"//src/core:ext/transport/chttp2/transport/chttp2_transport.cc", "//src/core:ext/transport/chttp2/transport/chttp2_transport.cc",
"//src/core:ext/transport/chttp2/transport/context_list.cc",
"//src/core:ext/transport/chttp2/transport/frame_data.cc", "//src/core:ext/transport/chttp2/transport/frame_data.cc",
"//src/core:ext/transport/chttp2/transport/frame_goaway.cc", "//src/core:ext/transport/chttp2/transport/frame_goaway.cc",
"//src/core:ext/transport/chttp2/transport/frame_ping.cc", "//src/core:ext/transport/chttp2/transport/frame_ping.cc",
@ -3728,7 +3772,6 @@ grpc_cc_library(
hdrs = [ hdrs = [
"//src/core:ext/transport/chttp2/transport/bin_decoder.h", "//src/core:ext/transport/chttp2/transport/bin_decoder.h",
"//src/core:ext/transport/chttp2/transport/chttp2_transport.h", "//src/core:ext/transport/chttp2/transport/chttp2_transport.h",
"//src/core:ext/transport/chttp2/transport/context_list.h",
"//src/core:ext/transport/chttp2/transport/frame_data.h", "//src/core:ext/transport/chttp2/transport/frame_data.h",
"//src/core:ext/transport/chttp2/transport/frame_goaway.h", "//src/core:ext/transport/chttp2/transport/frame_goaway.h",
"//src/core:ext/transport/chttp2/transport/frame_ping.h", "//src/core:ext/transport/chttp2/transport/frame_ping.h",
@ -3749,6 +3792,7 @@ grpc_cc_library(
language = "c++", language = "c++",
visibility = ["@grpc:grpclb"], visibility = ["@grpc:grpclb"],
deps = [ deps = [
"chttp2_context_list_entry",
"chttp2_frame", "chttp2_frame",
"chttp2_varint", "chttp2_varint",
"debug_location", "debug_location",
@ -3762,6 +3806,7 @@ grpc_cc_library(
"hpack_parser_table", "hpack_parser_table",
"http_trace", "http_trace",
"httpcli", "httpcli",
"iomgr_buffer_list",
"ref_counted_ptr", "ref_counted_ptr",
"stats", "stats",
"//src/core:arena", "//src/core:arena",

52
CMakeLists.txt generated

@ -910,7 +910,6 @@ if(gRPC_BUILD_TESTS)
add_dependencies(buildtests_cxx connection_refused_test) add_dependencies(buildtests_cxx connection_refused_test)
add_dependencies(buildtests_cxx connectivity_state_test) add_dependencies(buildtests_cxx connectivity_state_test)
add_dependencies(buildtests_cxx context_allocator_end2end_test) add_dependencies(buildtests_cxx context_allocator_end2end_test)
add_dependencies(buildtests_cxx context_list_test)
add_dependencies(buildtests_cxx context_test) add_dependencies(buildtests_cxx context_test)
add_dependencies(buildtests_cxx core_configuration_test) add_dependencies(buildtests_cxx core_configuration_test)
add_dependencies(buildtests_cxx core_end2end_tests) add_dependencies(buildtests_cxx core_end2end_tests)
@ -1660,7 +1659,6 @@ add_library(grpc
src/core/ext/transport/chttp2/transport/bin_decoder.cc src/core/ext/transport/chttp2/transport/bin_decoder.cc
src/core/ext/transport/chttp2/transport/bin_encoder.cc src/core/ext/transport/chttp2/transport/bin_encoder.cc
src/core/ext/transport/chttp2/transport/chttp2_transport.cc src/core/ext/transport/chttp2/transport/chttp2_transport.cc
src/core/ext/transport/chttp2/transport/context_list.cc
src/core/ext/transport/chttp2/transport/decode_huff.cc src/core/ext/transport/chttp2/transport/decode_huff.cc
src/core/ext/transport/chttp2/transport/flow_control.cc src/core/ext/transport/chttp2/transport/flow_control.cc
src/core/ext/transport/chttp2/transport/frame_data.cc src/core/ext/transport/chttp2/transport/frame_data.cc
@ -2669,7 +2667,6 @@ add_library(grpc_unsecure
src/core/ext/transport/chttp2/transport/bin_decoder.cc src/core/ext/transport/chttp2/transport/bin_decoder.cc
src/core/ext/transport/chttp2/transport/bin_encoder.cc src/core/ext/transport/chttp2/transport/bin_encoder.cc
src/core/ext/transport/chttp2/transport/chttp2_transport.cc src/core/ext/transport/chttp2/transport/chttp2_transport.cc
src/core/ext/transport/chttp2/transport/context_list.cc
src/core/ext/transport/chttp2/transport/decode_huff.cc src/core/ext/transport/chttp2/transport/decode_huff.cc
src/core/ext/transport/chttp2/transport/flow_control.cc src/core/ext/transport/chttp2/transport/flow_control.cc
src/core/ext/transport/chttp2/transport/frame_data.cc src/core/ext/transport/chttp2/transport/frame_data.cc
@ -9137,55 +9134,6 @@ target_link_libraries(context_allocator_end2end_test
) )
endif()
if(gRPC_BUILD_TESTS)
add_executable(context_list_test
test/core/transport/chttp2/context_list_test.cc
test/core/util/cmdline.cc
test/core/util/fuzzer_util.cc
test/core/util/grpc_profiler.cc
test/core/util/histogram.cc
test/core/util/mock_endpoint.cc
test/core/util/parse_hexstring.cc
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.cc
test/core/util/slice_splitter.cc
test/core/util/subprocess_posix.cc
test/core/util/subprocess_windows.cc
test/core/util/tracer_util.cc
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
)
target_compile_features(context_list_test PUBLIC cxx_std_14)
target_include_directories(context_list_test
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
${_gRPC_RE2_INCLUDE_DIR}
${_gRPC_SSL_INCLUDE_DIR}
${_gRPC_UPB_GENERATED_DIR}
${_gRPC_UPB_GRPC_GENERATED_DIR}
${_gRPC_UPB_INCLUDE_DIR}
${_gRPC_XXHASH_INCLUDE_DIR}
${_gRPC_ZLIB_INCLUDE_DIR}
third_party/googletest/googletest/include
third_party/googletest/googletest
third_party/googletest/googlemock/include
third_party/googletest/googlemock
${_gRPC_PROTO_GENS_DIR}
)
target_link_libraries(context_list_test
${_gRPC_BASELIB_LIBRARIES}
${_gRPC_PROTOBUF_LIBRARIES}
${_gRPC_ZLIB_LIBRARIES}
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_test_util
)
endif() endif()
if(gRPC_BUILD_TESTS) if(gRPC_BUILD_TESTS)

2
Makefile generated

@ -1047,7 +1047,6 @@ LIBGRPC_SRC = \
src/core/ext/transport/chttp2/transport/bin_decoder.cc \ src/core/ext/transport/chttp2/transport/bin_decoder.cc \
src/core/ext/transport/chttp2/transport/bin_encoder.cc \ src/core/ext/transport/chttp2/transport/bin_encoder.cc \
src/core/ext/transport/chttp2/transport/chttp2_transport.cc \ src/core/ext/transport/chttp2/transport/chttp2_transport.cc \
src/core/ext/transport/chttp2/transport/context_list.cc \
src/core/ext/transport/chttp2/transport/decode_huff.cc \ src/core/ext/transport/chttp2/transport/decode_huff.cc \
src/core/ext/transport/chttp2/transport/flow_control.cc \ src/core/ext/transport/chttp2/transport/flow_control.cc \
src/core/ext/transport/chttp2/transport/frame_data.cc \ src/core/ext/transport/chttp2/transport/frame_data.cc \
@ -1910,7 +1909,6 @@ LIBGRPC_UNSECURE_SRC = \
src/core/ext/transport/chttp2/transport/bin_decoder.cc \ src/core/ext/transport/chttp2/transport/bin_decoder.cc \
src/core/ext/transport/chttp2/transport/bin_encoder.cc \ src/core/ext/transport/chttp2/transport/bin_encoder.cc \
src/core/ext/transport/chttp2/transport/chttp2_transport.cc \ src/core/ext/transport/chttp2/transport/chttp2_transport.cc \
src/core/ext/transport/chttp2/transport/context_list.cc \
src/core/ext/transport/chttp2/transport/decode_huff.cc \ src/core/ext/transport/chttp2/transport/decode_huff.cc \
src/core/ext/transport/chttp2/transport/flow_control.cc \ src/core/ext/transport/chttp2/transport/flow_control.cc \
src/core/ext/transport/chttp2/transport/frame_data.cc \ src/core/ext/transport/chttp2/transport/frame_data.cc \

@ -103,6 +103,8 @@ def _update_visibility(visibility):
"http": PRIVATE, "http": PRIVATE,
"httpcli": PRIVATE, "httpcli": PRIVATE,
"iomgr_timer": PRIVATE, "iomgr_timer": PRIVATE,
"iomgr_internal_errqueue": PRIVATE,
"iomgr_buffer_list": PRIVATE,
"json_reader_legacy": PRIVATE, "json_reader_legacy": PRIVATE,
"public": PUBLIC, "public": PUBLIC,
"ref_counted_ptr": PRIVATE, "ref_counted_ptr": PRIVATE,

@ -281,7 +281,7 @@ libs:
- src/core/ext/transport/chttp2/transport/bin_decoder.h - src/core/ext/transport/chttp2/transport/bin_decoder.h
- src/core/ext/transport/chttp2/transport/bin_encoder.h - src/core/ext/transport/chttp2/transport/bin_encoder.h
- src/core/ext/transport/chttp2/transport/chttp2_transport.h - src/core/ext/transport/chttp2/transport/chttp2_transport.h
- src/core/ext/transport/chttp2/transport/context_list.h - src/core/ext/transport/chttp2/transport/context_list_entry.h
- src/core/ext/transport/chttp2/transport/decode_huff.h - src/core/ext/transport/chttp2/transport/decode_huff.h
- src/core/ext/transport/chttp2/transport/flow_control.h - src/core/ext/transport/chttp2/transport/flow_control.h
- src/core/ext/transport/chttp2/transport/frame.h - src/core/ext/transport/chttp2/transport/frame.h
@ -1081,7 +1081,6 @@ libs:
- src/core/ext/transport/chttp2/transport/bin_decoder.cc - src/core/ext/transport/chttp2/transport/bin_decoder.cc
- src/core/ext/transport/chttp2/transport/bin_encoder.cc - src/core/ext/transport/chttp2/transport/bin_encoder.cc
- src/core/ext/transport/chttp2/transport/chttp2_transport.cc - src/core/ext/transport/chttp2/transport/chttp2_transport.cc
- src/core/ext/transport/chttp2/transport/context_list.cc
- src/core/ext/transport/chttp2/transport/decode_huff.cc - src/core/ext/transport/chttp2/transport/decode_huff.cc
- src/core/ext/transport/chttp2/transport/flow_control.cc - src/core/ext/transport/chttp2/transport/flow_control.cc
- src/core/ext/transport/chttp2/transport/frame_data.cc - src/core/ext/transport/chttp2/transport/frame_data.cc
@ -1959,7 +1958,7 @@ libs:
- src/core/ext/transport/chttp2/transport/bin_decoder.h - src/core/ext/transport/chttp2/transport/bin_decoder.h
- src/core/ext/transport/chttp2/transport/bin_encoder.h - src/core/ext/transport/chttp2/transport/bin_encoder.h
- src/core/ext/transport/chttp2/transport/chttp2_transport.h - src/core/ext/transport/chttp2/transport/chttp2_transport.h
- src/core/ext/transport/chttp2/transport/context_list.h - src/core/ext/transport/chttp2/transport/context_list_entry.h
- src/core/ext/transport/chttp2/transport/decode_huff.h - src/core/ext/transport/chttp2/transport/decode_huff.h
- src/core/ext/transport/chttp2/transport/flow_control.h - src/core/ext/transport/chttp2/transport/flow_control.h
- src/core/ext/transport/chttp2/transport/frame.h - src/core/ext/transport/chttp2/transport/frame.h
@ -2369,7 +2368,6 @@ libs:
- src/core/ext/transport/chttp2/transport/bin_decoder.cc - src/core/ext/transport/chttp2/transport/bin_decoder.cc
- src/core/ext/transport/chttp2/transport/bin_encoder.cc - src/core/ext/transport/chttp2/transport/bin_encoder.cc
- src/core/ext/transport/chttp2/transport/chttp2_transport.cc - src/core/ext/transport/chttp2/transport/chttp2_transport.cc
- src/core/ext/transport/chttp2/transport/context_list.cc
- src/core/ext/transport/chttp2/transport/decode_huff.cc - src/core/ext/transport/chttp2/transport/decode_huff.cc
- src/core/ext/transport/chttp2/transport/flow_control.cc - src/core/ext/transport/chttp2/transport/flow_control.cc
- src/core/ext/transport/chttp2/transport/frame_data.cc - src/core/ext/transport/chttp2/transport/frame_data.cc
@ -6116,41 +6114,6 @@ targets:
- test/cpp/end2end/test_service_impl.cc - test/cpp/end2end/test_service_impl.cc
deps: deps:
- grpc++_test_util - grpc++_test_util
- name: context_list_test
gtest: true
build: test
language: c++
headers:
- test/core/util/cmdline.h
- test/core/util/evaluate_args_test_util.h
- test/core/util/fuzzer_util.h
- test/core/util/grpc_profiler.h
- test/core/util/histogram.h
- test/core/util/mock_authorization_endpoint.h
- test/core/util/mock_endpoint.h
- test/core/util/parse_hexstring.h
- test/core/util/passthru_endpoint.h
- test/core/util/resolve_localhost_ip46.h
- test/core/util/slice_splitter.h
- test/core/util/subprocess.h
- test/core/util/tracer_util.h
src:
- test/core/transport/chttp2/context_list_test.cc
- test/core/util/cmdline.cc
- test/core/util/fuzzer_util.cc
- test/core/util/grpc_profiler.cc
- test/core/util/histogram.cc
- test/core/util/mock_endpoint.cc
- test/core/util/parse_hexstring.cc
- test/core/util/passthru_endpoint.cc
- test/core/util/resolve_localhost_ip46.cc
- test/core/util/slice_splitter.cc
- test/core/util/subprocess_posix.cc
- test/core/util/subprocess_windows.cc
- test/core/util/tracer_util.cc
deps:
- grpc_test_util
uses_polling: false
- name: context_test - name: context_test
gtest: true gtest: true
build: test build: test

1
config.m4 generated

@ -127,7 +127,6 @@ if test "$PHP_GRPC" != "no"; then
src/core/ext/transport/chttp2/transport/bin_decoder.cc \ src/core/ext/transport/chttp2/transport/bin_decoder.cc \
src/core/ext/transport/chttp2/transport/bin_encoder.cc \ src/core/ext/transport/chttp2/transport/bin_encoder.cc \
src/core/ext/transport/chttp2/transport/chttp2_transport.cc \ src/core/ext/transport/chttp2/transport/chttp2_transport.cc \
src/core/ext/transport/chttp2/transport/context_list.cc \
src/core/ext/transport/chttp2/transport/decode_huff.cc \ src/core/ext/transport/chttp2/transport/decode_huff.cc \
src/core/ext/transport/chttp2/transport/flow_control.cc \ src/core/ext/transport/chttp2/transport/flow_control.cc \
src/core/ext/transport/chttp2/transport/frame_data.cc \ src/core/ext/transport/chttp2/transport/frame_data.cc \

1
config.w32 generated

@ -92,7 +92,6 @@ if (PHP_GRPC != "no") {
"src\\core\\ext\\transport\\chttp2\\transport\\bin_decoder.cc " + "src\\core\\ext\\transport\\chttp2\\transport\\bin_decoder.cc " +
"src\\core\\ext\\transport\\chttp2\\transport\\bin_encoder.cc " + "src\\core\\ext\\transport\\chttp2\\transport\\bin_encoder.cc " +
"src\\core\\ext\\transport\\chttp2\\transport\\chttp2_transport.cc " + "src\\core\\ext\\transport\\chttp2\\transport\\chttp2_transport.cc " +
"src\\core\\ext\\transport\\chttp2\\transport\\context_list.cc " +
"src\\core\\ext\\transport\\chttp2\\transport\\decode_huff.cc " + "src\\core\\ext\\transport\\chttp2\\transport\\decode_huff.cc " +
"src\\core\\ext\\transport\\chttp2\\transport\\flow_control.cc " + "src\\core\\ext\\transport\\chttp2\\transport\\flow_control.cc " +
"src\\core\\ext\\transport\\chttp2\\transport\\frame_data.cc " + "src\\core\\ext\\transport\\chttp2\\transport\\frame_data.cc " +

4
gRPC-C++.podspec generated

@ -352,7 +352,7 @@ Pod::Spec.new do |s|
'src/core/ext/transport/chttp2/transport/bin_decoder.h', 'src/core/ext/transport/chttp2/transport/bin_decoder.h',
'src/core/ext/transport/chttp2/transport/bin_encoder.h', 'src/core/ext/transport/chttp2/transport/bin_encoder.h',
'src/core/ext/transport/chttp2/transport/chttp2_transport.h', 'src/core/ext/transport/chttp2/transport/chttp2_transport.h',
'src/core/ext/transport/chttp2/transport/context_list.h', 'src/core/ext/transport/chttp2/transport/context_list_entry.h',
'src/core/ext/transport/chttp2/transport/decode_huff.h', 'src/core/ext/transport/chttp2/transport/decode_huff.h',
'src/core/ext/transport/chttp2/transport/flow_control.h', 'src/core/ext/transport/chttp2/transport/flow_control.h',
'src/core/ext/transport/chttp2/transport/frame.h', 'src/core/ext/transport/chttp2/transport/frame.h',
@ -1375,7 +1375,7 @@ Pod::Spec.new do |s|
'src/core/ext/transport/chttp2/transport/bin_decoder.h', 'src/core/ext/transport/chttp2/transport/bin_decoder.h',
'src/core/ext/transport/chttp2/transport/bin_encoder.h', 'src/core/ext/transport/chttp2/transport/bin_encoder.h',
'src/core/ext/transport/chttp2/transport/chttp2_transport.h', 'src/core/ext/transport/chttp2/transport/chttp2_transport.h',
'src/core/ext/transport/chttp2/transport/context_list.h', 'src/core/ext/transport/chttp2/transport/context_list_entry.h',
'src/core/ext/transport/chttp2/transport/decode_huff.h', 'src/core/ext/transport/chttp2/transport/decode_huff.h',
'src/core/ext/transport/chttp2/transport/flow_control.h', 'src/core/ext/transport/chttp2/transport/flow_control.h',
'src/core/ext/transport/chttp2/transport/frame.h', 'src/core/ext/transport/chttp2/transport/frame.h',

5
gRPC-Core.podspec generated

@ -368,8 +368,7 @@ Pod::Spec.new do |s|
'src/core/ext/transport/chttp2/transport/bin_encoder.h', 'src/core/ext/transport/chttp2/transport/bin_encoder.h',
'src/core/ext/transport/chttp2/transport/chttp2_transport.cc', 'src/core/ext/transport/chttp2/transport/chttp2_transport.cc',
'src/core/ext/transport/chttp2/transport/chttp2_transport.h', 'src/core/ext/transport/chttp2/transport/chttp2_transport.h',
'src/core/ext/transport/chttp2/transport/context_list.cc', 'src/core/ext/transport/chttp2/transport/context_list_entry.h',
'src/core/ext/transport/chttp2/transport/context_list.h',
'src/core/ext/transport/chttp2/transport/decode_huff.cc', 'src/core/ext/transport/chttp2/transport/decode_huff.cc',
'src/core/ext/transport/chttp2/transport/decode_huff.h', 'src/core/ext/transport/chttp2/transport/decode_huff.h',
'src/core/ext/transport/chttp2/transport/flow_control.cc', 'src/core/ext/transport/chttp2/transport/flow_control.cc',
@ -2093,7 +2092,7 @@ Pod::Spec.new do |s|
'src/core/ext/transport/chttp2/transport/bin_decoder.h', 'src/core/ext/transport/chttp2/transport/bin_decoder.h',
'src/core/ext/transport/chttp2/transport/bin_encoder.h', 'src/core/ext/transport/chttp2/transport/bin_encoder.h',
'src/core/ext/transport/chttp2/transport/chttp2_transport.h', 'src/core/ext/transport/chttp2/transport/chttp2_transport.h',
'src/core/ext/transport/chttp2/transport/context_list.h', 'src/core/ext/transport/chttp2/transport/context_list_entry.h',
'src/core/ext/transport/chttp2/transport/decode_huff.h', 'src/core/ext/transport/chttp2/transport/decode_huff.h',
'src/core/ext/transport/chttp2/transport/flow_control.h', 'src/core/ext/transport/chttp2/transport/flow_control.h',
'src/core/ext/transport/chttp2/transport/frame.h', 'src/core/ext/transport/chttp2/transport/frame.h',

3
grpc.gemspec generated

@ -274,8 +274,7 @@ Gem::Specification.new do |s|
s.files += %w( src/core/ext/transport/chttp2/transport/bin_encoder.h ) s.files += %w( src/core/ext/transport/chttp2/transport/bin_encoder.h )
s.files += %w( src/core/ext/transport/chttp2/transport/chttp2_transport.cc ) s.files += %w( src/core/ext/transport/chttp2/transport/chttp2_transport.cc )
s.files += %w( src/core/ext/transport/chttp2/transport/chttp2_transport.h ) s.files += %w( src/core/ext/transport/chttp2/transport/chttp2_transport.h )
s.files += %w( src/core/ext/transport/chttp2/transport/context_list.cc ) s.files += %w( src/core/ext/transport/chttp2/transport/context_list_entry.h )
s.files += %w( src/core/ext/transport/chttp2/transport/context_list.h )
s.files += %w( src/core/ext/transport/chttp2/transport/decode_huff.cc ) s.files += %w( src/core/ext/transport/chttp2/transport/decode_huff.cc )
s.files += %w( src/core/ext/transport/chttp2/transport/decode_huff.h ) s.files += %w( src/core/ext/transport/chttp2/transport/decode_huff.h )
s.files += %w( src/core/ext/transport/chttp2/transport/flow_control.cc ) s.files += %w( src/core/ext/transport/chttp2/transport/flow_control.cc )

2
grpc.gyp generated

@ -351,7 +351,6 @@
'src/core/ext/transport/chttp2/transport/bin_decoder.cc', 'src/core/ext/transport/chttp2/transport/bin_decoder.cc',
'src/core/ext/transport/chttp2/transport/bin_encoder.cc', 'src/core/ext/transport/chttp2/transport/bin_encoder.cc',
'src/core/ext/transport/chttp2/transport/chttp2_transport.cc', 'src/core/ext/transport/chttp2/transport/chttp2_transport.cc',
'src/core/ext/transport/chttp2/transport/context_list.cc',
'src/core/ext/transport/chttp2/transport/decode_huff.cc', 'src/core/ext/transport/chttp2/transport/decode_huff.cc',
'src/core/ext/transport/chttp2/transport/flow_control.cc', 'src/core/ext/transport/chttp2/transport/flow_control.cc',
'src/core/ext/transport/chttp2/transport/frame_data.cc', 'src/core/ext/transport/chttp2/transport/frame_data.cc',
@ -1155,7 +1154,6 @@
'src/core/ext/transport/chttp2/transport/bin_decoder.cc', 'src/core/ext/transport/chttp2/transport/bin_decoder.cc',
'src/core/ext/transport/chttp2/transport/bin_encoder.cc', 'src/core/ext/transport/chttp2/transport/bin_encoder.cc',
'src/core/ext/transport/chttp2/transport/chttp2_transport.cc', 'src/core/ext/transport/chttp2/transport/chttp2_transport.cc',
'src/core/ext/transport/chttp2/transport/context_list.cc',
'src/core/ext/transport/chttp2/transport/decode_huff.cc', 'src/core/ext/transport/chttp2/transport/decode_huff.cc',
'src/core/ext/transport/chttp2/transport/flow_control.cc', 'src/core/ext/transport/chttp2/transport/flow_control.cc',
'src/core/ext/transport/chttp2/transport/frame_data.cc', 'src/core/ext/transport/chttp2/transport/frame_data.cc',

3
package.xml generated

@ -256,8 +256,7 @@
<file baseinstalldir="/" name="src/core/ext/transport/chttp2/transport/bin_encoder.h" role="src" /> <file baseinstalldir="/" name="src/core/ext/transport/chttp2/transport/bin_encoder.h" role="src" />
<file baseinstalldir="/" name="src/core/ext/transport/chttp2/transport/chttp2_transport.cc" role="src" /> <file baseinstalldir="/" name="src/core/ext/transport/chttp2/transport/chttp2_transport.cc" role="src" />
<file baseinstalldir="/" name="src/core/ext/transport/chttp2/transport/chttp2_transport.h" role="src" /> <file baseinstalldir="/" name="src/core/ext/transport/chttp2/transport/chttp2_transport.h" role="src" />
<file baseinstalldir="/" name="src/core/ext/transport/chttp2/transport/context_list.cc" role="src" /> <file baseinstalldir="/" name="src/core/ext/transport/chttp2/transport/context_list_entry.h" role="src" />
<file baseinstalldir="/" name="src/core/ext/transport/chttp2/transport/context_list.h" role="src" />
<file baseinstalldir="/" name="src/core/ext/transport/chttp2/transport/decode_huff.cc" role="src" /> <file baseinstalldir="/" name="src/core/ext/transport/chttp2/transport/decode_huff.cc" role="src" />
<file baseinstalldir="/" name="src/core/ext/transport/chttp2/transport/decode_huff.h" role="src" /> <file baseinstalldir="/" name="src/core/ext/transport/chttp2/transport/decode_huff.h" role="src" />
<file baseinstalldir="/" name="src/core/ext/transport/chttp2/transport/flow_control.cc" role="src" /> <file baseinstalldir="/" name="src/core/ext/transport/chttp2/transport/flow_control.cc" role="src" />

@ -29,6 +29,7 @@
#include <new> #include <new>
#include <string> #include <string>
#include <utility> #include <utility>
#include <vector>
#include "absl/base/attributes.h" #include "absl/base/attributes.h"
#include "absl/status/status.h" #include "absl/status/status.h"
@ -47,7 +48,7 @@
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include <grpc/support/time.h> #include <grpc/support/time.h>
#include "src/core/ext/transport/chttp2/transport/context_list.h" #include "src/core/ext/transport/chttp2/transport/context_list_entry.h"
#include "src/core/ext/transport/chttp2/transport/flow_control.h" #include "src/core/ext/transport/chttp2/transport/flow_control.h"
#include "src/core/ext/transport/chttp2/transport/frame.h" #include "src/core/ext/transport/chttp2/transport/frame.h"
#include "src/core/ext/transport/chttp2/transport/frame_data.h" #include "src/core/ext/transport/chttp2/transport/frame_data.h"
@ -214,6 +215,9 @@ grpc_core::CallTracerInterface* CallTracerIfEnabled(grpc_chttp2_stream* s) {
s->context)[GRPC_CONTEXT_CALL_TRACER_ANNOTATION_INTERFACE] s->context)[GRPC_CONTEXT_CALL_TRACER_ANNOTATION_INTERFACE]
.value); .value);
} }
grpc_core::WriteTimestampsCallback g_write_timestamps_callback = nullptr;
grpc_core::CopyContextFn g_get_copied_context_fn = nullptr;
} // namespace } // namespace
namespace grpc_core { namespace grpc_core {
@ -240,6 +244,40 @@ void TestOnlyGlobalHttp2TransportDisableTransientFailureStateNotification(
test_only_disable_transient_failure_state_notification = disable; test_only_disable_transient_failure_state_notification = disable;
} }
void GrpcHttp2SetWriteTimestampsCallback(WriteTimestampsCallback fn) {
g_write_timestamps_callback = fn;
}
void GrpcHttp2SetCopyContextFn(CopyContextFn fn) {
g_get_copied_context_fn = fn;
}
WriteTimestampsCallback GrpcHttp2GetWriteTimestampsCallback() {
return g_write_timestamps_callback;
}
CopyContextFn GrpcHttp2GetCopyContextFn() { return g_get_copied_context_fn; }
// For each entry in the passed ContextList, it executes the function set using
// GrpcHttp2SetWriteTimestampsCallback method with each context in the list
// and \a ts. It also deletes/frees up the passed ContextList after this
// operation.
void ForEachContextListEntryExecute(void* arg, Timestamps* ts,
grpc_error_handle error) {
ContextList* context_list = reinterpret_cast<ContextList*>(arg);
if (!context_list) {
return;
}
for (auto it = context_list->begin(); it != context_list->end(); it++) {
ContextListEntry& entry = (*it);
if (ts) {
ts->byte_offset = static_cast<uint32_t>(entry.ByteOffsetInStream());
}
g_write_timestamps_callback(entry.TraceContext(), ts, error);
}
delete context_list;
}
} // namespace grpc_core } // namespace grpc_core
// //
@ -264,7 +302,9 @@ grpc_chttp2_transport::~grpc_chttp2_transport() {
grpc_error_handle error = GRPC_ERROR_CREATE("Transport destroyed"); grpc_error_handle error = GRPC_ERROR_CREATE("Transport destroyed");
// ContextList::Execute follows semantics of a callback function and does not // ContextList::Execute follows semantics of a callback function and does not
// take a ref on error // take a ref on error
grpc_core::ContextList::Execute(cl, nullptr, error); if (cl != nullptr) {
grpc_core::ForEachContextListEntryExecute(cl, nullptr, error);
}
cl = nullptr; cl = nullptr;
grpc_slice_buffer_destroy(&read_buffer); grpc_slice_buffer_destroy(&read_buffer);
@ -554,6 +594,7 @@ grpc_chttp2_transport::grpc_chttp2_transport(
event_engine( event_engine(
channel_args channel_args
.GetObjectRef<grpc_event_engine::experimental::EventEngine>()) { .GetObjectRef<grpc_event_engine::experimental::EventEngine>()) {
cl = new grpc_core::ContextList();
GPR_ASSERT(strlen(GRPC_CHTTP2_CLIENT_CONNECT_STRING) == GPR_ASSERT(strlen(GRPC_CHTTP2_CLIENT_CONNECT_STRING) ==
GRPC_CHTTP2_CLIENT_CONNECT_STRLEN); GRPC_CHTTP2_CLIENT_CONNECT_STRLEN);
base.vtable = get_vtable(); base.vtable = get_vtable();
@ -985,7 +1026,17 @@ static void write_action_begin_locked(void* gt,
static void write_action(void* gt, grpc_error_handle /*error*/) { static void write_action(void* gt, grpc_error_handle /*error*/) {
grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(gt); grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(gt);
void* cl = t->cl; void* cl = t->cl;
t->cl = nullptr; if (!t->cl->empty()) {
// Transfer the ownership of the context list to the endpoint and create and
// associate a new context list with the transport.
// The old context list is stored in the cl local variable which is passed
// to the endpoint. Its upto the endpoint to manage its lifetime.
t->cl = new grpc_core::ContextList();
} else {
// t->cl is Empty. There is nothing to trace in this endpoint_write. set cl
// to nullptr.
cl = nullptr;
}
// Choose max_frame_size as the prefered rx crypto frame size indicated by the // Choose max_frame_size as the prefered rx crypto frame size indicated by the
// peer. // peer.
int max_frame_size = int max_frame_size =

@ -27,8 +27,10 @@
#include "src/core/lib/channel/channelz.h" #include "src/core/lib/channel/channelz.h"
#include "src/core/lib/debug/trace.h" #include "src/core/lib/debug/trace.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/iomgr/buffer_list.h"
#include "src/core/lib/iomgr/closure.h" #include "src/core/lib/iomgr/closure.h"
#include "src/core/lib/iomgr/endpoint.h" #include "src/core/lib/iomgr/endpoint.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/transport/transport_fwd.h" #include "src/core/lib/transport/transport_fwd.h"
extern grpc_core::TraceFlag grpc_keepalive_trace; extern grpc_core::TraceFlag grpc_keepalive_trace;
@ -71,6 +73,25 @@ void TestOnlySetGlobalHttp2TransportDestructCallback(
// same time that a GOAWAY is received. // same time that a GOAWAY is received.
void TestOnlyGlobalHttp2TransportDisableTransientFailureStateNotification( void TestOnlyGlobalHttp2TransportDisableTransientFailureStateNotification(
bool disable); bool disable);
typedef void (*WriteTimestampsCallback)(void*, Timestamps*,
grpc_error_handle error);
typedef void* (*CopyContextFn)(void*);
void GrpcHttp2SetWriteTimestampsCallback(WriteTimestampsCallback fn);
void GrpcHttp2SetCopyContextFn(CopyContextFn fn);
WriteTimestampsCallback GrpcHttp2GetWriteTimestampsCallback();
CopyContextFn GrpcHttp2GetCopyContextFn();
// Interprets the passed arg as a ContextList type and for each entry in the
// passed ContextList, it executes the function set using
// GrpcHttp2SetWriteTimestampsCallback method with each context in the list
// and \a ts. It also deletes/frees up the passed ContextList after this
// operation.
void ForEachContextListEntryExecute(void* arg, Timestamps* ts,
grpc_error_handle error);
} // namespace grpc_core } // namespace grpc_core
#endif // GRPC_SRC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_CHTTP2_TRANSPORT_H #endif // GRPC_SRC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_CHTTP2_TRANSPORT_H

@ -1,71 +0,0 @@
//
//
// Copyright 2018 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//
#include <grpc/support/port_platform.h>
#include "src/core/ext/transport/chttp2/transport/context_list.h"
#include <stdint.h>
#include "src/core/ext/transport/chttp2/transport/internal.h"
namespace {
void (*write_timestamps_callback_g)(void*, grpc_core::Timestamps*,
grpc_error_handle error) = nullptr;
void* (*get_copied_context_fn_g)(void*) = nullptr;
} // namespace
namespace grpc_core {
void ContextList::Append(ContextList** head, grpc_chttp2_stream* s) {
if (get_copied_context_fn_g == nullptr ||
write_timestamps_callback_g == nullptr) {
return;
}
// Create a new element in the list and add it at the front
ContextList* elem = new ContextList();
elem->trace_context_ = get_copied_context_fn_g(s->context);
elem->byte_offset_ = s->byte_counter;
elem->next_ = *head;
*head = elem;
}
void ContextList::Execute(void* arg, Timestamps* ts, grpc_error_handle error) {
ContextList* head = static_cast<ContextList*>(arg);
ContextList* to_be_freed;
while (head != nullptr) {
if (write_timestamps_callback_g) {
if (ts) {
ts->byte_offset = static_cast<uint32_t>(head->byte_offset_);
}
write_timestamps_callback_g(head->trace_context_, ts, error);
}
to_be_freed = head;
head = head->next_;
delete to_be_freed;
}
}
void grpc_http2_set_write_timestamps_callback(
void (*fn)(void*, Timestamps*, grpc_error_handle error)) {
write_timestamps_callback_g = fn;
}
void grpc_http2_set_fn_get_copied_context(void* (*fn)(void*)) {
get_copied_context_fn_g = fn;
}
} // namespace grpc_core

@ -1,54 +0,0 @@
//
//
// Copyright 2018 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//
#ifndef GRPC_SRC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_CONTEXT_LIST_H
#define GRPC_SRC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_CONTEXT_LIST_H
#include <grpc/support/port_platform.h>
#include <stddef.h>
#include "src/core/ext/transport/chttp2/transport/frame.h"
#include "src/core/lib/iomgr/buffer_list.h"
#include "src/core/lib/iomgr/error.h"
namespace grpc_core {
/// A list of RPC Contexts
class ContextList {
public:
// Creates a new element with \a context as the value and appends it to the
// list.
static void Append(ContextList** head, grpc_chttp2_stream* s);
// Executes a function \a fn with each context in the list and \a ts. It also
// frees up the entire list after this operation. It is intended as a callback
// and hence does not take a ref on \a error
static void Execute(void* arg, Timestamps* ts, grpc_error_handle error);
private:
void* trace_context_ = nullptr;
ContextList* next_ = nullptr;
size_t byte_offset_ = 0;
};
void grpc_http2_set_write_timestamps_callback(
void (*fn)(void*, Timestamps*, grpc_error_handle error));
void grpc_http2_set_fn_get_copied_context(void* (*fn)(void*));
} // namespace grpc_core
#endif // GRPC_SRC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_CONTEXT_LIST_H

@ -0,0 +1,70 @@
//
//
// Copyright 2018 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//
#ifndef GRPC_SRC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_CONTEXT_LIST_ENTRY_H
#define GRPC_SRC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_CONTEXT_LIST_ENTRY_H
#include <grpc/support/port_platform.h>
#include <stddef.h>
#include <stdint.h>
#include <vector>
namespace grpc_core {
/// An RPC trace context and associated information. Each RPC/stream is
/// associated with a unique \a context. A new ContextList entry is created when
/// a chunk of data stored in an outgoing buffer is going to be
// sent over the wire. A data chunk being written over the wire is multiplexed
// with bytes from multiple RPCs. If one such RPC is traced, we store the
// following information about the traced RPC:
// - byte_offset_in_stream: Number of bytes belonging to that traced RPC which
// have been sent so far from the start of the RPC stream.
// - relative_start_pos_in_chunk: Starting offset of the traced RPC within
// the current chunk that is being sent.
// - num_traced_bytes_in_chunk: Number of bytes belonging to the traced RPC
// within the current chunk.
class ContextListEntry {
public:
ContextListEntry(void* context, int64_t relative_start_pos,
int64_t num_traced_bytes, size_t byte_offset)
: trace_context_(context),
relative_start_pos_in_chunk_(relative_start_pos),
num_traced_bytes_in_chunk_(num_traced_bytes),
byte_offset_in_stream_(byte_offset) {}
ContextListEntry() = delete;
void* TraceContext() { return trace_context_; }
int64_t RelativeStartPosInChunk() { return relative_start_pos_in_chunk_; }
int64_t NumTracedBytesInChunk() { return num_traced_bytes_in_chunk_; }
size_t ByteOffsetInStream() { return byte_offset_in_stream_; }
private:
void* trace_context_;
int64_t relative_start_pos_in_chunk_;
int64_t num_traced_bytes_in_chunk_;
size_t byte_offset_in_stream_;
};
/// A list of RPC Contexts
typedef std::vector<ContextListEntry> ContextList;
} // namespace grpc_core
#endif // GRPC_SRC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_CONTEXT_LIST_ENTRY_H

@ -35,6 +35,7 @@
#include <grpc/slice.h> #include <grpc/slice.h>
#include <grpc/support/time.h> #include <grpc/support/time.h>
#include "src/core/ext/transport/chttp2/transport/context_list_entry.h"
#include "src/core/ext/transport/chttp2/transport/flow_control.h" #include "src/core/ext/transport/chttp2/transport/flow_control.h"
#include "src/core/ext/transport/chttp2/transport/frame.h" #include "src/core/ext/transport/chttp2/transport/frame.h"
#include "src/core/ext/transport/chttp2/transport/frame_goaway.h" #include "src/core/ext/transport/chttp2/transport/frame_goaway.h"
@ -77,10 +78,6 @@
// bits being used for flags defined above) // bits being used for flags defined above)
#define CLOSURE_BARRIER_FIRST_REF_BIT (1 << 16) #define CLOSURE_BARRIER_FIRST_REF_BIT (1 << 16)
namespace grpc_core {
class ContextList;
}
// streams are kept in various linked lists depending on what things need to // streams are kept in various linked lists depending on what things need to
// happen to them... this enum labels each list // happen to them... this enum labels each list
typedef enum { typedef enum {

@ -39,7 +39,7 @@
// IWYU pragma: no_include "src/core/lib/gprpp/orphanable.h" // IWYU pragma: no_include "src/core/lib/gprpp/orphanable.h"
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/ext/transport/chttp2/transport/context_list.h" #include "src/core/ext/transport/chttp2/transport/context_list_entry.h"
#include "src/core/ext/transport/chttp2/transport/flow_control.h" #include "src/core/ext/transport/chttp2/transport/flow_control.h"
#include "src/core/ext/transport/chttp2/transport/frame.h" #include "src/core/ext/transport/chttp2/transport/frame.h"
#include "src/core/ext/transport/chttp2/transport/frame_data.h" #include "src/core/ext/transport/chttp2/transport/frame_data.h"
@ -627,6 +627,7 @@ class StreamWriteContext {
grpc_chttp2_begin_write_result grpc_chttp2_begin_write( grpc_chttp2_begin_write_result grpc_chttp2_begin_write(
grpc_chttp2_transport* t) { grpc_chttp2_transport* t) {
int64_t outbuf_relative_start_pos = 0;
WriteContext ctx(t); WriteContext ctx(t);
ctx.FlushSettings(); ctx.FlushSettings();
ctx.FlushPingAcks(); ctx.FlushPingAcks();
@ -642,16 +643,26 @@ grpc_chttp2_begin_write_result grpc_chttp2_begin_write(
while (grpc_chttp2_stream* s = ctx.NextStream()) { while (grpc_chttp2_stream* s = ctx.NextStream()) {
StreamWriteContext stream_ctx(&ctx, s); StreamWriteContext stream_ctx(&ctx, s);
size_t orig_len = t->outbuf.length; size_t orig_len = t->outbuf.length;
int64_t num_stream_bytes = 0;
stream_ctx.FlushInitialMetadata(); stream_ctx.FlushInitialMetadata();
stream_ctx.FlushWindowUpdates(); stream_ctx.FlushWindowUpdates();
stream_ctx.FlushData(); stream_ctx.FlushData();
stream_ctx.FlushTrailingMetadata(); stream_ctx.FlushTrailingMetadata();
if (t->outbuf.length > orig_len) { if (t->outbuf.length > orig_len) {
// Add this stream to the list of the contexts to be traced at TCP // Add this stream to the list of the contexts to be traced at TCP
s->byte_counter += t->outbuf.length - orig_len; num_stream_bytes = t->outbuf.length - orig_len;
s->byte_counter += static_cast<size_t>(num_stream_bytes);
if (s->traced && grpc_endpoint_can_track_err(t->ep)) { if (s->traced && grpc_endpoint_can_track_err(t->ep)) {
grpc_core::ContextList::Append(&t->cl, s); grpc_core::CopyContextFn copy_context_fn =
grpc_core::GrpcHttp2GetCopyContextFn();
if (copy_context_fn != nullptr &&
grpc_core::GrpcHttp2GetWriteTimestampsCallback() != nullptr) {
t->cl->emplace_back(copy_context_fn(s->context),
outbuf_relative_start_pos, num_stream_bytes,
s->byte_counter);
}
} }
outbuf_relative_start_pos += num_stream_bytes;
} }
if (stream_ctx.stream_became_writable()) { if (stream_ctx.stream_became_writable()) {
if (!grpc_chttp2_list_add_writing_stream(t, s)) { if (!grpc_chttp2_list_add_writing_stream(t, s)) {

@ -23,7 +23,6 @@
#include "absl/types/optional.h" #include "absl/types/optional.h"
#include <grpc/grpc.h>
#include <grpc/support/time.h> #include <grpc/support/time.h>
#include "src/core/lib/gprpp/sync.h" #include "src/core/lib/gprpp/sync.h"

@ -101,7 +101,6 @@ CORE_SOURCE_FILES = [
'src/core/ext/transport/chttp2/transport/bin_decoder.cc', 'src/core/ext/transport/chttp2/transport/bin_decoder.cc',
'src/core/ext/transport/chttp2/transport/bin_encoder.cc', 'src/core/ext/transport/chttp2/transport/bin_encoder.cc',
'src/core/ext/transport/chttp2/transport/chttp2_transport.cc', 'src/core/ext/transport/chttp2/transport/chttp2_transport.cc',
'src/core/ext/transport/chttp2/transport/context_list.cc',
'src/core/ext/transport/chttp2/transport/decode_huff.cc', 'src/core/ext/transport/chttp2/transport/decode_huff.cc',
'src/core/ext/transport/chttp2/transport/flow_control.cc', 'src/core/ext/transport/chttp2/transport/flow_control.cc',
'src/core/ext/transport/chttp2/transport/frame_data.cc', 'src/core/ext/transport/chttp2/transport/frame_data.cc',

@ -122,23 +122,6 @@ grpc_cc_test(
], ],
) )
grpc_cc_test(
name = "context_list_test",
srcs = ["context_list_test.cc"],
external_deps = [
"gtest",
],
language = "C++",
uses_event_engine = False,
uses_polling = False,
deps = [
"//:gpr",
"//:grpc",
"//test/core/util:grpc_test_util",
"//test/core/util:grpc_test_util_base",
],
)
grpc_cc_test( grpc_cc_test(
name = "flow_control_test", name = "flow_control_test",
srcs = ["flow_control_test.cc"], srcs = ["flow_control_test.cc"],

@ -1,181 +0,0 @@
//
//
// Copyright 2018 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//
#include "src/core/ext/transport/chttp2/transport/context_list.h"
#include <stdint.h>
#include <algorithm>
#include <vector>
#include "absl/status/status.h"
#include "gtest/gtest.h"
#include <grpc/grpc.h>
#include <grpc/slice.h>
#include <grpc/support/alloc.h>
#include <grpc/support/atm.h>
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/ext/transport/chttp2/transport/internal.h"
#include "src/core/lib/channel/channel_args_preconditioning.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/iomgr/endpoint.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/transport/transport.h"
#include "src/core/lib/transport/transport_fwd.h"
#include "test/core/util/mock_endpoint.h"
#include "test/core/util/test_config.h"
namespace grpc_core {
namespace testing {
namespace {
const uint32_t kByteOffset = 123;
void* PhonyArgsCopier(void* arg) { return arg; }
void TestExecuteFlushesListVerifier(void* arg, Timestamps* ts,
grpc_error_handle error) {
ASSERT_NE(arg, nullptr);
EXPECT_EQ(error, absl::OkStatus());
if (ts) {
EXPECT_EQ(ts->byte_offset, kByteOffset);
}
gpr_atm* done = reinterpret_cast<gpr_atm*>(arg);
gpr_atm_rel_store(done, gpr_atm{1});
}
void discard_write(grpc_slice /*slice*/) {}
class ContextListTest : public ::testing::Test {
protected:
void SetUp() override {
grpc_http2_set_write_timestamps_callback(TestExecuteFlushesListVerifier);
grpc_http2_set_fn_get_copied_context(PhonyArgsCopier);
}
};
/// Tests that all ContextList elements in the list are flushed out on
/// execute.
/// Also tests that arg and byte_counter are passed correctly.
///
TEST_F(ContextListTest, ExecuteFlushesList) {
ContextList* list = nullptr;
const int kNumElems = 5;
ExecCtx exec_ctx;
grpc_stream_refcount ref;
GRPC_STREAM_REF_INIT(&ref, 1, nullptr, nullptr, "phony ref");
grpc_endpoint* mock_endpoint = grpc_mock_endpoint_create(discard_write);
auto args = CoreConfiguration::Get()
.channel_args_preconditioning()
.PreconditionChannelArgs(nullptr);
grpc_transport* t = grpc_create_chttp2_transport(args, mock_endpoint, true);
std::vector<grpc_chttp2_stream*> s;
s.reserve(kNumElems);
gpr_atm verifier_called[kNumElems];
for (auto i = 0; i < kNumElems; i++) {
s.push_back(static_cast<grpc_chttp2_stream*>(
gpr_malloc(grpc_transport_stream_size(t))));
grpc_transport_init_stream(reinterpret_cast<grpc_transport*>(t),
reinterpret_cast<grpc_stream*>(s[i]), &ref,
nullptr, nullptr);
s[i]->context = &verifier_called[i];
s[i]->byte_counter = kByteOffset;
gpr_atm_rel_store(&verifier_called[i], gpr_atm{0});
ContextList::Append(&list, s[i]);
}
Timestamps ts;
ContextList::Execute(list, &ts, absl::OkStatus());
for (auto i = 0; i < kNumElems; i++) {
EXPECT_EQ(gpr_atm_acq_load(&verifier_called[i]), 1);
grpc_transport_destroy_stream(reinterpret_cast<grpc_transport*>(t),
reinterpret_cast<grpc_stream*>(s[i]),
nullptr);
exec_ctx.Flush();
gpr_free(s[i]);
}
grpc_transport_destroy(t);
exec_ctx.Flush();
}
TEST_F(ContextListTest, EmptyList) {
ContextList* list = nullptr;
ExecCtx exec_ctx;
Timestamps ts;
ContextList::Execute(list, &ts, absl::OkStatus());
exec_ctx.Flush();
}
TEST_F(ContextListTest, EmptyListEmptyTimestamp) {
ContextList* list = nullptr;
ExecCtx exec_ctx;
ContextList::Execute(list, nullptr, absl::OkStatus());
exec_ctx.Flush();
}
TEST_F(ContextListTest, NonEmptyListEmptyTimestamp) {
ContextList* list = nullptr;
const int kNumElems = 5;
ExecCtx exec_ctx;
grpc_stream_refcount ref;
GRPC_STREAM_REF_INIT(&ref, 1, nullptr, nullptr, "phony ref");
grpc_endpoint* mock_endpoint = grpc_mock_endpoint_create(discard_write);
auto args = CoreConfiguration::Get()
.channel_args_preconditioning()
.PreconditionChannelArgs(nullptr);
grpc_transport* t = grpc_create_chttp2_transport(args, mock_endpoint, true);
std::vector<grpc_chttp2_stream*> s;
s.reserve(kNumElems);
gpr_atm verifier_called[kNumElems];
for (auto i = 0; i < kNumElems; i++) {
s.push_back(static_cast<grpc_chttp2_stream*>(
gpr_malloc(grpc_transport_stream_size(t))));
grpc_transport_init_stream(reinterpret_cast<grpc_transport*>(t),
reinterpret_cast<grpc_stream*>(s[i]), &ref,
nullptr, nullptr);
s[i]->context = &verifier_called[i];
s[i]->byte_counter = kByteOffset;
gpr_atm_rel_store(&verifier_called[i], gpr_atm{0});
ContextList::Append(&list, s[i]);
}
ContextList::Execute(list, nullptr, absl::OkStatus());
for (auto i = 0; i < kNumElems; i++) {
EXPECT_EQ(gpr_atm_acq_load(&verifier_called[i]), 1);
grpc_transport_destroy_stream(reinterpret_cast<grpc_transport*>(t),
reinterpret_cast<grpc_stream*>(s[i]),
nullptr);
exec_ctx.Flush();
gpr_free(s[i]);
}
grpc_transport_destroy(t);
exec_ctx.Flush();
}
} // namespace
} // namespace testing
} // namespace grpc_core
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
grpc::testing::TestEnvironment env(&argc, argv);
grpc_init();
int ret = RUN_ALL_TESTS();
grpc_shutdown();
return ret;
}

@ -1269,8 +1269,7 @@ src/core/ext/transport/chttp2/transport/bin_encoder.cc \
src/core/ext/transport/chttp2/transport/bin_encoder.h \ src/core/ext/transport/chttp2/transport/bin_encoder.h \
src/core/ext/transport/chttp2/transport/chttp2_transport.cc \ src/core/ext/transport/chttp2/transport/chttp2_transport.cc \
src/core/ext/transport/chttp2/transport/chttp2_transport.h \ src/core/ext/transport/chttp2/transport/chttp2_transport.h \
src/core/ext/transport/chttp2/transport/context_list.cc \ src/core/ext/transport/chttp2/transport/context_list_entry.h \
src/core/ext/transport/chttp2/transport/context_list.h \
src/core/ext/transport/chttp2/transport/decode_huff.cc \ src/core/ext/transport/chttp2/transport/decode_huff.cc \
src/core/ext/transport/chttp2/transport/decode_huff.h \ src/core/ext/transport/chttp2/transport/decode_huff.h \
src/core/ext/transport/chttp2/transport/flow_control.cc \ src/core/ext/transport/chttp2/transport/flow_control.cc \

@ -1046,8 +1046,7 @@ src/core/ext/transport/chttp2/transport/bin_encoder.cc \
src/core/ext/transport/chttp2/transport/bin_encoder.h \ src/core/ext/transport/chttp2/transport/bin_encoder.h \
src/core/ext/transport/chttp2/transport/chttp2_transport.cc \ src/core/ext/transport/chttp2/transport/chttp2_transport.cc \
src/core/ext/transport/chttp2/transport/chttp2_transport.h \ src/core/ext/transport/chttp2/transport/chttp2_transport.h \
src/core/ext/transport/chttp2/transport/context_list.cc \ src/core/ext/transport/chttp2/transport/context_list_entry.h \
src/core/ext/transport/chttp2/transport/context_list.h \
src/core/ext/transport/chttp2/transport/decode_huff.cc \ src/core/ext/transport/chttp2/transport/decode_huff.cc \
src/core/ext/transport/chttp2/transport/decode_huff.h \ src/core/ext/transport/chttp2/transport/decode_huff.h \
src/core/ext/transport/chttp2/transport/flow_control.cc \ src/core/ext/transport/chttp2/transport/flow_control.cc \

@ -2133,30 +2133,6 @@
], ],
"uses_polling": true "uses_polling": true
}, },
{
"args": [],
"benchmark": false,
"ci_platforms": [
"linux",
"mac",
"posix",
"windows"
],
"cpu_cost": 1.0,
"exclude_configs": [],
"exclude_iomgrs": [],
"flaky": false,
"gtest": true,
"language": "c++",
"name": "context_list_test",
"platforms": [
"linux",
"mac",
"posix",
"windows"
],
"uses_polling": false
},
{ {
"args": [], "args": [],
"benchmark": false, "benchmark": false,

Loading…
Cancel
Save