Commit 387d034b authored by zhujiashun's avatar zhujiashun

health_check_using_rpc: use HealthCheckChannel instead of Channel to hc

parent cfbe1e5c
......@@ -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) {
......
......@@ -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;
......
......@@ -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;
HealthCheckChannel channel;
if (channel.Init(_id, &options) != 0) {
ptr->SetFailed();
++ ptr->_hc_count;
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment