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