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
686771fe
Commit
686771fe
authored
Apr 17, 2019
by
zhujiashun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
revived_from_all_failed: revert unrelated files
parent
3aa31a2c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
33 deletions
+36
-33
consistent_hashing_load_balancer.cpp
src/brpc/policy/consistent_hashing_load_balancer.cpp
+10
-10
uri.h
src/brpc/uri.h
+3
-3
string_splitter.h
src/butil/string_splitter.h
+11
-11
variable.cpp
src/bvar/variable.cpp
+9
-6
string_splitter_unittest.cpp
test/string_splitter_unittest.cpp
+3
-3
No files found.
src/brpc/policy/consistent_hashing_load_balancer.cpp
View file @
686771fe
...
...
@@ -270,11 +270,10 @@ size_t ConsistentHashingLoadBalancer::RemoveServersInBatch(
return
n
;
}
LoadBalancer
*
ConsistentHashingLoadBalancer
::
New
(
const
butil
::
StringPiece
&
params
)
const
{
LoadBalancer
*
ConsistentHashingLoadBalancer
::
New
(
const
butil
::
StringPiece
&
params
)
const
{
ConsistentHashingLoadBalancer
*
lb
=
new
(
std
::
nothrow
)
ConsistentHashingLoadBalancer
(
_type
);
if
(
lb
&&
!
lb
->
SetParameters
(
params
))
{
if
(
lb
!=
nullptr
&&
!
lb
->
SetParameters
(
params
))
{
delete
lb
;
lb
=
nullptr
;
}
...
...
@@ -378,19 +377,20 @@ void ConsistentHashingLoadBalancer::GetLoads(
}
bool
ConsistentHashingLoadBalancer
::
SetParameters
(
const
butil
::
StringPiece
&
params
)
{
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
(
)
==
"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/brpc/uri.h
View file @
686771fe
...
...
@@ -198,15 +198,15 @@ inline std::ostream& operator<<(std::ostream& os, const URI& uri) {
class
QuerySplitter
:
public
butil
::
KeyValuePairsSplitter
{
public
:
inline
QuerySplitter
(
const
char
*
str_begin
,
const
char
*
str_end
)
:
KeyValuePairsSplitter
(
str_begin
,
str_end
,
'
&'
,
'=
'
)
:
KeyValuePairsSplitter
(
str_begin
,
str_end
,
'
='
,
'&
'
)
{}
inline
QuerySplitter
(
const
char
*
str_begin
)
:
KeyValuePairsSplitter
(
str_begin
,
'
&'
,
'=
'
)
:
KeyValuePairsSplitter
(
str_begin
,
'
='
,
'&
'
)
{}
inline
QuerySplitter
(
const
butil
::
StringPiece
&
sp
)
:
KeyValuePairsSplitter
(
sp
,
'
&'
,
'=
'
)
:
KeyValuePairsSplitter
(
sp
,
'
='
,
'&
'
)
{}
};
...
...
src/butil/string_splitter.h
View file @
686771fe
...
...
@@ -167,8 +167,8 @@ private:
// Split query in the format according to the given delimiters.
// This class can also handle some exceptional cases.
// 1. consecutive pair_delimiter are omitted, for example,
// suppose key_value_delimiter is '=' and pair_delimiter
// 1. consecutive
key_value_
pair_delimiter are omitted, for example,
// suppose key_value_delimiter is '=' and
key_value_
pair_delimiter
// is '&', then 'k1=v1&&&k2=v2' is normalized to 'k1=k2&k2=v2'.
// 2. key or value can be empty or both can be empty.
// 3. consecutive key_value_delimiter are not omitted, for example,
...
...
@@ -178,25 +178,25 @@ class KeyValuePairsSplitter {
public
:
inline
KeyValuePairsSplitter
(
const
char
*
str_begin
,
const
char
*
str_end
,
char
pair
_delimiter
,
char
key_value_delimiter
)
:
_sp
(
str_begin
,
str_end
,
pair_delimiter
)
char
key_value
_delimiter
,
char
key_value_
pair_
delimiter
)
:
_sp
(
str_begin
,
str_end
,
key_value_
pair_delimiter
)
,
_delim_pos
(
StringPiece
::
npos
)
,
_key_value_delim
(
key_value_delimiter
)
{
UpdateDelimiterPosition
();
}
inline
KeyValuePairsSplitter
(
const
char
*
str_begin
,
char
pair
_delimiter
,
char
key_value_delimiter
)
char
key_value
_delimiter
,
char
key_value_
pair_
delimiter
)
:
KeyValuePairsSplitter
(
str_begin
,
NULL
,
pair_delimiter
,
key_value
_delimiter
)
{}
key_value_delimiter
,
key_value_pair
_delimiter
)
{}
inline
KeyValuePairsSplitter
(
const
StringPiece
&
sp
,
char
pair
_delimiter
,
char
key_value_delimiter
)
char
key_value
_delimiter
,
char
key_value_
pair_
delimiter
)
:
KeyValuePairsSplitter
(
sp
.
begin
(),
sp
.
end
(),
pair_delimiter
,
key_value
_delimiter
)
{}
key_value_delimiter
,
key_value_pair
_delimiter
)
{}
inline
StringPiece
key
()
{
return
key_and_value
().
substr
(
0
,
_delim_pos
);
...
...
src/bvar/variable.cpp
View file @
686771fe
...
...
@@ -24,6 +24,7 @@
#include "butil/containers/flat_map.h" // butil::FlatMap
#include "butil/scoped_lock.h" // BAIDU_SCOPE_LOCK
#include "butil/string_splitter.h" // butil::StringSplitter
#include "butil/strings/string_split.h" // butil::SplitStringIntoKeyValuePairs
#include "butil/errno.h" // berror
#include "butil/time.h" // milliseconds_from_now
#include "butil/file_util.h" // butil::FilePath
...
...
@@ -626,13 +627,15 @@ public:
// .data will be appended later
path
=
path
.
RemoveFinalExtension
();
}
for
(
butil
::
KeyValuePairsSplitter
sp
(
tabs
,
';'
,
'='
);
sp
;
++
sp
)
{
std
::
string
key
=
sp
.
key
().
as_string
();
std
::
string
value
=
sp
.
value
().
as_string
();
butil
::
StringPairs
pairs
;
pairs
.
reserve
(
8
);
butil
::
SplitStringIntoKeyValuePairs
(
tabs
,
'='
,
';'
,
&
pairs
);
dumpers
.
reserve
(
pairs
.
size
()
+
1
);
//matchers.reserve(pairs.size());
for
(
size_t
i
=
0
;
i
<
pairs
.
size
();
++
i
)
{
FileDumper
*
f
=
new
FileDumper
(
path
.
AddExtension
(
key
).
AddExtension
(
"data"
).
value
(),
s
);
WildcardMatcher
*
m
=
new
WildcardMatcher
(
value
,
'?'
,
true
);
path
.
AddExtension
(
pairs
[
i
].
first
).
AddExtension
(
"data"
).
value
(),
s
);
WildcardMatcher
*
m
=
new
WildcardMatcher
(
pairs
[
i
].
second
,
'?'
,
true
);
dumpers
.
push_back
(
std
::
make_pair
(
f
,
m
));
}
dumpers
.
push_back
(
std
::
make_pair
(
...
...
test/string_splitter_unittest.cpp
View file @
686771fe
...
...
@@ -343,12 +343,12 @@ TEST_F(StringSplitterTest, key_value_pairs_splitter_sanity) {
// Test three constructors
butil
::
KeyValuePairsSplitter
*
psplitter
=
NULL
;
if
(
i
==
0
)
{
psplitter
=
new
butil
::
KeyValuePairsSplitter
(
kvstr
,
'
&'
,
'=
'
);
psplitter
=
new
butil
::
KeyValuePairsSplitter
(
kvstr
,
'
='
,
'&
'
);
}
else
if
(
i
==
1
)
{
psplitter
=
new
butil
::
KeyValuePairsSplitter
(
kvstr
.
data
(),
kvstr
.
data
()
+
kvstr
.
size
(),
'
&'
,
'=
'
);
kvstr
.
data
(),
kvstr
.
data
()
+
kvstr
.
size
(),
'
='
,
'&
'
);
}
else
if
(
i
==
2
)
{
psplitter
=
new
butil
::
KeyValuePairsSplitter
(
kvstr
.
c_str
(),
'
&'
,
'=
'
);
psplitter
=
new
butil
::
KeyValuePairsSplitter
(
kvstr
.
c_str
(),
'
='
,
'&
'
);
}
butil
::
KeyValuePairsSplitter
&
splitter
=
*
psplitter
;
...
...
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