| 135 | } |
| 136 | |
| 137 | void |
| 138 | ParentConsistentHash::selectParent(bool first_call, ParentResult *result, RequestData *rdata, |
| 139 | unsigned int /* fail_threshold ATS_UNUSED */, unsigned int retry_time) |
| 140 | { |
| 141 | ATSHash64Sip24 hash; |
| 142 | ATSConsistentHash *fhash; |
| 143 | HttpRequestData *request_info = static_cast<HttpRequestData *>(rdata); |
| 144 | bool firstCall = first_call; |
| 145 | bool parentRetry = false; |
| 146 | bool wrap_around[2] = {false, false}; |
| 147 | int lookups = 0; |
| 148 | uint64_t path_hash = 0; |
| 149 | uint32_t last_lookup; |
| 150 | pRecord *prtmp = nullptr, *pRec = nullptr; |
| 151 | HostStatus &pStatus = HostStatus::instance(); |
| 152 | TSHostStatus host_stat = TSHostStatus::TS_HOST_STATUS_INIT; |
| 153 | |
| 154 | Dbg(dbg_ctl_parent_select, "ParentConsistentHash::%s(): Using a consistent hash parent selection strategy.", __func__); |
| 155 | ink_assert(numParents(result) > 0 || result->rec->go_direct == true); |
| 156 | |
| 157 | // Should only get into this state if we are supposed to go direct. |
| 158 | if (parents[PRIMARY] == nullptr && parents[SECONDARY] == nullptr) { |
| 159 | if (result->rec->go_direct == true && result->rec->parent_is_proxy == true) { |
| 160 | result->result = PARENT_DIRECT; |
| 161 | } else { |
| 162 | result->result = PARENT_FAIL; |
| 163 | } |
| 164 | result->hostname = nullptr; |
| 165 | result->port = 0; |
| 166 | return; |
| 167 | } |
| 168 | |
| 169 | // ---------------------------------------------------------------------------------------------------- |
| 170 | // Initial parent look-up for either findParent() (firstCall) or nextParent() (!firstCall) |
| 171 | // ---------------------------------------------------------------------------------------------------- |
| 172 | |
| 173 | // firstCall means called from findParent() and always use PRIMARY parent list. |
| 174 | if (firstCall) { |
| 175 | last_lookup = PRIMARY; |
| 176 | } else { |
| 177 | // !firstCall means called from nextParent() and must determine which parent list to use. |
| 178 | switch (secondary_mode) { |
| 179 | case 2: |
| 180 | last_lookup = PRIMARY; |
| 181 | break; |
| 182 | case 3: |
| 183 | if (result->first_choice_status == TS_HOST_STATUS_DOWN && chash[SECONDARY] != nullptr) { |
| 184 | last_lookup = SECONDARY; |
| 185 | } else { |
| 186 | last_lookup = PRIMARY; |
| 187 | } |
| 188 | break; |
| 189 | case 1: |
| 190 | default: |
| 191 | if (chash[SECONDARY] != nullptr) { |
| 192 | last_lookup = SECONDARY; |
| 193 | } else { |
| 194 | last_lookup = PRIMARY; |
nothing calls this directly
no test coverage detected