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
b1f7ea03
Unverified
Commit
b1f7ea03
authored
Oct 20, 2020
by
jamesge
Committed by
GitHub
Oct 20, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1270 from gydong/master
coding style fix in brpc/trackme.cpp
parents
a4e28d68
123e4440
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
20 deletions
+19
-20
trackme.cpp
src/brpc/trackme.cpp
+19
-19
task_group.cpp
src/bthread/task_group.cpp
+0
-1
No files found.
src/brpc/trackme.cpp
View file @
b1f7ea03
...
...
@@ -43,11 +43,11 @@ static const int32_t TRACKME_MIN_INTERVAL = 30;
static
const
int32_t
TRACKME_MAX_INTERVAL
=
600
;
static
int32_t
s_trackme_interval
=
TRACKME_MIN_INTERVAL
;
// Protecting global vars on trackme
static
pthread_mutex_t
g
_trackme_mutex
=
PTHREAD_MUTEX_INITIALIZER
;
static
pthread_mutex_t
s
_trackme_mutex
=
PTHREAD_MUTEX_INITIALIZER
;
// For contacting with trackme_server.
static
Channel
*
g
_trackme_chan
=
NULL
;
static
Channel
*
s
_trackme_chan
=
NULL
;
// Any server address in this process.
static
std
::
string
*
g
_trackme_addr
=
NULL
;
static
std
::
string
*
s
_trackme_addr
=
NULL
;
// Information of bugs.
// Notice that this structure may be a combination of all affected bugs.
...
...
@@ -65,7 +65,7 @@ struct BugInfo {
// can avoid showing the same bug repeatly.
static
BugInfo
*
g_bug_info
=
NULL
;
// The timestamp(microseconds) that we sent TrackMeRequest.
static
int64_t
g
_trackme_last_time
=
0
;
static
int64_t
s
_trackme_last_time
=
0
;
// version of RPC.
// Since the code for getting BRPC_REVISION often fails,
...
...
@@ -116,8 +116,8 @@ int ReadJPaasHostPort(int container_port) {
// Called in server.cpp
void
SetTrackMeAddress
(
butil
::
EndPoint
pt
)
{
BAIDU_SCOPED_LOCK
(
g
_trackme_mutex
);
if
(
g
_trackme_addr
==
NULL
)
{
BAIDU_SCOPED_LOCK
(
s
_trackme_mutex
);
if
(
s
_trackme_addr
==
NULL
)
{
// JPAAS has NAT capabilities, read its log to figure out the open port
// accessible from outside.
const
int
jpaas_port
=
ReadJPaasHostPort
(
pt
.
port
);
...
...
@@ -126,7 +126,7 @@ void SetTrackMeAddress(butil::EndPoint pt) {
<<
" instead of jpaas_container_port="
<<
pt
.
port
;
pt
.
port
=
jpaas_port
;
}
g
_trackme_addr
=
new
std
::
string
(
butil
::
endpoint2str
(
pt
).
c_str
());
s
_trackme_addr
=
new
std
::
string
(
butil
::
endpoint2str
(
pt
).
c_str
());
}
}
...
...
@@ -139,7 +139,7 @@ static void HandleTrackMeResponse(Controller* cntl, TrackMeResponse* res) {
cur_info
.
error_text
=
res
->
error_text
();
bool
already_reported
=
false
;
{
BAIDU_SCOPED_LOCK
(
g
_trackme_mutex
);
BAIDU_SCOPED_LOCK
(
s
_trackme_mutex
);
if
(
g_bug_info
!=
NULL
&&
*
g_bug_info
==
cur_info
)
{
// we've shown the bug.
already_reported
=
true
;
...
...
@@ -187,10 +187,10 @@ static void HandleTrackMeResponse(Controller* cntl, TrackMeResponse* res) {
}
static
void
TrackMeNow
(
std
::
unique_lock
<
pthread_mutex_t
>&
mu
)
{
if
(
g
_trackme_addr
==
NULL
)
{
if
(
s
_trackme_addr
==
NULL
)
{
return
;
}
if
(
g
_trackme_chan
==
NULL
)
{
if
(
s
_trackme_chan
==
NULL
)
{
Channel
*
chan
=
new
(
std
::
nothrow
)
Channel
;
if
(
chan
==
NULL
)
{
LOG
(
FATAL
)
<<
"Fail to new trackme channel"
;
...
...
@@ -204,16 +204,16 @@ static void TrackMeNow(std::unique_lock<pthread_mutex_t>& mu) {
delete
chan
;
return
;
}
g
_trackme_chan
=
chan
;
s
_trackme_chan
=
chan
;
}
mu
.
unlock
();
TrackMeService_Stub
stub
(
g
_trackme_chan
);
TrackMeService_Stub
stub
(
s
_trackme_chan
);
TrackMeRequest
req
;
req
.
set_rpc_version
(
g_rpc_version
);
req
.
set_server_addr
(
*
g
_trackme_addr
);
req
.
set_server_addr
(
*
s
_trackme_addr
);
TrackMeResponse
*
res
=
new
TrackMeResponse
;
Controller
*
cntl
=
new
Controller
;
cntl
->
set_request_code
(
policy
::
MurmurHash32
(
g_trackme_addr
->
data
(),
g
_trackme_addr
->
size
()));
cntl
->
set_request_code
(
policy
::
MurmurHash32
(
s_trackme_addr
->
data
(),
s
_trackme_addr
->
size
()));
google
::
protobuf
::
Closure
*
done
=
::
brpc
::
NewCallback
(
&
HandleTrackMeResponse
,
cntl
,
res
);
stub
.
TrackMe
(
cntl
,
&
req
,
res
,
done
);
...
...
@@ -226,15 +226,15 @@ void TrackMe() {
return
;
}
int64_t
now
=
butil
::
gettimeofday_us
();
std
::
unique_lock
<
pthread_mutex_t
>
mu
(
g
_trackme_mutex
);
if
(
g
_trackme_last_time
==
0
)
{
std
::
unique_lock
<
pthread_mutex_t
>
mu
(
s
_trackme_mutex
);
if
(
s
_trackme_last_time
==
0
)
{
// Delay the first ping randomly within s_trackme_interval. This
// protects trackme_server from ping storms.
g
_trackme_last_time
=
s
_trackme_last_time
=
now
+
butil
::
fast_rand_less_than
(
s_trackme_interval
)
*
1000000L
;
}
if
(
now
>
g
_trackme_last_time
+
1000000L
*
s_trackme_interval
)
{
g
_trackme_last_time
=
now
;
if
(
now
>
s
_trackme_last_time
+
1000000L
*
s_trackme_interval
)
{
s
_trackme_last_time
=
now
;
return
TrackMeNow
(
mu
);
}
}
...
...
src/bthread/task_group.cpp
View file @
b1f7ea03
...
...
@@ -169,7 +169,6 @@ void TaskGroup::run_main_task() {
(
name
,
&
cumulated_cputime
,
1
));
}
}
// stop_main_task() was called.
// Don't forget to add elapse of last wait_task.
current_task
()
->
stat
.
cputime_ns
+=
butil
::
cpuwide_time_ns
()
-
_last_run_ns
;
}
...
...
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