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
75f89a5a
Commit
75f89a5a
authored
Apr 11, 2019
by
zhujiashun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
revived_from_all_failed: optimize code
parent
f0224fcc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
8 deletions
+7
-8
cluster_recover_policy.cpp
src/brpc/cluster_recover_policy.cpp
+4
-5
cluster_recover_policy.h
src/brpc/cluster_recover_policy.h
+3
-3
No files found.
src/brpc/cluster_recover_policy.cpp
View file @
75f89a5a
...
...
@@ -62,12 +62,12 @@ bool DefaultClusterRecoverPolicy::StopRecoverIfNecessary() {
return
true
;
}
in
t
DefaultClusterRecoverPolicy
::
GetUsableServerCount
(
uint64_
t
DefaultClusterRecoverPolicy
::
GetUsableServerCount
(
int64_t
now_ms
,
const
std
::
vector
<
ServerId
>&
server_list
)
{
if
(
now_ms
-
_usable_cache_time_ms
<
FLAGS_detect_available_server_interval_ms
)
{
return
_usable_cache
;
}
in
t
usable
=
0
;
uint64_
t
usable
=
0
;
size_t
n
=
server_list
.
size
();
SocketUniquePtr
ptr
;
for
(
size_t
i
=
0
;
i
<
n
;
++
i
)
{
...
...
@@ -90,7 +90,7 @@ bool DefaultClusterRecoverPolicy::DoReject(const std::vector<ServerId>& server_l
return
false
;
}
int64_t
now_ms
=
butil
::
gettimeofday_ms
();
in
t
usable
=
GetUsableServerCount
(
now_ms
,
server_list
);
uint64_
t
usable
=
GetUsableServerCount
(
now_ms
,
server_list
);
if
(
_last_usable
!=
usable
)
{
std
::
unique_lock
<
butil
::
Mutex
>
mu
(
_mutex
);
if
(
_last_usable
!=
usable
)
{
...
...
@@ -98,8 +98,7 @@ bool DefaultClusterRecoverPolicy::DoReject(const std::vector<ServerId>& server_l
_last_usable_change_time_ms
=
now_ms
;
}
}
int
rand
=
butil
::
fast_rand_less_than
(
_minimum_working_instances
);
if
(
rand
>=
usable
)
{
if
(
butil
::
fast_rand_less_than
(
_minimum_working_instances
)
>=
usable
)
{
return
true
;
}
return
false
;
...
...
src/brpc/cluster_recover_policy.h
View file @
75f89a5a
...
...
@@ -62,16 +62,16 @@ public:
bool
StopRecoverIfNecessary
();
private
:
in
t
GetUsableServerCount
(
int64_t
now_ms
,
const
std
::
vector
<
ServerId
>&
server_list
);
uint64_
t
GetUsableServerCount
(
int64_t
now_ms
,
const
std
::
vector
<
ServerId
>&
server_list
);
private
:
bool
_recovering
;
int64_t
_minimum_working_instances
;
butil
::
Mutex
_mutex
;
int64_t
_last_usable
;
u
int64_t
_last_usable
;
int64_t
_last_usable_change_time_ms
;
int64_t
_hold_time_ms
;
int64_t
_usable_cache
;
u
int64_t
_usable_cache
;
int64_t
_usable_cache_time_ms
;
};
...
...
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