Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
a25b1c8d
Commit
a25b1c8d
authored
8 years ago
by
Yuchen Zeng
Browse files
Options
Downloads
Plain Diff
Merge branch 'cares_combiner' into cares_buildin
parents
8a6cba25
64204a6f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/core/ext/resolver/dns/c_ares/dns_resolver_ares.c
+96
-40
96 additions, 40 deletions
src/core/ext/resolver/dns/c_ares/dns_resolver_ares.c
with
96 additions
and
40 deletions
src/core/ext/resolver/dns/c_ares/dns_resolver_ares.c
+
96
−
40
View file @
a25b1c8d
...
...
@@ -44,6 +44,7 @@
#include
"src/core/ext/resolver/dns/c_ares/grpc_ares_ev_driver.h"
#include
"src/core/ext/resolver/dns/c_ares/grpc_ares_wrapper.h"
#include
"src/core/lib/channel/channel_args.h"
#include
"src/core/lib/iomgr/combiner.h"
#include
"src/core/lib/iomgr/resolve_address.h"
#include
"src/core/lib/iomgr/timer.h"
#include
"src/core/lib/support/backoff.h"
...
...
@@ -67,8 +68,14 @@ typedef struct {
/** the event driver to drive the lookups */
grpc_ares_ev_driver
*
ev_driver
;
/** mutex guarding the rest of the state */
gpr_mu
mu
;
/** Closures used by the combiner */
grpc_closure
dns_ares_shutdown_locked
;
grpc_closure
dns_ares_channel_saw_error_locked
;
grpc_closure
dns_ares_on_retry_timer_locked
;
grpc_closure
dns_ares_on_resolved_locked
;
/** Combiner guarding the rest of the state */
grpc_combiner
*
lock
;
/** are we currently resolving? */
bool
resolving
;
/** which version of the result have we published? */
...
...
@@ -109,10 +116,10 @@ static const grpc_resolver_vtable dns_ares_resolver_vtable = {
dns_ares_destroy
,
dns_ares_shutdown
,
dns_ares_channel_saw_error
,
dns_ares_next
};
static
void
dns_ares_shutdown
(
grpc_exec_ctx
*
exec_ctx
,
grpc_resolver
*
resolve
r
)
{
ares_dns_resolver
*
r
=
(
ar
es_dns_resolver
*
)
resolver
;
gpr_mu_lock
(
&
r
->
mu
);
static
void
dns_ares_shutdown
_locked
(
grpc_exec_ctx
*
exec_ctx
,
void
*
arg
,
grpc_error
*
erro
r
)
{
ares_dns_resolver
*
r
=
ar
g
;
GPR_ASSERT
(
error
==
GRPC_ERROR_NONE
);
if
(
r
->
have_retry_timer
)
{
grpc_timer_cancel
(
exec_ctx
,
&
r
->
retry_timer
);
}
...
...
@@ -122,39 +129,60 @@ static void dns_ares_shutdown(grpc_exec_ctx *exec_ctx,
GRPC_ERROR_CREATE
(
"Resolver Shutdown"
),
NULL
);
r
->
next_completion
=
NULL
;
}
gpr_mu_unlock
(
&
r
->
mu
);
GRPC_RESOLVER_UNREF
(
exec_ctx
,
&
r
->
base
,
"dns-ares-shutdown"
);
}
static
void
dns_ares_
channel_saw_error
(
grpc_exec_ctx
*
exec_ctx
,
grpc_resolver
*
resolver
)
{
static
void
dns_ares_
shutdown
(
grpc_exec_ctx
*
exec_ctx
,
grpc_resolver
*
resolver
)
{
ares_dns_resolver
*
r
=
(
ares_dns_resolver
*
)
resolver
;
gpr_mu_lock
(
&
r
->
mu
);
GRPC_RESOLVER_REF
(
&
r
->
base
,
"dns-ares-shutdown"
);
grpc_combiner_execute
(
exec_ctx
,
r
->
lock
,
&
r
->
dns_ares_shutdown_locked
,
GRPC_ERROR_NONE
,
false
);
}
static
void
dns_ares_channel_saw_error_locked
(
grpc_exec_ctx
*
exec_ctx
,
void
*
arg
,
grpc_error
*
error
)
{
GPR_ASSERT
(
error
==
GRPC_ERROR_NONE
);
ares_dns_resolver
*
r
=
arg
;
if
(
!
r
->
resolving
)
{
gpr_backoff_reset
(
&
r
->
backoff_state
);
dns_ares_start_resolving_locked
(
exec_ctx
,
r
);
}
gpr_mu_unlock
(
&
r
->
mu
);
GRPC_RESOLVER_UNREF
(
exec_ctx
,
&
r
->
base
,
"ares-channel-saw-error"
);
}
static
void
dns_ares_on_retry_timer
(
grpc_exec_ctx
*
exec_ctx
,
void
*
arg
,
grpc_error
*
error
)
{
static
void
dns_ares_channel_saw_error
(
grpc_exec_ctx
*
exec_ctx
,
grpc_resolver
*
resolver
)
{
ares_dns_resolver
*
r
=
(
ares_dns_resolver
*
)
resolver
;
GRPC_RESOLVER_REF
(
&
r
->
base
,
"ares-channel-saw-error"
);
grpc_combiner_execute
(
exec_ctx
,
r
->
lock
,
&
r
->
dns_ares_channel_saw_error_locked
,
GRPC_ERROR_NONE
,
false
);
}
static
void
dns_ares_on_retry_timer_locked
(
grpc_exec_ctx
*
exec_ctx
,
void
*
arg
,
grpc_error
*
error
)
{
ares_dns_resolver
*
r
=
arg
;
gpr_mu_lock
(
&
r
->
mu
);
r
->
have_retry_timer
=
false
;
if
(
error
==
GRPC_ERROR_NONE
)
{
if
(
!
r
->
resolving
)
{
dns_ares_start_resolving_locked
(
exec_ctx
,
r
);
}
}
gpr_mu_unlock
(
&
r
->
mu
);
GRPC_RESOLVER_UNREF
(
exec_ctx
,
&
r
->
base
,
"retry-timer"
);
}
static
void
dns_ares_on_resolved
(
grpc_exec_ctx
*
exec_ctx
,
void
*
arg
,
grpc_error
*
error
)
{
static
void
dns_ares_on_retry_timer
(
grpc_exec_ctx
*
exec_ctx
,
void
*
arg
,
grpc_error
*
error
)
{
ares_dns_resolver
*
r
=
arg
;
grpc_combiner_execute
(
exec_ctx
,
r
->
lock
,
&
r
->
dns_ares_on_retry_timer_locked
,
GRPC_ERROR_REF
(
error
),
false
);
}
static
void
dns_ares_on_resolved_locked
(
grpc_exec_ctx
*
exec_ctx
,
void
*
arg
,
grpc_error
*
error
)
{
ares_dns_resolver
*
r
=
arg
;
grpc_channel_args
*
result
=
NULL
;
gpr_mu_lock
(
&
r
->
mu
);
GPR_ASSERT
(
r
->
resolving
);
r
->
resolving
=
false
;
if
(
r
->
addresses
!=
NULL
)
{
...
...
@@ -171,16 +199,16 @@ static void dns_ares_on_resolved(grpc_exec_ctx *exec_ctx, void *arg,
grpc_resolved_addresses_destroy
(
r
->
addresses
);
grpc_lb_addresses_destroy
(
addresses
);
}
else
{
gpr_timespec
now
=
gpr_now
(
GPR_CLOCK_MONOTONIC
);
gpr_timespec
next_try
=
gpr_backoff_step
(
&
r
->
backoff_state
,
now
);
gpr_timespec
timeout
=
gpr_time_sub
(
next_try
,
now
);
const
char
*
msg
=
grpc_error_string
(
error
);
gpr_log
(
GPR_DEBUG
,
"dns resolution failed: %s"
,
msg
);
grpc_error_free_string
(
msg
);
gpr_timespec
now
=
gpr_now
(
GPR_CLOCK_MONOTONIC
);
gpr_timespec
next_try
=
gpr_backoff_step
(
&
r
->
backoff_state
,
now
);
gpr_timespec
timeout
=
gpr_time_sub
(
next_try
,
now
);
GPR_ASSERT
(
!
r
->
have_retry_timer
);
r
->
have_retry_timer
=
true
;
GRPC_RESOLVER_REF
(
&
r
->
base
,
"retry-timer"
);
if
(
gpr_time_cmp
(
timeout
,
gpr_time_0
(
timeout
.
clock_type
))
<=
0
)
{
if
(
gpr_time_cmp
(
timeout
,
gpr_time_0
(
timeout
.
clock_type
))
>
0
)
{
gpr_log
(
GPR_DEBUG
,
"retrying in %"
PRId64
".%09d seconds"
,
timeout
.
tv_sec
,
timeout
.
tv_nsec
);
}
else
{
...
...
@@ -195,33 +223,54 @@ static void dns_ares_on_resolved(grpc_exec_ctx *exec_ctx, void *arg,
r
->
resolved_result
=
result
;
r
->
resolved_version
++
;
dns_ares_maybe_finish_next_locked
(
exec_ctx
,
r
);
gpr_mu_unlock
(
&
r
->
mu
);
GRPC_RESOLVER_UNREF
(
exec_ctx
,
&
r
->
base
,
"dns-resolving"
);
}
static
void
dns_ares_next
(
grpc_exec_ctx
*
exec_ctx
,
grpc_resolver
*
resolver
,
grpc_channel_args
**
target_result
,
grpc_closure
*
on_complete
)
{
ares_dns_resolver
*
r
=
(
ares_dns_resolver
*
)
resolver
;
gpr_mu_lock
(
&
r
->
mu
);
static
void
dns_ares_on_resolved
(
grpc_exec_ctx
*
exec_ctx
,
void
*
arg
,
grpc_error
*
error
)
{
ares_dns_resolver
*
r
=
arg
;
grpc_combiner_execute
(
exec_ctx
,
r
->
lock
,
&
r
->
dns_ares_on_resolved_locked
,
GRPC_ERROR_REF
(
error
),
false
);
}
typedef
struct
dns_ares_next_locked_args
{
grpc_resolver
*
resolver
;
grpc_channel_args
**
target_result
;
grpc_closure
*
on_complete
;
}
dns_ares_next_locked_args
;
static
void
dns_ares_next_locked
(
grpc_exec_ctx
*
exec_ctx
,
void
*
arg
,
grpc_error
*
error
)
{
GPR_ASSERT
(
error
==
GRPC_ERROR_NONE
);
dns_ares_next_locked_args
*
args
=
arg
;
ares_dns_resolver
*
r
=
(
ares_dns_resolver
*
)
args
->
resolver
;
gpr_log
(
GPR_DEBUG
,
"dns_ares_next is called."
);
GPR_ASSERT
(
!
r
->
next_completion
);
r
->
next_completion
=
on_complete
;
r
->
target_result
=
target_result
;
r
->
next_completion
=
args
->
on_complete
;
r
->
target_result
=
args
->
target_result
;
gpr_free
(
arg
);
if
(
r
->
resolved_version
==
0
&&
!
r
->
resolving
)
{
gpr_backoff_reset
(
&
r
->
backoff_state
);
dns_ares_start_resolving_locked
(
exec_ctx
,
r
);
// GRPC_RESOLVER_REF(&r->base, "dns-resolving");
// GPR_ASSERT(!r->resolving);
// r->resolving = true;
// r->addresses = NULL;
// grpc_resolve_address_ares(
// exec_ctx, r->name_to_resolve, r->default_port, r->ev_driver,
// grpc_closure_create(dns_ares_on_resolved, r), &r->addresses);
}
else
{
dns_ares_maybe_finish_next_locked
(
exec_ctx
,
r
);
}
gpr_mu_unlock
(
&
r
->
mu
);
GRPC_RESOLVER_UNREF
(
exec_ctx
,
&
r
->
base
,
"ares-next"
);
}
static
void
dns_ares_next
(
grpc_exec_ctx
*
exec_ctx
,
grpc_resolver
*
resolver
,
grpc_channel_args
**
target_result
,
grpc_closure
*
on_complete
)
{
ares_dns_resolver
*
r
=
(
ares_dns_resolver
*
)
resolver
;
dns_ares_next_locked_args
*
args
=
gpr_malloc
(
sizeof
(
dns_ares_next_locked_args
));
args
->
target_result
=
target_result
;
args
->
on_complete
=
on_complete
;
args
->
resolver
=
resolver
;
GRPC_RESOLVER_REF
(
resolver
,
"ares-next"
);
grpc_combiner_execute
(
exec_ctx
,
r
->
lock
,
grpc_closure_create
(
dns_ares_next_locked
,
args
),
GRPC_ERROR_NONE
,
false
);
}
static
void
dns_ares_start_resolving_locked
(
grpc_exec_ctx
*
exec_ctx
,
...
...
@@ -252,7 +301,7 @@ static void dns_ares_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *gr) {
gpr_log
(
GPR_DEBUG
,
"dns_ares_destroy"
);
ares_dns_resolver
*
r
=
(
ares_dns_resolver
*
)
gr
;
grpc_ares_ev_driver_destroy
(
exec_ctx
,
r
->
ev_driver
);
g
pr_mu_destroy
(
&
r
->
mu
);
g
rpc_combiner_destroy
(
exec_ctx
,
r
->
lock
);
grpc_ares_cleanup
();
if
(
r
->
resolved_result
!=
NULL
)
{
grpc_channel_args_destroy
(
r
->
resolved_result
);
...
...
@@ -296,7 +345,7 @@ static grpc_resolver *dns_ares_create(grpc_resolver_args *args,
gpr_free
(
r
);
return
NULL
;
}
gpr_mu_init
(
&
r
->
mu
);
r
->
lock
=
grpc_combiner_create
(
NULL
);
r
->
name_to_resolve
=
proxy_name
==
NULL
?
gpr_strdup
(
path
)
:
proxy_name
;
r
->
default_port
=
gpr_strdup
(
default_port
);
grpc_arg
server_name_arg
;
...
...
@@ -307,6 +356,13 @@ static grpc_resolver *dns_ares_create(grpc_resolver_args *args,
grpc_channel_args_copy_and_add
(
args
->
args
,
&
server_name_arg
,
1
);
gpr_backoff_init
(
&
r
->
backoff_state
,
BACKOFF_MULTIPLIER
,
BACKOFF_JITTER
,
BACKOFF_MIN_SECONDS
*
1000
,
BACKOFF_MAX_SECONDS
*
1000
);
grpc_closure_init
(
&
r
->
dns_ares_shutdown_locked
,
dns_ares_shutdown_locked
,
r
);
grpc_closure_init
(
&
r
->
dns_ares_channel_saw_error_locked
,
dns_ares_channel_saw_error_locked
,
r
);
grpc_closure_init
(
&
r
->
dns_ares_on_retry_timer_locked
,
dns_ares_on_retry_timer_locked
,
r
);
grpc_closure_init
(
&
r
->
dns_ares_on_resolved_locked
,
dns_ares_on_resolved_locked
,
r
);
return
&
r
->
base
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment