Commit 6a75adeb authored by zhujiashun's avatar zhujiashun

restore _abstime_ns to _abstime_us

parent 695a35c2
...@@ -493,12 +493,12 @@ void Channel::CallMethod(const google::protobuf::MethodDescriptor* method, ...@@ -493,12 +493,12 @@ void Channel::CallMethod(const google::protobuf::MethodDescriptor* method,
// Setup timer for backup request. When it occurs, we'll setup a // Setup timer for backup request. When it occurs, we'll setup a
// timer of timeout_ms before sending backup request. // timer of timeout_ms before sending backup request.
// _abstime_ns is for truncating _connect_timeout_ms and resetting // _abstime_us is for truncating _connect_timeout_ms and resetting
// timer when EBACKUPREQUEST occurs. // timer when EBACKUPREQUEST occurs.
if (cntl->timeout_ms() < 0) { if (cntl->timeout_ms() < 0) {
cntl->_abstime_ns = -1; cntl->_abstime_us = -1;
} else { } else {
cntl->_abstime_ns = cntl->timeout_ms() * 1000000L + start_send_real_us * 1000L; cntl->_abstime_us = cntl->timeout_ms() * 1000L + start_send_real_us;
} }
const int rc = bthread_timer_add( const int rc = bthread_timer_add(
&cntl->_timeout_id, &cntl->_timeout_id,
...@@ -512,18 +512,18 @@ void Channel::CallMethod(const google::protobuf::MethodDescriptor* method, ...@@ -512,18 +512,18 @@ void Channel::CallMethod(const google::protobuf::MethodDescriptor* method,
} else if (cntl->timeout_ms() >= 0) { } else if (cntl->timeout_ms() >= 0) {
// Setup timer for RPC timetout // Setup timer for RPC timetout
// _abstime_ns is for truncating _connect_timeout_ms // _abstime_us is for truncating _connect_timeout_ms
cntl->_abstime_ns = cntl->timeout_ms() * 1000000L + start_send_real_us * 1000L; cntl->_abstime_us = cntl->timeout_ms() * 1000L + start_send_real_us;
const int rc = bthread_timer_add( const int rc = bthread_timer_add(
&cntl->_timeout_id, &cntl->_timeout_id,
butil::nanoseconds_to_timespec(cntl->_abstime_ns), butil::microseconds_to_timespec(cntl->_abstime_us),
HandleTimeout, (void*)correlation_id.value); HandleTimeout, (void*)correlation_id.value);
if (BAIDU_UNLIKELY(rc != 0)) { if (BAIDU_UNLIKELY(rc != 0)) {
cntl->SetFailed(rc, "Fail to add timer for timeout"); cntl->SetFailed(rc, "Fail to add timer for timeout");
return cntl->HandleSendFailed(); return cntl->HandleSendFailed();
} }
} else { } else {
cntl->_abstime_ns = -1; cntl->_abstime_us = -1;
} }
cntl->IssueRPC(start_send_real_us); cntl->IssueRPC(start_send_real_us);
......
...@@ -222,7 +222,7 @@ void Controller::ResetPods() { ...@@ -222,7 +222,7 @@ void Controller::ResetPods() {
_timeout_ms = UNSET_MAGIC_NUM; _timeout_ms = UNSET_MAGIC_NUM;
_backup_request_ms = UNSET_MAGIC_NUM; _backup_request_ms = UNSET_MAGIC_NUM;
_connect_timeout_ms = UNSET_MAGIC_NUM; _connect_timeout_ms = UNSET_MAGIC_NUM;
_abstime_ns = -1; _abstime_us = -1;
_timeout_id = 0; _timeout_id = 0;
_begin_time_us = 0; _begin_time_us = 0;
_end_time_us = 0; _end_time_us = 0;
...@@ -568,7 +568,7 @@ void Controller::OnVersionedRPCReturned(const CompletionInfo& info, ...@@ -568,7 +568,7 @@ void Controller::OnVersionedRPCReturned(const CompletionInfo& info,
if (timeout_ms() >= 0) { if (timeout_ms() >= 0) {
rc = bthread_timer_add( rc = bthread_timer_add(
&_timeout_id, &_timeout_id,
butil::nanoseconds_to_timespec(_abstime_ns), butil::microseconds_to_timespec(_abstime_us),
HandleTimeout, (void*)_correlation_id.value); HandleTimeout, (void*)_correlation_id.value);
} }
if (rc != 0) { if (rc != 0) {
...@@ -1111,10 +1111,10 @@ void Controller::IssueRPC(int64_t start_realtime_us) { ...@@ -1111,10 +1111,10 @@ void Controller::IssueRPC(int64_t start_realtime_us) {
timespec connect_abstime; timespec connect_abstime;
timespec* pabstime = NULL; timespec* pabstime = NULL;
if (_connect_timeout_ms > 0) { if (_connect_timeout_ms > 0) {
if (_abstime_ns >= 0) { if (_abstime_us >= 0) {
connect_abstime = butil::nanoseconds_to_timespec( connect_abstime = butil::microseconds_to_timespec(
std::min(_connect_timeout_ms * 1000000L + start_realtime_us * 1000L, std::min(_connect_timeout_ms * 1000L + start_realtime_us,
_abstime_ns)); _abstime_us));
} else { } else {
connect_abstime = butil::microseconds_to_timespec( connect_abstime = butil::microseconds_to_timespec(
_connect_timeout_ms * 1000L + start_realtime_us); _connect_timeout_ms * 1000L + start_realtime_us);
......
...@@ -480,9 +480,9 @@ public: ...@@ -480,9 +480,9 @@ public:
// Get sock option. .e.g get vip info through ttm kernel module hook, // Get sock option. .e.g get vip info through ttm kernel module hook,
int GetSockOption(int level, int optname, void* optval, socklen_t* optlen); int GetSockOption(int level, int optname, void* optval, socklen_t* optlen);
// Get deadline of this RPC (since the Epoch in nanoseconds). // Get deadline of this RPC (since the Epoch in microseconds).
// -1 means no deadline. // -1 means no deadline.
int64_t deadline_ns() const { return _abstime_ns; } int64_t deadline_us() const { return _abstime_us; }
private: private:
struct CompletionInfo { struct CompletionInfo {
...@@ -666,8 +666,8 @@ private: ...@@ -666,8 +666,8 @@ private:
int32_t _timeout_ms; int32_t _timeout_ms;
int32_t _connect_timeout_ms; int32_t _connect_timeout_ms;
int32_t _backup_request_ms; int32_t _backup_request_ms;
// Deadline of this RPC (since the Epoch in nanoseconds). // Deadline of this RPC (since the Epoch in microseconds).
int64_t _abstime_ns; int64_t _abstime_us;
// Timer registered to trigger RPC timeout event // Timer registered to trigger RPC timeout event
bthread_timer_t _timeout_id; bthread_timer_t _timeout_id;
......
...@@ -128,8 +128,8 @@ public: ...@@ -128,8 +128,8 @@ public:
std::string& protocol_param() { return _cntl->protocol_param(); } std::string& protocol_param() { return _cntl->protocol_param(); }
const std::string& protocol_param() const { return _cntl->protocol_param(); } const std::string& protocol_param() const { return _cntl->protocol_param(); }
void set_deadline_ns(int64_t timeout_ns) { void set_deadline_us(int64_t timeout_us) {
_cntl->_abstime_ns = butil::gettimeofday_us() * 1000L + timeout_ns; _cntl->_abstime_us = butil::gettimeofday_us() + timeout_us;
} }
private: private:
......
...@@ -658,18 +658,18 @@ void ParallelChannel::CallMethod( ...@@ -658,18 +658,18 @@ void ParallelChannel::CallMethod(
cntl->set_timeout_ms(_options.timeout_ms); cntl->set_timeout_ms(_options.timeout_ms);
} }
if (cntl->timeout_ms() >= 0) { if (cntl->timeout_ms() >= 0) {
cntl->_abstime_ns = cntl->timeout_ms() * 1000000L + cntl->_begin_time_us * 1000L; cntl->_abstime_us = cntl->timeout_ms() * 1000L + cntl->_begin_time_us;
// Setup timer for RPC timetout // Setup timer for RPC timetout
const int rc = bthread_timer_add( const int rc = bthread_timer_add(
&cntl->_timeout_id, &cntl->_timeout_id,
butil::nanoseconds_to_timespec(cntl->_abstime_ns), butil::microseconds_to_timespec(cntl->_abstime_us),
HandleTimeout, (void*)cid.value); HandleTimeout, (void*)cid.value);
if (rc != 0) { if (rc != 0) {
cntl->SetFailed(rc, "Fail to add timer"); cntl->SetFailed(rc, "Fail to add timer");
goto FAIL; goto FAIL;
} }
} else { } else {
cntl->_abstime_ns = -1; cntl->_abstime_us = -1;
} }
d->SaveThreadInfoOfCallsite(); d->SaveThreadInfoOfCallsite();
CHECK_EQ(0, bthread_id_unlock(cid)); CHECK_EQ(0, bthread_id_unlock(cid));
......
...@@ -1191,23 +1191,27 @@ void EndRunningCallMethodInPool( ...@@ -1191,23 +1191,27 @@ void EndRunningCallMethodInPool(
::google::protobuf::Message* response, ::google::protobuf::Message* response,
::google::protobuf::Closure* done); ::google::protobuf::Closure* done);
static int64_t ConvertGrpcTimeoutToNS(int64_t timeout_value, const char timeout_unit) { static int64_t ConvertGrpcTimeoutToMS(int64_t timeout_value, const char timeout_unit) {
switch (timeout_unit) { switch (timeout_unit) {
case 'H': case 'H':
timeout_value *= (3600 * 1000000000L); timeout_value *= (3600 * 1000000L);
break; break;
case 'M': case 'M':
timeout_value *= (60 * 1000000000L); timeout_value *= (60 * 1000000L);
break; break;
case 'S': case 'S':
timeout_value *= 1000000000L; timeout_value *= 1000000L;
break; break;
case 'm': case 'm':
timeout_value *= 1000000L; timeout_value *= 1000L;
break; break;
case 'u': case 'u':
timeout_value *= 1000L; break;
case 'n': case 'n':
timeout_value = (timeout_value + 500) / 1000;
if (timeout_value == 0) {
timeout_value = 1;
}
break; break;
default: default:
return -1; return -1;
...@@ -1447,10 +1451,10 @@ void ProcessHttpRequest(InputMessageBase *msg) { ...@@ -1447,10 +1451,10 @@ void ProcessHttpRequest(InputMessageBase *msg) {
const std::string* grpc_timeout = req_header.GetHeader(common->GRPC_TIMEOUT); const std::string* grpc_timeout = req_header.GetHeader(common->GRPC_TIMEOUT);
if (grpc_timeout) { if (grpc_timeout) {
const char timeout_unit = grpc_timeout->back(); const char timeout_unit = grpc_timeout->back();
int64_t timeout_value_ns = int64_t timeout_value_ms =
ConvertGrpcTimeoutToNS((int64_t)strtol(grpc_timeout->data(), NULL, 10), timeout_unit); ConvertGrpcTimeoutToMS((int64_t)strtol(grpc_timeout->data(), NULL, 10), timeout_unit);
if (timeout_value_ns >= 0) { if (timeout_value_ms >= 0) {
accessor.set_deadline_ns(timeout_value_ns); accessor.set_deadline_us(timeout_value_ms);
} }
} }
} }
......
...@@ -65,9 +65,9 @@ public: ...@@ -65,9 +65,9 @@ public:
cntl->SetFailed(brpc::EINTERNAL, "%s", g_prefix.c_str()); cntl->SetFailed(brpc::EINTERNAL, "%s", g_prefix.c_str());
return; return;
} }
if (req->has_timeout_ns()) { if (req->has_timeout_us()) {
EXPECT_NEAR(cntl->deadline_ns() / 1000000000L, EXPECT_NEAR(cntl->deadline_us(),
butil::gettimeofday_s() + req->timeout_ns() / 1000000000L, 1); butil::gettimeofday_us() + req->timeout_us(), 30);
} }
} }
...@@ -204,12 +204,12 @@ TEST_F(GrpcTest, MethodNotExist) { ...@@ -204,12 +204,12 @@ TEST_F(GrpcTest, MethodNotExist) {
TEST_F(GrpcTest, GrpcTimeOut) { TEST_F(GrpcTest, GrpcTimeOut) {
const char* timeouts[] = { const char* timeouts[] = {
"2H", "7200000000000", "2H", "7200000000",
"3M", "180000000000", "3M", "180000000",
"+1S", "1000000000", "+1S", "1000000",
"4m", "4000000", "4m", "4000",
"5u", "5000", "5u", "5",
"6n", "6" "6n", "1"
}; };
for (size_t i = 0; i < arraysize(timeouts); i = i + 2) { for (size_t i = 0; i < arraysize(timeouts); i = i + 2) {
...@@ -219,7 +219,7 @@ TEST_F(GrpcTest, GrpcTimeOut) { ...@@ -219,7 +219,7 @@ TEST_F(GrpcTest, GrpcTimeOut) {
req.set_message(g_req); req.set_message(g_req);
req.set_gzip(false); req.set_gzip(false);
req.set_return_error(false); req.set_return_error(false);
req.set_timeout_ns((int64_t)(strtol(timeouts[i+1], NULL, 10))); req.set_timeout_us((int64_t)(strtol(timeouts[i+1], NULL, 10)));
cntl.http_request().SetHeader("grpc-timeout", timeouts[i]); cntl.http_request().SetHeader("grpc-timeout", timeouts[i]);
test::GrpcService_Stub stub(&_channel); test::GrpcService_Stub stub(&_channel);
stub.Method(&cntl, &req, &res, NULL); stub.Method(&cntl, &req, &res, NULL);
......
...@@ -7,7 +7,7 @@ message GrpcRequest { ...@@ -7,7 +7,7 @@ message GrpcRequest {
required string message = 1; required string message = 1;
required bool gzip = 2; required bool gzip = 2;
required bool return_error = 3; required bool return_error = 3;
optional int64 timeout_ns = 4; optional int64 timeout_us = 4;
}; };
message GrpcResponse { message GrpcResponse {
......
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