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
f98fd01f
Commit
f98fd01f
authored
Apr 16, 2019
by
zhujiashun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
revived_from_all_failed: split KeyValuePairSplitter into different pr
parent
662ff4a4
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
16 additions
and
65 deletions
+16
-65
cluster_recover_policy.cpp
src/brpc/cluster_recover_policy.cpp
+11
-9
cluster_recover_policy.h
src/brpc/cluster_recover_policy.h
+2
-0
consistent_hashing_load_balancer.cpp
src/brpc/policy/consistent_hashing_load_balancer.cpp
+3
-3
string_splitter.h
src/butil/string_splitter.h
+0
-1
string_splitter_unittest.cpp
test/string_splitter_unittest.cpp
+0
-52
No files found.
src/brpc/cluster_recover_policy.cpp
View file @
f98fd01f
...
...
@@ -54,6 +54,7 @@ bool DefaultClusterRecoverPolicy::StopRecoverIfNecessary() {
if
(
_last_usable_change_time_ms
!=
0
&&
_last_usable
!=
0
&&
(
now_ms
-
_last_usable_change_time_ms
>
_hold_time_ms
))
{
_recovering
=
false
;
_last_usable
=
0
;
_last_usable_change_time_ms
=
0
;
mu
.
unlock
();
return
false
;
...
...
@@ -109,26 +110,27 @@ bool GetRecoverPolicyByParams(const butil::StringPiece& params,
int64_t
minimum_working_instances
=
-
1
;
int64_t
hold_time_ms
=
-
1
;
bool
has_meet_params
=
false
;
for
(
butil
::
KeyValuePairsSplitter
sp
(
params
.
begin
(),
params
.
end
(),
'='
,
' '
);
sp
;
++
sp
)
{
if
(
sp
.
value
().
empty
())
{
LOG
(
ERROR
)
<<
"Empty value for "
<<
sp
.
key
()
<<
" in lb parameter"
;
for
(
butil
::
StringSplitter
sp
(
params
.
begin
(),
params
.
end
(),
' '
);
sp
!=
nullptr
;
++
sp
)
{
butil
::
StringPiece
key_value
(
sp
.
field
(),
sp
.
length
());
size_t
p
=
key_value
.
find
(
'='
);
if
(
p
==
key_value
.
npos
||
p
==
key_value
.
size
()
-
1
)
{
// No value configed.
return
false
;
}
if
(
sp
.
key
(
)
==
"minimum_working_instances"
)
{
if
(
!
butil
::
StringToInt64
(
sp
.
value
(
),
&
minimum_working_instances
))
{
if
(
key_value
.
substr
(
0
,
p
)
==
"minimum_working_instances"
)
{
if
(
!
butil
::
StringToInt64
(
key_value
.
substr
(
p
+
1
),
&
minimum_working_instances
))
{
return
false
;
}
has_meet_params
=
true
;
continue
;
}
else
if
(
sp
.
key
(
)
==
"hold_time_ms"
)
{
if
(
!
butil
::
StringToInt64
(
sp
.
value
(
),
&
hold_time_ms
))
{
}
else
if
(
key_value
.
substr
(
0
,
p
)
==
"hold_time_ms"
)
{
if
(
!
butil
::
StringToInt64
(
key_value
.
substr
(
p
+
1
),
&
hold_time_ms
))
{
return
false
;
}
has_meet_params
=
true
;
continue
;
}
LOG
(
ERROR
)
<<
"Failed to set this unknown parameters "
<<
sp
.
key_and_value
()
;
LOG
(
ERROR
)
<<
"Failed to set this unknown parameters "
<<
key_value
;
}
if
(
minimum_working_instances
>
0
&&
hold_time_ms
>
0
)
{
ptr_out
->
reset
(
...
...
src/brpc/cluster_recover_policy.h
View file @
f98fd01f
...
...
@@ -36,6 +36,8 @@ class ServerId;
// servers when recovering from all servers are down.
class
ClusterRecoverPolicy
{
public
:
virtual
~
ClusterRecoverPolicy
()
{}
// Indicate that recover from all server being down is happening.
virtual
void
StartRecover
()
=
0
;
...
...
src/brpc/policy/consistent_hashing_load_balancer.cpp
View file @
f98fd01f
...
...
@@ -385,13 +385,13 @@ bool ConsistentHashingLoadBalancer::SetParameters(const butil::StringPiece& para
LOG
(
ERROR
)
<<
"Empty value for "
<<
sp
.
key
()
<<
" in lb parameter"
;
return
false
;
}
if
(
sp
.
key
(
)
==
"replicas"
)
{
if
(
!
butil
::
StringToSizeT
(
sp
.
value
(
),
&
_num_replicas
))
{
if
(
key_value
.
substr
(
0
,
p
)
==
"replicas"
)
{
if
(
!
butil
::
StringToSizeT
(
key_value
.
substr
(
p
+
1
),
&
_num_replicas
))
{
return
false
;
}
continue
;
}
LOG
(
ERROR
)
<<
"Failed to set this unknown parameters "
<<
sp
.
key_and_value
()
;
LOG
(
ERROR
)
<<
"Failed to set this unknown parameters "
<<
key_value
;
}
return
true
;
}
...
...
src/butil/string_splitter.h
View file @
f98fd01f
...
...
@@ -22,7 +22,6 @@
#include <stdlib.h>
#include <stdint.h>
#include "butil/strings/string_piece.h"
// It's common to encode data into strings separated by special characters
// and decode them back, but functions such as `split_string' has to modify
...
...
test/string_splitter_unittest.cpp
View file @
f98fd01f
...
...
@@ -386,56 +386,4 @@ TEST_F(StringSplitterTest, key_value_pairs_splitter_sanity) {
}
}
TEST_F
(
StringSplitterTest
,
key_value_pairs_splitter_sanity
)
{
std
::
string
kvstr
=
"key1=value1&key2=value2&key3=value3"
;
{
butil
::
KeyValuePairsSplitter
splitter
(
kvstr
,
'='
,
'&'
);
ASSERT_TRUE
(
splitter
);
ASSERT_EQ
(
splitter
.
key
(),
"key1"
);
ASSERT_EQ
(
splitter
.
value
(),
"value1"
);
++
splitter
;
ASSERT_TRUE
(
splitter
);
ASSERT_EQ
(
splitter
.
key
(),
"key2"
);
ASSERT_EQ
(
splitter
.
value
(),
"value2"
);
++
splitter
;
ASSERT_TRUE
(
splitter
);
ASSERT_EQ
(
splitter
.
key
(),
"key3"
);
ASSERT_EQ
(
splitter
.
value
(),
"value3"
);
++
splitter
;
ASSERT_FALSE
(
splitter
);
}
{
butil
::
KeyValuePairsSplitter
splitter
(
kvstr
.
data
(),
kvstr
.
data
()
+
kvstr
.
size
(),
'='
,
'&'
);
ASSERT_TRUE
(
splitter
);
ASSERT_EQ
(
splitter
.
key
(),
"key1"
);
ASSERT_EQ
(
splitter
.
value
(),
"value1"
);
++
splitter
;
ASSERT_TRUE
(
splitter
);
ASSERT_EQ
(
splitter
.
key
(),
"key2"
);
ASSERT_EQ
(
splitter
.
value
(),
"value2"
);
++
splitter
;
ASSERT_TRUE
(
splitter
);
ASSERT_EQ
(
splitter
.
key
(),
"key3"
);
ASSERT_EQ
(
splitter
.
value
(),
"value3"
);
++
splitter
;
ASSERT_FALSE
(
splitter
);
}
{
butil
::
KeyValuePairsSplitter
splitter
(
kvstr
.
c_str
(),
'='
,
'&'
);
ASSERT_TRUE
(
splitter
);
ASSERT_EQ
(
splitter
.
key
(),
"key1"
);
ASSERT_EQ
(
splitter
.
value
(),
"value1"
);
++
splitter
;
ASSERT_TRUE
(
splitter
);
ASSERT_EQ
(
splitter
.
key
(),
"key2"
);
ASSERT_EQ
(
splitter
.
value
(),
"value2"
);
++
splitter
;
ASSERT_TRUE
(
splitter
);
ASSERT_EQ
(
splitter
.
key
(),
"key3"
);
ASSERT_EQ
(
splitter
.
value
(),
"value3"
);
++
splitter
;
ASSERT_FALSE
(
splitter
);
}
}
}
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