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
387d034b
Commit
387d034b
authored
Mar 22, 2019
by
zhujiashun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
health_check_using_rpc: use HealthCheckChannel instead of Channel to hc
parent
cfbe1e5c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
15 deletions
+20
-15
channel.cpp
src/brpc/channel.cpp
+0
-9
channel.h
src/brpc/channel.h
+0
-4
socket.cpp
src/brpc/socket.cpp
+19
-1
brpc_socket_unittest.cpp
test/brpc_socket_unittest.cpp
+1
-1
No files found.
src/brpc/channel.cpp
View file @
387d034b
...
...
@@ -281,15 +281,6 @@ int Channel::Init(butil::EndPoint server_addr_and_port,
return
InitSingle
(
server_addr_and_port
,
""
,
options
);
}
int
Channel
::
Init
(
SocketId
id
,
const
ChannelOptions
*
options
)
{
GlobalInitializeOrDie
();
if
(
InitChannelOptions
(
options
)
!=
0
)
{
return
-
1
;
}
_server_id
=
id
;
return
0
;
}
int
Channel
::
InitSingle
(
const
butil
::
EndPoint
&
server_addr_and_port
,
const
char
*
raw_server_address
,
const
ChannelOptions
*
options
)
{
...
...
src/brpc/channel.h
View file @
387d034b
...
...
@@ -215,10 +215,6 @@ protected:
const
char
*
raw_server_address
,
const
ChannelOptions
*
options
);
// Init a channel from a known SocketId. Currently it is
// used only by health check using rpc.
int
Init
(
SocketId
id
,
const
ChannelOptions
*
options
);
butil
::
EndPoint
_server_address
;
SocketId
_server_id
;
Protocol
::
SerializeRequest
_serialize_request
;
...
...
src/brpc/socket.cpp
View file @
387d034b
...
...
@@ -50,6 +50,7 @@
#include "brpc/periodic_task.h"
#include "brpc/channel.h"
#include "brpc/controller.h"
#include "brpc/global.h"
#if defined(OS_MACOSX)
#include <sys/event.h>
#endif
...
...
@@ -998,6 +999,23 @@ void HealthCheckTask::OnDestroyingTask() {
delete
this
;
}
class
HealthCheckChannel
:
public
brpc
::
Channel
{
public
:
HealthCheckChannel
()
{}
~
HealthCheckChannel
()
{}
int
Init
(
SocketId
id
,
const
ChannelOptions
*
options
);
};
int
HealthCheckChannel
::
Init
(
SocketId
id
,
const
ChannelOptions
*
options
)
{
brpc
::
GlobalInitializeOrDie
();
if
(
InitChannelOptions
(
options
)
!=
0
)
{
return
-
1
;
}
_server_id
=
id
;
return
0
;
}
bool
HealthCheckTask
::
OnTriggeringTask
(
timespec
*
next_abstime
)
{
SocketUniquePtr
ptr
;
const
int
rc
=
Socket
::
AddressFailedAsWell
(
_id
,
&
ptr
);
...
...
@@ -1050,7 +1068,7 @@ bool HealthCheckTask::OnTriggeringTask(timespec* next_abstime) {
options
.
protocol
=
"http"
;
options
.
max_retry
=
0
;
options
.
timeout_ms
=
FLAGS_health_check_timeout_ms
;
brpc
::
Channel
channel
;
HealthCheck
Channel
channel
;
if
(
channel
.
Init
(
_id
,
&
options
)
!=
0
)
{
ptr
->
SetFailed
();
++
ptr
->
_hc_count
;
...
...
test/brpc_socket_unittest.cpp
View file @
387d034b
...
...
@@ -578,7 +578,7 @@ TEST_F(SocketTest, health_check_using_rpc) {
ASSERT_EQ
(
0
,
server
.
AddService
(
&
hc_service
,
brpc
::
SERVER_DOESNT_OWN_SERVICE
));
ASSERT_EQ
(
0
,
server
.
Start
(
"127.0.0.1:7777"
,
NULL
));
for
(
int
i
=
0
;
i
<
3
;
++
i
)
{
for
(
int
i
=
0
;
i
<
4
;
++
i
)
{
// although ::connect would succeed, the stall in hc_service makes
// the health checking rpc fail.
brpc
::
Controller
cntl
;
...
...
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