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,
int64_t minimum_working_instances = -1;
int64_t hold_time_ms = -1;
bool has_meet_params = false;
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.
for (butil::KeyValuePairsSplitter sp(params.begin(), params.end(), '=', ' ');
sp; ++sp) {
if (sp.value().empty()) {
LOG(ERROR) << "Empty value for " << sp.key() << " in lb parameter";
return false;
}
if (key_value.substr(0, p) == "minimum_working_instances") {
if (!butil::StringToInt64(key_value.substr(p + 1), &minimum_working_instances)) {
if (sp.key() == "minimum_working_instances") {
if (!butil::StringToInt64(sp.value(), &minimum_working_instances)) {
return false;
}
has_meet_params = true;
continue;
} else if (key_value.substr(0, p) == "hold_time_ms") {
if (!butil::StringToInt64(key_value.substr(p + 1), &hold_time_ms)) {
} else if (sp.key() == "hold_time_ms") {
if (!butil::StringToInt64(sp.value(), &hold_time_ms)) {
return false;
}
has_meet_params = true;
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) {
ptr_out->reset(
......
......@@ -385,13 +385,13 @@ bool ConsistentHashingLoadBalancer::SetParameters(const butil::StringPiece& para
LOG(ERROR) << "Empty value for " << sp.key() << " in lb parameter";
return false;
}
if (key_value.substr(0, p) == "replicas") {
if (!butil::StringToSizeT(key_value.substr(p + 1), &_num_replicas)) {
if (sp.key() == "replicas") {
if (!butil::StringToSizeT(sp.value(), &_num_replicas)) {
return false;
}
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;
}
......
......@@ -22,6 +22,7 @@
#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
......
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