Commit df189862 authored by zhujiashun's avatar zhujiashun

revived_from_all_failed: replace StringSplitter with KeyValyePairsSplitter

parent 24d21623
...@@ -110,27 +110,26 @@ bool GetRecoverPolicyByParams(const butil::StringPiece& params, ...@@ -110,27 +110,26 @@ bool GetRecoverPolicyByParams(const butil::StringPiece& params,
int64_t minimum_working_instances = -1; int64_t minimum_working_instances = -1;
int64_t hold_time_ms = -1; int64_t hold_time_ms = -1;
bool has_meet_params = false; bool has_meet_params = false;
for (butil::StringSplitter sp(params.begin(), params.end(), ' '); sp != nullptr; ++sp) { for (butil::KeyValuePairsSplitter sp(params.begin(), params.end(), '=', ' ');
butil::StringPiece key_value(sp.field(), sp.length()); sp; ++sp) {
size_t p = key_value.find('='); if (sp.value().empty()) {
if (p == key_value.npos || p == key_value.size() - 1) { LOG(ERROR) << "Empty value for " << sp.key() << " in lb parameter";
// No value configed.
return false; return false;
} }
if (key_value.substr(0, p) == "minimum_working_instances") { if (sp.key() == "minimum_working_instances") {
if (!butil::StringToInt64(key_value.substr(p + 1), &minimum_working_instances)) { if (!butil::StringToInt64(sp.value(), &minimum_working_instances)) {
return false; return false;
} }
has_meet_params = true; has_meet_params = true;
continue; continue;
} else if (key_value.substr(0, p) == "hold_time_ms") { } else if (sp.key() == "hold_time_ms") {
if (!butil::StringToInt64(key_value.substr(p + 1), &hold_time_ms)) { if (!butil::StringToInt64(sp.value(), &hold_time_ms)) {
return false; return false;
} }
has_meet_params = true; has_meet_params = true;
continue; continue;
} }
LOG(ERROR) << "Failed to set this unknown parameters " << key_value; LOG(ERROR) << "Failed to set this unknown parameters " << sp.key_and_value();
} }
if (minimum_working_instances > 0 && hold_time_ms > 0) { if (minimum_working_instances > 0 && hold_time_ms > 0) {
ptr_out->reset( ptr_out->reset(
......
...@@ -385,13 +385,13 @@ bool ConsistentHashingLoadBalancer::SetParameters(const butil::StringPiece& para ...@@ -385,13 +385,13 @@ bool ConsistentHashingLoadBalancer::SetParameters(const butil::StringPiece& para
LOG(ERROR) << "Empty value for " << sp.key() << " in lb parameter"; LOG(ERROR) << "Empty value for " << sp.key() << " in lb parameter";
return false; return false;
} }
if (key_value.substr(0, p) == "replicas") { if (sp.key() == "replicas") {
if (!butil::StringToSizeT(key_value.substr(p + 1), &_num_replicas)) { if (!butil::StringToSizeT(sp.value(), &_num_replicas)) {
return false; return false;
} }
continue; continue;
} }
LOG(ERROR) << "Failed to set this unknown parameters " << key_value; LOG(ERROR) << "Failed to set this unknown parameters " << sp.key_and_value();
} }
return true; return true;
} }
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include "butil/strings/string_piece.h"
// It's common to encode data into strings separated by special characters // 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 // and decode them back, but functions such as `split_string' has to modify
......
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