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

Method getHostStatus

src/proxy/HostStatus.cc:322–380  ·  view source on GitHub ↗

retrieve the named host status.

Source from the content-addressed store, hash-verified

320
321// retrieve the named host status.
322HostStatRec *
323HostStatus::getHostStatus(const std::string_view name)
324{
325 HostStatRec *_status = nullptr;
326 time_t now = time(0);
327 bool lookup = false;
328
329 // if host_statuses is empty, just return
330 // a nullptr as there is no need to lock
331 // and search. A return of nullptr indicates
332 // to the caller that the host is available,
333 // HOST_STATUS_UP.
334 if (hosts_statuses.empty()) {
335 return _status;
336 }
337
338 // the hash table value pointer has the TSHostStatus value.
339 ink_rwlock_rdlock(&host_status_rwlock);
340 {
341 auto it = hosts_statuses.find(std::string(name));
342 lookup = it != hosts_statuses.end();
343 if (lookup) {
344 _status = it->second;
345 }
346 }
347 ink_rwlock_unlock(&host_status_rwlock);
348
349 // if the host was marked down and it's down_time has elapsed, mark it up.
350 if (lookup && _status->status == TSHostStatus::TS_HOST_STATUS_DOWN) {
351 unsigned int reasons = _status->reasons;
352 if ((_status->reasons & Reason::ACTIVE) && _status->active_down_time > 0) {
353 if ((_status->active_down_time + _status->active_marked_down) < now) {
354 Dbg(dbg_ctl_host_statuses, "name: %.*s, now: %ld, down_time: %d, marked_down: %ld, reason: %s", int(name.size()),
355 name.data(), now, _status->active_down_time, _status->active_marked_down, Reason::ACTIVE_REASON);
356 setHostStatus(name, TSHostStatus::TS_HOST_STATUS_UP, 0, Reason::ACTIVE);
357 reasons ^= Reason::ACTIVE;
358 }
359 }
360 if ((_status->reasons & Reason::LOCAL) && _status->local_down_time > 0) {
361 if ((_status->local_down_time + _status->local_marked_down) < now) {
362 Dbg(dbg_ctl_host_statuses, "name: %.*s, now: %ld, down_time: %d, marked_down: %ld, reason: %s", int(name.size()),
363 name.data(), now, _status->local_down_time, _status->local_marked_down, Reason::LOCAL_REASON);
364 setHostStatus(name, TSHostStatus::TS_HOST_STATUS_UP, 0, Reason::LOCAL);
365 reasons ^= Reason::LOCAL;
366 }
367 }
368 if ((_status->reasons & Reason::MANUAL) && _status->manual_down_time > 0) {
369 if ((_status->manual_down_time + _status->manual_marked_down) < now) {
370 Dbg(dbg_ctl_host_statuses, "name: %.*s, now: %ld, down_time: %d, marked_down: %ld, reason: %s", int(name.size()),
371 name.data(), now, _status->manual_down_time, _status->manual_marked_down, Reason::MANUAL_REASON);
372 setHostStatus(name, TSHostStatus::TS_HOST_STATUS_UP, 0, Reason::MANUAL);
373 reasons ^= Reason::MANUAL;
374 }
375 }
376 _status->reasons = reasons;
377 }
378
379 return _status;

Callers 4

selectParentMethod · 0.45
server_get_statusFunction · 0.45
selectParentMethod · 0.45
TSHostStatusGetFunction · 0.45

Calls 8

ink_rwlock_rdlockFunction · 0.85
stringClass · 0.85
ink_rwlock_unlockFunction · 0.85
emptyMethod · 0.45
findMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected