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
be11fcda
Commit
be11fcda
authored
Dec 14, 2018
by
cdjgit
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add code comments && move brpc::policy::HashFunc to hasher.cpp
parent
b1ed71ce
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
7 additions
and
5 deletions
+7
-5
load_balancer.h
src/brpc/load_balancer.h
+2
-1
consistent_hashing_load_balancer.cpp
src/brpc/policy/consistent_hashing_load_balancer.cpp
+1
-1
consistent_hashing_load_balancer.h
src/brpc/policy/consistent_hashing_load_balancer.h
+0
-1
hasher.cpp
src/brpc/policy/hasher.cpp
+1
-1
hasher.h
src/brpc/policy/hasher.h
+2
-0
brpc_load_balancer_unittest.cpp
test/brpc_load_balancer_unittest.cpp
+1
-1
No files found.
src/brpc/load_balancer.h
View file @
be11fcda
...
...
@@ -104,7 +104,8 @@ public:
// Caller is responsible for Destroy() the instance after usage.
virtual
LoadBalancer
*
New
()
const
=
0
;
// Set other
// Config user passed parameters to lb after constrction which
// make lb function more flexible.
virtual
bool
SetParameters
(
const
butil
::
StringPairs
&
params
)
{
return
true
;
}
protected
:
...
...
src/brpc/policy/consistent_hashing_load_balancer.cpp
View file @
be11fcda
...
...
@@ -35,7 +35,7 @@ namespace {
bool
BuildReplicasDefault
(
const
ServerId
server
,
const
size_t
num_replicas
,
ConsistentHashingLoadBalancer
::
HashFunc
hash
,
HashFunc
hash
,
std
::
vector
<
ConsistentHashingLoadBalancer
::
Node
>*
replicas
)
{
SocketUniquePtr
ptr
;
if
(
Socket
::
AddressFailedAsWell
(
server
.
id
,
&
ptr
)
==
-
1
)
{
...
...
src/brpc/policy/consistent_hashing_load_balancer.h
View file @
be11fcda
...
...
@@ -43,7 +43,6 @@ public:
return
hash
<
code
;
}
};
using
HashFunc
=
uint32_t
(
*
)(
const
void
*
,
size_t
);
using
BuildReplicasFunc
=
std
::
function
<
bool
(
const
ServerId
server
,
const
size_t
num_replicas
,
std
::
vector
<
Node
>*
replicas
)
>
;
explicit
ConsistentHashingLoadBalancer
(
const
char
*
name
);
...
...
src/brpc/policy/hasher.cpp
View file @
be11fcda
...
...
@@ -155,7 +155,7 @@ uint32_t CRCHash32(const void* key, size_t len) {
return
((
~
crc
)
>>
16
)
&
0x7fff
;
}
const
char
*
GetHashName
(
uint32_t
(
*
hasher
)(
const
void
*
key
,
size_t
len
)
)
{
const
char
*
GetHashName
(
HashFunc
hasher
)
{
if
(
hasher
==
MurmurHash32
)
{
return
"murmurhash3"
;
}
...
...
src/brpc/policy/hasher.h
View file @
be11fcda
...
...
@@ -25,6 +25,8 @@
namespace
brpc
{
namespace
policy
{
using
HashFunc
=
uint32_t
(
*
)(
const
void
*
,
size_t
);
void
MD5HashSignature
(
const
void
*
key
,
size_t
len
,
unsigned
char
*
results
);
uint32_t
MD5Hash32
(
const
void
*
key
,
size_t
len
);
uint32_t
MD5Hash32V
(
const
butil
::
StringPiece
*
keys
,
size_t
num_keys
);
...
...
test/brpc_load_balancer_unittest.cpp
View file @
be11fcda
...
...
@@ -485,7 +485,7 @@ TEST_F(LoadBalancerTest, fairness) {
}
TEST_F
(
LoadBalancerTest
,
consistent_hashing
)
{
::
brpc
::
policy
::
ConsistentHashingLoadBalancer
::
HashFunc
hashs
[]
=
{
::
brpc
::
policy
::
HashFunc
hashs
[]
=
{
::
brpc
::
policy
::
MurmurHash32
,
::
brpc
::
policy
::
MD5Hash32
,
::
brpc
::
policy
::
KetamaHash
...
...
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