Skip to content

Commit 8fedbe5

Browse files
committed
WIP: address review comments.
1 parent f54a0af commit 8fedbe5

File tree

11 files changed

+511
-498
lines changed

11 files changed

+511
-498
lines changed

doc/admin-guide/files/strategies.yaml.en.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,13 @@ Each **strategy** in the list may using the following parameters::
184184
- **parent_is_proxy**: A boolean value which indicates if the groups of hosts are proxy caches or origins. **true** (default) means all the hosts used in the reamp are trafficserver caches. **false** means the hosts are origins that the next hop strategies may use for load balancing and/or failover.
185185
- **scheme Indicates which scheme the strategy supports, *http* or *https*
186186
- **failover**: A map of **failover** information.
187-
- **max_simple_retries**: Part of the **failover** map and is an integer value of the maixmum number of retries for simple retry on the list of indicated response codes.
187+
- **max_simple_retries**: Part of the **failover** map and is an integer value of the maximum number of retries for a **simple retry** on the list of indicated response codes. **simple retry** is used to retry an upstream request using another upstream server if the response received on from the original upstream request matches any of the response codes configured for this strategy in the **failover** map. If no failover response codes are configured, no **simple retry** is attempted.
188+
188189
- **ring_mode**: Part of the **failover** map. The host ring selection mode. Use either **exhaust_ring** or **alternate_ring**
189190
#. **exhaust_ring**: when a host normally selected by the policy fails, another host is selected from the same group. A new group is not selected until all hosts on the previous group have been exhausted.
190191
#. **alternate_ring**: retry hosts are selected from groups in an alternatin group fashion.
191192
- **response_codes**: Part of the **failover** map. This is a list of **http** response codes that may be used for **simple retry**.
192-
- **health_check**: Part of the **failover** map. A list of health checks. **passive** is the default and means that the state machine marks down **hosts** when a transaction timeout or connection error is detected. **passive** is always used by the next hop strategies. **active** means that some external process may actively health check the hosts using the defined **health check url** and mart them down using **traffic_ctl**.
193+
- **health_check**: Part of the **failover** map. A list of health checks. **passive** is the default and means that the state machine marks down **hosts** when a transaction timeout or connection error is detected. **passive** is always used by the next hop strategies. **active** means that some external process may actively health check the hosts using the defined **health check url** and mark them down using **traffic_ctl**.
193194

194195

195196
Example::

proxy/http/HttpTransact.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ findParent(HttpTransact::State *s)
207207
url_mapping *mp = s->url_map.getMapping();
208208
209209
if (mp && mp->strategy) {
210-
return mp->strategy->findNextHop(s->state_machine->sm_id, &s->parent_result, &s->request_data,
211-
s->txn_conf->parent_fail_threshold, s->txn_conf->parent_retry_time);
210+
return mp->strategy->findNextHop(s->state_machine->sm_id, s->parent_result, s->request_data, s->txn_conf->parent_fail_threshold,
211+
s->txn_conf->parent_retry_time);
212212
} else if (s->parent_params) {
213213
return s->parent_params->findParent(&s->request_data, &s->parent_result, s->txn_conf->parent_fail_threshold,
214214
s->txn_conf->parent_retry_time);
@@ -223,7 +223,7 @@ markParentDown(HttpTransact::State *s)
223223
url_mapping *mp = s->url_map.getMapping();
224224
225225
if (mp && mp->strategy) {
226-
return mp->strategy->markNextHopDown(s->state_machine->sm_id, &s->parent_result, s->txn_conf->parent_fail_threshold,
226+
return mp->strategy->markNextHopDown(s->state_machine->sm_id, s->parent_result, s->txn_conf->parent_fail_threshold,
227227
s->txn_conf->parent_retry_time);
228228
} else if (s->parent_params) {
229229
return s->parent_params->markParentDown(&s->parent_result, s->txn_conf->parent_fail_threshold, s->txn_conf->parent_retry_time);
@@ -237,7 +237,7 @@ markParentUp(HttpTransact::State *s)
237237
{
238238
url_mapping *mp = s->url_map.getMapping();
239239
if (mp && mp->strategy) {
240-
return mp->strategy->markNextHopUp(s->state_machine->sm_id, &s->parent_result);
240+
return mp->strategy->markNextHopUp(s->state_machine->sm_id, s->parent_result);
241241
} else if (s->parent_params) {
242242
return s->parent_params->markParentUp(&s->parent_result);
243243
}
@@ -251,8 +251,8 @@ nextParent(HttpTransact::State *s)
251251
url_mapping *mp = s->url_map.getMapping();
252252
if (mp && mp->strategy) {
253253
// NextHop only has a findNextHop() function.
254-
return mp->strategy->findNextHop(s->state_machine->sm_id, &s->parent_result, &s->request_data,
255-
s->txn_conf->parent_fail_threshold, s->txn_conf->parent_retry_time);
254+
return mp->strategy->findNextHop(s->state_machine->sm_id, s->parent_result, s->request_data, s->txn_conf->parent_fail_threshold,
255+
s->txn_conf->parent_retry_time);
256256
} else if (s->parent_params) {
257257
return s->parent_params->nextParent(&s->request_data, &s->parent_result, s->txn_conf->parent_fail_threshold,
258258
s->txn_conf->parent_retry_time);

proxy/http/remap/NextHopConsistentHash.cc

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ NextHopConsistentHash::getHashKey(uint64_t sm_id, HttpRequestData *hrdata, ATSHa
9797
url_string_ref = url->string_get_ref(&len, true);
9898
if (url_string_ref && len > 0) {
9999
h->update(url_string_ref, len);
100-
NH_Debug(NH_DEBUG_TAG, "[%" PRId64 "] url hash string: %s", sm_id, url_string_ref);
100+
NH_Debug(NH_DEBUG_TAG, "[%" PRIu64 "] url hash string: %s", sm_id, url_string_ref);
101101
}
102102
h->final();
103103
hash_value = h->get();
@@ -147,14 +147,14 @@ NextHopConsistentHash::getHashKey(uint64_t sm_id, HttpRequestData *hrdata, ATSHa
147147
if (ps_url) {
148148
url_string_ref = ps_url->string_get_ref(&len);
149149
if (url_string_ref && len > 0) {
150-
NH_Debug(NH_DEBUG_TAG, "[%" PRId64 "] using parent selection over-ride string:'%.*s'.", sm_id, len, url_string_ref);
150+
NH_Debug(NH_DEBUG_TAG, "[%" PRIu64 "] using parent selection over-ride string:'%.*s'.", sm_id, len, url_string_ref);
151151
h->update(url_string_ref, len);
152152
}
153153
} else {
154154
url_string_ref = url->path_get(&len);
155155
h->update("/", 1);
156156
if (url_string_ref && len > 0) {
157-
NH_Debug(NH_DEBUG_TAG, "[%" PRId64 "] the parent selection over-ride url is not set, using default path: %s.", sm_id,
157+
NH_Debug(NH_DEBUG_TAG, "[%" PRIu64 "] the parent selection over-ride url is not set, using default path: %s.", sm_id,
158158
url_string_ref);
159159
h->update(url_string_ref, len);
160160
}
@@ -178,7 +178,7 @@ NextHopConsistentHash::getHashKey(uint64_t sm_id, HttpRequestData *hrdata, ATSHa
178178
}
179179

180180
void
181-
NextHopConsistentHash::findNextHop(const uint64_t sm_id, ParentResult *result, RequestData *rdata, const uint64_t fail_threshold,
181+
NextHopConsistentHash::findNextHop(const uint64_t sm_id, ParentResult &result, RequestData &rdata, const uint64_t fail_threshold,
182182
const uint64_t retry_time)
183183
{
184184
bool firstcall = false;
@@ -189,43 +189,43 @@ NextHopConsistentHash::findNextHop(const uint64_t sm_id, ParentResult *result, R
189189
uint64_t hash_key = 0;
190190
uint32_t lookups = 0;
191191
ATSHash64Sip24 hash;
192-
HttpRequestData *request_info = static_cast<HttpRequestData *>(rdata);
192+
HttpRequestData *request_info = static_cast<HttpRequestData *>(&rdata);
193193
HostRecord *hostRec = nullptr;
194194
std::shared_ptr<HostRecord> pRec = nullptr;
195195
HostStatus &pStatus = HostStatus::instance();
196196
HostStatus_t host_stat = HostStatus_t::HOST_STATUS_INIT;
197197
HostStatRec *hst = nullptr;
198198

199-
if (result->line_number == -1 && result->result == PARENT_UNDEFINED) {
199+
if (result.line_number == -1 && result.result == PARENT_UNDEFINED) {
200200
firstcall = true;
201201
}
202202

203203
if (firstcall) {
204-
NH_Debug(NH_DEBUG_TAG, "[%" PRId64 "] firstcall, line_number: %d, result: %s", sm_id, result->line_number,
205-
ParentResultStr[result->result]);
206-
result->line_number = distance;
207-
cur_ring = 0;
204+
NH_Debug(NH_DEBUG_TAG, "[%" PRIu64 "] firstcall, line_number: %d, result: %s", sm_id, result.line_number,
205+
ParentResultStr[result.result]);
206+
result.line_number = distance;
207+
cur_ring = 0;
208208
for (uint32_t i = 0; i < groups; i++) {
209-
result->chash_init[i] = false;
210-
wrap_around[i] = false;
209+
result.chash_init[i] = false;
210+
wrap_around[i] = false;
211211
}
212212
} else {
213-
NH_Debug(NH_DEBUG_TAG, "[%" PRId64 "] not firstcall, line_number: %d, result: %s", sm_id, result->line_number,
214-
ParentResultStr[result->result]);
213+
NH_Debug(NH_DEBUG_TAG, "[%" PRIu64 "] not firstcall, line_number: %d, result: %s", sm_id, result.line_number,
214+
ParentResultStr[result.result]);
215215
switch (ring_mode) {
216216
case NH_ALTERNATE_RING:
217217
if (groups > 1) {
218-
cur_ring = (result->last_group + 1) % groups;
218+
cur_ring = (result.last_group + 1) % groups;
219219
} else {
220-
cur_ring = result->last_group;
220+
cur_ring = result.last_group;
221221
}
222222
break;
223223
case NH_EXHAUST_RING:
224224
default:
225225
if (!wrapped) {
226-
cur_ring = result->last_group;
226+
cur_ring = result.last_group;
227227
} else if (groups > 1) {
228-
cur_ring = (result->last_group + 1) % groups;
228+
cur_ring = (result.last_group + 1) % groups;
229229
}
230230
break;
231231
}
@@ -236,23 +236,23 @@ NextHopConsistentHash::findNextHop(const uint64_t sm_id, ParentResult *result, R
236236

237237
do { // search until we've selected a different parent if !firstcall
238238
std::shared_ptr<ATSConsistentHash> r = rings[cur_ring];
239-
hostRec = chash_lookup(r, hash_key, &result->chashIter[cur_ring], &wrapped, &hash, &result->chash_init[cur_ring], sm_id);
239+
hostRec = chash_lookup(r, hash_key, &result.chashIter[cur_ring], &wrapped, &hash, &result.chash_init[cur_ring], sm_id);
240240
wrap_around[cur_ring] = wrapped;
241241
lookups++;
242242
// the 'available' flag is maintained in 'host_groups' and not the hash ring.
243243
if (hostRec) {
244244
pRec = host_groups[hostRec->group_index][hostRec->host_index];
245245
if (firstcall) {
246-
hst = (pRec) ? pStatus.getHostStatus(pRec->hostname.c_str()) : nullptr;
247-
result->first_choice_status = (hst) ? hst->status : HostStatus_t::HOST_STATUS_UP;
246+
hst = (pRec) ? pStatus.getHostStatus(pRec->hostname.c_str()) : nullptr;
247+
result.first_choice_status = (hst) ? hst->status : HostStatus_t::HOST_STATUS_UP;
248248
break;
249249
}
250250
} else {
251251
pRec = nullptr;
252252
}
253-
} while (pRec && result->hostname && strcmp(pRec->hostname.c_str(), result->hostname) == 0);
253+
} while (pRec && result.hostname && strcmp(pRec->hostname.c_str(), result.hostname) == 0);
254254

255-
NH_Debug(NH_DEBUG_TAG, "[%" PRId64 "] Initial parent lookups: %d", sm_id, lookups);
255+
NH_Debug(NH_DEBUG_TAG, "[%" PRIu64 "] Initial parent lookups: %d", sm_id, lookups);
256256

257257
// ----------------------------------------------------------------------------------------------------
258258
// Validate initial parent look-up and perform additional look-ups if required.
@@ -274,12 +274,12 @@ NextHopConsistentHash::findNextHop(const uint64_t sm_id, ParentResult *result, R
274274
time_t now = time(nullptr);
275275
// check if the host is retryable. It's retryable if the retry window has elapsed
276276
if ((pRec->failedAt + retry_time) < static_cast<unsigned>(now)) {
277-
nextHopRetry = true;
278-
result->last_parent = pRec->host_index;
279-
result->last_lookup = pRec->group_index;
280-
result->retry = nextHopRetry;
281-
result->result = PARENT_SPECIFIED;
282-
NH_Debug(NH_DEBUG_TAG, "[%" PRId64 "] next hop %s is now retryable, marked it available.", sm_id, pRec->hostname.c_str());
277+
nextHopRetry = true;
278+
result.last_parent = pRec->host_index;
279+
result.last_lookup = pRec->group_index;
280+
result.retry = nextHopRetry;
281+
result.result = PARENT_SPECIFIED;
282+
NH_Debug(NH_DEBUG_TAG, "[%" PRIu64 "] next hop %s is now retryable, marked it available.", sm_id, pRec->hostname.c_str());
283283
break;
284284
}
285285
}
@@ -297,7 +297,7 @@ NextHopConsistentHash::findNextHop(const uint64_t sm_id, ParentResult *result, R
297297
break;
298298
}
299299
std::shared_ptr<ATSConsistentHash> r = rings[cur_ring];
300-
hostRec = chash_lookup(r, hash_key, &result->chashIter[cur_ring], &wrapped, &hash, &result->chash_init[cur_ring], sm_id);
300+
hostRec = chash_lookup(r, hash_key, &result.chashIter[cur_ring], &wrapped, &hash, &result.chash_init[cur_ring], sm_id);
301301
wrap_around[cur_ring] = wrapped;
302302
lookups++;
303303
if (hostRec) {
@@ -311,7 +311,7 @@ NextHopConsistentHash::findNextHop(const uint64_t sm_id, ParentResult *result, R
311311
host_stat = HOST_STATUS_UP;
312312
}
313313
}
314-
NH_Debug(NH_DEBUG_TAG, "[%" PRId64 "] Selected a new parent: %s, available: %s, wrapped: %s, lookups: %d.", sm_id,
314+
NH_Debug(NH_DEBUG_TAG, "[%" PRIu64 "] Selected a new parent: %s, available: %s, wrapped: %s, lookups: %d.", sm_id,
315315
pRec->hostname.c_str(), (pRec->available) ? "true" : "false", (wrapped) ? "true" : "false", lookups);
316316
// use available host.
317317
if (pRec->available && host_stat == HOST_STATUS_UP) {
@@ -327,7 +327,7 @@ NextHopConsistentHash::findNextHop(const uint64_t sm_id, ParentResult *result, R
327327
}
328328
}
329329
if (all_wrapped) {
330-
NH_Debug(NH_DEBUG_TAG, "[%" PRId64 "] No available parents.", sm_id);
330+
NH_Debug(NH_DEBUG_TAG, "[%" PRIu64 "] No available parents.", sm_id);
331331
if (pRec) {
332332
pRec = nullptr;
333333
}
@@ -344,33 +344,33 @@ NextHopConsistentHash::findNextHop(const uint64_t sm_id, ParentResult *result, R
344344
hst = (pRec) ? pStatus.getHostStatus(pRec->hostname.c_str()) : nullptr;
345345
host_stat = (hst) ? hst->status : HostStatus_t::HOST_STATUS_UP;
346346

347-
if (pRec && host_stat == HOST_STATUS_UP && (pRec->available || result->retry)) {
348-
result->result = PARENT_SPECIFIED;
349-
result->hostname = pRec->hostname.c_str();
350-
result->last_parent = pRec->host_index;
351-
result->last_lookup = result->last_group = cur_ring;
347+
if (pRec && host_stat == HOST_STATUS_UP && (pRec->available || result.retry)) {
348+
result.result = PARENT_SPECIFIED;
349+
result.hostname = pRec->hostname.c_str();
350+
result.last_parent = pRec->host_index;
351+
result.last_lookup = result.last_group = cur_ring;
352352
switch (scheme) {
353353
case NH_SCHEME_NONE:
354354
case NH_SCHEME_HTTP:
355-
result->port = pRec->getPort(scheme);
355+
result.port = pRec->getPort(scheme);
356356
break;
357357
case NH_SCHEME_HTTPS:
358-
result->port = pRec->getPort(scheme);
358+
result.port = pRec->getPort(scheme);
359359
break;
360360
}
361-
result->retry = nextHopRetry;
362-
ink_assert(result->hostname != nullptr);
363-
ink_assert(result->port != 0);
364-
NH_Debug(NH_DEBUG_TAG, "[%" PRId64 "] Chosen parent: %s.%d", sm_id, result->hostname, result->port);
361+
result.retry = nextHopRetry;
362+
ink_assert(result.hostname != nullptr);
363+
ink_assert(result.port != 0);
364+
NH_Debug(NH_DEBUG_TAG, "[%" PRIu64 "] Chosen parent: %s.%d", sm_id, result.hostname, result.port);
365365
} else {
366366
if (go_direct == true) {
367-
result->result = PARENT_DIRECT;
367+
result.result = PARENT_DIRECT;
368368
} else {
369-
result->result = PARENT_FAIL;
369+
result.result = PARENT_FAIL;
370370
}
371-
result->hostname = nullptr;
372-
result->port = 0;
373-
result->retry = false;
371+
result.hostname = nullptr;
372+
result.port = 0;
373+
result.retry = false;
374374
}
375375

376376
return;

proxy/http/remap/NextHopConsistentHash.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ class NextHopConsistentHash : public NextHopSelectionStrategy
3838
NextHopConsistentHash(const std::string_view name, const NHPolicyType &policy) : NextHopSelectionStrategy(name, policy) {}
3939
~NextHopConsistentHash();
4040
bool Init(const YAML::Node &n);
41-
void findNextHop(const uint64_t sm_id, ParentResult *result, RequestData *rdata, const uint64_t fail_threshold,
41+
void findNextHop(const uint64_t sm_id, ParentResult &result, RequestData &rdata, const uint64_t fail_threshold,
4242
const uint64_t retry_time) override;
4343
};

0 commit comments

Comments
 (0)