Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
413db42c
Commit
413db42c
authored
Mar 27, 2019
by
zhujiashun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
health_check_using_rpc: wrap to StartHealthCheckWithDelayMS
parent
6cb01912
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
14 deletions
+15
-14
health_check.cpp
src/brpc/details/health_check.cpp
+11
-9
health_check.h
src/brpc/details/health_check.h
+2
-1
socket.cpp
src/brpc/socket.cpp
+2
-4
No files found.
src/brpc/details/health_check.cpp
View file @
413db42c
...
...
@@ -27,6 +27,9 @@
namespace
brpc
{
// declared at socket.cpp
extern
SocketVarsCollector
*
g_vars
;
DEFINE_string
(
health_check_path
,
""
,
"Http path of health check call."
"By default health check succeeds if the server is connectable."
"If this flag is set, health check is not completed until a http "
...
...
@@ -154,20 +157,18 @@ void OnAppHealthCheckDone::Run() {
class
HealthCheckTask
:
public
PeriodicTask
{
public
:
explicit
HealthCheckTask
(
SocketId
id
,
SocketVarsCollector
*
nhealthcheck
);
explicit
HealthCheckTask
(
SocketId
id
);
bool
OnTriggeringTask
(
timespec
*
next_abstime
)
override
;
void
OnDestroyingTask
()
override
;
private
:
SocketId
_id
;
bool
_first_time
;
SocketVarsCollector
*
_collector
;
};
HealthCheckTask
::
HealthCheckTask
(
SocketId
id
,
SocketVarsCollector
*
collector
)
HealthCheckTask
::
HealthCheckTask
(
SocketId
id
)
:
_id
(
id
)
,
_first_time
(
true
)
,
_collector
(
collector
)
{}
,
_first_time
(
true
)
{}
bool
HealthCheckTask
::
OnTriggeringTask
(
timespec
*
next_abstime
)
{
SocketUniquePtr
ptr
;
...
...
@@ -203,7 +204,7 @@ bool HealthCheckTask::OnTriggeringTask(timespec* next_abstime) {
}
}
_collector
->
nhealthcheck
<<
1
;
g_vars
->
nhealthcheck
<<
1
;
int
hc
=
0
;
if
(
ptr
->
_user
)
{
hc
=
ptr
->
_user
->
CheckHealth
(
ptr
.
get
());
...
...
@@ -212,7 +213,7 @@ bool HealthCheckTask::OnTriggeringTask(timespec* next_abstime) {
}
if
(
hc
==
0
)
{
if
(
ptr
->
CreatedByConnect
())
{
_collector
->
channel_conn
<<
-
1
;
g_vars
->
channel_conn
<<
-
1
;
}
if
(
!
FLAGS_health_check_path
.
empty
())
{
ptr
->
_ninflight_app_health_check
.
fetch_add
(
...
...
@@ -237,8 +238,9 @@ void HealthCheckTask::OnDestroyingTask() {
delete
this
;
}
PeriodicTask
*
NewHealthCheckTask
(
SocketId
id
,
SocketVarsCollector
*
collector
)
{
return
new
HealthCheckTask
(
id
,
collector
);
void
StartHealthCheckWithDelayMS
(
SocketId
id
,
int64_t
delay_ms
)
{
PeriodicTaskManager
::
StartTaskAt
(
new
HealthCheckTask
(
id
),
butil
::
milliseconds_from_now
(
delay_ms
));
}
}
// namespace brpc
src/brpc/details/health_check.h
View file @
413db42c
...
...
@@ -25,7 +25,8 @@
namespace
brpc
{
PeriodicTask
*
NewHealthCheckTask
(
SocketId
id
,
SocketVarsCollector
*
collector
);
// Start health check for socket id after delay_ms.
void
StartHealthCheckWithDelayMS
(
SocketId
id
,
int64_t
delay_ms
);
}
// namespace brpc
...
...
src/brpc/socket.cpp
View file @
413db42c
...
...
@@ -837,10 +837,8 @@ int Socket::SetFailed(int error_code, const char* error_fmt, ...) {
// comes online.
if
(
_health_check_interval_s
>
0
)
{
GetOrNewSharedPart
()
->
circuit_breaker
.
MarkAsBroken
();
PeriodicTaskManager
::
StartTaskAt
(
NewHealthCheckTask
(
id
(),
g_vars
),
butil
::
milliseconds_from_now
(
GetOrNewSharedPart
()
->
circuit_breaker
.
isolation_duration_ms
()));
StartHealthCheckWithDelayMS
(
id
(),
GetOrNewSharedPart
()
->
circuit_breaker
.
isolation_duration_ms
());
}
// Wake up all threads waiting on EPOLLOUT when closing fd
_epollout_butex
->
fetch_add
(
1
,
butil
::
memory_order_relaxed
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment