Commit 686771fe authored by zhujiashun's avatar zhujiashun

revived_from_all_failed: revert unrelated files

parent 3aa31a2c
...@@ -270,11 +270,10 @@ size_t ConsistentHashingLoadBalancer::RemoveServersInBatch( ...@@ -270,11 +270,10 @@ size_t ConsistentHashingLoadBalancer::RemoveServersInBatch(
return n; return n;
} }
LoadBalancer *ConsistentHashingLoadBalancer::New( LoadBalancer *ConsistentHashingLoadBalancer::New(const butil::StringPiece& params) const {
const butil::StringPiece& params) const {
ConsistentHashingLoadBalancer* lb = ConsistentHashingLoadBalancer* lb =
new (std::nothrow) ConsistentHashingLoadBalancer(_type); new (std::nothrow) ConsistentHashingLoadBalancer(_type);
if (lb && !lb->SetParameters(params)) { if (lb != nullptr && !lb->SetParameters(params)) {
delete lb; delete lb;
lb = nullptr; lb = nullptr;
} }
...@@ -378,19 +377,20 @@ void ConsistentHashingLoadBalancer::GetLoads( ...@@ -378,19 +377,20 @@ void ConsistentHashingLoadBalancer::GetLoads(
} }
bool ConsistentHashingLoadBalancer::SetParameters(const butil::StringPiece& params) { bool ConsistentHashingLoadBalancer::SetParameters(const butil::StringPiece& params) {
for (butil::KeyValuePairsSplitter sp(params.begin(), params.end(), ' ', '='); for (butil::StringSplitter sp(params.begin(), params.end(), ' '); sp != nullptr; ++sp) {
sp; ++sp) { butil::StringPiece key_value(sp.field(), sp.length());
if (sp.value().empty()) { size_t p = key_value.find('=');
LOG(ERROR) << "Empty value for " << sp.key() << " in lb parameter"; if (p == key_value.npos || p == key_value.size() - 1) {
// No value configed.
return false; return false;
} }
if (sp.key() == "replicas") { if (key_value.substr(0, p) == "replicas") {
if (!butil::StringToSizeT(sp.value(), &_num_replicas)) { if (!butil::StringToSizeT(key_value.substr(p + 1), &_num_replicas)) {
return false; return false;
} }
continue; 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; return true;
} }
......
...@@ -198,15 +198,15 @@ inline std::ostream& operator<<(std::ostream& os, const URI& uri) { ...@@ -198,15 +198,15 @@ inline std::ostream& operator<<(std::ostream& os, const URI& uri) {
class QuerySplitter : public butil::KeyValuePairsSplitter { class QuerySplitter : public butil::KeyValuePairsSplitter {
public: public:
inline QuerySplitter(const char* str_begin, const char* str_end) 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) inline QuerySplitter(const char* str_begin)
: KeyValuePairsSplitter(str_begin, '&', '=') : KeyValuePairsSplitter(str_begin, '=', '&')
{} {}
inline QuerySplitter(const butil::StringPiece &sp) inline QuerySplitter(const butil::StringPiece &sp)
: KeyValuePairsSplitter(sp, '&', '=') : KeyValuePairsSplitter(sp, '=', '&')
{} {}
}; };
......
...@@ -167,8 +167,8 @@ private: ...@@ -167,8 +167,8 @@ private:
// Split query in the format according to the given delimiters. // Split query in the format according to the given delimiters.
// This class can also handle some exceptional cases. // This class can also handle some exceptional cases.
// 1. consecutive pair_delimiter are omitted, for example, // 1. consecutive key_value_pair_delimiter are omitted, for example,
// suppose key_value_delimiter is '=' and pair_delimiter // suppose key_value_delimiter is '=' and key_value_pair_delimiter
// is '&', then 'k1=v1&&&k2=v2' is normalized to 'k1=k2&k2=v2'. // 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. // 2. key or value can be empty or both can be empty.
// 3. consecutive key_value_delimiter are not omitted, for example, // 3. consecutive key_value_delimiter are not omitted, for example,
...@@ -178,25 +178,25 @@ class KeyValuePairsSplitter { ...@@ -178,25 +178,25 @@ class KeyValuePairsSplitter {
public: public:
inline KeyValuePairsSplitter(const char* str_begin, inline KeyValuePairsSplitter(const char* str_begin,
const char* str_end, const char* str_end,
char pair_delimiter, char key_value_delimiter,
char key_value_delimiter) char key_value_pair_delimiter)
: _sp(str_begin, str_end, pair_delimiter) : _sp(str_begin, str_end, key_value_pair_delimiter)
, _delim_pos(StringPiece::npos) , _delim_pos(StringPiece::npos)
, _key_value_delim(key_value_delimiter) { , _key_value_delim(key_value_delimiter) {
UpdateDelimiterPosition(); UpdateDelimiterPosition();
} }
inline KeyValuePairsSplitter(const char* str_begin, 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, : KeyValuePairsSplitter(str_begin, NULL,
pair_delimiter, key_value_delimiter) {} key_value_delimiter, key_value_pair_delimiter) {}
inline KeyValuePairsSplitter(const StringPiece &sp, 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(), : KeyValuePairsSplitter(sp.begin(), sp.end(),
pair_delimiter, key_value_delimiter) {} key_value_delimiter, key_value_pair_delimiter) {}
inline StringPiece key() { inline StringPiece key() {
return key_and_value().substr(0, _delim_pos); return key_and_value().substr(0, _delim_pos);
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "butil/containers/flat_map.h" // butil::FlatMap #include "butil/containers/flat_map.h" // butil::FlatMap
#include "butil/scoped_lock.h" // BAIDU_SCOPE_LOCK #include "butil/scoped_lock.h" // BAIDU_SCOPE_LOCK
#include "butil/string_splitter.h" // butil::StringSplitter #include "butil/string_splitter.h" // butil::StringSplitter
#include "butil/strings/string_split.h" // butil::SplitStringIntoKeyValuePairs
#include "butil/errno.h" // berror #include "butil/errno.h" // berror
#include "butil/time.h" // milliseconds_from_now #include "butil/time.h" // milliseconds_from_now
#include "butil/file_util.h" // butil::FilePath #include "butil/file_util.h" // butil::FilePath
...@@ -626,13 +627,15 @@ public: ...@@ -626,13 +627,15 @@ public:
// .data will be appended later // .data will be appended later
path = path.RemoveFinalExtension(); path = path.RemoveFinalExtension();
} }
butil::StringPairs pairs;
for (butil::KeyValuePairsSplitter sp(tabs, ';', '='); sp; ++sp) { pairs.reserve(8);
std::string key = sp.key().as_string(); butil::SplitStringIntoKeyValuePairs(tabs, '=', ';', &pairs);
std::string value = sp.value().as_string(); dumpers.reserve(pairs.size() + 1);
//matchers.reserve(pairs.size());
for (size_t i = 0; i < pairs.size(); ++i) {
FileDumper *f = new FileDumper( FileDumper *f = new FileDumper(
path.AddExtension(key).AddExtension("data").value(), s); path.AddExtension(pairs[i].first).AddExtension("data").value(), s);
WildcardMatcher *m = new WildcardMatcher(value, '?', true); WildcardMatcher *m = new WildcardMatcher(pairs[i].second, '?', true);
dumpers.push_back(std::make_pair(f, m)); dumpers.push_back(std::make_pair(f, m));
} }
dumpers.push_back(std::make_pair( dumpers.push_back(std::make_pair(
......
...@@ -343,12 +343,12 @@ TEST_F(StringSplitterTest, key_value_pairs_splitter_sanity) { ...@@ -343,12 +343,12 @@ TEST_F(StringSplitterTest, key_value_pairs_splitter_sanity) {
// Test three constructors // Test three constructors
butil::KeyValuePairsSplitter* psplitter = NULL; butil::KeyValuePairsSplitter* psplitter = NULL;
if (i == 0) { if (i == 0) {
psplitter = new butil::KeyValuePairsSplitter(kvstr, '&', '='); psplitter = new butil::KeyValuePairsSplitter(kvstr, '=', '&');
} else if (i == 1) { } else if (i == 1) {
psplitter = new butil::KeyValuePairsSplitter( psplitter = new butil::KeyValuePairsSplitter(
kvstr.data(), kvstr.data() + kvstr.size(), '&', '='); kvstr.data(), kvstr.data() + kvstr.size(), '=', '&');
} else if (i == 2) { } else if (i == 2) {
psplitter = new butil::KeyValuePairsSplitter(kvstr.c_str(), '&', '='); psplitter = new butil::KeyValuePairsSplitter(kvstr.c_str(), '=', '&');
} }
butil::KeyValuePairsSplitter& splitter = *psplitter; butil::KeyValuePairsSplitter& splitter = *psplitter;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment