MCPcopy Create free account
hub / github.com/apache/brpc / GetRecoverPolicyByParams

Function GetRecoverPolicyByParams

src/brpc/cluster_recover_policy.cpp:110–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

108}
109
110bool GetRecoverPolicyByParams(const butil::StringPiece& params,
111 std::shared_ptr<ClusterRecoverPolicy>* ptr_out) {
112 int64_t min_working_instances = -1;
113 int64_t hold_seconds = -1;
114 bool has_meet_params = false;
115 for (butil::KeyValuePairsSplitter sp(params.begin(), params.end(), ' ', '=');
116 sp; ++sp) {
117 if (sp.value().empty()) {
118 LOG(ERROR) << "Empty value for " << sp.key() << " in lb parameter";
119 return false;
120 }
121 if (sp.key() == "min_working_instances") {
122 if (!butil::StringToInt64(sp.value(), &min_working_instances)) {
123 return false;
124 }
125 has_meet_params = true;
126 continue;
127 } else if (sp.key() == "hold_seconds") {
128 if (!butil::StringToInt64(sp.value(), &hold_seconds)) {
129 return false;
130 }
131 has_meet_params = true;
132 continue;
133 }
134 LOG(ERROR) << "Failed to set this unknown parameters " << sp.key_and_value();
135 return false;
136 }
137 if (min_working_instances > 0 && hold_seconds > 0) {
138 ptr_out->reset(
139 new DefaultClusterRecoverPolicy(min_working_instances, hold_seconds));
140 } else if (has_meet_params) {
141 // In this case, user set some params but not in the right way, just return
142 // false to let user take care of this situation.
143 LOG(ERROR) << "Invalid params=`" << params << "'";
144 return false;
145 }
146 return true;
147}
148
149} // namespace brpc

Callers 2

SetParametersMethod · 0.85
SetParametersMethod · 0.85

Calls 8

StringToInt64Function · 0.85
beginMethod · 0.45
endMethod · 0.45
emptyMethod · 0.45
valueMethod · 0.45
keyMethod · 0.45
key_and_valueMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected