Merge pull request #16575 from AspirinSJL/fix_sc_cmp

Fix subchannel key comparison if forcing creation
pull/16593/head
Juanli Shen 6 years ago committed by GitHub
commit 23a24f5961
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      src/core/ext/filters/client_channel/subchannel_index.cc
  2. 5
      src/core/ext/filters/client_channel/subchannel_index.h

@ -42,7 +42,7 @@ struct grpc_subchannel_key {
grpc_subchannel_args args; grpc_subchannel_args args;
}; };
static bool g_force_creation = false; static gpr_atm g_force_creation = false;
static grpc_subchannel_key* create_key( static grpc_subchannel_key* create_key(
const grpc_subchannel_args* args, const grpc_subchannel_args* args,
@ -73,7 +73,8 @@ static grpc_subchannel_key* subchannel_key_copy(grpc_subchannel_key* k) {
int grpc_subchannel_key_compare(const grpc_subchannel_key* a, int grpc_subchannel_key_compare(const grpc_subchannel_key* a,
const grpc_subchannel_key* b) { const grpc_subchannel_key* b) {
if (g_force_creation) return false; // To pretend the keys are different, return a non-zero value.
if (GPR_UNLIKELY(gpr_atm_no_barrier_load(&g_force_creation))) return 1;
int c = GPR_ICMP(a->args.filter_count, b->args.filter_count); int c = GPR_ICMP(a->args.filter_count, b->args.filter_count);
if (c != 0) return c; if (c != 0) return c;
if (a->args.filter_count > 0) { if (a->args.filter_count > 0) {
@ -250,5 +251,5 @@ void grpc_subchannel_index_unregister(grpc_subchannel_key* key,
} }
void grpc_subchannel_index_test_only_set_force_creation(bool force_creation) { void grpc_subchannel_index_test_only_set_force_creation(bool force_creation) {
g_force_creation = force_creation; gpr_atm_no_barrier_store(&g_force_creation, force_creation);
} }

@ -65,13 +65,10 @@ void grpc_subchannel_index_ref(void);
void grpc_subchannel_index_unref(void); void grpc_subchannel_index_unref(void);
/** \em TEST ONLY. /** \em TEST ONLY.
* If \a force_creation is true, all key comparisons will be false, resulting in * If \a force_creation is true, all keys are regarded different, resulting in
* new subchannels always being created. Otherwise, the keys will be compared as * new subchannels always being created. Otherwise, the keys will be compared as
* usual. * usual.
* *
* This function is *not* threadsafe on purpose: it should *only* be used in
* test code.
*
* Tests using this function \em MUST run tests with and without \a * Tests using this function \em MUST run tests with and without \a
* force_creation set. */ * force_creation set. */
void grpc_subchannel_index_test_only_set_force_creation(bool force_creation); void grpc_subchannel_index_test_only_set_force_creation(bool force_creation);

Loading…
Cancel
Save