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
2b550fd0
Commit
2b550fd0
authored
Apr 11, 2019
by
zhujiashun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
revived_from_all_failed: remove RevivePolicy to ClusterRecoverPolicy
parent
a1c05b58
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
53 additions
and
58 deletions
+53
-58
cluster_recover_policy.cpp
src/brpc/cluster_recover_policy.cpp
+15
-16
cluster_recover_policy.h
src/brpc/cluster_recover_policy.h
+23
-24
locality_aware_load_balancer.cpp
src/brpc/policy/locality_aware_load_balancer.cpp
+0
-1
randomized_load_balancer.cpp
src/brpc/policy/randomized_load_balancer.cpp
+6
-6
randomized_load_balancer.h
src/brpc/policy/randomized_load_balancer.h
+2
-2
round_robin_load_balancer.cpp
src/brpc/policy/round_robin_load_balancer.cpp
+5
-6
round_robin_load_balancer.h
src/brpc/policy/round_robin_load_balancer.h
+2
-2
weighted_round_robin_load_balancer.cpp
src/brpc/policy/weighted_round_robin_load_balancer.cpp
+0
-1
No files found.
src/brpc/
revive
_policy.cpp
→
src/brpc/
cluster_recover
_policy.cpp
View file @
2b550fd0
...
@@ -16,7 +16,7 @@
...
@@ -16,7 +16,7 @@
#include <vector>
#include <vector>
#include <gflags/gflags.h>
#include <gflags/gflags.h>
#include "brpc/
revive
_policy.h"
#include "brpc/
cluster_recover
_policy.h"
#include "butil/scoped_lock.h"
#include "butil/scoped_lock.h"
#include "butil/synchronization/lock.h"
#include "butil/synchronization/lock.h"
#include "brpc/server_id.h"
#include "brpc/server_id.h"
...
@@ -28,11 +28,11 @@
...
@@ -28,11 +28,11 @@
namespace
brpc
{
namespace
brpc
{
DEFINE_int64
(
detect_available_server_interval_ms
,
10
,
"The interval "
DEFINE_int64
(
detect_available_server_interval_ms
,
10
,
"The interval "
"to detect available server count in Default
Revive
Policy"
);
"to detect available server count in Default
ClusterRecover
Policy"
);
Default
RevivePolicy
::
DefaultRevive
Policy
(
Default
ClusterRecoverPolicy
::
DefaultClusterRecover
Policy
(
int64_t
minimum_working_instances
,
int64_t
hold_time_ms
)
int64_t
minimum_working_instances
,
int64_t
hold_time_ms
)
:
_re
viv
ing
(
false
)
:
_re
cover
ing
(
false
)
,
_minimum_working_instances
(
minimum_working_instances
)
,
_minimum_working_instances
(
minimum_working_instances
)
,
_last_usable
(
0
)
,
_last_usable
(
0
)
,
_last_usable_change_time_ms
(
0
)
,
_last_usable_change_time_ms
(
0
)
...
@@ -40,20 +40,20 @@ DefaultRevivePolicy::DefaultRevivePolicy(
...
@@ -40,20 +40,20 @@ DefaultRevivePolicy::DefaultRevivePolicy(
,
_usable_cache
(
0
)
,
_usable_cache
(
0
)
,
_usable_cache_time_ms
(
0
)
{
}
,
_usable_cache_time_ms
(
0
)
{
}
void
Default
RevivePolicy
::
StartReviving
()
{
void
Default
ClusterRecoverPolicy
::
StartRecover
()
{
std
::
unique_lock
<
butil
::
Mutex
>
mu
(
_mutex
);
std
::
unique_lock
<
butil
::
Mutex
>
mu
(
_mutex
);
_re
viv
ing
=
true
;
_re
cover
ing
=
true
;
}
}
bool
Default
RevivePolicy
::
StopReviving
IfNecessary
()
{
bool
Default
ClusterRecoverPolicy
::
StopRecover
IfNecessary
()
{
if
(
!
_re
viv
ing
)
{
if
(
!
_re
cover
ing
)
{
return
false
;
return
false
;
}
}
int64_t
now_ms
=
butil
::
gettimeofday_ms
();
int64_t
now_ms
=
butil
::
gettimeofday_ms
();
std
::
unique_lock
<
butil
::
Mutex
>
mu
(
_mutex
);
std
::
unique_lock
<
butil
::
Mutex
>
mu
(
_mutex
);
if
(
_last_usable_change_time_ms
!=
0
&&
_last_usable
!=
0
&&
if
(
_last_usable_change_time_ms
!=
0
&&
_last_usable
!=
0
&&
(
now_ms
-
_last_usable_change_time_ms
>
_hold_time_ms
))
{
(
now_ms
-
_last_usable_change_time_ms
>
_hold_time_ms
))
{
_re
viv
ing
=
false
;
_re
cover
ing
=
false
;
_last_usable_change_time_ms
=
0
;
_last_usable_change_time_ms
=
0
;
mu
.
unlock
();
mu
.
unlock
();
return
false
;
return
false
;
...
@@ -62,7 +62,7 @@ bool DefaultRevivePolicy::StopRevivingIfNecessary() {
...
@@ -62,7 +62,7 @@ bool DefaultRevivePolicy::StopRevivingIfNecessary() {
return
true
;
return
true
;
}
}
int
Default
Revive
Policy
::
GetUsableServerCount
(
int
Default
ClusterRecover
Policy
::
GetUsableServerCount
(
int64_t
now_ms
,
const
std
::
vector
<
ServerId
>&
server_list
)
{
int64_t
now_ms
,
const
std
::
vector
<
ServerId
>&
server_list
)
{
if
(
now_ms
-
_usable_cache_time_ms
<
FLAGS_detect_available_server_interval_ms
)
{
if
(
now_ms
-
_usable_cache_time_ms
<
FLAGS_detect_available_server_interval_ms
)
{
return
_usable_cache
;
return
_usable_cache
;
...
@@ -85,8 +85,8 @@ int DefaultRevivePolicy::GetUsableServerCount(
...
@@ -85,8 +85,8 @@ int DefaultRevivePolicy::GetUsableServerCount(
}
}
bool
Default
Revive
Policy
::
DoReject
(
const
std
::
vector
<
ServerId
>&
server_list
)
{
bool
Default
ClusterRecover
Policy
::
DoReject
(
const
std
::
vector
<
ServerId
>&
server_list
)
{
if
(
!
_re
viv
ing
)
{
if
(
!
_re
cover
ing
)
{
return
false
;
return
false
;
}
}
int64_t
now_ms
=
butil
::
gettimeofday_ms
();
int64_t
now_ms
=
butil
::
gettimeofday_ms
();
...
@@ -105,8 +105,8 @@ bool DefaultRevivePolicy::DoReject(const std::vector<ServerId>& server_list) {
...
@@ -105,8 +105,8 @@ bool DefaultRevivePolicy::DoReject(const std::vector<ServerId>& server_list) {
return
false
;
return
false
;
}
}
bool
GetRe
vive
PolicyByParams
(
const
butil
::
StringPiece
&
params
,
bool
GetRe
cover
PolicyByParams
(
const
butil
::
StringPiece
&
params
,
std
::
shared_ptr
<
Revive
Policy
>*
ptr_out
)
{
std
::
shared_ptr
<
ClusterRecover
Policy
>*
ptr_out
)
{
int64_t
minimum_working_instances
=
-
1
;
int64_t
minimum_working_instances
=
-
1
;
int64_t
hold_time_ms
=
-
1
;
int64_t
hold_time_ms
=
-
1
;
bool
has_meet_params
=
false
;
bool
has_meet_params
=
false
;
...
@@ -133,7 +133,7 @@ bool GetRevivePolicyByParams(const butil::StringPiece& params,
...
@@ -133,7 +133,7 @@ bool GetRevivePolicyByParams(const butil::StringPiece& params,
}
}
if
(
minimum_working_instances
>
0
&&
hold_time_ms
>
0
)
{
if
(
minimum_working_instances
>
0
&&
hold_time_ms
>
0
)
{
ptr_out
->
reset
(
ptr_out
->
reset
(
new
Default
Revive
Policy
(
minimum_working_instances
,
hold_time_ms
));
new
Default
ClusterRecover
Policy
(
minimum_working_instances
,
hold_time_ms
));
}
else
if
(
has_meet_params
)
{
}
else
if
(
has_meet_params
)
{
// In this case, user set some params but not in the right way, just return
// In this case, user set some params but not in the right way, just return
// false to let user take care of this situation.
// false to let user take care of this situation.
...
@@ -143,5 +143,4 @@ bool GetRevivePolicyByParams(const butil::StringPiece& params,
...
@@ -143,5 +143,4 @@ bool GetRevivePolicyByParams(const butil::StringPiece& params,
return
true
;
return
true
;
}
}
}
// namespace brpc
}
// namespace brpc
src/brpc/
revive
_policy.h
→
src/brpc/
cluster_recover
_policy.h
View file @
2b550fd0
...
@@ -14,8 +14,8 @@
...
@@ -14,8 +14,8 @@
// Authors: Jiashun Zhu(zhujiashun@bilibili.com)
// Authors: Jiashun Zhu(zhujiashun@bilibili.com)
#ifndef BRPC_
REVIVE
_POLICY
#ifndef BRPC_
CLUSTER_RECOVER
_POLICY
#define BRPC_
REVIVE
_POLICY
#define BRPC_
CLUSTER_RECOVER
_POLICY
#include <cstdint>
#include <cstdint>
#include <memory>
#include <memory>
...
@@ -27,46 +27,45 @@ namespace brpc {
...
@@ -27,46 +27,45 @@ namespace brpc {
class
ServerId
;
class
ServerId
;
// After all servers are
shut
down and health check happens, servers are
// After all servers are down and health check happens, servers are
// online one by one. Once one server is up, all the request that should
// online one by one. Once one server is up, all the request that should
// be sent to all servers, would be sent to one server, which may be a
// be sent to all servers, would be sent to one server, which may be a
// disastrous behaviour. In the worst case it would cause the server
shut
down
// disastrous behaviour. In the worst case it would cause the server
being
down
// again if circuit breaker is enabled and the
server cluster would never
// again if circuit breaker is enabled and the
cluster would never recover.
//
recover.
This class controls the amount of requests that sent to the revived
// This class controls the amount of requests that sent to the revived
// servers when recovering from all servers are
shut
down.
// servers when recovering from all servers are down.
class
Revive
Policy
{
class
ClusterRecover
Policy
{
public
:
public
:
// Indicate that re
viving from the shutdown of all server
is happening.
// Indicate that re
cover from all server being down
is happening.
virtual
void
StartRe
viving
()
=
0
;
virtual
void
StartRe
cover
()
=
0
;
// Return true if some customized policies are satisfied.
// Return true if some customized policies are satisfied.
virtual
bool
DoReject
(
const
std
::
vector
<
ServerId
>&
server_list
)
=
0
;
virtual
bool
DoReject
(
const
std
::
vector
<
ServerId
>&
server_list
)
=
0
;
// Stop reviving state and do not reject the request if some condition is
// Stop recover state and do not reject the request if some condition is
// satisfied.
// satisfied. Return true if the current state is still in recovering.
// Return true if the current state is still in reviving.
virtual
bool
StopRecoverIfNecessary
()
=
0
;
virtual
bool
StopRevivingIfNecessary
()
=
0
;
};
};
// The default
revive policy. Once no servers are available, reviving
is start.
// The default
cluster recover policy. Once no servers are available, recover
is start.
// If in re
viving
state, the probability that a request is accepted is q/n, in
// If in re
cover
state, the probability that a request is accepted is q/n, in
// which q is the number of current available server, n is the number of minimum
// which q is the number of current available server, n is the number of minimum
// working instances setting by user. If q is not changed during a given time,
// working instances setting by user. If q is not changed during a given time,
// hold_time_ms, then the cluster is considered recovered and all the request
// hold_time_ms, then the cluster is considered recovered and all the request
// would be sent to the current available servers.
// would be sent to the current available servers.
class
Default
RevivePolicy
:
public
Revive
Policy
{
class
Default
ClusterRecoverPolicy
:
public
ClusterRecover
Policy
{
public
:
public
:
Default
Revive
Policy
(
int64_t
minimum_working_instances
,
int64_t
hold_time_ms
);
Default
ClusterRecover
Policy
(
int64_t
minimum_working_instances
,
int64_t
hold_time_ms
);
void
StartRe
viving
();
void
StartRe
cover
();
bool
DoReject
(
const
std
::
vector
<
ServerId
>&
server_list
);
bool
DoReject
(
const
std
::
vector
<
ServerId
>&
server_list
);
bool
StopRe
viving
IfNecessary
();
bool
StopRe
cover
IfNecessary
();
private
:
private
:
int
GetUsableServerCount
(
int64_t
now_ms
,
const
std
::
vector
<
ServerId
>&
server_list
);
int
GetUsableServerCount
(
int64_t
now_ms
,
const
std
::
vector
<
ServerId
>&
server_list
);
private
:
private
:
bool
_re
viv
ing
;
bool
_re
cover
ing
;
int64_t
_minimum_working_instances
;
int64_t
_minimum_working_instances
;
butil
::
Mutex
_mutex
;
butil
::
Mutex
_mutex
;
int64_t
_last_usable
;
int64_t
_last_usable
;
...
@@ -76,10 +75,10 @@ private:
...
@@ -76,10 +75,10 @@ private:
int64_t
_usable_cache_time_ms
;
int64_t
_usable_cache_time_ms
;
};
};
// Return a Default
Revive
Policy object by params. The caller is responsible
// Return a Default
ClusterRecover
Policy object by params. The caller is responsible
// for memory management of the return value.
// for memory management of the return value.
bool
GetRe
vive
PolicyByParams
(
const
butil
::
StringPiece
&
params
,
bool
GetRe
cover
PolicyByParams
(
const
butil
::
StringPiece
&
params
,
std
::
shared_ptr
<
Revive
Policy
>*
ptr_out
);
std
::
shared_ptr
<
ClusterRecover
Policy
>*
ptr_out
);
}
// namespace brpc
}
// namespace brpc
...
...
src/brpc/policy/locality_aware_load_balancer.cpp
View file @
2b550fd0
...
@@ -22,7 +22,6 @@
...
@@ -22,7 +22,6 @@
#include "brpc/socket.h"
#include "brpc/socket.h"
#include "brpc/reloadable_flags.h"
#include "brpc/reloadable_flags.h"
#include "brpc/policy/locality_aware_load_balancer.h"
#include "brpc/policy/locality_aware_load_balancer.h"
#include "brpc/revive_policy.h"
namespace
brpc
{
namespace
brpc
{
namespace
policy
{
namespace
policy
{
...
...
src/brpc/policy/randomized_load_balancer.cpp
View file @
2b550fd0
...
@@ -32,7 +32,7 @@ inline uint32_t GenRandomStride() {
...
@@ -32,7 +32,7 @@ inline uint32_t GenRandomStride() {
}
}
RandomizedLoadBalancer
::
RandomizedLoadBalancer
()
RandomizedLoadBalancer
::
RandomizedLoadBalancer
()
:
_
revive
_policy
(
NULL
)
:
_
cluster_recover
_policy
(
NULL
)
{}
{}
bool
RandomizedLoadBalancer
::
Add
(
Servers
&
bg
,
const
ServerId
&
id
)
{
bool
RandomizedLoadBalancer
::
Add
(
Servers
&
bg
,
const
ServerId
&
id
)
{
...
@@ -114,8 +114,8 @@ int RandomizedLoadBalancer::SelectServer(const SelectIn& in, SelectOut* out) {
...
@@ -114,8 +114,8 @@ int RandomizedLoadBalancer::SelectServer(const SelectIn& in, SelectOut* out) {
if
(
n
==
0
)
{
if
(
n
==
0
)
{
return
ENODATA
;
return
ENODATA
;
}
}
if
(
_
revive_policy
&&
_revive_policy
->
StopReviving
IfNecessary
())
{
if
(
_
cluster_recover_policy
&&
_cluster_recover_policy
->
StopRecover
IfNecessary
())
{
if
(
_
revive
_policy
->
DoReject
(
s
->
server_list
))
{
if
(
_
cluster_recover
_policy
->
DoReject
(
s
->
server_list
))
{
return
EREJECT
;
return
EREJECT
;
}
}
}
}
...
@@ -137,8 +137,8 @@ int RandomizedLoadBalancer::SelectServer(const SelectIn& in, SelectOut* out) {
...
@@ -137,8 +137,8 @@ int RandomizedLoadBalancer::SelectServer(const SelectIn& in, SelectOut* out) {
// this failed server won't be visited again inside for
// this failed server won't be visited again inside for
offset
=
(
offset
+
stride
)
%
n
;
offset
=
(
offset
+
stride
)
%
n
;
}
}
if
(
_
revive
_policy
)
{
if
(
_
cluster_recover
_policy
)
{
_
revive_policy
->
StartReviving
();
_
cluster_recover_policy
->
StartRecover
();
}
}
// After we traversed the whole server list, there is still no
// After we traversed the whole server list, there is still no
// available server
// available server
...
@@ -179,7 +179,7 @@ void RandomizedLoadBalancer::Describe(
...
@@ -179,7 +179,7 @@ void RandomizedLoadBalancer::Describe(
}
}
bool
RandomizedLoadBalancer
::
SetParameters
(
const
butil
::
StringPiece
&
params
)
{
bool
RandomizedLoadBalancer
::
SetParameters
(
const
butil
::
StringPiece
&
params
)
{
return
GetRe
vivePolicyByParams
(
params
,
&
_revive
_policy
);
return
GetRe
coverPolicyByParams
(
params
,
&
_cluster_recover
_policy
);
}
}
}
// namespace policy
}
// namespace policy
...
...
src/brpc/policy/randomized_load_balancer.h
View file @
2b550fd0
...
@@ -21,7 +21,7 @@
...
@@ -21,7 +21,7 @@
#include <map> // std::map
#include <map> // std::map
#include "butil/containers/doubly_buffered_data.h"
#include "butil/containers/doubly_buffered_data.h"
#include "brpc/load_balancer.h"
#include "brpc/load_balancer.h"
#include "brpc/
revive
_policy.h"
#include "brpc/
cluster_recover
_policy.h"
namespace
brpc
{
namespace
brpc
{
namespace
policy
{
namespace
policy
{
...
@@ -53,7 +53,7 @@ private:
...
@@ -53,7 +53,7 @@ private:
static
size_t
BatchRemove
(
Servers
&
bg
,
const
std
::
vector
<
ServerId
>&
servers
);
static
size_t
BatchRemove
(
Servers
&
bg
,
const
std
::
vector
<
ServerId
>&
servers
);
butil
::
DoublyBufferedData
<
Servers
>
_db_servers
;
butil
::
DoublyBufferedData
<
Servers
>
_db_servers
;
std
::
shared_ptr
<
RevivePolicy
>
_revive
_policy
;
std
::
shared_ptr
<
ClusterRecoverPolicy
>
_cluster_recover
_policy
;
};
};
}
// namespace policy
}
// namespace policy
...
...
src/brpc/policy/round_robin_load_balancer.cpp
View file @
2b550fd0
...
@@ -110,8 +110,8 @@ int RoundRobinLoadBalancer::SelectServer(const SelectIn& in, SelectOut* out) {
...
@@ -110,8 +110,8 @@ int RoundRobinLoadBalancer::SelectServer(const SelectIn& in, SelectOut* out) {
if
(
n
==
0
)
{
if
(
n
==
0
)
{
return
ENODATA
;
return
ENODATA
;
}
}
if
(
_
revive_policy
&&
_revive_policy
->
StopReviving
IfNecessary
())
{
if
(
_
cluster_recover_policy
&&
_cluster_recover_policy
->
StopRecover
IfNecessary
())
{
if
(
_
revive
_policy
->
DoReject
(
s
->
server_list
))
{
if
(
_
cluster_recover
_policy
->
DoReject
(
s
->
server_list
))
{
return
EREJECT
;
return
EREJECT
;
}
}
}
}
...
@@ -132,8 +132,8 @@ int RoundRobinLoadBalancer::SelectServer(const SelectIn& in, SelectOut* out) {
...
@@ -132,8 +132,8 @@ int RoundRobinLoadBalancer::SelectServer(const SelectIn& in, SelectOut* out) {
return
0
;
return
0
;
}
}
}
}
if
(
_
revive
_policy
)
{
if
(
_
cluster_recover
_policy
)
{
_
revive_policy
->
StartReviving
();
_
cluster_recover_policy
->
StartRecover
();
}
}
s
.
tls
()
=
tls
;
s
.
tls
()
=
tls
;
return
EHOSTDOWN
;
return
EHOSTDOWN
;
...
@@ -173,9 +173,8 @@ void RoundRobinLoadBalancer::Describe(
...
@@ -173,9 +173,8 @@ void RoundRobinLoadBalancer::Describe(
}
}
bool
RoundRobinLoadBalancer
::
SetParameters
(
const
butil
::
StringPiece
&
params
)
{
bool
RoundRobinLoadBalancer
::
SetParameters
(
const
butil
::
StringPiece
&
params
)
{
return
GetRe
vivePolicyByParams
(
params
,
&
_revive
_policy
);
return
GetRe
coverPolicyByParams
(
params
,
&
_cluster_recover
_policy
);
}
}
}
// namespace policy
}
// namespace policy
}
// namespace brpc
}
// namespace brpc
src/brpc/policy/round_robin_load_balancer.h
View file @
2b550fd0
...
@@ -21,7 +21,7 @@
...
@@ -21,7 +21,7 @@
#include <map> // std::map
#include <map> // std::map
#include "butil/containers/doubly_buffered_data.h"
#include "butil/containers/doubly_buffered_data.h"
#include "brpc/load_balancer.h"
#include "brpc/load_balancer.h"
#include "brpc/
revive
_policy.h"
#include "brpc/
cluster_recover
_policy.h"
namespace
brpc
{
namespace
brpc
{
namespace
policy
{
namespace
policy
{
...
@@ -56,7 +56,7 @@ private:
...
@@ -56,7 +56,7 @@ private:
static
size_t
BatchRemove
(
Servers
&
bg
,
const
std
::
vector
<
ServerId
>&
servers
);
static
size_t
BatchRemove
(
Servers
&
bg
,
const
std
::
vector
<
ServerId
>&
servers
);
butil
::
DoublyBufferedData
<
Servers
,
TLS
>
_db_servers
;
butil
::
DoublyBufferedData
<
Servers
,
TLS
>
_db_servers
;
std
::
shared_ptr
<
RevivePolicy
>
_revive
_policy
;
std
::
shared_ptr
<
ClusterRecoverPolicy
>
_cluster_recover
_policy
;
};
};
}
// namespace policy
}
// namespace policy
...
...
src/brpc/policy/weighted_round_robin_load_balancer.cpp
View file @
2b550fd0
...
@@ -20,7 +20,6 @@
...
@@ -20,7 +20,6 @@
#include "brpc/socket.h"
#include "brpc/socket.h"
#include "brpc/policy/weighted_round_robin_load_balancer.h"
#include "brpc/policy/weighted_round_robin_load_balancer.h"
#include "butil/strings/string_number_conversions.h"
#include "butil/strings/string_number_conversions.h"
#include "brpc/revive_policy.h"
namespace
{
namespace
{
...
...
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