MCPcopy Create free account
hub / github.com/apache/trafficserver / setHostStatus

Method setHostStatus

src/proxy/HostStatus.cc:203–297  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

201}
202
203void
204HostStatus::setHostStatus(const std::string_view name, TSHostStatus status, const unsigned int down_time, const unsigned int reason)
205{
206 std::string stat_name;
207
208 // update / insert status.
209 // using the hash table pointer to store the TSHostStatus value.
210 HostStatRec *host_stat = nullptr;
211 ink_rwlock_wrlock(&host_status_rwlock);
212 {
213 if (auto it = hosts_statuses.find(std::string(name)); it != hosts_statuses.end()) {
214 host_stat = it->second;
215 } else {
216 host_stat = static_cast<HostStatRec *>(ats_malloc(sizeof(HostStatRec)));
217 bzero(static_cast<void *>(host_stat), sizeof(HostStatRec));
218 hosts_statuses.emplace(name, host_stat);
219 }
220 if (reason & Reason::ACTIVE) {
221 Dbg(dbg_ctl_host_statuses, "for host %.*s set status: %s, Reason:ACTIVE", int(name.size()), name.data(),
222 HostStatusNames[status]);
223 if (status == TSHostStatus::TS_HOST_STATUS_DOWN) {
224 host_stat->active_marked_down = time(0);
225 host_stat->active_down_time = down_time;
226 host_stat->reasons |= Reason::ACTIVE;
227 } else {
228 host_stat->active_marked_down = 0;
229 host_stat->active_down_time = 0;
230 if (host_stat->reasons & Reason::ACTIVE) {
231 host_stat->reasons ^= Reason::ACTIVE;
232 }
233 }
234 }
235 if (reason & Reason::LOCAL) {
236 Dbg(dbg_ctl_host_statuses, "for host %.*s set status: %s, Reason:LOCAL", int(name.size()), name.data(),
237 HostStatusNames[status]);
238 if (status == TSHostStatus::TS_HOST_STATUS_DOWN) {
239 host_stat->local_marked_down = time(0);
240 host_stat->local_down_time = down_time;
241 host_stat->reasons |= Reason::LOCAL;
242 } else {
243 host_stat->local_marked_down = 0;
244 host_stat->local_down_time = 0;
245 if (host_stat->reasons & Reason::LOCAL) {
246 host_stat->reasons ^= Reason::LOCAL;
247 }
248 }
249 }
250 if (reason & Reason::MANUAL) {
251 Dbg(dbg_ctl_host_statuses, "for host %.*s set status: %s, Reason:MANUAL", int(name.size()), name.data(),
252 HostStatusNames[status]);
253 if (status == TSHostStatus::TS_HOST_STATUS_DOWN) {
254 host_stat->manual_marked_down = time(0);
255 host_stat->manual_down_time = down_time;
256 host_stat->reasons |= Reason::MANUAL;
257 } else {
258 host_stat->manual_marked_down = 0;
259 host_stat->manual_down_time = 0;
260 if (host_stat->reasons & Reason::MANUAL) {

Callers 4

server_set_statusFunction · 0.45
PreProcessParentsMethod · 0.45
TSHostStatusSetFunction · 0.45

Calls 9

ink_rwlock_wrlockFunction · 0.85
stringClass · 0.85
ats_mallocFunction · 0.85
ink_rwlock_unlockFunction · 0.85
emplaceMethod · 0.80
findMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected