Replace in-house rand with absl::Random for backoff (#26463)

* Replace in-house rand with absl::Random for backoff

* Run sanity

* Added bscrypt dependency
reviewable/pr26471/r1
Esun Kim 4 years ago committed by GitHub
parent a7fdf12bb4
commit b5191d0930
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      BUILD
  2. 1
      BUILD.gn
  3. 35
      CMakeLists.txt
  4. 13
      Makefile
  5. 1
      build_autogenerated.yaml
  6. 13
      config.m4
  7. 13
      config.w32
  8. 1
      gRPC-C++.podspec
  9. 1
      gRPC-Core.podspec
  10. 46
      grpc.gemspec
  11. 1
      grpc.gyp
  12. 46
      package.xml
  13. 3
      setup.py
  14. 34
      src/core/lib/backoff/backoff.cc
  15. 6
      src/core/lib/backoff/backoff.h
  16. 11
      src/python/grpcio/grpc_core_dependencies.py
  17. 2
      templates/Makefile.template
  18. 2
      test/core/backoff/backoff_test.cc

@ -650,6 +650,7 @@ grpc_cc_library(
external_deps = [
"absl/base",
"absl/memory",
"absl/random",
"absl/status",
"absl/strings",
"absl/strings:str_format",

@ -203,6 +203,7 @@ config("grpc_config") {
deps = [
":absl/base:base",
":absl/memory:memory",
":absl/random:random",
":absl/status:status",
":absl/strings:str_format",
":absl/strings:strings",

@ -121,6 +121,7 @@ set(gRPC_ABSL_USED_TARGETS
absl_endian
absl_errno_saver
absl_exponential_biased
absl_fast_type_id
absl_fixed_array
absl_flat_hash_map
absl_function_ref
@ -141,6 +142,29 @@ set(gRPC_ABSL_USED_TARGETS
absl_memory
absl_numeric_representation
absl_optional
absl_random_distributions
absl_random_internal_distribution_caller
absl_random_internal_fast_uniform_bits
absl_random_internal_fastmath
absl_random_internal_generate_real
absl_random_internal_iostream_state_saver
absl_random_internal_nonsecure_base
absl_random_internal_pcg_engine
absl_random_internal_platform
absl_random_internal_pool_urbg
absl_random_internal_randen
absl_random_internal_randen_engine
absl_random_internal_randen_hwaes
absl_random_internal_randen_hwaes_impl
absl_random_internal_randen_slow
absl_random_internal_salted_seed_seq
absl_random_internal_seed_material
absl_random_internal_traits
absl_random_internal_uniform_helper
absl_random_internal_wide_multiply
absl_random_random
absl_random_seed_gen_exception
absl_random_seed_sequences
absl_raw_hash_map
absl_raw_hash_set
absl_raw_logging_internal
@ -1417,6 +1441,7 @@ target_link_libraries(gpr
${_gRPC_ALLTARGETS_LIBRARIES}
absl::base
absl::memory
absl::random_random
absl::status
absl::str_format
absl::strings
@ -15814,7 +15839,7 @@ generate_pkgconfig(
"gpr"
"gRPC platform support library"
"${gRPC_CORE_VERSION}"
"absl_base absl_memory absl_optional absl_status absl_str_format absl_strings absl_synchronization absl_time"
"absl_base absl_memory absl_optional absl_random_random absl_status absl_str_format absl_strings absl_synchronization absl_time"
"-lgpr"
""
"gpr.pc")
@ -15824,7 +15849,7 @@ generate_pkgconfig(
"gRPC"
"high performance general RPC framework"
"${gRPC_CORE_VERSION}"
"gpr openssl absl_base absl_bind_front absl_flat_hash_map absl_inlined_vector absl_memory absl_optional absl_status absl_statusor absl_str_format absl_strings absl_synchronization absl_time"
"gpr openssl absl_base absl_bind_front absl_flat_hash_map absl_inlined_vector absl_memory absl_optional absl_random_random absl_status absl_statusor absl_str_format absl_strings absl_synchronization absl_time"
"-lgrpc -laddress_sorting -lre2 -lupb -lcares -lz"
""
"grpc.pc")
@ -15834,7 +15859,7 @@ generate_pkgconfig(
"gRPC unsecure"
"high performance general RPC framework without SSL"
"${gRPC_CORE_VERSION}"
"gpr absl_base absl_flat_hash_map absl_inlined_vector absl_memory absl_optional absl_status absl_statusor absl_str_format absl_strings absl_synchronization absl_time"
"gpr absl_base absl_flat_hash_map absl_inlined_vector absl_memory absl_optional absl_random_random absl_status absl_statusor absl_str_format absl_strings absl_synchronization absl_time"
"-lgrpc_unsecure"
""
"grpc_unsecure.pc")
@ -15844,7 +15869,7 @@ generate_pkgconfig(
"gRPC++"
"C++ wrapper for gRPC"
"${gRPC_CPP_VERSION}"
"grpc absl_base absl_bind_front absl_flat_hash_map absl_inlined_vector absl_memory absl_optional absl_status absl_statusor absl_str_format absl_strings absl_synchronization absl_time"
"grpc absl_base absl_bind_front absl_flat_hash_map absl_inlined_vector absl_memory absl_optional absl_random_random absl_status absl_statusor absl_str_format absl_strings absl_synchronization absl_time"
"-lgrpc++"
""
"grpc++.pc")
@ -15854,7 +15879,7 @@ generate_pkgconfig(
"gRPC++ unsecure"
"C++ wrapper for gRPC without SSL"
"${gRPC_CPP_VERSION}"
"grpc_unsecure absl_base absl_flat_hash_map absl_inlined_vector absl_memory absl_optional absl_status absl_statusor absl_str_format absl_strings absl_synchronization absl_time"
"grpc_unsecure absl_base absl_flat_hash_map absl_inlined_vector absl_memory absl_optional absl_random_random absl_status absl_statusor absl_str_format absl_strings absl_synchronization absl_time"
"-lgrpc++_unsecure"
""
"grpc++_unsecure.pc")

@ -418,7 +418,7 @@ LDFLAGS += -pthread
endif
ifeq ($(SYSTEM),MINGW32)
LIBS = m pthread ws2_32 dbghelp
LIBS = m pthread ws2_32 dbghelp bcrypt
LDFLAGS += -pthread
endif
@ -2588,6 +2588,17 @@ LIBGRPC_ABSEIL_SRC = \
third_party/abseil-cpp/absl/hash/internal/hash.cc \
third_party/abseil-cpp/absl/hash/internal/wyhash.cc \
third_party/abseil-cpp/absl/numeric/int128.cc \
third_party/abseil-cpp/absl/random/discrete_distribution.cc \
third_party/abseil-cpp/absl/random/gaussian_distribution.cc \
third_party/abseil-cpp/absl/random/internal/pool_urbg.cc \
third_party/abseil-cpp/absl/random/internal/randen.cc \
third_party/abseil-cpp/absl/random/internal/randen_detect.cc \
third_party/abseil-cpp/absl/random/internal/randen_hwaes.cc \
third_party/abseil-cpp/absl/random/internal/randen_round_keys.cc \
third_party/abseil-cpp/absl/random/internal/randen_slow.cc \
third_party/abseil-cpp/absl/random/internal/seed_material.cc \
third_party/abseil-cpp/absl/random/seed_gen_exception.cc \
third_party/abseil-cpp/absl/random/seed_sequences.cc \
third_party/abseil-cpp/absl/status/status.cc \
third_party/abseil-cpp/absl/status/status_payload_printer.cc \
third_party/abseil-cpp/absl/status/statusor.cc \

@ -383,6 +383,7 @@ libs:
deps:
- absl/base:base
- absl/memory:memory
- absl/random:random
- absl/status:status
- absl/strings:str_format
- absl/strings:strings

@ -680,6 +680,17 @@ if test "$PHP_GRPC" != "no"; then
third_party/abseil-cpp/absl/hash/internal/hash.cc \
third_party/abseil-cpp/absl/hash/internal/wyhash.cc \
third_party/abseil-cpp/absl/numeric/int128.cc \
third_party/abseil-cpp/absl/random/discrete_distribution.cc \
third_party/abseil-cpp/absl/random/gaussian_distribution.cc \
third_party/abseil-cpp/absl/random/internal/pool_urbg.cc \
third_party/abseil-cpp/absl/random/internal/randen.cc \
third_party/abseil-cpp/absl/random/internal/randen_detect.cc \
third_party/abseil-cpp/absl/random/internal/randen_hwaes.cc \
third_party/abseil-cpp/absl/random/internal/randen_round_keys.cc \
third_party/abseil-cpp/absl/random/internal/randen_slow.cc \
third_party/abseil-cpp/absl/random/internal/seed_material.cc \
third_party/abseil-cpp/absl/random/seed_gen_exception.cc \
third_party/abseil-cpp/absl/random/seed_sequences.cc \
third_party/abseil-cpp/absl/status/status.cc \
third_party/abseil-cpp/absl/status/status_payload_printer.cc \
third_party/abseil-cpp/absl/status/statusor.cc \
@ -1216,6 +1227,8 @@ if test "$PHP_GRPC" != "no"; then
PHP_ADD_BUILD_DIR($ext_builddir/third_party/abseil-cpp/absl/debugging/internal)
PHP_ADD_BUILD_DIR($ext_builddir/third_party/abseil-cpp/absl/hash/internal)
PHP_ADD_BUILD_DIR($ext_builddir/third_party/abseil-cpp/absl/numeric)
PHP_ADD_BUILD_DIR($ext_builddir/third_party/abseil-cpp/absl/random)
PHP_ADD_BUILD_DIR($ext_builddir/third_party/abseil-cpp/absl/random/internal)
PHP_ADD_BUILD_DIR($ext_builddir/third_party/abseil-cpp/absl/status)
PHP_ADD_BUILD_DIR($ext_builddir/third_party/abseil-cpp/absl/strings)
PHP_ADD_BUILD_DIR($ext_builddir/third_party/abseil-cpp/absl/strings/internal)

@ -646,6 +646,17 @@ if (PHP_GRPC != "no") {
"third_party\\abseil-cpp\\absl\\hash\\internal\\hash.cc " +
"third_party\\abseil-cpp\\absl\\hash\\internal\\wyhash.cc " +
"third_party\\abseil-cpp\\absl\\numeric\\int128.cc " +
"third_party\\abseil-cpp\\absl\\random\\discrete_distribution.cc " +
"third_party\\abseil-cpp\\absl\\random\\gaussian_distribution.cc " +
"third_party\\abseil-cpp\\absl\\random\\internal\\pool_urbg.cc " +
"third_party\\abseil-cpp\\absl\\random\\internal\\randen.cc " +
"third_party\\abseil-cpp\\absl\\random\\internal\\randen_detect.cc " +
"third_party\\abseil-cpp\\absl\\random\\internal\\randen_hwaes.cc " +
"third_party\\abseil-cpp\\absl\\random\\internal\\randen_round_keys.cc " +
"third_party\\abseil-cpp\\absl\\random\\internal\\randen_slow.cc " +
"third_party\\abseil-cpp\\absl\\random\\internal\\seed_material.cc " +
"third_party\\abseil-cpp\\absl\\random\\seed_gen_exception.cc " +
"third_party\\abseil-cpp\\absl\\random\\seed_sequences.cc " +
"third_party\\abseil-cpp\\absl\\status\\status.cc " +
"third_party\\abseil-cpp\\absl\\status\\status_payload_printer.cc " +
"third_party\\abseil-cpp\\absl\\status\\statusor.cc " +
@ -1327,6 +1338,8 @@ if (PHP_GRPC != "no") {
FSO.CreateFolder(base_dir+"\\ext\\grpc\\third_party\\abseil-cpp\\absl\\hash");
FSO.CreateFolder(base_dir+"\\ext\\grpc\\third_party\\abseil-cpp\\absl\\hash\\internal");
FSO.CreateFolder(base_dir+"\\ext\\grpc\\third_party\\abseil-cpp\\absl\\numeric");
FSO.CreateFolder(base_dir+"\\ext\\grpc\\third_party\\abseil-cpp\\absl\\random");
FSO.CreateFolder(base_dir+"\\ext\\grpc\\third_party\\abseil-cpp\\absl\\random\\internal");
FSO.CreateFolder(base_dir+"\\ext\\grpc\\third_party\\abseil-cpp\\absl\\status");
FSO.CreateFolder(base_dir+"\\ext\\grpc\\third_party\\abseil-cpp\\absl\\strings");
FSO.CreateFolder(base_dir+"\\ext\\grpc\\third_party\\abseil-cpp\\absl\\strings\\internal");

@ -193,6 +193,7 @@ Pod::Spec.new do |s|
ss.dependency 'abseil/container/inlined_vector', abseil_version
ss.dependency 'abseil/functional/bind_front', abseil_version
ss.dependency 'abseil/memory/memory', abseil_version
ss.dependency 'abseil/random/random', abseil_version
ss.dependency 'abseil/status/status', abseil_version
ss.dependency 'abseil/status/statusor', abseil_version
ss.dependency 'abseil/strings/str_format', abseil_version

@ -180,6 +180,7 @@ Pod::Spec.new do |s|
ss.dependency 'abseil/container/inlined_vector', abseil_version
ss.dependency 'abseil/functional/bind_front', abseil_version
ss.dependency 'abseil/memory/memory', abseil_version
ss.dependency 'abseil/random/random', abseil_version
ss.dependency 'abseil/status/status', abseil_version
ss.dependency 'abseil/status/statusor', abseil_version
ss.dependency 'abseil/strings/str_format', abseil_version

@ -1270,6 +1270,7 @@ Gem::Specification.new do |s|
s.files += %w( third_party/abseil-cpp/absl/base/internal/errno_saver.h )
s.files += %w( third_party/abseil-cpp/absl/base/internal/exponential_biased.cc )
s.files += %w( third_party/abseil-cpp/absl/base/internal/exponential_biased.h )
s.files += %w( third_party/abseil-cpp/absl/base/internal/fast_type_id.h )
s.files += %w( third_party/abseil-cpp/absl/base/internal/hide_ptr.h )
s.files += %w( third_party/abseil-cpp/absl/base/internal/identity.h )
s.files += %w( third_party/abseil-cpp/absl/base/internal/inline_variable.h )
@ -1371,6 +1372,51 @@ Gem::Specification.new do |s|
s.files += %w( third_party/abseil-cpp/absl/numeric/int128_no_intrinsic.inc )
s.files += %w( third_party/abseil-cpp/absl/numeric/internal/bits.h )
s.files += %w( third_party/abseil-cpp/absl/numeric/internal/representation.h )
s.files += %w( third_party/abseil-cpp/absl/random/bernoulli_distribution.h )
s.files += %w( third_party/abseil-cpp/absl/random/beta_distribution.h )
s.files += %w( third_party/abseil-cpp/absl/random/discrete_distribution.cc )
s.files += %w( third_party/abseil-cpp/absl/random/discrete_distribution.h )
s.files += %w( third_party/abseil-cpp/absl/random/distributions.h )
s.files += %w( third_party/abseil-cpp/absl/random/exponential_distribution.h )
s.files += %w( third_party/abseil-cpp/absl/random/gaussian_distribution.cc )
s.files += %w( third_party/abseil-cpp/absl/random/gaussian_distribution.h )
s.files += %w( third_party/abseil-cpp/absl/random/internal/distribution_caller.h )
s.files += %w( third_party/abseil-cpp/absl/random/internal/fast_uniform_bits.h )
s.files += %w( third_party/abseil-cpp/absl/random/internal/fastmath.h )
s.files += %w( third_party/abseil-cpp/absl/random/internal/generate_real.h )
s.files += %w( third_party/abseil-cpp/absl/random/internal/iostream_state_saver.h )
s.files += %w( third_party/abseil-cpp/absl/random/internal/nonsecure_base.h )
s.files += %w( third_party/abseil-cpp/absl/random/internal/pcg_engine.h )
s.files += %w( third_party/abseil-cpp/absl/random/internal/platform.h )
s.files += %w( third_party/abseil-cpp/absl/random/internal/pool_urbg.cc )
s.files += %w( third_party/abseil-cpp/absl/random/internal/pool_urbg.h )
s.files += %w( third_party/abseil-cpp/absl/random/internal/randen.cc )
s.files += %w( third_party/abseil-cpp/absl/random/internal/randen.h )
s.files += %w( third_party/abseil-cpp/absl/random/internal/randen_detect.cc )
s.files += %w( third_party/abseil-cpp/absl/random/internal/randen_detect.h )
s.files += %w( third_party/abseil-cpp/absl/random/internal/randen_engine.h )
s.files += %w( third_party/abseil-cpp/absl/random/internal/randen_hwaes.cc )
s.files += %w( third_party/abseil-cpp/absl/random/internal/randen_hwaes.h )
s.files += %w( third_party/abseil-cpp/absl/random/internal/randen_round_keys.cc )
s.files += %w( third_party/abseil-cpp/absl/random/internal/randen_slow.cc )
s.files += %w( third_party/abseil-cpp/absl/random/internal/randen_slow.h )
s.files += %w( third_party/abseil-cpp/absl/random/internal/randen_traits.h )
s.files += %w( third_party/abseil-cpp/absl/random/internal/salted_seed_seq.h )
s.files += %w( third_party/abseil-cpp/absl/random/internal/seed_material.cc )
s.files += %w( third_party/abseil-cpp/absl/random/internal/seed_material.h )
s.files += %w( third_party/abseil-cpp/absl/random/internal/traits.h )
s.files += %w( third_party/abseil-cpp/absl/random/internal/uniform_helper.h )
s.files += %w( third_party/abseil-cpp/absl/random/internal/wide_multiply.h )
s.files += %w( third_party/abseil-cpp/absl/random/log_uniform_int_distribution.h )
s.files += %w( third_party/abseil-cpp/absl/random/poisson_distribution.h )
s.files += %w( third_party/abseil-cpp/absl/random/random.h )
s.files += %w( third_party/abseil-cpp/absl/random/seed_gen_exception.cc )
s.files += %w( third_party/abseil-cpp/absl/random/seed_gen_exception.h )
s.files += %w( third_party/abseil-cpp/absl/random/seed_sequences.cc )
s.files += %w( third_party/abseil-cpp/absl/random/seed_sequences.h )
s.files += %w( third_party/abseil-cpp/absl/random/uniform_int_distribution.h )
s.files += %w( third_party/abseil-cpp/absl/random/uniform_real_distribution.h )
s.files += %w( third_party/abseil-cpp/absl/random/zipf_distribution.h )
s.files += %w( third_party/abseil-cpp/absl/status/internal/status_internal.h )
s.files += %w( third_party/abseil-cpp/absl/status/internal/statusor_internal.h )
s.files += %w( third_party/abseil-cpp/absl/status/status.cc )

@ -384,6 +384,7 @@
'dependencies': [
'absl/base:base',
'absl/memory:memory',
'absl/random:random',
'absl/status:status',
'absl/strings:str_format',
'absl/strings:strings',

@ -1272,6 +1272,7 @@
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/base/internal/errno_saver.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/base/internal/exponential_biased.cc" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/base/internal/exponential_biased.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/base/internal/fast_type_id.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/base/internal/hide_ptr.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/base/internal/identity.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/base/internal/inline_variable.h" role="src" />
@ -1373,6 +1374,51 @@
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/numeric/int128_no_intrinsic.inc" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/numeric/internal/bits.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/numeric/internal/representation.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/bernoulli_distribution.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/beta_distribution.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/discrete_distribution.cc" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/discrete_distribution.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/distributions.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/exponential_distribution.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/gaussian_distribution.cc" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/gaussian_distribution.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/internal/distribution_caller.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/internal/fast_uniform_bits.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/internal/fastmath.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/internal/generate_real.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/internal/iostream_state_saver.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/internal/nonsecure_base.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/internal/pcg_engine.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/internal/platform.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/internal/pool_urbg.cc" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/internal/pool_urbg.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/internal/randen.cc" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/internal/randen.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/internal/randen_detect.cc" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/internal/randen_detect.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/internal/randen_engine.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/internal/randen_hwaes.cc" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/internal/randen_hwaes.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/internal/randen_round_keys.cc" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/internal/randen_slow.cc" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/internal/randen_slow.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/internal/randen_traits.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/internal/salted_seed_seq.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/internal/seed_material.cc" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/internal/seed_material.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/internal/traits.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/internal/uniform_helper.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/internal/wide_multiply.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/log_uniform_int_distribution.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/poisson_distribution.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/random.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/seed_gen_exception.cc" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/seed_gen_exception.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/seed_sequences.cc" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/seed_sequences.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/uniform_int_distribution.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/uniform_real_distribution.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/random/zipf_distribution.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/status/internal/status_internal.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/status/internal/statusor_internal.h" role="src" />
<file baseinstalldir="/" name="third_party/abseil-cpp/absl/status/status.cc" role="src" />

@ -311,8 +311,9 @@ if not "win32" in sys.platform:
if "win32" in sys.platform:
EXTENSION_LIBRARIES += (
'advapi32',
'ws2_32',
'bcrypt',
'dbghelp',
'ws2_32',
)
if BUILD_WITH_SYSTEM_OPENSSL:
EXTENSION_LIBRARIES += (

@ -26,31 +26,7 @@
namespace grpc_core {
namespace {
/* Generate a random number between 0 and 1. We roll our own RNG because seeding
* rand() modifies a global variable we have no control over. */
double generate_uniform_random_number(uint32_t* rng_state) {
constexpr uint32_t two_raise_31 = uint32_t(1) << 31;
*rng_state = (1103515245 * *rng_state + 12345) % two_raise_31;
return *rng_state / static_cast<double>(two_raise_31);
}
double generate_uniform_random_number_between(uint32_t* rng_state, double a,
double b) {
if (a == b) return a;
if (a > b) GPR_SWAP(double, a, b); // make sure a < b
const double range = b - a;
return a + generate_uniform_random_number(rng_state) * range;
}
} // namespace
BackOff::BackOff(const Options& options)
: options_(options),
rng_state_(static_cast<uint32_t>(gpr_now(GPR_CLOCK_REALTIME).tv_nsec)) {
Reset();
}
BackOff::BackOff(const Options& options) : options_(options) { Reset(); }
grpc_millis BackOff::NextAttemptTime() {
if (initial_) {
@ -60,9 +36,9 @@ grpc_millis BackOff::NextAttemptTime() {
current_backoff_ = static_cast<grpc_millis>(
std::min(current_backoff_ * options_.multiplier(),
static_cast<double>(options_.max_backoff())));
const double jitter = generate_uniform_random_number_between(
&rng_state_, -options_.jitter() * current_backoff_,
options_.jitter() * current_backoff_);
const double jitter =
absl::Uniform(rand_gen_, -options_.jitter() * current_backoff_,
options_.jitter() * current_backoff_);
const grpc_millis next_timeout =
static_cast<grpc_millis>(current_backoff_ + jitter);
return next_timeout + grpc_core::ExecCtx::Get()->Now();
@ -73,6 +49,4 @@ void BackOff::Reset() {
initial_ = true;
}
void BackOff::SetRandomSeed(uint32_t seed) { rng_state_ = seed; }
} // namespace grpc_core

@ -23,6 +23,8 @@
#include "src/core/lib/iomgr/exec_ctx.h"
#include "absl/random/random.h"
namespace grpc_core {
/// Implementation of the backoff mechanism described in
@ -41,8 +43,6 @@ class BackOff {
/// will be the time of the second attempt (rather than the Nth).
void Reset();
void SetRandomSeed(unsigned int seed);
class Options {
public:
Options& set_initial_backoff(grpc_millis initial_backoff) {
@ -79,7 +79,7 @@ class BackOff {
private:
const Options options_;
uint32_t rng_state_;
absl::BitGen rand_gen_;
bool initial_;
/// current delay before retries
grpc_millis current_backoff_;

@ -645,6 +645,17 @@ CORE_SOURCE_FILES = [
'third_party/abseil-cpp/absl/hash/internal/hash.cc',
'third_party/abseil-cpp/absl/hash/internal/wyhash.cc',
'third_party/abseil-cpp/absl/numeric/int128.cc',
'third_party/abseil-cpp/absl/random/discrete_distribution.cc',
'third_party/abseil-cpp/absl/random/gaussian_distribution.cc',
'third_party/abseil-cpp/absl/random/internal/pool_urbg.cc',
'third_party/abseil-cpp/absl/random/internal/randen.cc',
'third_party/abseil-cpp/absl/random/internal/randen_detect.cc',
'third_party/abseil-cpp/absl/random/internal/randen_hwaes.cc',
'third_party/abseil-cpp/absl/random/internal/randen_round_keys.cc',
'third_party/abseil-cpp/absl/random/internal/randen_slow.cc',
'third_party/abseil-cpp/absl/random/internal/seed_material.cc',
'third_party/abseil-cpp/absl/random/seed_gen_exception.cc',
'third_party/abseil-cpp/absl/random/seed_sequences.cc',
'third_party/abseil-cpp/absl/status/status.cc',
'third_party/abseil-cpp/absl/status/status_payload_printer.cc',
'third_party/abseil-cpp/absl/status/statusor.cc',

@ -284,7 +284,7 @@
endif
ifeq ($(SYSTEM),MINGW32)
LIBS = m pthread ws2_32 dbghelp
LIBS = m pthread ws2_32 dbghelp bcrypt
LDFLAGS += -pthread
endif

@ -138,8 +138,6 @@ TEST(BackOffTest, JitterBackOff) {
.set_max_backoff(max_backoff);
BackOff backoff(options);
backoff.SetRandomSeed(0); // force consistent PRNG
grpc_core::ExecCtx exec_ctx;
grpc_millis next = backoff.NextAttemptTime();
EXPECT_EQ(next - grpc_core::ExecCtx::Get()->Now(), initial_backoff);

Loading…
Cancel
Save