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
95d61d72
Commit
95d61d72
authored
Apr 04, 2019
by
cdjgit
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move GetReplicaPolicy out of class ReplicaPolicy
parent
37d2a3bd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
15 deletions
+16
-15
consistent_hashing_load_balancer.cpp
src/brpc/policy/consistent_hashing_load_balancer.cpp
+16
-15
No files found.
src/brpc/policy/consistent_hashing_load_balancer.cpp
View file @
95d61d72
...
@@ -35,25 +35,14 @@ class ReplicaPolicy {
...
@@ -35,25 +35,14 @@ class ReplicaPolicy {
public
:
public
:
ReplicaPolicy
()
:
_hash_func
(
nullptr
)
{}
ReplicaPolicy
()
:
_hash_func
(
nullptr
)
{}
ReplicaPolicy
(
HashFunc
hash
)
:
_hash_func
(
hash
)
{}
ReplicaPolicy
(
HashFunc
hash
)
:
_hash_func
(
hash
)
{}
virtual
~
ReplicaPolicy
();
virtual
~
ReplicaPolicy
();
virtual
bool
Build
(
ServerId
server
,
virtual
bool
Build
(
ServerId
server
,
size_t
num_replicas
,
size_t
num_replicas
,
std
::
vector
<
ConsistentHashingLoadBalancer
::
Node
>*
replicas
)
const
=
0
;
std
::
vector
<
ConsistentHashingLoadBalancer
::
Node
>*
replicas
)
const
=
0
;
static
const
ReplicaPolicy
*
GetReplicaPolicy
(
const
std
::
string
&
name
)
{
auto
iter
=
_policy_map
.
find
(
name
);
if
(
iter
!=
_policy_map
.
end
())
{
return
iter
->
second
;
}
return
nullptr
;
}
protected
:
protected
:
HashFunc
_hash_func
=
nullptr
;
HashFunc
_hash_func
;
private
:
static
const
std
::
map
<
std
::
string
,
const
ReplicaPolicy
*>
_policy_map
;
};
};
class
DefaultReplicaPolicy
:
public
ReplicaPolicy
{
class
DefaultReplicaPolicy
:
public
ReplicaPolicy
{
...
@@ -124,15 +113,27 @@ bool KetamaReplicaPolicy::Build(ServerId server,
...
@@ -124,15 +113,27 @@ bool KetamaReplicaPolicy::Build(ServerId server,
return
true
;
return
true
;
}
}
const
std
::
map
<
std
::
string
,
const
ReplicaPolicy
*>
ReplicaPolicy
::
_policy_map
=
{
namespace
{
const
std
::
map
<
std
::
string
,
const
ReplicaPolicy
*>
g_replica_policy_map
=
{
{
"murmurhash3"
,
new
DefaultReplicaPolicy
(
MurmurHash32
)},
{
"murmurhash3"
,
new
DefaultReplicaPolicy
(
MurmurHash32
)},
{
"md5"
,
new
DefaultReplicaPolicy
(
MD5Hash32
)},
{
"md5"
,
new
DefaultReplicaPolicy
(
MD5Hash32
)},
{
"ketama"
,
new
KetamaReplicaPolicy
}
{
"ketama"
,
new
KetamaReplicaPolicy
}
};
};
const
ReplicaPolicy
*
GetReplicaPolicy
(
const
std
::
string
&
name
)
{
auto
iter
=
g_replica_policy_map
.
find
(
name
);
if
(
iter
!=
g_replica_policy_map
.
end
())
{
return
iter
->
second
;
}
return
nullptr
;
}
}
// namespace
ConsistentHashingLoadBalancer
::
ConsistentHashingLoadBalancer
(
const
char
*
name
)
ConsistentHashingLoadBalancer
::
ConsistentHashingLoadBalancer
(
const
char
*
name
)
:
_num_replicas
(
FLAGS_chash_num_replicas
),
_name
(
name
)
{
:
_num_replicas
(
FLAGS_chash_num_replicas
),
_name
(
name
)
{
_replicas_policy
=
ReplicaPolicy
::
GetReplicaPolicy
(
name
);
_replicas_policy
=
GetReplicaPolicy
(
name
);
CHECK
(
_replicas_policy
)
CHECK
(
_replicas_policy
)
<<
"Fail to find replica policy for consistency lb: '"
<<
name
<<
'\''
;
<<
"Fail to find replica policy for consistency lb: '"
<<
name
<<
'\''
;
}
}
...
...
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