Commit d35d8210 authored by zhujiashun's avatar zhujiashun

Check emptiness of grpc_timeout && change the name of _abstime_us to _deadline_us

parent 6a75adeb
......@@ -493,12 +493,12 @@ void Channel::CallMethod(const google::protobuf::MethodDescriptor* method,
// Setup timer for backup request. When it occurs, we'll setup a
// timer of timeout_ms before sending backup request.
// _abstime_us is for truncating _connect_timeout_ms and resetting
// _deadline_us is for truncating _connect_timeout_ms and resetting
// timer when EBACKUPREQUEST occurs.
if (cntl->timeout_ms() < 0) {
cntl->_abstime_us = -1;
cntl->_deadline_us = -1;
} else {
cntl->_abstime_us = cntl->timeout_ms() * 1000L + start_send_real_us;
cntl->_deadline_us = cntl->timeout_ms() * 1000L + start_send_real_us;
}
const int rc = bthread_timer_add(
&cntl->_timeout_id,
......@@ -512,18 +512,18 @@ void Channel::CallMethod(const google::protobuf::MethodDescriptor* method,
} else if (cntl->timeout_ms() >= 0) {
// Setup timer for RPC timetout
// _abstime_us is for truncating _connect_timeout_ms
cntl->_abstime_us = cntl->timeout_ms() * 1000L + start_send_real_us;
// _deadline_us is for truncating _connect_timeout_ms
cntl->_deadline_us = cntl->timeout_ms() * 1000L + start_send_real_us;
const int rc = bthread_timer_add(
&cntl->_timeout_id,
butil::microseconds_to_timespec(cntl->_abstime_us),
butil::microseconds_to_timespec(cntl->_deadline_us),
HandleTimeout, (void*)correlation_id.value);
if (BAIDU_UNLIKELY(rc != 0)) {
cntl->SetFailed(rc, "Fail to add timer for timeout");
return cntl->HandleSendFailed();
}
} else {
cntl->_abstime_us = -1;
cntl->_deadline_us = -1;
}
cntl->IssueRPC(start_send_real_us);
......
......@@ -222,7 +222,7 @@ void Controller::ResetPods() {
_timeout_ms = UNSET_MAGIC_NUM;
_backup_request_ms = UNSET_MAGIC_NUM;
_connect_timeout_ms = UNSET_MAGIC_NUM;
_abstime_us = -1;
_deadline_us = -1;
_timeout_id = 0;
_begin_time_us = 0;
_end_time_us = 0;
......@@ -568,7 +568,7 @@ void Controller::OnVersionedRPCReturned(const CompletionInfo& info,
if (timeout_ms() >= 0) {
rc = bthread_timer_add(
&_timeout_id,
butil::microseconds_to_timespec(_abstime_us),
butil::microseconds_to_timespec(_deadline_us),
HandleTimeout, (void*)_correlation_id.value);
}
if (rc != 0) {
......@@ -1111,10 +1111,10 @@ void Controller::IssueRPC(int64_t start_realtime_us) {
timespec connect_abstime;
timespec* pabstime = NULL;
if (_connect_timeout_ms > 0) {
if (_abstime_us >= 0) {
if (_deadline_us >= 0) {
connect_abstime = butil::microseconds_to_timespec(
std::min(_connect_timeout_ms * 1000L + start_realtime_us,
_abstime_us));
_deadline_us));
} else {
connect_abstime = butil::microseconds_to_timespec(
_connect_timeout_ms * 1000L + start_realtime_us);
......
......@@ -482,7 +482,7 @@ public:
// Get deadline of this RPC (since the Epoch in microseconds).
// -1 means no deadline.
int64_t deadline_us() const { return _abstime_us; }
int64_t deadline_us() const { return _deadline_us; }
private:
struct CompletionInfo {
......@@ -667,7 +667,7 @@ private:
int32_t _connect_timeout_ms;
int32_t _backup_request_ms;
// Deadline of this RPC (since the Epoch in microseconds).
int64_t _abstime_us;
int64_t _deadline_us;
// Timer registered to trigger RPC timeout event
bthread_timer_t _timeout_id;
......
......@@ -128,9 +128,7 @@ public:
std::string& protocol_param() { return _cntl->protocol_param(); }
const std::string& protocol_param() const { return _cntl->protocol_param(); }
void set_deadline_us(int64_t timeout_us) {
_cntl->_abstime_us = butil::gettimeofday_us() + timeout_us;
}
void set_deadline_us(int64_t deadline_us) { _cntl->_deadline_us = deadline_us; }
private:
Controller* _cntl;
......
......@@ -658,18 +658,18 @@ void ParallelChannel::CallMethod(
cntl->set_timeout_ms(_options.timeout_ms);
}
if (cntl->timeout_ms() >= 0) {
cntl->_abstime_us = cntl->timeout_ms() * 1000L + cntl->_begin_time_us;
cntl->_deadline_us = cntl->timeout_ms() * 1000L + cntl->_begin_time_us;
// Setup timer for RPC timetout
const int rc = bthread_timer_add(
&cntl->_timeout_id,
butil::microseconds_to_timespec(cntl->_abstime_us),
butil::microseconds_to_timespec(cntl->_deadline_us),
HandleTimeout, (void*)cid.value);
if (rc != 0) {
cntl->SetFailed(rc, "Fail to add timer");
goto FAIL;
}
} else {
cntl->_abstime_us = -1;
cntl->_deadline_us = -1;
}
d->SaveThreadInfoOfCallsite();
CHECK_EQ(0, bthread_id_unlock(cid));
......
......@@ -1449,12 +1449,14 @@ void ProcessHttpRequest(InputMessageBase *msg) {
}
}
const std::string* grpc_timeout = req_header.GetHeader(common->GRPC_TIMEOUT);
if (grpc_timeout) {
if (grpc_timeout && !grpc_timeout->empty()) {
const char timeout_unit = grpc_timeout->back();
// If no digits were found, strtol returns zero as timeout value
int64_t timeout_value_ms =
ConvertGrpcTimeoutToMS((int64_t)strtol(grpc_timeout->data(), NULL, 10), timeout_unit);
if (timeout_value_ms >= 0) {
accessor.set_deadline_us(timeout_value_ms);
accessor.set_deadline_us(
butil::gettimeofday_us() + timeout_value_ms);
}
}
}
......
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