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
6a75adeb
Commit
6a75adeb
authored
Oct 29, 2018
by
zhujiashun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
restore _abstime_ns to _abstime_us
parent
695a35c2
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
47 additions
and
43 deletions
+47
-43
channel.cpp
src/brpc/channel.cpp
+7
-7
controller.cpp
src/brpc/controller.cpp
+6
-6
controller.h
src/brpc/controller.h
+4
-4
controller_private_accessor.h
src/brpc/details/controller_private_accessor.h
+2
-2
parallel_channel.cpp
src/brpc/parallel_channel.cpp
+3
-3
http_rpc_protocol.cpp
src/brpc/policy/http_rpc_protocol.cpp
+14
-10
brpc_grpc_protocol_unittest.cpp
test/brpc_grpc_protocol_unittest.cpp
+10
-10
grpc.proto
test/grpc.proto
+1
-1
No files found.
src/brpc/channel.cpp
View file @
6a75adeb
...
@@ -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_
n
s is for truncating _connect_timeout_ms and resetting
// _abstime_
u
s 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_
n
s
=
-
1
;
cntl
->
_abstime_
u
s
=
-
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_
n
s is for truncating _connect_timeout_ms
// _abstime_
u
s 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_n
s
),
butil
::
microseconds_to_timespec
(
cntl
->
_abstime_u
s
),
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_
n
s
=
-
1
;
cntl
->
_abstime_
u
s
=
-
1
;
}
}
cntl
->
IssueRPC
(
start_send_real_us
);
cntl
->
IssueRPC
(
start_send_real_us
);
...
...
src/brpc/controller.cpp
View file @
6a75adeb
...
@@ -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_
n
s
=
-
1
;
_abstime_
u
s
=
-
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_n
s
),
butil
::
microseconds_to_timespec
(
_abstime_u
s
),
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_
n
s
>=
0
)
{
if
(
_abstime_
u
s
>=
0
)
{
connect_abstime
=
butil
::
nan
oseconds_to_timespec
(
connect_abstime
=
butil
::
micr
oseconds_to_timespec
(
std
::
min
(
_connect_timeout_ms
*
1000
000L
+
start_realtime_us
*
1000L
,
std
::
min
(
_connect_timeout_ms
*
1000
L
+
start_realtime_us
,
_abstime_
n
s
));
_abstime_
u
s
));
}
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
);
...
...
src/brpc/controller.h
View file @
6a75adeb
...
@@ -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
nan
oseconds).
// Get deadline of this RPC (since the Epoch in
micr
oseconds).
// -1 means no deadline.
// -1 means no deadline.
int64_t
deadline_
ns
()
const
{
return
_abstime_n
s
;
}
int64_t
deadline_
us
()
const
{
return
_abstime_u
s
;
}
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
nan
oseconds).
// Deadline of this RPC (since the Epoch in
micr
oseconds).
int64_t
_abstime_
n
s
;
int64_t
_abstime_
u
s
;
// Timer registered to trigger RPC timeout event
// Timer registered to trigger RPC timeout event
bthread_timer_t
_timeout_id
;
bthread_timer_t
_timeout_id
;
...
...
src/brpc/details/controller_private_accessor.h
View file @
6a75adeb
...
@@ -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_n
s
)
{
void
set_deadline_
us
(
int64_t
timeout_u
s
)
{
_cntl
->
_abstime_
ns
=
butil
::
gettimeofday_us
()
*
1000L
+
timeout_n
s
;
_cntl
->
_abstime_
us
=
butil
::
gettimeofday_us
()
+
timeout_u
s
;
}
}
private
:
private
:
...
...
src/brpc/parallel_channel.cpp
View file @
6a75adeb
...
@@ -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_n
s
),
butil
::
microseconds_to_timespec
(
cntl
->
_abstime_u
s
),
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_
n
s
=
-
1
;
cntl
->
_abstime_
u
s
=
-
1
;
}
}
d
->
SaveThreadInfoOfCallsite
();
d
->
SaveThreadInfoOfCallsite
();
CHECK_EQ
(
0
,
bthread_id_unlock
(
cid
));
CHECK_EQ
(
0
,
bthread_id_unlock
(
cid
));
...
...
src/brpc/policy/http_rpc_protocol.cpp
View file @
6a75adeb
...
@@ -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
ConvertGrpcTimeoutTo
N
S
(
int64_t
timeout_value
,
const
char
timeout_unit
)
{
static
int64_t
ConvertGrpcTimeoutTo
M
S
(
int64_t
timeout_value
,
const
char
timeout_unit
)
{
switch
(
timeout_unit
)
{
switch
(
timeout_unit
)
{
case
'H'
:
case
'H'
:
timeout_value
*=
(
3600
*
1000000
000
L
);
timeout_value
*=
(
3600
*
1000000L
);
break
;
break
;
case
'M'
:
case
'M'
:
timeout_value
*=
(
60
*
1000000
000
L
);
timeout_value
*=
(
60
*
1000000L
);
break
;
break
;
case
'S'
:
case
'S'
:
timeout_value
*=
1000000
000
L
;
timeout_value
*=
1000000L
;
break
;
break
;
case
'm'
:
case
'm'
:
timeout_value
*=
1000
000
L
;
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_
n
s
=
int64_t
timeout_value_
m
s
=
ConvertGrpcTimeoutTo
N
S
((
int64_t
)
strtol
(
grpc_timeout
->
data
(),
NULL
,
10
),
timeout_unit
);
ConvertGrpcTimeoutTo
M
S
((
int64_t
)
strtol
(
grpc_timeout
->
data
(),
NULL
,
10
),
timeout_unit
);
if
(
timeout_value_
n
s
>=
0
)
{
if
(
timeout_value_
m
s
>=
0
)
{
accessor
.
set_deadline_
ns
(
timeout_value_n
s
);
accessor
.
set_deadline_
us
(
timeout_value_m
s
);
}
}
}
}
}
}
...
...
test/brpc_grpc_protocol_unittest.cpp
View file @
6a75adeb
...
@@ -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_
n
s
())
{
if
(
req
->
has_timeout_
u
s
())
{
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"
,
"7200000000
000
"
,
"2H"
,
"7200000000"
,
"3M"
,
"180000000
000
"
,
"3M"
,
"180000000"
,
"+1S"
,
"1000000
000
"
,
"+1S"
,
"1000000"
,
"4m"
,
"4000
000
"
,
"4m"
,
"4000"
,
"5u"
,
"5
000
"
,
"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_
n
s
((
int64_t
)(
strtol
(
timeouts
[
i
+
1
],
NULL
,
10
)));
req
.
set_timeout_
u
s
((
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
);
...
...
test/grpc.proto
View file @
6a75adeb
...
@@ -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_
n
s
=
4
;
optional
int64
timeout_
u
s
=
4
;
};
};
message
GrpcResponse
{
message
GrpcResponse
{
...
...
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