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

Method selectParent

src/proxy/ParentRoundRobin.cc:62–200  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60ParentRoundRobin::~ParentRoundRobin() = default;
61
62void
63ParentRoundRobin::selectParent(bool first_call, ParentResult *result, RequestData *rdata, unsigned int fail_threshold,
64 unsigned int retry_time)
65{
66 Dbg(dbg_ctl_parent_select, "In ParentRoundRobin::selectParent(): Using a round robin parent selection strategy.");
67 int cur_index = 0;
68 bool parentUp = false;
69 bool parentRetry = false;
70 HostStatus &pStatus = HostStatus::instance();
71 TSHostStatus host_stat = TSHostStatus::TS_HOST_STATUS_UP;
72
73 HttpRequestData *request_info = static_cast<HttpRequestData *>(rdata);
74
75 ink_assert(num_parents > 0 || result->rec->go_direct == true);
76
77 if (first_call) {
78 if (parents == nullptr) {
79 // We should only get into this state if
80 // if we are supposed to go direct
81 ink_assert(result->rec->go_direct == true);
82 // Could not find a parent
83 if (result->rec->go_direct == true && result->rec->parent_is_proxy == true) {
84 result->result = PARENT_DIRECT;
85 } else {
86 result->result = PARENT_FAIL;
87 }
88
89 result->hostname = nullptr;
90 result->port = 0;
91 return;
92 } else {
93 switch (round_robin_type) {
94 case P_HASH_ROUND_ROBIN:
95 // INKqa12817 - make sure to convert to host byte order
96 // Why was it important to do host order here? And does this have any
97 // impact with the transition to IPv6? The IPv4 functionality is
98 // preserved for now anyway as ats_ip_hash returns the 32-bit address in
99 // that case.
100 if (rdata->get_client_ip() != nullptr) {
101 cur_index = result->start_parent = ntohl(ats_ip_hash(rdata->get_client_ip())) % num_parents;
102 } else {
103 cur_index = 0;
104 }
105 break;
106 case P_STRICT_ROUND_ROBIN:
107 cur_index = result->start_parent =
108 ink_atomic_increment(reinterpret_cast<uint32_t *>(&result->rec->rr_next), 1) % num_parents;
109 break;
110 case P_NO_ROUND_ROBIN:
111 cur_index = result->start_parent = 0;
112 break;
113 case P_LATCHED_ROUND_ROBIN:
114 cur_index = result->start_parent = latched_parent;
115 break;
116 default:
117 ink_release_assert(0);
118 }
119 }

Callers

nothing calls this directly

Calls 5

ats_ip_hashFunction · 0.85
ink_atomic_incrementFunction · 0.85
get_client_ipMethod · 0.45
getHostStatusMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected